def invoke(self, trans, workflow_id, payload, **kwd): """ POST /api/workflows/{encoded_workflow_id}/invocations Schedule the workflow specified by `workflow_id` to run. """ # Get workflow + accessibility check. stored_workflow = self.__get_stored_accessible_workflow( trans, workflow_id) workflow = stored_workflow.latest_workflow run_configs = build_workflow_run_configs(trans, workflow, payload) is_batch = payload.get('batch') if not is_batch and len(run_configs) != 1: raise exceptions.RequestParameterInvalidException( "Must specify 'batch' to use batch parameters.") invocations = [] for run_config in run_configs: workflow_scheduler_id = payload.get('scheduler', None) # TODO: workflow scheduler hints work_request_params = dict(scheduler=workflow_scheduler_id) workflow_invocation = queue_invoke( trans=trans, workflow=workflow, workflow_run_config=run_config, request_params=work_request_params) invocation = self.encode_all_ids(trans, workflow_invocation.to_dict(), recursive=True) invocations.append(invocation) if is_batch: return invocations else: return invocations[0]
def invoke(self, trans, workflow_id, payload, **kwd): """ POST /api/workflows/{encoded_workflow_id}/invocations Schedule the workflow specified by `workflow_id` to run. """ # /usage is awkward in this context but is consistent with the rest of # this module. Would prefer to redo it all to use /invocation(s). # Get workflow + accessibility check. stored_workflow = self.__get_stored_accessible_workflow( trans, workflow_id) workflow = stored_workflow.latest_workflow run_config = build_workflow_run_config(trans, workflow, payload) workflow_scheduler_id = payload.get("scheduler", None) # TODO: workflow scheduler hints work_request_params = dict(scheduler=workflow_scheduler_id) workflow_invocation = queue_invoke(trans=trans, workflow=workflow, workflow_run_config=run_config, request_params=work_request_params) return self.encode_all_ids(trans, workflow_invocation.to_dict(), recursive=True)
def invoke(self, trans, workflow_id, payload, **kwd): """ POST /api/workflows/{encoded_workflow_id}/invocations Schedule the workflow specified by `workflow_id` to run. """ # Get workflow + accessibility check. stored_workflow = self.__get_stored_accessible_workflow(trans, workflow_id) workflow = stored_workflow.latest_workflow run_configs = build_workflow_run_configs(trans, workflow, payload) is_batch = payload.get('batch') if not is_batch and len(run_configs) != 1: raise exceptions.RequestParameterInvalidException("Must specify 'batch' to use batch parameters.") invocations = [] for run_config in run_configs: workflow_scheduler_id = payload.get('scheduler', None) # TODO: workflow scheduler hints work_request_params = dict(scheduler=workflow_scheduler_id) workflow_invocation = queue_invoke( trans=trans, workflow=workflow, workflow_run_config=run_config, request_params=work_request_params ) invocation = self.encode_all_ids(trans, workflow_invocation.to_dict(), recursive=True) invocations.append(invocation) if is_batch: return invocations else: return invocations[0]
def run( self, trans, workflow_id, payload, **kwd ): """ POST /api_internal/workflows/{encoded_workflow_id}/run Run a workflow with a dictionary of prefixed_name/value pairs e.g. payload = { inputs: { step_0: { parameter_0|parameter_1 : value_0, ... }, ... } } """ workflow = self.__get_stored_accessible_workflow( trans, workflow_id ).latest_workflow trans.workflow_building_mode = workflow_building_modes.USE_HISTORY module_injector = WorkflowModuleInjector( trans ) params, param_keys = expand_workflow_inputs( payload.get( 'inputs', [] ) ) errors = {} for workflow_args in params: for step in workflow.steps: step_args = workflow_args.get( str( step.id ), {} ) step_errors = module_injector.inject( step, step_args ) if step_errors: errors[ step.id ] = step_errors if errors: log.exception( errors ) raise exceptions.MessageException( err_data=errors ) invocations = [] for index, workflow_args in enumerate( params ): for step in workflow.steps: step_args = workflow_args.get( str( step.id ), {} ) module_injector.inject( step, step_args ) new_history = None if 'new_history_name' in payload: if payload[ 'new_history_name' ]: nh_name = payload[ 'new_history_name' ] else: nh_name = 'History from %s workflow' % workflow.name if index in param_keys: ids = param_keys[ index ] nids = len( ids ) if nids == 1: nh_name = '%s on %s' % ( nh_name, ids[ 0 ] ) elif nids > 1: nh_name = '%s on %s and %s' % ( nh_name, ', '.join( ids[ 0:-1 ] ), ids[ -1 ] ) new_history = trans.app.model.History( user=trans.user, name=nh_name ) new_history.copy_tags_from( trans.user, trans.history ) trans.sa_session.add( new_history ) target_history = new_history elif 'history_id' in payload: target_history = histories.HistoryManager( trans.app ).get_owned( trans.security.decode_id( payload.get( 'history_id' ), trans.user, current_history=trans.history ) ) else: target_history = trans.history run_config = WorkflowRunConfig( target_history=target_history, replacement_dict=payload.get( 'replacement_params', {} ), copy_inputs_to_history=new_history is not None ) invocation = queue_invoke( trans=trans, workflow=workflow, workflow_run_config=run_config, populate_state=False ) invocations.append({ 'history' : { 'id' : trans.app.security.encode_id( new_history.id ), 'name' : new_history.name } if new_history else None, 'scheduled' : invocation.state == trans.app.model.WorkflowInvocation.states.SCHEDULED }) trans.sa_session.flush() return invocations
def invoke(self, trans, workflow_id, payload, **kwd): """ POST /api/workflows/{encoded_workflow_id}/invocations Schedule the workflow specified by `workflow_id` to run. """ # /usage is awkward in this context but is consistent with the rest of # this module. Would prefer to redo it all to use /invocation(s). # Get workflow + accessibility check. stored_workflow = self.__get_stored_accessible_workflow( trans, workflow_id) workflow = stored_workflow.latest_workflow run_configs = build_workflow_run_configs(trans, workflow, payload) index = 0 thingy = run_configs[0].param_map for key, value in thingy.iteritems(): for key1, val in value.iteritems(): if 'JPCNn681vcGV4KuvuT16' == key1: val = '"' + val + '"' workflow.steps[index].tool_inputs[unicode( 'JPCNn681vcGV4KuvuT16', "utf-8")] = val index = index + 1 is_batch = payload.get('batch') if not is_batch and len(run_configs) != 1: raise exceptions.RequestParameterInvalidException( "Must specify 'batch' to use batch parameters.") invocations = [] for run_config in run_configs: workflow_scheduler_id = payload.get('scheduler', None) # TODO: workflow scheduler hints work_request_params = dict(scheduler=workflow_scheduler_id) workflow_invocation = queue_invoke( trans=trans, workflow=workflow, workflow_run_config=run_config, request_params=work_request_params) invocation = self.encode_all_ids(trans, workflow_invocation.to_dict(), recursive=True) invocations.append(invocation) if is_batch: return invocations else: return invocations[0]
def invoke(self, trans, workflow_id, payload, **kwd): """ POST /api/workflows/{encoded_workflow_id}/invocations Schedule the workflow specified by `workflow_id` to run. """ # /usage is awkward in this context but is consistent with the rest of # this module. Would prefer to redo it all to use /invocation(s). # Get workflow + accessibility check. stored_workflow = self.__get_stored_accessible_workflow(trans, workflow_id) workflow = stored_workflow.latest_workflow run_config = build_workflow_run_config(trans, workflow, payload) workflow_scheduler_id = payload.get("scheduler", None) # TODO: workflow scheduler hints work_request_params = dict(scheduler=workflow_scheduler_id) workflow_invocation = queue_invoke( trans=trans, workflow=workflow, workflow_run_config=run_config, request_params=work_request_params ) return self.encode_all_ids(trans, workflow_invocation.to_dict(), recursive=True)
def run(self, trans, workflow_id, payload, **kwd): """ POST /api_internal/workflows/{encoded_workflow_id}/run Run a workflow with a dictionary of prefixed_name/value pairs e.g. payload = { inputs: { step_0: { parameter_0|parameter_1 : value_0, ... }, ... } } """ workflow = self.__get_stored_accessible_workflow( trans, workflow_id).latest_workflow trans.workflow_building_mode = workflow_building_modes.USE_HISTORY module_injector = WorkflowModuleInjector(trans) params, param_keys = expand_workflow_inputs(payload.get('inputs', [])) errors = {} for workflow_args in params: for step in workflow.steps: step_args = workflow_args.get(str(step.id), {}) step_errors = module_injector.inject(step, step_args) if step_errors: errors[step.id] = step_errors if errors: log.exception(errors) raise exceptions.MessageException(err_data=errors) invocations = [] for index, workflow_args in enumerate(params): for step in workflow.steps: step_args = workflow_args.get(str(step.id), {}) module_injector.inject(step, step_args) new_history = None if 'new_history_name' in payload: if payload['new_history_name']: nh_name = payload['new_history_name'] else: nh_name = 'History from %s workflow' % workflow.name if index in param_keys: ids = param_keys[index] nids = len(ids) if nids == 1: nh_name = '%s on %s' % (nh_name, ids[0]) elif nids > 1: nh_name = '%s on %s and %s' % (nh_name, ', '.join( ids[0:-1]), ids[-1]) new_history = trans.app.model.History(user=trans.user, name=nh_name) new_history.copy_tags_from(trans.user, trans.history) trans.sa_session.add(new_history) target_history = new_history elif 'history_id' in payload: target_history = histories.HistoryManager(trans.app).get_owned( trans.security.decode_id(payload.get('history_id'), trans.user, current_history=trans.history)) else: target_history = trans.history run_config = WorkflowRunConfig(target_history=target_history, replacement_dict=payload.get( 'replacement_params', {}), copy_inputs_to_history=new_history is not None) invocation = queue_invoke(trans=trans, workflow=workflow, workflow_run_config=run_config, populate_state=False) invocations.append({ 'history': { 'id': trans.app.security.encode_id(new_history.id), 'name': new_history.name } if new_history else None, 'scheduled': invocation.state == trans.app.model.WorkflowInvocation.states.SCHEDULED }) trans.sa_session.flush() return invocations