本文整理汇总了Python中st2common.services.action.request_cancellation函数的典型用法代码示例。如果您正苦于以下问题:Python request_cancellation函数的具体用法?Python request_cancellation怎么用?Python request_cancellation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request_cancellation函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: cancel
def cancel(self):
# Cancel the target workflow.
wf_svc.request_cancellation(self.execution)
# Request cancellation of tasks that are workflows and still running.
for child_ex_id in self.execution.children:
child_ex = ex_db_access.ActionExecution.get(id=child_ex_id)
if (child_ex.runner['name'] in ac_const.WORKFLOW_RUNNER_TYPES and
child_ex.status in ac_const.LIVEACTION_CANCELABLE_STATES):
ac_svc.request_cancellation(
lv_db_access.LiveAction.get(id=child_ex.liveaction['id']),
self.context.get('user', None)
)
status = (
ac_const.LIVEACTION_STATUS_CANCELING
if ac_svc.is_children_active(self.liveaction.id)
else ac_const.LIVEACTION_STATUS_CANCELED
)
return (
status,
self.liveaction.result,
self.liveaction.context
)
开发者ID:lyandut,项目名称:st2,代码行数:25,代码来源:orchestra_runner.py
示例2: test_on_cancellation
def test_on_cancellation(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency.attr')
self.assertGreater(policy_db.parameters['threshold'], 0)
self.assertIn('actionstr', policy_db.parameters['attributes'])
for i in range(0, policy_db.parameters['threshold']):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'})
action_service.request(liveaction)
scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES]
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'})
liveaction, _ = action_service.request(liveaction)
delayed = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(delayed.status, action_constants.LIVEACTION_STATUS_DELAYED)
# Execution is expected to be scheduled since concurrency threshold is not reached.
# The execution with actionstr "fu" is over the threshold but actionstr "bar" is not.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'bar'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
# Cancel execution.
action_service.request_cancellation(scheduled[0], 'stanley')
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(delayed.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
开发者ID:Pulsant,项目名称:st2,代码行数:31,代码来源:test_concurrency_by_attr.py
示例3: request_cancellation
def request_cancellation(ac_ex_db):
wf_ex_dbs = wf_db_access.WorkflowExecution.query(action_execution=str(ac_ex_db.id))
if not wf_ex_dbs:
raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))
if len(wf_ex_dbs) > 1:
raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))
wf_ex_db = wf_ex_dbs[0]
if wf_ex_db.status in states.COMPLETED_STATES:
raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))
conductor = deserialize_conductor(wf_ex_db)
if conductor.get_workflow_state() in states.COMPLETED_STATES:
raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))
conductor.set_workflow_state(states.CANCELED)
# Write the updated workflow state and task flow to the database.
wf_ex_db.status = conductor.get_workflow_state()
wf_ex_db.flow = conductor.flow.serialize()
wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)
# Cascade the cancellation up to the root of the workflow.
root_ac_ex_db = ac_svc.get_root_execution(ac_ex_db)
if root_ac_ex_db != ac_ex_db and root_ac_ex_db.status not in ac_const.LIVEACTION_CANCEL_STATES:
root_lv_ac_db = lv_db_access.LiveAction.get(id=root_ac_ex_db.liveaction['id'])
ac_svc.request_cancellation(root_lv_ac_db, None)
return wf_ex_db
开发者ID:lyandut,项目名称:st2,代码行数:34,代码来源:workflows.py
示例4: test_on_cancellation
def test_on_cancellation(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency')
self.assertGreater(policy_db.parameters['threshold'], 0)
# Launch action executions until the expected threshold is reached.
for i in range(0, policy_db.parameters['threshold']):
parameters = {'actionstr': 'foo-' + str(i)}
liveaction = LiveActionDB(action='wolfpack.action-1', parameters=parameters)
action_service.request(liveaction)
# Run the scheduler to schedule action executions.
self._process_scheduling_queue()
# Check the number of action executions in scheduled state.
scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES]
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
# duplicate executions caused by accidental publishing of state in the concurrency policies.
# num_state_changes = len(scheduled) * len(['requested', 'scheduled', 'running'])
expected_num_exec = len(scheduled)
expected_num_pubs = expected_num_exec * 3
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
expected_num_pubs += 1 # Tally requested state.
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
# Run the scheduler to schedule action executions.
self._process_scheduling_queue()
# Since states are being processed async, wait for the liveaction to go into delayed state.
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_DELAYED)
expected_num_exec += 0 # This request will not be scheduled for execution.
expected_num_pubs += 0 # The delayed status change should not be published.
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Cancel execution.
action_service.request_cancellation(scheduled[0], 'stanley')
expected_num_pubs += 2 # Tally the canceling and canceled states.
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
# Run the scheduler to schedule action executions.
self._process_scheduling_queue()
# Once capacity freed up, the delayed execution is published as requested again.
expected_num_exec += 1 # This request is expected to be executed.
expected_num_pubs += 2 # Tally scheduled and running state.
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
开发者ID:StackStorm,项目名称:st2,代码行数:59,代码来源:test_concurrency.py
示例5: test_on_cancellation
def test_on_cancellation(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency.attr')
self.assertGreater(policy_db.parameters['threshold'], 0)
self.assertIn('actionstr', policy_db.parameters['attributes'])
for i in range(0, policy_db.parameters['threshold']):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'})
action_service.request(liveaction)
scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES]
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
# duplicate executions caused by accidental publishing of state in the concurrency policies.
# num_state_changes = len(scheduled) * len(['requested', 'scheduled', 'running'])
expected_num_exec = len(scheduled)
expected_num_pubs = expected_num_exec * 3
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'})
liveaction, _ = action_service.request(liveaction)
expected_num_pubs += 1 # Tally requested state.
# Assert the action is delayed.
delayed = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(delayed.status, action_constants.LIVEACTION_STATUS_DELAYED)
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Execution is expected to be scheduled since concurrency threshold is not reached.
# The execution with actionstr "fu" is over the threshold but actionstr "bar" is not.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'bar'})
liveaction, _ = action_service.request(liveaction)
expected_num_exec += 1 # This request is expected to be executed.
expected_num_pubs += 3 # Tally requested, scheduled, and running states.
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Cancel execution.
action_service.request_cancellation(scheduled[0], 'stanley')
expected_num_pubs += 2 # Tally the canceling and canceled states.
# Once capacity freed up, the delayed execution is published as requested again.
expected_num_exec += 1 # The delayed request is expected to be executed.
expected_num_pubs += 3 # Tally requested, scheduled, and running state.
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(delayed.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
开发者ID:peak6,项目名称:st2,代码行数:55,代码来源:test_concurrency_by_attr.py
示例6: test_basic_cancel
def test_basic_cancel(self):
liveaction = LiveActionDB(action='executions.local', parameters={'cmd': 'uname -a'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_RUNNING)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELED)
self.assertDictEqual(liveaction.result, MOCK_RESULT)
开发者ID:hejin,项目名称:st2,代码行数:11,代码来源:test_execution_cancellation.py
示例7: test_failed_cancel
def test_failed_cancel(self):
liveaction = LiveActionDB(action='executions.local', parameters={'cmd': 'uname -a'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_RUNNING)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
# Cancellation failed and execution state remains "canceling".
ActionRunner.cancel.assert_called_once_with()
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELING)
开发者ID:hejin,项目名称:st2,代码行数:13,代码来源:test_execution_cancellation.py
示例8: test_noop_cancel
def test_noop_cancel(self):
liveaction = LiveActionDB(action='executions.local', parameters={'cmd': 'uname -a'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_REQUESTED)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
# Cancel is only called when liveaction is still in running state.
# Otherwise, the cancellation is only a state change.
self.assertFalse(ActionRunner.cancel.called)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELED)
开发者ID:Pulsant,项目名称:st2,代码行数:14,代码来源:test_execution_cancellation.py
示例9: test_basic_cancel
def test_basic_cancel(self):
runner_cls = self.get_runner_class('runner')
runner_run_result = (action_constants.LIVEACTION_STATUS_RUNNING, 'foobar', None)
runner_cls.run = mock.Mock(return_value=runner_run_result)
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_RUNNING)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELED)
开发者ID:lyandut,项目名称:st2,代码行数:14,代码来源:test_execution_cancellation.py
示例10: test_chain_cancel_cascade_to_subworkflow
def test_chain_cancel_cascade_to_subworkflow(self):
# A temp file is created during test setup. Ensure the temp file exists.
# The test action chain will stall until this file is deleted. This gives
# the unit test a moment to run any test related logic.
path = self.temp_file_path
self.assertTrue(os.path.exists(path))
action = TEST_PACK + '.' + 'test_cancel_with_subworkflow'
params = {'tempfile': path, 'message': 'foobar'}
liveaction = LiveActionDB(action=action, parameters=params)
liveaction, execution = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
# Wait until the liveaction is running.
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_RUNNING)
# Wait for subworkflow to register.
execution = self._wait_for_children(execution)
self.assertEqual(len(execution.children), 1)
# Wait until the subworkflow is running.
task1_exec = ActionExecution.get_by_id(execution.children[0])
task1_live = LiveAction.get_by_id(task1_exec.liveaction['id'])
task1_live = self._wait_on_status(task1_live, action_constants.LIVEACTION_STATUS_RUNNING)
# Request action chain to cancel.
liveaction, execution = action_service.request_cancellation(liveaction, USERNAME)
# Wait until the liveaction is canceling.
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_CANCELING)
self.assertEqual(len(execution.children), 1)
# Wait until the subworkflow is canceling.
task1_exec = ActionExecution.get_by_id(execution.children[0])
task1_live = LiveAction.get_by_id(task1_exec.liveaction['id'])
task1_live = self._wait_on_status(task1_live, action_constants.LIVEACTION_STATUS_CANCELING)
# Delete the temporary file that the action chain is waiting on.
os.remove(path)
self.assertFalse(os.path.exists(path))
# Wait until the liveaction is canceled.
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_CANCELED)
self.assertEqual(len(execution.children), 1)
# Wait until the subworkflow is canceled.
task1_exec = ActionExecution.get_by_id(execution.children[0])
task1_live = LiveAction.get_by_id(task1_exec.liveaction['id'])
task1_live = self._wait_on_status(task1_live, action_constants.LIVEACTION_STATUS_CANCELED)
# Wait for non-blocking threads to complete. Ensure runner is not running.
MockLiveActionPublisherNonBlocking.wait_all()
# Check liveaction result.
self.assertIn('tasks', liveaction.result)
self.assertEqual(len(liveaction.result['tasks']), 1)
subworkflow = liveaction.result['tasks'][0]
self.assertEqual(len(subworkflow['result']['tasks']), 1)
self.assertEqual(subworkflow['state'], action_constants.LIVEACTION_STATUS_CANCELED)
开发者ID:nzlosh,项目名称:st2,代码行数:60,代码来源:test_actionchain_cancel.py
示例11: test_cancel_subworkflow_action
def test_cancel_subworkflow_action(self):
liveaction1 = LiveActionDB(action=WF2_NAME, parameters=ACTION_PARAMS)
liveaction1, execution1 = action_service.request(liveaction1)
liveaction1 = LiveAction.get_by_id(str(liveaction1.id))
self.assertEqual(liveaction1.status, action_constants.LIVEACTION_STATUS_RUNNING)
liveaction2 = LiveActionDB(action=WF1_NAME, parameters=ACTION_PARAMS)
liveaction2, execution2 = action_service.request(liveaction2)
liveaction2 = LiveAction.get_by_id(str(liveaction2.id))
self.assertEqual(liveaction2.status, action_constants.LIVEACTION_STATUS_RUNNING)
# Mock the children of the parent execution to make this
# test case has subworkflow execution.
with mock.patch.object(
ActionExecutionDB, 'children',
new_callable=mock.PropertyMock) as action_ex_children_mock:
action_ex_children_mock.return_value = [execution2.id]
mistral_context = liveaction1.context.get('mistral', None)
self.assertIsNotNone(mistral_context)
self.assertEqual(mistral_context['execution_id'], WF2_EXEC.get('id'))
self.assertEqual(mistral_context['workflow_name'], WF2_EXEC.get('workflow_name'))
requester = cfg.CONF.system_user.user
liveaction1, execution1 = action_service.request_cancellation(liveaction1, requester)
self.assertTrue(executions.ExecutionManager.update.called)
self.assertEqual(executions.ExecutionManager.update.call_count, 2)
calls = [
mock.call(WF2_EXEC.get('id'), 'CANCELLED'),
mock.call(WF1_EXEC.get('id'), 'CANCELLED')
]
executions.ExecutionManager.update.assert_has_calls(calls, any_order=False)
开发者ID:lyandut,项目名称:st2,代码行数:35,代码来源:test_mistral_v2_cancel.py
示例12: cancel
def cancel(self):
# Identify the list of action executions that are workflows and cascade pause.
for child_exec_id in self.execution.children:
child_exec = ActionExecution.get(id=child_exec_id, raise_exception=True)
if (child_exec.runner['name'] in action_constants.WORKFLOW_RUNNER_TYPES and
child_exec.status in action_constants.LIVEACTION_CANCELABLE_STATES):
action_service.request_cancellation(
LiveAction.get(id=child_exec.liveaction['id']),
self.context.get('user', None)
)
return (
action_constants.LIVEACTION_STATUS_CANCELING,
self.liveaction.result,
self.liveaction.context
)
开发者ID:nzlosh,项目名称:st2,代码行数:16,代码来源:action_chain_runner.py
示例13: test_cancel_workflow_cascade_down_to_subworkflow
def test_cancel_workflow_cascade_down_to_subworkflow(self):
wf_meta = base.get_wf_fixture_meta_data(TEST_PACK_PATH, 'subworkflow.yaml')
lv_ac_db = lv_db_models.LiveActionDB(action=wf_meta['name'])
lv_ac_db, ac_ex_db = ac_svc.request(lv_ac_db)
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_RUNNING, lv_ac_db.result)
# Identify the records for the subworkflow.
wf_ex_dbs = wf_db_access.WorkflowExecution.query(action_execution=str(ac_ex_db.id))
self.assertEqual(len(wf_ex_dbs), 1)
tk_ex_dbs = wf_db_access.TaskExecution.query(workflow_execution=str(wf_ex_dbs[0].id))
self.assertEqual(len(tk_ex_dbs), 1)
tk_ac_ex_dbs = ex_db_access.ActionExecution.query(task_execution=str(tk_ex_dbs[0].id))
self.assertEqual(len(tk_ac_ex_dbs), 1)
tk_lv_ac_db = lv_db_access.LiveAction.get_by_id(tk_ac_ex_dbs[0].liveaction['id'])
self.assertEqual(tk_lv_ac_db.status, ac_const.LIVEACTION_STATUS_RUNNING)
# Cancel the main workflow.
requester = cfg.CONF.system_user.user
lv_ac_db, ac_ex_db = ac_svc.request_cancellation(lv_ac_db, requester)
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELING)
# Assert the subworkflow is canceled.
tk_lv_ac_db = lv_db_access.LiveAction.get_by_id(str(tk_lv_ac_db.id))
self.assertEqual(tk_lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
# Assert the main workflow is canceled.
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
开发者ID:nzlosh,项目名称:st2,代码行数:32,代码来源:test_cancel.py
示例14: test_cancel_delayed_execution
def test_cancel_delayed_execution(self):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_REQUESTED)
# Manually update the liveaction from requested to delayed to mock concurrency policy.
action_service.update_status(liveaction, action_constants.LIVEACTION_STATUS_DELAYED)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_DELAYED)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
# Cancel is only called when liveaction is still in running state.
# Otherwise, the cancellation is only a state change.
self.assertFalse(runners.ActionRunner.cancel.called)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELED)
开发者ID:lyandut,项目名称:st2,代码行数:19,代码来源:test_execution_cancellation.py
示例15: test_failed_cancel
def test_failed_cancel(self):
runner_run_result = (action_constants.LIVEACTION_STATUS_RUNNING, 'foobar', None)
mock_runner_run = mock.Mock(return_value=runner_run_result)
with mock.patch.object(runner.MockActionRunner, 'run', mock_runner_run):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
liveaction = self._wait_on_status(
liveaction,
action_constants.LIVEACTION_STATUS_RUNNING
)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
# Cancellation failed and execution state remains "canceling".
runners.ActionRunner.cancel.assert_called_once_with()
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELING)
开发者ID:nzlosh,项目名称:st2,代码行数:19,代码来源:test_execution_cancellation.py
示例16: test_cancel_subworkflow_cascade_up_to_workflow_with_other_subworkflows
def test_cancel_subworkflow_cascade_up_to_workflow_with_other_subworkflows(self):
wf_meta = base.get_wf_fixture_meta_data(TEST_PACK_PATH, 'subworkflows.yaml')
lv_ac_db = lv_db_models.LiveActionDB(action=wf_meta['name'])
lv_ac_db, ac_ex_db = ac_svc.request(lv_ac_db)
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_RUNNING, lv_ac_db.result)
# Identify the records for the subworkflow.
wf_ex_dbs = wf_db_access.WorkflowExecution.query(action_execution=str(ac_ex_db.id))
self.assertEqual(len(wf_ex_dbs), 1)
tk_ex_dbs = wf_db_access.TaskExecution.query(workflow_execution=str(wf_ex_dbs[0].id))
self.assertEqual(len(tk_ex_dbs), 2)
tk1_ac_ex_dbs = ex_db_access.ActionExecution.query(task_execution=str(tk_ex_dbs[0].id))
self.assertEqual(len(tk1_ac_ex_dbs), 1)
tk1_lv_ac_db = lv_db_access.LiveAction.get_by_id(tk1_ac_ex_dbs[0].liveaction['id'])
self.assertEqual(tk1_lv_ac_db.status, ac_const.LIVEACTION_STATUS_RUNNING)
tk2_ac_ex_dbs = ex_db_access.ActionExecution.query(task_execution=str(tk_ex_dbs[1].id))
self.assertEqual(len(tk2_ac_ex_dbs), 1)
tk2_lv_ac_db = lv_db_access.LiveAction.get_by_id(tk2_ac_ex_dbs[0].liveaction['id'])
self.assertEqual(tk2_lv_ac_db.status, ac_const.LIVEACTION_STATUS_RUNNING)
# Cancel the subworkflow which should cascade up to the root.
requester = cfg.CONF.system_user.user
tk1_lv_ac_db, tk1_ac_ex_db = ac_svc.request_cancellation(tk1_lv_ac_db, requester)
self.assertEqual(tk1_lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELING)
# Assert the main workflow is canceling.
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELING)
# Assert both subworkflows are canceled.
tk1_lv_ac_db = lv_db_access.LiveAction.get_by_id(str(tk1_lv_ac_db.id))
self.assertEqual(tk1_lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
tk2_lv_ac_db = lv_db_access.LiveAction.get_by_id(str(tk2_lv_ac_db.id))
self.assertEqual(tk2_lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
# Manually handle action execution completion for one of the tasks.
tk1_ac_ex_db = ex_db_access.ActionExecution.get_by_id(str(tk1_ac_ex_db.id))
self.assertEqual(tk1_ac_ex_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
wf_svc.handle_action_execution_completion(tk1_ac_ex_db)
# Manually handle action execution completion for the other task.
tk2_ac_ex_db = tk2_ac_ex_dbs[0]
tk2_ac_ex_db = ex_db_access.ActionExecution.get_by_id(str(tk2_ac_ex_db.id))
self.assertEqual(tk2_ac_ex_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
wf_svc.handle_action_execution_completion(tk2_ac_ex_db)
# Assert the main workflow is canceling.
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELED)
开发者ID:nzlosh,项目名称:st2,代码行数:55,代码来源:test_cancel.py
示例17: test_cancel
def test_cancel(self):
wf_meta = base.get_wf_fixture_meta_data(TEST_PACK_PATH, 'sequential.yaml')
lv_ac_db = lv_db_models.LiveActionDB(action=wf_meta['name'])
lv_ac_db, ac_ex_db = ac_svc.request(lv_ac_db)
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_RUNNING, lv_ac_db.result)
requester = cfg.CONF.system_user.user
lv_ac_db, ac_ex_db = ac_svc.request_cancellation(lv_ac_db, requester)
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELING)
开发者ID:nzlosh,项目名称:st2,代码行数:11,代码来源:test_cancel.py
示例18: test_basic_cancel
def test_basic_cancel(self):
runner_run_result = (action_constants.LIVEACTION_STATUS_RUNNING, 'foobar', None)
mock_runner_run = mock.Mock(return_value=runner_run_result)
with mock.patch.object(runner.MockActionRunner, 'run', mock_runner_run):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
liveaction = self._wait_on_status(
liveaction,
action_constants.LIVEACTION_STATUS_RUNNING
)
# Cancel execution.
action_service.request_cancellation(liveaction, cfg.CONF.system_user.user)
liveaction = self._wait_on_status(
liveaction,
action_constants.LIVEACTION_STATUS_CANCELED
)
开发者ID:nzlosh,项目名称:st2,代码行数:20,代码来源:test_execution_cancellation.py
示例19: request_cancellation
def request_cancellation(ac_ex_db):
wf_ac_ex_id = str(ac_ex_db.id)
LOG.info('[%s] Processing cancelation request for workflow.', wf_ac_ex_id)
wf_ex_dbs = wf_db_access.WorkflowExecution.query(action_execution=str(ac_ex_db.id))
if not wf_ex_dbs:
raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))
if len(wf_ex_dbs) > 1:
raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))
wf_ex_db = wf_ex_dbs[0]
if wf_ex_db.status in statuses.COMPLETED_STATUSES:
raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))
conductor = deserialize_conductor(wf_ex_db)
if conductor.get_workflow_status() in statuses.COMPLETED_STATUSES:
raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))
conductor.request_workflow_status(statuses.CANCELED)
# Write the updated workflow status and task flow to the database.
wf_ex_db.status = conductor.get_workflow_status()
wf_ex_db.state = conductor.workflow_state.serialize()
wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)
# Cascade the cancellation up to the root of the workflow.
root_ac_ex_db = ac_svc.get_root_execution(ac_ex_db)
if root_ac_ex_db != ac_ex_db and root_ac_ex_db.status not in ac_const.LIVEACTION_CANCEL_STATES:
LOG.info('[%s] Cascading cancelation request to parent workflow.', wf_ac_ex_id)
root_lv_ac_db = lv_db_access.LiveAction.get(id=root_ac_ex_db.liveaction['id'])
ac_svc.request_cancellation(root_lv_ac_db, None)
LOG.debug('[%s] %s', wf_ac_ex_id, conductor.serialize())
LOG.info('[%s] Completed processing cancelation request for workflow.', wf_ac_ex_id)
return wf_ex_db
开发者ID:nzlosh,项目名称:st2,代码行数:41,代码来源:workflows.py
示例20: delete
def delete(self, id, requester_user, show_secrets=False):
"""
Stops a single execution.
Handles requests:
DELETE /executions/<id>
"""
if not requester_user:
requester_user = UserDB(cfg.CONF.system_user.user)
from_model_kwargs = {
'mask_secrets': self._get_mask_secrets(requester_user, show_secrets=show_secrets)
}
execution_api = self._get_one_by_id(id=id, requester_user=requester_user,
from_model_kwargs=from_model_kwargs,
permission_type=PermissionType.EXECUTION_STOP)
if not execution_api:
abort(http_client.NOT_FOUND, 'Execution with id %s not found.' % id)
liveaction_id = execution_api.liveaction['id']
if not liveaction_id:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
try:
liveaction_db = LiveAction.get_by_id(liveaction_id)
except:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
if liveaction_db.status == action_constants.LIVEACTION_STATUS_CANCELED:
LOG.info(
'Action %s already in "canceled" state; \
returning execution object.' % liveaction_db.id
)
return execution_api
if liveaction_db.status not in action_constants.LIVEACTION_CANCELABLE_STATES:
abort(http_client.OK, 'Action cannot be canceled. State = %s.' % liveaction_db.status)
try:
(liveaction_db, execution_db) = action_service.request_cancellation(
liveaction_db, requester_user.name or cfg.CONF.system_user.user)
except:
LOG.exception('Failed requesting cancellation for liveaction %s.', liveaction_db.id)
abort(http_client.INTERNAL_SERVER_ERROR, 'Failed canceling execution.')
return ActionExecutionAPI.from_model(execution_db,
mask_secrets=from_model_kwargs['mask_secrets'])
开发者ID:nzlosh,项目名称:st2,代码行数:51,代码来源:actionexecutions.py
注:本文中的st2common.services.action.request_cancellation函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论