def workflow_run_config_to_request(trans, run_config, workflow): param_types = model.WorkflowRequestInputParameter.types workflow_invocation = model.WorkflowInvocation() workflow_invocation.uuid = uuid.uuid1() workflow_invocation.history = run_config.target_history def add_parameter(name, value, type): parameter = model.WorkflowRequestInputParameter( name=name, value=value, type=type, ) workflow_invocation.input_parameters.append(parameter) replacement_dict = run_config.replacement_dict for name, value in replacement_dict.iteritems(): add_parameter( name=name, value=value, type=param_types.REPLACEMENT_PARAMETERS, ) for step_id, content in run_config.inputs.iteritems(): if content.history_content_type == "dataset": request_to_content = model.WorkflowRequestToInputDatasetAssociation( ) request_to_content.dataset = content request_to_content.workflow_step_id = step_id workflow_invocation.input_datasets.append(request_to_content) else: request_to_content = model.WorkflowRequestToInputDatasetCollectionAssociation( ) request_to_content.dataset_collection = content request_to_content.workflow_step_id = step_id workflow_invocation.input_dataset_collections.append( request_to_content) for step in workflow.steps: state = step.state serializable_runtime_state = step.module.normalize_runtime_state(state) step_state = model.WorkflowRequestStepState() step_state.workflow_step_id = step.id step_state.value = serializable_runtime_state workflow_invocation.step_states.append(step_state) add_parameter("copy_inputs_to_history", "true" if run_config.copy_inputs_to_history else "false", param_types.META_PARAMETERS) return workflow_invocation
def test_workflows(self): model = self.model user = model.User( email="*****@*****.**", password="******" ) def workflow_from_steps(steps): stored_workflow = model.StoredWorkflow() stored_workflow.user = user workflow = model.Workflow() workflow.steps = steps workflow.stored_workflow = stored_workflow return workflow child_workflow = workflow_from_steps([]) self.persist(child_workflow) workflow_step_1 = model.WorkflowStep() workflow_step_1.order_index = 0 workflow_step_1.type = "data_input" workflow_step_2 = model.WorkflowStep() workflow_step_2.order_index = 1 workflow_step_2.type = "subworkflow" workflow_step_2.subworkflow = child_workflow workflow_step_1.get_or_add_input("moo1") workflow_step_1.get_or_add_input("moo2") workflow_step_2.get_or_add_input("moo") workflow_step_1.add_connection("foo", "cow", workflow_step_2) workflow = workflow_from_steps([workflow_step_1, workflow_step_2]) self.persist(workflow) workflow_id = workflow.id annotation = model.WorkflowStepAnnotationAssociation() annotation.annotation = "Test Step Annotation" annotation.user = user annotation.workflow_step = workflow_step_1 self.persist(annotation) assert workflow_step_1.id is not None h1 = model.History(name="WorkflowHistory1", user=user) invocation_uuid = uuid.uuid1() workflow_invocation = model.WorkflowInvocation() workflow_invocation.uuid = invocation_uuid workflow_invocation.history = h1 workflow_invocation_step1 = model.WorkflowInvocationStep() workflow_invocation_step1.workflow_invocation = workflow_invocation workflow_invocation_step1.workflow_step = workflow_step_1 subworkflow_invocation = model.WorkflowInvocation() workflow_invocation.attach_subworkflow_invocation_for_step(workflow_step_2, subworkflow_invocation) workflow_invocation_step2 = model.WorkflowInvocationStep() workflow_invocation_step2.workflow_invocation = workflow_invocation workflow_invocation_step2.workflow_step = workflow_step_2 workflow_invocation.workflow = workflow d1 = self.new_hda(h1, name="1") workflow_request_dataset = model.WorkflowRequestToInputDatasetAssociation() workflow_request_dataset.workflow_invocation = workflow_invocation workflow_request_dataset.workflow_step = workflow_step_1 workflow_request_dataset.dataset = d1 self.persist(workflow_invocation) assert workflow_request_dataset is not None assert workflow_invocation.id is not None history_id = h1.id self.expunge() loaded_invocation = self.query(model.WorkflowInvocation).get(workflow_invocation.id) assert loaded_invocation.uuid == invocation_uuid, "%s != %s" % (loaded_invocation.uuid, invocation_uuid) assert loaded_invocation assert loaded_invocation.history.id == history_id step_1, step_2 = loaded_invocation.workflow.steps assert not step_1.subworkflow assert step_2.subworkflow assert len(loaded_invocation.steps) == 2 subworkflow_invocation_assoc = loaded_invocation.get_subworkflow_invocation_association_for_step(step_2) assert subworkflow_invocation_assoc is not None assert isinstance(subworkflow_invocation_assoc.subworkflow_invocation, model.WorkflowInvocation) assert isinstance(subworkflow_invocation_assoc.parent_workflow_invocation, model.WorkflowInvocation) assert subworkflow_invocation_assoc.subworkflow_invocation.history.id == history_id loaded_workflow = self.query(model.Workflow).get(workflow_id) assert len(loaded_workflow.steps[0].annotations) == 1 copied_workflow = loaded_workflow.copy(user=user) annotations = copied_workflow.steps[0].annotations assert len(annotations) == 1