Creates a new workflow in the data store

@param workflow the workflow to be created
@return the id of the created workflow
516683
public String createWorkflow(Workflow workflow) {
        executionDAO.createWorkflow(workflow);
        indexDAO.indexWorkflow(workflow);
        return workflow.getWorkflowId();
    }
84602
@PUT
    @Path("/resume")
    @ApiOperation("Resume the list of workflows")
    public BulkResponse resumeWorkflow(List<String> workflowIds)  {
        return workflowBulkService.resumeWorkflow(workflowIds);
    }
435837
def start_workflow(flow)
      @http.post(
        instance_worker_url,
        ATTR_PROG => PROG,
        ATTR_CANONICAL => canonical_name(flow),
        ATTR_NAME => class_name(flow),
        ATTR_DATA => @serializer.encode(@properties.from(flow)),
        ATTR_ID => parse_custom_id_from(flow)
      )
    end
1090946
public WorkflowDef getWorkflowDef(String name, Integer version) {
        Preconditions.checkArgument(StringUtils.isNotBlank(name), "name cannot be blank");
        return getForEntity("metadata/workflow/{name}", new Object[]{"version", version}, WorkflowDef.class, name);
    }
30148
public DeciderOutcome decide(Workflow workflow) throws TerminateWorkflowException {

        //In case of a new workflow the list of tasks will be empty.
        final List<Task> tasks = workflow.getTasks();
        // Filter the list of tasks and include only tasks that are not executed,
        // not marked to be skipped and not ready for rerun.
        // For a new workflow, the list of unprocessedTasks will be empty
        List<Task> unprocessedTasks = tasks.stream()
                .filter(t -> !t.getStatus().equals(SKIPPED) && !t.getStatus().equals(READY_FOR_RERUN) && !t.isExecuted())
                .collect(Collectors.toList());

        List<Task> tasksToBeScheduled = new LinkedList<>();
        if (unprocessedTasks.isEmpty()) {
            //this is the flow that the new workflow will go through
            tasksToBeScheduled = startWorkflow(workflow);
            if (tasksToBeScheduled == null) {
                tasksToBeScheduled = new LinkedList<>();
            }
        }
        return decide(workflow, tasksToBeScheduled);
    }
1060934
def commit_workflow(self, workflow_id):
        
        # TODO: We should also be committing the Stream definitions if there are new ones

        workflow = self.workflows[workflow_id]

        with switch_db(WorkflowDefinitionModel, "hyperstream"):
            workflows = WorkflowDefinitionModel.objects(workflow_id=workflow_id)
            if len(workflows) > 0:
                logging.warn("Workflow with id {} already exists in database".format(workflow_id))
                return

            factors = []
            for f in workflow.factors:
                tool = f.tool.get_model()

                if isinstance(f, Factor):
                    sources = [s.node_id for s in f.sources] if f.sources else []
                    sinks = [f.sink.node_id]
                    alignment_node = f.alignment_node.node_id if f.alignment_node else None
                    splitting_node = None
                    output_plate = None

                elif isinstance(f, MultiOutputFactor):
                    sources = [f.source.node_id] if f.source else []
                    sinks = [f.sink.node_id]
                    alignment_node = None
                    splitting_node = f.splitting_node.node_id if f.splitting_node else None
                    output_plate = None

                elif isinstance(f, NodeCreationFactor):
                    sources = [f.source.node_id] if f.source else []
                    sinks = []
                    alignment_node = None
                    splitting_node = None
                    output_plate = f.output_plate

                else:
                    raise NotImplementedError("Unsupported factor type")

                if output_plate:
                    output_plate_copy = deepcopy(output_plate)
                    if 'parent_plate' in output_plate_copy:
                        del output_plate_copy['parent_plate']
                else:
                    output_plate_copy = None

                factor = FactorDefinitionModel(
                    tool=tool,
                    factor_type=f.__class__.__name__,
                    sources=sources,
                    sinks=sinks,
                    alignment_node=alignment_node,
                    splitting_node=splitting_node,
                    output_plate=output_plate_copy
                )

                factors.append(factor)

            nodes = []
            for n in workflow.nodes.values():
                nodes.append(NodeDefinitionModel(
                    stream_name=n.node_id,
                    plate_ids=n.plate_ids,
                    channel_id=n._channel.channel_id
                ))

            workflow_definition = WorkflowDefinitionModel(
                workflow_id=workflow.workflow_id,
                name=workflow.name,
                description=workflow.description,
                nodes=nodes,
                factors=factors,
                owner=workflow.owner,
                online=workflow.online,
                monitor=workflow.monitor
            )

            workflow_definition.save()

        with switch_db(WorkflowStatusModel, db_alias='hyperstream'):
            workflow_status = WorkflowStatusModel(
                workflow_id=workflow.workflow_id,
                last_updated=utcnow(),
                last_accessed=utcnow(),
                requested_intervals=[]
            )

            workflow_status.save()

        self.uncommitted_workflows.remove(workflow_id)
        logging.info("Committed workflow {} to database".format(workflow_id))
274628
private void setLastWorkflowForUser(String workflowId) throws CmsException {

        CmsUser user = getCmsObject().getRequestContext().getCurrentUser();
        user.setAdditionalInfo(PARAM_WORKFLOW_ID, workflowId);
        getCmsObject().writeUser(user);
    }
423203
public void setWorkflowState(java.util.Collection<StringFilter> workflowState) {
        if (workflowState == null) {
            this.workflowState = null;
            return;
        }

        this.workflowState = new java.util.ArrayList<StringFilter>(workflowState);
    }
677032
public static Flow create() {
        return new Flow(ID_GENERATOR.updateAndGet(i -> i == Integer.MAX_VALUE ? 0 : i + 1), 0);
    }
79130
@Service
    public List<String> getRunningWorkflows(String workflowName, Integer version,
                                            Long startTime, Long endTime) {
        if (Optional.ofNullable(startTime).orElse(0l) != 0 && Optional.ofNullable(endTime).orElse(0l) != 0) {
            return workflowExecutor.getWorkflows(workflowName, version, startTime, endTime);
        } else {
            return workflowExecutor.getRunningWorkflowIds(workflowName);
        }
    }
1177776
def register_workflow(self, name, workflow):
        """"""
        assert name not in self.workflows
        self.workflows[name] = workflow
1084209
public Flow<Flow<T>> getOrCreateFlow()
   {
      List<Node> nodeList = childNode.get("flow");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new FlowImpl<Flow<T>>(this, "flow", childNode, nodeList.get(0));
      }
      return createFlow();
   }
706512
public String rerunWorkflow(String workflowId, RerunWorkflowRequest rerunWorkflowRequest) {
        Preconditions.checkArgument(StringUtils.isNotBlank(workflowId), "workflow id cannot be blank");
        Preconditions.checkNotNull(rerunWorkflowRequest, "RerunWorkflowRequest cannot be null");

        return postForEntity("workflow/{workflowId}/rerun", rerunWorkflowRequest, null, String.class, workflowId);
    }
330747
public Flow<JobXMLDescriptor> getOrCreateFlow()
   {
      List<Node> nodeList = model.get("flow");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new FlowImpl<JobXMLDescriptor>(this, "flow", model, nodeList.get(0));
      }
      return createFlow();
   }
814341
private WorkflowInstanceRestModel createInstanceModel( WorkflowInstanceState woin ){
        return new WorkflowInstanceRestModel( woin.getRefNum(),
                woin.getWorkflowName(),
                woin.getWorkflowVersion(),
                woin.getLabel1(),
                woin.getLabel2(),
                WorkflowInstanceStatus.valueOf( woin.getStatus() ) );
    }
71703
public void retryLastFailedTask(String workflowId) {
        Preconditions.checkArgument(StringUtils.isNotBlank(workflowId), "workflow id cannot be blank");
        stub.retryWorkflow(WorkflowServicePb.RetryWorkflowRequest.newBuilder()
                .setWorkflowId(workflowId)
                .build()
        );
    }
227806
def workflow_start(obj, queue, keep_data, name, workflow_args):
    
    try:
        start_workflow(name=name,
                       config=obj['config'],
                       queue=queue,
                       clear_data_store=not keep_data,
                       store_args=dict([arg.split('=', maxsplit=1)
                                        for arg in workflow_args]))
    except (WorkflowArgumentError, WorkflowImportError) as e:
        click.echo(_style(obj['show_color'],
                          'An error occurred when trying to start the workflow',
                          fg='red', bold=True))
        click.echo('{}'.format(e))
    except WorkflowDefinitionError as e:
        click.echo(_style(obj['show_color'],
                          'The graph {} in workflow {} is not a directed acyclic graph'.
                          format(e.graph_name, e.workflow_name), fg='red', bold=True))