def test_get_trace_db_by_action_execution(self): action_execution = DummyComponent( id_=self.trace1.action_executions[0].object_id) trace_db = trace_service.get_trace_db_by_action_execution( action_execution=action_execution) self.assertEqual(trace_db.id, self.trace1.id, 'Incorrect trace_db returned.')
def test_re_run_workflow_tasks_reset_success(self): # Create a new execution post_resp = self._do_post(LIVE_ACTION_4) self.assertEqual(post_resp.status_int, 201) execution_id = self._get_actionexecution_id(post_resp) # Re-run created execution (tasks option for non workflow) data = {'tasks': ['x', 'y'], 'reset': ['y']} re_run_resp = self.app.post_json('/v1/executions/%s/re_run' % (execution_id), data, expect_errors=True) self.assertEqual(re_run_resp.status_int, 201) # Get the trace trace = trace_service.get_trace_db_by_action_execution(action_execution_id=execution_id) expected_context = { 'user': '******', 're-run': { 'ref': execution_id, 'tasks': data['tasks'], 'reset': data['reset'] }, 'trace_context': { 'id_': str(trace.id) } } self.assertDictEqual(re_run_resp.json['context'], expected_context)
def test_re_run_workflow_tasks_reset_success(self): # Create a new execution post_resp = self._do_post(LIVE_ACTION_4) self.assertEqual(post_resp.status_int, 201) execution_id = self._get_actionexecution_id(post_resp) # Re-run created execution (tasks option for non workflow) data = {'tasks': ['x', 'y'], 'reset': ['y']} re_run_resp = self.app.post_json('/v1/executions/%s/re_run' % (execution_id), data, expect_errors=True) self.assertEqual(re_run_resp.status_int, 201) # Get the trace trace = trace_service.get_trace_db_by_action_execution( action_execution_id=execution_id) expected_context = { 'user': '******', 're-run': { 'ref': execution_id, 'tasks': data['tasks'], 'reset': data['reset'] }, 'trace_context': { 'id_': str(trace.id) } } self.assertDictEqual(re_run_resp.json['context'], expected_context)
def _get_trace_context(self, execution_id): trace_db = trace_service.get_trace_db_by_action_execution(action_execution_id=execution_id) if trace_db: return TraceContext(id_=str(trace_db.id), trace_tag=trace_db.trace_tag) # If no trace_context is found then do not create a new one here. If necessary # it shall be created downstream. Sure this is impl leakage of some sort. return None
def _get_trace_context(self, execution_id): trace_db = trace_service.get_trace_db_by_action_execution( action_execution_id=execution_id) if trace_db: return TraceContext(id_=str(trace_db.id), trace_tag=trace_db.trace_tag) # If no trace_context is found then do not create a new one here. If necessary # it shall be created downstream. Sure this is impl leakage of some sort. return None
def post(self, spec_api, execution_id, no_merge=False): """ Re-run the provided action execution optionally specifying override parameters. Handles requests: POST /executions/<id>/re_run """ no_merge = cast_argument_value(value_type=bool, value=no_merge) existing_execution = self._get_one(id=execution_id, exclude_fields=self.exclude_fields) if spec_api.tasks and existing_execution.runner['name'] != 'mistral-v2': raise ValueError( 'Task option is only supported for Mistral workflows.') # Merge in any parameters provided by the user new_parameters = {} if not no_merge: new_parameters.update(getattr(existing_execution, 'parameters', {})) new_parameters.update(spec_api.parameters) # Create object for the new execution action_ref = existing_execution.action['ref'] # Include additional option(s) for the execution context = { 're-run': { 'ref': execution_id, } } if spec_api.tasks: context['re-run']['tasks'] = spec_api.tasks if spec_api.reset: context['re-run']['reset'] = spec_api.reset # Add trace to the new execution trace = trace_service.get_trace_db_by_action_execution( action_execution_id=existing_execution.id) if trace: context['trace_context'] = {'id_': str(trace.id)} new_liveaction_api = LiveActionCreateAPI(action=action_ref, context=context, parameters=new_parameters, user=spec_api.user) return self._handle_schedule_execution( liveaction_api=new_liveaction_api)
def post(self, spec_api, execution_id, no_merge=False): """ Re-run the provided action execution optionally specifying override parameters. Handles requests: POST /executions/<id>/re_run """ no_merge = cast_argument_value(value_type=bool, value=no_merge) existing_execution = self._get_one(id=execution_id, exclude_fields=self.exclude_fields) if spec_api.tasks and existing_execution.runner['name'] != 'mistral-v2': raise ValueError('Task option is only supported for Mistral workflows.') # Merge in any parameters provided by the user new_parameters = {} if not no_merge: new_parameters.update(getattr(existing_execution, 'parameters', {})) new_parameters.update(spec_api.parameters) # Create object for the new execution action_ref = existing_execution.action['ref'] # Include additional option(s) for the execution context = { 're-run': { 'ref': execution_id, } } if spec_api.tasks: context['re-run']['tasks'] = spec_api.tasks if spec_api.reset: context['re-run']['reset'] = spec_api.reset # Add trace to the new execution trace = trace_service.get_trace_db_by_action_execution( action_execution_id=existing_execution.id) if trace: context['trace_context'] = {'id_': str(trace.id)} new_liveaction_api = LiveActionCreateAPI(action=action_ref, context=context, parameters=new_parameters, user=spec_api.user) return self._handle_schedule_execution(liveaction_api=new_liveaction_api)
def test_re_run_workflow_success(self): # Create a new execution post_resp = self._do_post(LIVE_ACTION_4) self.assertEqual(post_resp.status_int, 201) execution_id = self._get_actionexecution_id(post_resp) # Re-run created execution (tasks option for non workflow) data = {} re_run_resp = self.app.post_json("/v1/executions/%s/re_run" % (execution_id), data, expect_errors=True) self.assertEqual(re_run_resp.status_int, 201) # Get the trace trace = trace_service.get_trace_db_by_action_execution(action_execution_id=execution_id) expected_context = {"user": "******", "re-run": {"ref": execution_id}, "trace_context": {"id_": str(trace.id)}} self.assertDictEqual(re_run_resp.json["context"], expected_context)
def post(self, spec_api, id, requester_user, no_merge=False, show_secrets=False): """ Re-run the provided action execution optionally specifying override parameters. Handles requests: POST /executions/<id>/re_run """ if (spec_api.tasks or spec_api.reset) and spec_api.parameters: raise ValueError('Parameters override is not supported when ' 're-running task(s) for a workflow.') if spec_api.parameters: assert isinstance(spec_api.parameters, dict) if spec_api.tasks: assert isinstance(spec_api.tasks, list) if spec_api.reset: assert isinstance(spec_api.reset, list) if list(set(spec_api.reset) - set(spec_api.tasks)): raise ValueError( 'List of tasks to reset does not match the tasks to rerun.') no_merge = cast_argument_value(value_type=bool, value=no_merge) existing_execution = self._get_one_by_id( id=id, exclude_fields=self.exclude_fields, requester_user=requester_user, permission_type=PermissionType.EXECUTION_VIEW) if spec_api.tasks and existing_execution.runner['name'] != 'mistral-v2': raise ValueError( 'Task option is only supported for Mistral workflows.') # Merge in any parameters provided by the user new_parameters = {} if not no_merge: new_parameters.update(getattr(existing_execution, 'parameters', {})) new_parameters.update(spec_api.parameters) # Create object for the new execution action_ref = existing_execution.action['ref'] # Include additional option(s) for the execution context = { 're-run': { 'ref': id, } } if spec_api.tasks: context['re-run']['tasks'] = spec_api.tasks if spec_api.reset: context['re-run']['reset'] = spec_api.reset # Add trace to the new execution trace = trace_service.get_trace_db_by_action_execution( action_execution_id=existing_execution.id) if trace: context['trace_context'] = {'id_': str(trace.id)} new_liveaction_api = LiveActionCreateAPI(action=action_ref, context=context, parameters=new_parameters, user=spec_api.user) return self._handle_schedule_execution( liveaction_api=new_liveaction_api, requester_user=requester_user, show_secrets=show_secrets)
def post(self, spec_api, id, requester_user, no_merge=False, show_secrets=False): """ Re-run the provided action execution optionally specifying override parameters. Handles requests: POST /executions/<id>/re_run """ if (spec_api.tasks or spec_api.reset) and spec_api.parameters: raise ValueError("Parameters override is not supported when " "re-running task(s) for a workflow.") if spec_api.parameters: if not isinstance(spec_api.parameters, dict): raise TypeError( f"The parameters needs to be a dictionary (was {type(spec_api.parameters)})." ) if spec_api.tasks: if not isinstance(spec_api.tasks, list): raise TypeError( f"The tasks needs to be a list (was {type(spec_api.tasks)})." ) if spec_api.reset: if not isinstance(spec_api.reset, list): raise TypeError( f"The reset needs to be a list (was {type(spec_api.reset)})." ) if list(set(spec_api.reset) - set(spec_api.tasks)): raise ValueError( "List of tasks to reset does not match the tasks to rerun.") delay = None if hasattr(spec_api, "delay") and isinstance(spec_api.delay, int): delay = spec_api.delay no_merge = cast_argument_value(value_type=bool, value=no_merge) existing_execution = self._get_one_by_id( id=id, exclude_fields=self.exclude_fields, requester_user=requester_user, permission_type=PermissionType.EXECUTION_VIEW, ) if spec_api.tasks and existing_execution.runner["name"] != "orquesta": raise ValueError( "Task option is only supported for Orquesta workflows.") # Merge in any parameters provided by the user new_parameters = {} if not no_merge: new_parameters.update(getattr(existing_execution, "parameters", {})) new_parameters.update(spec_api.parameters) # Create object for the new execution action_ref = existing_execution.action["ref"] # Include additional option(s) for the execution context = { "re-run": { "ref": id, } } if spec_api.tasks: context["re-run"]["tasks"] = spec_api.tasks if spec_api.reset: context["re-run"]["reset"] = spec_api.reset # Add trace to the new execution trace = trace_service.get_trace_db_by_action_execution( action_execution_id=existing_execution.id) if trace: context["trace_context"] = {"id_": str(trace.id)} new_liveaction_api = LiveActionCreateAPI( action=action_ref, context=context, parameters=new_parameters, user=spec_api.user, delay=delay, ) return self._handle_schedule_execution( liveaction_api=new_liveaction_api, requester_user=requester_user, show_secrets=show_secrets, )
def test_get_trace_db_by_action_execution(self): action_execution = DummyComponent(id_=self.trace1.action_executions[0].object_id) trace_db = trace_service.get_trace_db_by_action_execution(action_execution=action_execution) self.assertEqual(trace_db.id, self.trace1.id, 'Incorrect trace_db returned.')
def post(self, spec_api, id, requester_user, no_merge=False, show_secrets=False): """ Re-run the provided action execution optionally specifying override parameters. Handles requests: POST /executions/<id>/re_run """ if (spec_api.tasks or spec_api.reset) and spec_api.parameters: raise ValueError('Parameters override is not supported when ' 're-running task(s) for a workflow.') if spec_api.parameters: assert isinstance(spec_api.parameters, dict) if spec_api.tasks: assert isinstance(spec_api.tasks, list) if spec_api.reset: assert isinstance(spec_api.reset, list) if list(set(spec_api.reset) - set(spec_api.tasks)): raise ValueError('List of tasks to reset does not match the tasks to rerun.') delay = None if hasattr(spec_api, "delay") and isinstance(spec_api.delay, int): delay = spec_api.delay no_merge = cast_argument_value(value_type=bool, value=no_merge) existing_execution = self._get_one_by_id(id=id, exclude_fields=self.exclude_fields, requester_user=requester_user, permission_type=PermissionType.EXECUTION_VIEW) if spec_api.tasks and existing_execution.runner['name'] != 'mistral-v2': raise ValueError('Task option is only supported for Mistral workflows.') # Merge in any parameters provided by the user new_parameters = {} if not no_merge: new_parameters.update(getattr(existing_execution, 'parameters', {})) new_parameters.update(spec_api.parameters) # Create object for the new execution action_ref = existing_execution.action['ref'] # Include additional option(s) for the execution context = { 're-run': { 'ref': id, } } if spec_api.tasks: context['re-run']['tasks'] = spec_api.tasks if spec_api.reset: context['re-run']['reset'] = spec_api.reset # Add trace to the new execution trace = trace_service.get_trace_db_by_action_execution( action_execution_id=existing_execution.id) if trace: context['trace_context'] = {'id_': str(trace.id)} new_liveaction_api = LiveActionCreateAPI(action=action_ref, context=context, parameters=new_parameters, user=spec_api.user, delay=delay) return self._handle_schedule_execution(liveaction_api=new_liveaction_api, requester_user=requester_user, show_secrets=show_secrets)