Commit 77c28447 by huangfusuper

增加节点保存删除已加载实例功能

parent a2c9fc23
...@@ -9,10 +9,6 @@ public interface ApiNodeCheckService { ...@@ -9,10 +9,6 @@ public interface ApiNodeCheckService {
* 工作流校验 * 工作流校验
* @param mainFlowId 主工作流的id * @param mainFlowId 主工作流的id
*/ */
void checkFlowNode(Integer mainFlowId); int checkFlowNode(Integer mainFlowId);
/**
* 工作流节点校验 删除不在调度上的节点
*/
int checkFlowNode();
} }
...@@ -133,7 +133,7 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -133,7 +133,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
log.debug("生成版本"); log.debug("生成版本");
FlowVersion flowVersion = saveFlowVersion(flow); FlowVersion flowVersion = saveFlowVersion(flow);
int checkFlowNode = apiNodeCheckService.checkFlowNode(); int checkFlowNode = apiNodeCheckService.checkFlowNode(flow.getFlowId());
log.warn("-------删除错误节点{}个--------",checkFlowNode); log.warn("-------删除错误节点{}个--------",checkFlowNode);
log.debug("插件端通过API保存成功!"); log.debug("插件端通过API保存成功!");
} }
......
package com.byit.service.impl; package com.byit.service.impl;
import com.byit.model.Node; import cn.hutool.core.collection.CollectionUtil;
import com.byit.model.vo.FlowVo; import com.byit.enums.DagCheckEnum;
import com.byit.service.ApiNodeCheckService; import com.byit.model.RunRecording;
import com.byit.service.FlowService; import com.byit.service.*;
import com.byit.service.NodeService; import com.byit.utils.ValidationUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author huangfu * @author huangfu
...@@ -21,54 +19,44 @@ import java.util.stream.Collectors; ...@@ -21,54 +19,44 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class ApiNodeCheckServiceImpl implements ApiNodeCheckService { public class ApiNodeCheckServiceImpl implements ApiNodeCheckService {
private final NodeService nodeService; private final NodeService nodeService;
private final FlowService flowService; private final JobTaskService jobTaskService;
private final RunRecordingService runRecordingService;
public ApiNodeCheckServiceImpl(NodeService nodeService, FlowService flowService) { public ApiNodeCheckServiceImpl(NodeService nodeService, JobTaskService jobTaskService, RunRecordingService runRecordingService) {
this.nodeService = nodeService; this.nodeService = nodeService;
this.flowService = flowService; this.jobTaskService = jobTaskService;
this.runRecordingService = runRecordingService;
} }
/** /**
* 废弃原因:查询次数多,性能低
* @param mainFlowId 主工作流的id * @param mainFlowId 主工作流的id
*/ */
@Override @Override
@Deprecated public int checkFlowNode(Integer mainFlowId) {
public void checkFlowNode(Integer mainFlowId) { //查询实例表
//查询工作流 List<RunRecording> runRecordingByFlowId = runRecordingService.findRunRecordingByFlowId(mainFlowId);
FlowVo mainFlow = flowService.getFlowId(mainFlowId); log.debug("--------{}下有{}个实例------------",mainFlowId,runRecordingByFlowId.size());
String flowVersionName = mainFlow.getVersionName(); //检查是否有运行中的
//基于主工作流查询所有的节点 boolean runRecordingIsRunning = runRecordingService.findRunRecordingIsRunning(mainFlowId);
List<Node> mainNode = nodeService.findNodeByFlowIdAndVersionName(mainFlowId); ValidationUtil.isTrueValidation(runRecordingIsRunning, "当前工作流正在运行不允许重新发布!");
//迭代获取所有的虚节点 if(CollectionUtil.isNotEmpty(runRecordingByFlowId)){
List<Node> allNodes = new ArrayList<>(); RunRecording runRecording = runRecordingByFlowId.stream().filter(recording -> {
getAllInnerNode(mainNode,allNodes); boolean isFlow = "1".equals(recording.getFlowStatus());
//筛选版本号不一致的 boolean isType = 1 == recording.getScheduleType();
List<Node> errorNode = allNodes.stream().filter(node -> { return isFlow && isType;
String nodeVersionName = node.getVersionName(); }).findFirst().orElse(null);
return !flowVersionName.equals(nodeVersionName); if(runRecording != null) {
}).collect(Collectors.toList()); String runId = runRecording.getRunId();
List<Integer> collect = errorNode.stream().map(Node::getNodeId).collect(Collectors.toList()); //根据runID删除实例
log.warn("-------删除错误节点{}个--------",collect.size()); int deleteRunId = runRecordingService.deleteRunId(runId);
nodeService.deleteNode(collect); log.info("-----删除已经被加载的实例{}个------",deleteRunId);
} //根据runID删除任务表
int removeByRunId = jobTaskService.removeByRunId(runId);
log.info("-----删除已经被加载的任务{}个------",removeByRunId);
}
}
/**
* 删除不在调度上的节点
*/
@Override
public int checkFlowNode() {
return nodeService.deleteNoForkNode(); return nodeService.deleteNoForkNode();
} }
private void getAllInnerNode(List<Node> mainNodes,List<Node> candidateNodes){
for (Node node : mainNodes) {
if("1".equals(node.getIsVirtual())) {
candidateNodes.add(node);
}else{
List<Node> mainNode = nodeService.findNodeByFlowIdAndVersionName(node.getMapFlowId());
getAllInnerNode(mainNode,candidateNodes);
}
}
}
} }
...@@ -58,5 +58,5 @@ public interface JobTaskService { ...@@ -58,5 +58,5 @@ public interface JobTaskService {
void deleteInIds(List<Integer> ids); void deleteInIds(List<Integer> ids);
void removeByRunId(String runId); int removeByRunId(String runId);
} }
...@@ -68,6 +68,13 @@ public interface RunRecordingService { ...@@ -68,6 +68,13 @@ public interface RunRecordingService {
boolean findRunRecordingIsRunning(Integer flowId); boolean findRunRecordingIsRunning(Integer flowId);
/** /**
* 工作流ID
* @param flowId 工作流ID
* @return 该工作流下的所由实例
*/
List<RunRecording> findRunRecordingByFlowId(Integer flowId);
/**
* 这个方法是会根据任务流的id和运行标识找到唯一对应的一个任务流,这个任务流就是一个虚拟节点 * 这个方法是会根据任务流的id和运行标识找到唯一对应的一个任务流,这个任务流就是一个虚拟节点
* @param flowId * @param flowId
* @param runId * @param runId
...@@ -108,5 +115,7 @@ public interface RunRecordingService { ...@@ -108,5 +115,7 @@ public interface RunRecordingService {
*/ */
int deleteById(Integer recordingId); int deleteById(Integer recordingId);
int deleteRunId(String runId);
} }
\ No newline at end of file
...@@ -91,7 +91,7 @@ public class JobTaskServiceImpl implements JobTaskService { ...@@ -91,7 +91,7 @@ public class JobTaskServiceImpl implements JobTaskService {
} }
@Override @Override
public void removeByRunId(String runId) { public int removeByRunId(String runId) {
jobTaskMapper.deleteByRunId(runId); return jobTaskMapper.deleteByRunId(runId);
} }
} }
package com.byit.service.impl; package com.byit.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.byit.dto.FlowConditionDto; import com.byit.dto.FlowConditionDto;
import com.byit.dto.StatisticsConditionDto; import com.byit.dto.StatisticsConditionDto;
import com.byit.enums.RunRecordingEnum; import com.byit.enums.RunRecordingEnum;
...@@ -106,18 +107,25 @@ public class RunRecordingServiceImpl implements RunRecordingService { ...@@ -106,18 +107,25 @@ public class RunRecordingServiceImpl implements RunRecordingService {
@Override @Override
public boolean findRunRecordingIsRunning(Integer flowId) { public boolean findRunRecordingIsRunning(Integer flowId) {
List<RunRecording> runRecordings = runRecordingMapper.findRunRecordingByFlowId(flowId); List<RunRecording> runRecordings = runRecordingMapper.findRunRecordingByFlowId(flowId);
for (RunRecording runRecording : runRecordings) { if(CollectionUtil.isNotEmpty(runRecordings)) {
//判断当前的实例 中是否有 未完成的 for (RunRecording runRecording : runRecordings) {
if (RunRecordingEnum.FLOW_STATUS_RUN_ING.getCode().equals(runRecording.getFlowStatus()) || //判断当前的实例 中是否有 未完成的
RunRecordingEnum.FLOW_STATUS_IS_STOP.getCode().equals(runRecording.getFlowStatus())) { if (RunRecordingEnum.FLOW_STATUS_RUN_ING.getCode().equals(runRecording.getFlowStatus()) ||
log.debug("----------{}实例正在运行中--------",runRecording); RunRecordingEnum.FLOW_STATUS_IS_STOP.getCode().equals(runRecording.getFlowStatus())) {
return true; log.debug("----------{}实例正在运行中--------",runRecording);
} return true;
} }
}
}
return false; return false;
} }
@Override @Override
public List<RunRecording> findRunRecordingByFlowId(Integer flowId) {
return runRecordingMapper.findRunRecordingByFlowId(flowId);
}
@Override
public RunRecording findRunRecordingByFlowIdAndRunId(Integer flowId, String runId) { public RunRecording findRunRecordingByFlowIdAndRunId(Integer flowId, String runId) {
return runRecordingMapper.findRunRecordingByFlowIdAndRunId(flowId,runId); return runRecordingMapper.findRunRecordingByFlowIdAndRunId(flowId,runId);
} }
...@@ -146,4 +154,9 @@ public class RunRecordingServiceImpl implements RunRecordingService { ...@@ -146,4 +154,9 @@ public class RunRecordingServiceImpl implements RunRecordingService {
public int deleteById(Integer recordingId) { public int deleteById(Integer recordingId) {
return runRecordingMapper.deleteById(recordingId); return runRecordingMapper.deleteById(recordingId);
} }
@Override
public int deleteRunId(String runId) {
return runRecordingMapper.deleteByRunId(runId);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment