def process(self, execution_db): execution_id = str(execution_db.id) extra = {'execution': execution_db} LOG.debug('Processing action execution "%s".', execution_id, extra=extra) # Get the corresponding liveaction record. liveaction_db = LiveAction.get_by_id(execution_db.liveaction['id']) if execution_db.status in LIVEACTION_COMPLETED_STATES: # If the action execution is executed under an orquesta workflow, policies for the # action execution will be applied by the workflow engine. A policy may affect the # final state of the action execution thereby impacting the state of the workflow. if not workflow_service.is_action_execution_under_workflow_context( execution_db): with CounterWithTimer(key='notifier.apply_post_run_policies'): policy_service.apply_post_run_policies(liveaction_db) if liveaction_db.notify: with CounterWithTimer(key='notifier.notify_trigger.post'): self._post_notify_triggers(liveaction_db=liveaction_db, execution_db=execution_db) self._post_generic_trigger(liveaction_db=liveaction_db, execution_db=execution_db)
def test_disabled_policy_not_applied_on_post_run(self): ########## # First test a scenario where policy is enabled ########## self.assertTrue(self.policy_db.enabled) # Post run hasn't been called yet, call count should be 0 self.assertEqual(policies.get_driver.call_count, 0) liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'}) live_action_db, execution_db = action_service.request(liveaction) policy_service.apply_post_run_policies(live_action_db) # Ony policy has been applied so call count should be 1 self.assertEqual(policies.get_driver.call_count, 1) ########## # Now a scenaro with disabled policy ########## policies.get_driver.call_count = 0 self.policy_db.enabled = False self.policy_db = Policy.add_or_update(self.policy_db) self.assertFalse(self.policy_db.enabled) self.assertEqual(policies.get_driver.call_count, 0) liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'}) live_action_db, execution_db = action_service.request(liveaction) policy_service.apply_post_run_policies(live_action_db) # Policy is disabled so call_count should stay the same as before as no policies have been # applied self.assertEqual(policies.get_driver.call_count, 0)
def process(self, execution_db): execution_id = str(execution_db.id) extra = {'execution': execution_db} LOG.debug('Processing action execution "%s".', execution_id, extra=extra) if execution_db.status not in LIVEACTION_COMPLETED_STATES: msg = 'Skip action execution "%s" because state "%s" is not in a completed state.' LOG.debug(msg % (str(execution_db.id), execution_db.status), extra=extra) return # Get the corresponding liveaction record. liveaction_db = LiveAction.get_by_id(execution_db.liveaction['id']) # If the action execution is executed under an orquesta workflow, policies for the # action execution will be applied by the workflow engine. A policy may affect the # final state of the action execution thereby impacting the state of the workflow. if not workflow_service.is_action_execution_under_workflow_context( execution_db): policy_service.apply_post_run_policies(liveaction_db) if liveaction_db.notify is not None: self._post_notify_triggers(liveaction_db=liveaction_db, execution_db=execution_db) self._post_generic_trigger(liveaction_db=liveaction_db, execution_db=execution_db)
def handle_action_execution(self, ac_ex_db): # Exit if action execution is not executed under an orquesta workflow. if 'orquesta' not in ac_ex_db.context: return # Process pause request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PAUSED: wf_svc.handle_action_execution_pause(ac_ex_db) # Get execution records for logging purposes. wf_ex_id = ac_ex_db.context['orquesta']['workflow_execution_id'] wf_ex_db = wf_db_access.WorkflowExecution.get_by_id(wf_ex_id) # Exit if action execution has not completed yet. if ac_ex_db.status not in ac_const.LIVEACTION_COMPLETED_STATES: extra = {'execution': ac_ex_db} msg = '[%s] Skip action execution "%s" because state "%s" is not in a completed state.' msg = msg % (wf_ex_db.action_execution, str(ac_ex_db.id), ac_ex_db.status) LOG.debug(msg, extra=extra) return # Apply post run policies. lv_ac_db = lv_db_access.LiveAction.get_by_id(ac_ex_db.liveaction['id']) pc_svc.apply_post_run_policies(lv_ac_db) # Process completion of the action execution. wf_svc.handle_action_execution_completion(ac_ex_db)
def handle_action_execution(self, ac_ex_db): # Exit if action execution is not executed under an orquesta workflow. if not wf_svc.is_action_execution_under_workflow_context(ac_ex_db): return # Get related record identifiers. wf_ex_id = ac_ex_db.context["orquesta"]["workflow_execution_id"] task_ex_id = ac_ex_db.context["orquesta"]["task_execution_id"] # Get execution records for logging purposes. wf_ex_db = wf_db_access.WorkflowExecution.get_by_id(wf_ex_id) task_ex_db = wf_db_access.TaskExecution.get_by_id(task_ex_id) msg = 'Action execution "%s" for task "%s" is updated and in "%s" state.' % ( str(ac_ex_db.id), task_ex_db.task_id, ac_ex_db.status, ) wf_svc.update_progress(wf_ex_db, msg) # Skip if task execution is already in completed state. if task_ex_db.status in statuses.COMPLETED_STATUSES: msg = ( 'Action execution "%s" for task "%s", route "%s", is not processed ' 'because task execution "%s" is already in completed state "%s".' % ( str(ac_ex_db.id), task_ex_db.task_id, str(task_ex_db.task_route), str(task_ex_db.id), task_ex_db.status, ) ) wf_svc.update_progress(wf_ex_db, msg) return # Process pending request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PENDING: wf_svc.handle_action_execution_pending(ac_ex_db) return # Process pause request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PAUSED: wf_svc.handle_action_execution_pause(ac_ex_db) return # Exit if action execution has not completed yet. if ac_ex_db.status not in ac_const.LIVEACTION_COMPLETED_STATES: return # Apply post run policies. lv_ac_db = lv_db_access.LiveAction.get_by_id(ac_ex_db.liveaction["id"]) pc_svc.apply_post_run_policies(lv_ac_db) # Process completion of the action execution. wf_svc.handle_action_execution_completion(ac_ex_db)
def handle_action_execution(self, ac_ex_db): # Exit if action execution is not executed under an orquesta workflow. if not wf_svc.is_action_execution_under_workflow_context(ac_ex_db): return # Get related record identifiers. wf_ex_id = ac_ex_db.context['orquesta']['workflow_execution_id'] task_ex_id = ac_ex_db.context['orquesta']['task_execution_id'] # Get execution records for logging purposes. wf_ex_db = wf_db_access.WorkflowExecution.get_by_id(wf_ex_id) task_ex_db = wf_db_access.TaskExecution.get_by_id(task_ex_id) wf_ac_ex_id = wf_ex_db.action_execution msg = '[%s] Action execution "%s" for task "%s" is updated and in "%s" state.' LOG.info(msg, wf_ac_ex_id, str(ac_ex_db.id), task_ex_db.task_id, ac_ex_db.status) # Skip if task execution is already in completed state. if task_ex_db.status in states.COMPLETED_STATES: LOG.info( '[%s] Action execution "%s" for task "%s" is not processed because ' 'task execution "%s" is already in completed state "%s".', wf_ac_ex_id, str(ac_ex_db.id), task_ex_db.task_id, str(task_ex_db.id), task_ex_db.status) return # Process pending request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PENDING: wf_svc.handle_action_execution_pending(ac_ex_db) return # Process pause request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PAUSED: wf_svc.handle_action_execution_pause(ac_ex_db) return # Exit if action execution has not completed yet. if ac_ex_db.status not in ac_const.LIVEACTION_COMPLETED_STATES: return # Apply post run policies. lv_ac_db = lv_db_access.LiveAction.get_by_id(ac_ex_db.liveaction['id']) pc_svc.apply_post_run_policies(lv_ac_db) # Process completion of the action execution. wf_svc.handle_action_execution_completion(ac_ex_db)
def handle_action_execution(self, ac_ex_db): # Exit if action execution is not executed under an orquesta workflow. if not wf_svc.is_action_execution_under_workflow_context(ac_ex_db): return # Get related record identifiers. wf_ex_id = ac_ex_db.context['orquesta']['workflow_execution_id'] task_ex_id = ac_ex_db.context['orquesta']['task_execution_id'] # Get execution records for logging purposes. wf_ex_db = wf_db_access.WorkflowExecution.get_by_id(wf_ex_id) task_ex_db = wf_db_access.TaskExecution.get_by_id(task_ex_id) wf_ac_ex_id = wf_ex_db.action_execution msg = '[%s] Action execution "%s" for task "%s" is updated and in "%s" state.' LOG.info(msg, wf_ac_ex_id, str(ac_ex_db.id), task_ex_db.task_id, ac_ex_db.status) # Skip if task execution is already in completed state. if task_ex_db.status in statuses.COMPLETED_STATUSES: msg = ('[%s] Action execution "%s" for task "%s (%s)", route "%s", is not processed ' 'because task execution "%s" is already in completed state "%s".') LOG.info(msg, wf_ac_ex_id, str(ac_ex_db.id), task_ex_db.task_id, str(task_ex_db.task_route), str(task_ex_db.id), task_ex_db.status) return # Process pending request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PENDING: wf_svc.handle_action_execution_pending(ac_ex_db) return # Process pause request on the action execution. if ac_ex_db.status == ac_const.LIVEACTION_STATUS_PAUSED: wf_svc.handle_action_execution_pause(ac_ex_db) return # Exit if action execution has not completed yet. if ac_ex_db.status not in ac_const.LIVEACTION_COMPLETED_STATES: return # Apply post run policies. lv_ac_db = lv_db_access.LiveAction.get_by_id(ac_ex_db.liveaction['id']) pc_svc.apply_post_run_policies(lv_ac_db) # Process completion of the action execution. wf_svc.handle_action_execution_completion(ac_ex_db)
def process(self, execution_db): execution_id = str(execution_db.id) extra = {'execution': execution_db} LOG.debug('Processing action execution "%s".', execution_id, extra=extra) # Get the corresponding liveaction record. liveaction_db = LiveAction.get_by_id(execution_db.liveaction['id']) if execution_db.status in LIVEACTION_COMPLETED_STATES: # If the action execution is executed under an orquesta workflow, policies for the # action execution will be applied by the workflow engine. A policy may affect the # final state of the action execution thereby impacting the state of the workflow. if not workflow_service.is_action_execution_under_workflow_context(execution_db): with CounterWithTimer(key='notifier.apply_post_run_policies'): policy_service.apply_post_run_policies(liveaction_db) if liveaction_db.notify: with CounterWithTimer(key='notifier.notify_trigger.post'): self._post_notify_triggers(liveaction_db=liveaction_db, execution_db=execution_db) self._post_generic_trigger(liveaction_db=liveaction_db, execution_db=execution_db)