@Test public void testScheduleFlowToExecution() { }
public ExecutionFlow scheduleFlowToExecution(Integer projectId, Integer workflowId, int submitUser, Date scheduleTime, ExecType runType, FailurePolicyType failurePolicyType, Integer maxTryTimes, String nodeName, NodeDepType nodeDep, NotifyType notifyType, List<String> mails, int timeout) throws Exception { logger.info("project id:{}, workflow id:{}, schedule time:{}", projectId, workflowId, scheduleTime); List<FlowNode> flowNodes = flowNodeMapper.selectByFlowId(workflowId); List<FlowNodeRelation> flowNodeRelations = new ArrayList<>(); for (FlowNode flowNode : flowNodes) { String dep = flowNode.getDep(); List<String> depList = JsonUtil.parseObjectList(dep, String.class); if (depList != null) { for (String depNode : depList) { flowNodeRelations.add(new FlowNodeRelation(depNode, flowNode.getName())); } } } ProjectFlow projectFlow = projectFlowMapper.findById(workflowId); FlowDag flowDag = new FlowDag(); flowDag.setEdges(flowNodeRelations); flowDag.setNodes(flowNodes); ExecutionFlow executionFlow = new ExecutionFlow(); Date now = new Date(); executionFlow.setFlowId(workflowId); executionFlow.setSubmitUserId(submitUser); executionFlow.setSubmitTime(now); executionFlow.setQueue(projectFlow.getQueue()); executionFlow.setProxyUser(projectFlow.getProxyUser()); executionFlow.setScheduleTime(scheduleTime); executionFlow.setStartTime(now); if (nodeName != null) { FlowNode flowNode = DagHelper.findNodeByName(flowNodes, nodeName); if (flowNode != null) { switch (nodeDep) { case NODE_POST: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, true); break; case NODE_PRE: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, false); break; case NODE_ONLY: default: flowDag.setEdges(null); flowDag.setNodes(Arrays.asList(flowNode)); } } else { throw new Exception(String.format("node %s not found in flow %d", nodeName, workflowId)); } } executionFlow.setWorkflowData(JsonUtil.toJsonString(flowDag)); executionFlow.setUserDefinedParams(projectFlow.getUserDefinedParams()); executionFlow.setType(runType); executionFlow.setFailurePolicy(failurePolicyType); executionFlow.setMaxTryTimes(maxTryTimes); executionFlow.setNotifyType(notifyType); executionFlow.setNotifyMailList(mails); executionFlow.setTimeout(timeout); executionFlow.setStatus(FlowStatus.INIT); executionFlow.setExtras(projectFlow.getExtras()); executionFlowMapper.insertAndGetId(executionFlow); return executionFlow; }
FlowDao extends BaseDao { public ExecutionFlow scheduleFlowToExecution(Integer projectId, Integer workflowId, int submitUser, Date scheduleTime, ExecType runType, FailurePolicyType failurePolicyType, Integer maxTryTimes, String nodeName, NodeDepType nodeDep, NotifyType notifyType, List<String> mails, int timeout) throws Exception { logger.info("project id:{}, workflow id:{}, schedule time:{}", projectId, workflowId, scheduleTime); List<FlowNode> flowNodes = flowNodeMapper.selectByFlowId(workflowId); List<FlowNodeRelation> flowNodeRelations = new ArrayList<>(); for (FlowNode flowNode : flowNodes) { String dep = flowNode.getDep(); List<String> depList = JsonUtil.parseObjectList(dep, String.class); if (depList != null) { for (String depNode : depList) { flowNodeRelations.add(new FlowNodeRelation(depNode, flowNode.getName())); } } } ProjectFlow projectFlow = projectFlowMapper.findById(workflowId); FlowDag flowDag = new FlowDag(); flowDag.setEdges(flowNodeRelations); flowDag.setNodes(flowNodes); ExecutionFlow executionFlow = new ExecutionFlow(); Date now = new Date(); executionFlow.setFlowId(workflowId); executionFlow.setSubmitUserId(submitUser); executionFlow.setSubmitTime(now); executionFlow.setQueue(projectFlow.getQueue()); executionFlow.setProxyUser(projectFlow.getProxyUser()); executionFlow.setScheduleTime(scheduleTime); executionFlow.setStartTime(now); if (nodeName != null) { FlowNode flowNode = DagHelper.findNodeByName(flowNodes, nodeName); if (flowNode != null) { switch (nodeDep) { case NODE_POST: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, true); break; case NODE_PRE: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, false); break; case NODE_ONLY: default: flowDag.setEdges(null); flowDag.setNodes(Arrays.asList(flowNode)); } } else { throw new Exception(String.format("node %s not found in flow %d", nodeName, workflowId)); } } executionFlow.setWorkflowData(JsonUtil.toJsonString(flowDag)); executionFlow.setUserDefinedParams(projectFlow.getUserDefinedParams()); executionFlow.setType(runType); executionFlow.setFailurePolicy(failurePolicyType); executionFlow.setMaxTryTimes(maxTryTimes); executionFlow.setNotifyType(notifyType); executionFlow.setNotifyMailList(mails); executionFlow.setTimeout(timeout); executionFlow.setStatus(FlowStatus.INIT); executionFlow.setExtras(projectFlow.getExtras()); executionFlowMapper.insertAndGetId(executionFlow); return executionFlow; } }
FlowDao extends BaseDao { public ExecutionFlow scheduleFlowToExecution(Integer projectId, Integer workflowId, int submitUser, Date scheduleTime, ExecType runType, FailurePolicyType failurePolicyType, Integer maxTryTimes, String nodeName, NodeDepType nodeDep, NotifyType notifyType, List<String> mails, int timeout) throws Exception { logger.info("project id:{}, workflow id:{}, schedule time:{}", projectId, workflowId, scheduleTime); List<FlowNode> flowNodes = flowNodeMapper.selectByFlowId(workflowId); List<FlowNodeRelation> flowNodeRelations = new ArrayList<>(); for (FlowNode flowNode : flowNodes) { String dep = flowNode.getDep(); List<String> depList = JsonUtil.parseObjectList(dep, String.class); if (depList != null) { for (String depNode : depList) { flowNodeRelations.add(new FlowNodeRelation(depNode, flowNode.getName())); } } } ProjectFlow projectFlow = projectFlowMapper.findById(workflowId); FlowDag flowDag = new FlowDag(); flowDag.setEdges(flowNodeRelations); flowDag.setNodes(flowNodes); ExecutionFlow executionFlow = new ExecutionFlow(); Date now = new Date(); executionFlow.setFlowId(workflowId); executionFlow.setSubmitUserId(submitUser); executionFlow.setSubmitTime(now); executionFlow.setQueue(projectFlow.getQueue()); executionFlow.setProxyUser(projectFlow.getProxyUser()); executionFlow.setScheduleTime(scheduleTime); executionFlow.setStartTime(now); if (nodeName != null) { FlowNode flowNode = DagHelper.findNodeByName(flowNodes, nodeName); if (flowNode != null) { switch (nodeDep) { case NODE_POST: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, true); break; case NODE_PRE: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, false); break; case NODE_ONLY: default: flowDag.setEdges(null); flowDag.setNodes(Arrays.asList(flowNode)); } } else { throw new Exception(String.format("node %s not found in flow %d", nodeName, workflowId)); } } executionFlow.setWorkflowData(JsonUtil.toJsonString(flowDag)); executionFlow.setUserDefinedParams(projectFlow.getUserDefinedParams()); executionFlow.setType(runType); executionFlow.setFailurePolicy(failurePolicyType); executionFlow.setMaxTryTimes(maxTryTimes); executionFlow.setNotifyType(notifyType); executionFlow.setNotifyMailList(mails); executionFlow.setTimeout(timeout); executionFlow.setStatus(FlowStatus.INIT); executionFlow.setExtras(projectFlow.getExtras()); executionFlowMapper.insertAndGetId(executionFlow); return executionFlow; }  }
FlowDao extends BaseDao { public ExecutionFlow scheduleFlowToExecution(Integer projectId, Integer workflowId, int submitUser, Date scheduleTime, ExecType runType, FailurePolicyType failurePolicyType, Integer maxTryTimes, String nodeName, NodeDepType nodeDep, NotifyType notifyType, List<String> mails, int timeout) throws Exception { logger.info("project id:{}, workflow id:{}, schedule time:{}", projectId, workflowId, scheduleTime); List<FlowNode> flowNodes = flowNodeMapper.selectByFlowId(workflowId); List<FlowNodeRelation> flowNodeRelations = new ArrayList<>(); for (FlowNode flowNode : flowNodes) { String dep = flowNode.getDep(); List<String> depList = JsonUtil.parseObjectList(dep, String.class); if (depList != null) { for (String depNode : depList) { flowNodeRelations.add(new FlowNodeRelation(depNode, flowNode.getName())); } } } ProjectFlow projectFlow = projectFlowMapper.findById(workflowId); FlowDag flowDag = new FlowDag(); flowDag.setEdges(flowNodeRelations); flowDag.setNodes(flowNodes); ExecutionFlow executionFlow = new ExecutionFlow(); Date now = new Date(); executionFlow.setFlowId(workflowId); executionFlow.setSubmitUserId(submitUser); executionFlow.setSubmitTime(now); executionFlow.setQueue(projectFlow.getQueue()); executionFlow.setProxyUser(projectFlow.getProxyUser()); executionFlow.setScheduleTime(scheduleTime); executionFlow.setStartTime(now); if (nodeName != null) { FlowNode flowNode = DagHelper.findNodeByName(flowNodes, nodeName); if (flowNode != null) { switch (nodeDep) { case NODE_POST: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, true); break; case NODE_PRE: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, false); break; case NODE_ONLY: default: flowDag.setEdges(null); flowDag.setNodes(Arrays.asList(flowNode)); } } else { throw new Exception(String.format("node %s not found in flow %d", nodeName, workflowId)); } } executionFlow.setWorkflowData(JsonUtil.toJsonString(flowDag)); executionFlow.setUserDefinedParams(projectFlow.getUserDefinedParams()); executionFlow.setType(runType); executionFlow.setFailurePolicy(failurePolicyType); executionFlow.setMaxTryTimes(maxTryTimes); executionFlow.setNotifyType(notifyType); executionFlow.setNotifyMailList(mails); executionFlow.setTimeout(timeout); executionFlow.setStatus(FlowStatus.INIT); executionFlow.setExtras(projectFlow.getExtras()); executionFlowMapper.insertAndGetId(executionFlow); return executionFlow; }  ExecutionFlow queryExecutionFlow(int execId); int deleteExecutionNodes(int execId); List<ExecutionFlow> queryAllNoFinishFlow(); List<ExecutionFlow> queryNoFinishFlow(String worker); ExecutionFlow queryExecutionFlowByScheduleTime(int flowId, Date scheduleTime); boolean updateExecutionFlowStatus(int execId, FlowStatus status); boolean updateExecutionFlowStatus(int execId, FlowStatus status, String worker); boolean updateExecutionFlow(ExecutionFlow executionFlow); boolean updateExecutionFlowDataSub(ExecutionFlow executionFlow); ExecutionFlow scheduleFlowToExecution(Integer projectId,
      Integer workflowId,
      int submitUser,
      Date scheduleTime,
      ExecType runType,
      FailurePolicyType failurePolicyType,
      Integer maxTryTimes,
      String nodeName,
      NodeDepType nodeDep,
      NotifyType notifyType,
      List<String> mails,
      int timeout); @Transactional(value = "TransactionManager") void deleteWorkflow(int workflowId); void insertExecutionNode(ExecutionNode executionNode); void updateExecutionNode(ExecutionNode executionNode); ExecutionNode queryExecutionNode(long execId, String nodeName); Schedule querySchedule(int flowId); ProjectFlow projectFlowfindByName(int projectId, String name); ProjectFlow projectFlowFindById(int id); @Transactional(value = "TransactionManager", rollbackFor = Exception.class) void createProjectFlow(ProjectFlow projectFlow); @Transactional(value = "TransactionManager", rollbackFor = Exception.class) void modifyProjectFlow(ProjectFlow projectFlow); ProjectFlow projectFlowFindByPorjectNameAndName(String projectName, String name); List<ProjectFlow> projectFlowFindByProject(int projectId); ExecutionFlow executionFlowPreDate(int flowId, Date date); ExecutionFlow executionFlowPreDate2(int flowId, Date date); ExecutionFlow executionFlowByStartTimeAndScheduleTime(int flowId, Date startTIme,
      Date scheduleTime); }
FlowDao extends BaseDao { public ExecutionFlow scheduleFlowToExecution(Integer projectId, Integer workflowId, int submitUser, Date scheduleTime, ExecType runType, FailurePolicyType failurePolicyType, Integer maxTryTimes, String nodeName, NodeDepType nodeDep, NotifyType notifyType, List<String> mails, int timeout) throws Exception { logger.info("project id:{}, workflow id:{}, schedule time:{}", projectId, workflowId, scheduleTime); List<FlowNode> flowNodes = flowNodeMapper.selectByFlowId(workflowId); List<FlowNodeRelation> flowNodeRelations = new ArrayList<>(); for (FlowNode flowNode : flowNodes) { String dep = flowNode.getDep(); List<String> depList = JsonUtil.parseObjectList(dep, String.class); if (depList != null) { for (String depNode : depList) { flowNodeRelations.add(new FlowNodeRelation(depNode, flowNode.getName())); } } } ProjectFlow projectFlow = projectFlowMapper.findById(workflowId); FlowDag flowDag = new FlowDag(); flowDag.setEdges(flowNodeRelations); flowDag.setNodes(flowNodes); ExecutionFlow executionFlow = new ExecutionFlow(); Date now = new Date(); executionFlow.setFlowId(workflowId); executionFlow.setSubmitUserId(submitUser); executionFlow.setSubmitTime(now); executionFlow.setQueue(projectFlow.getQueue()); executionFlow.setProxyUser(projectFlow.getProxyUser()); executionFlow.setScheduleTime(scheduleTime); executionFlow.setStartTime(now); if (nodeName != null) { FlowNode flowNode = DagHelper.findNodeByName(flowNodes, nodeName); if (flowNode != null) { switch (nodeDep) { case NODE_POST: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, true); break; case NODE_PRE: flowDag = DagHelper.findNodeDepDag(flowDag, flowNode, false); break; case NODE_ONLY: default: flowDag.setEdges(null); flowDag.setNodes(Arrays.asList(flowNode)); } } else { throw new Exception(String.format("node %s not found in flow %d", nodeName, workflowId)); } } executionFlow.setWorkflowData(JsonUtil.toJsonString(flowDag)); executionFlow.setUserDefinedParams(projectFlow.getUserDefinedParams()); executionFlow.setType(runType); executionFlow.setFailurePolicy(failurePolicyType); executionFlow.setMaxTryTimes(maxTryTimes); executionFlow.setNotifyType(notifyType); executionFlow.setNotifyMailList(mails); executionFlow.setTimeout(timeout); executionFlow.setStatus(FlowStatus.INIT); executionFlow.setExtras(projectFlow.getExtras()); executionFlowMapper.insertAndGetId(executionFlow); return executionFlow; }  ExecutionFlow queryExecutionFlow(int execId); int deleteExecutionNodes(int execId); List<ExecutionFlow> queryAllNoFinishFlow(); List<ExecutionFlow> queryNoFinishFlow(String worker); ExecutionFlow queryExecutionFlowByScheduleTime(int flowId, Date scheduleTime); boolean updateExecutionFlowStatus(int execId, FlowStatus status); boolean updateExecutionFlowStatus(int execId, FlowStatus status, String worker); boolean updateExecutionFlow(ExecutionFlow executionFlow); boolean updateExecutionFlowDataSub(ExecutionFlow executionFlow); ExecutionFlow scheduleFlowToExecution(Integer projectId,
      Integer workflowId,
      int submitUser,
      Date scheduleTime,
      ExecType runType,
      FailurePolicyType failurePolicyType,
      Integer maxTryTimes,
      String nodeName,
      NodeDepType nodeDep,
      NotifyType notifyType,
      List<String> mails,
      int timeout); @Transactional(value = "TransactionManager") void deleteWorkflow(int workflowId); void insertExecutionNode(ExecutionNode executionNode); void updateExecutionNode(ExecutionNode executionNode); ExecutionNode queryExecutionNode(long execId, String nodeName); Schedule querySchedule(int flowId); ProjectFlow projectFlowfindByName(int projectId, String name); ProjectFlow projectFlowFindById(int id); @Transactional(value = "TransactionManager", rollbackFor = Exception.class) void createProjectFlow(ProjectFlow projectFlow); @Transactional(value = "TransactionManager", rollbackFor = Exception.class) void modifyProjectFlow(ProjectFlow projectFlow); ProjectFlow projectFlowFindByPorjectNameAndName(String projectName, String name); List<ProjectFlow> projectFlowFindByProject(int projectId); ExecutionFlow executionFlowPreDate(int flowId, Date date); ExecutionFlow executionFlowPreDate2(int flowId, Date date); ExecutionFlow executionFlowByStartTimeAndScheduleTime(int flowId, Date startTIme,
      Date scheduleTime);  }