Commit ea296dda by guominglei

插件端保存工作流修改

parent 0c38bcbb
......@@ -26,8 +26,8 @@ public class ApiFlowController {
@PostMapping("publish")
@ApiOperation("发布工作流,并开始调度")
public String publishFlow(@RequestBody PluginPackage pluginPackage) throws Exception {
apiFlowService.publishFlow(pluginPackage);
public String publishFlow(String param) throws Exception {
apiFlowService.publishFlow(param);
return "SUCCESS";
}
......
package com.byit.service;
import com.byit.job.dto.plugin.PluginFlow;
import com.byit.job.dto.plugin.PluginPackage;
/**
* @description: 工作流的api请求业务处理接口
......@@ -22,7 +21,7 @@ public interface ApiFlowService {
void reStartSchedule(String runId);
void publishFlow(PluginPackage pluginPackage) throws Exception;
void publishFlow(String param) throws Exception;
/**
* 判断工作流石佛存在
......
package com.byit.service.impl;
import com.alibaba.fastjson.JSON;
import com.byit.enums.DagCheckEnum;
import com.byit.enums.FlowPropertyEnum;
import com.byit.enums.NodePropertyEnum;
......@@ -62,7 +63,10 @@ public class ApiFlowServiceImpl implements ApiFlowService {
@Override
@Transactional(rollbackFor = Exception.class)
public void publishFlow(PluginPackage pluginPackage) throws Exception {
public void publishFlow(String param) throws Exception {
PluginPackage pluginPackage = JSON.parseObject(param, PluginPackage.class);
//校验参数
log.info("校验参数是否符合规范");
Workspace workspace = validate(pluginPackage);
......@@ -115,7 +119,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
if (pluginFlow.isRePublish()){
Flow oldFlow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName());
String version = oldFlow.getVersionName();
Integer versionTag = Integer.valueOf(version.split(".")[1]);
Integer versionTag = Integer.valueOf(version.split("\\.")[1]);
flow.setFlowId(oldFlow.getFlowId());
flow.setVersionName("V." + (versionTag + 1));
flowMapper.updateByIdSelective(flow);
......@@ -256,13 +260,15 @@ public class ApiFlowServiceImpl implements ApiFlowService {
*/
public void buildDepend(List<PluginBaseNode> nodeList, HashMap<String, Integer> nameIdRel){
for (PluginBaseNode pluginNode : nodeList){
pluginNode.getDependNodeNameList().forEach(dependNodeName -> {
Integer nodeId = nameIdRel.get(pluginNode.getName());
Integer dependNodeId = nameIdRel.get(dependNodeName);
ValidationUtil.isTrueValidation(null == nodeId , pluginNode.getName() + "节点不存在!");
ValidationUtil.isTrueValidation(null == dependNodeId , "依赖的节点" + dependNodeName + "不存在!");
nodeDependencyMapper.insert(nodeId, dependNodeId);
});
if (null != pluginNode.getDependNodeNameList() && pluginNode.getDependNodeNameList().size() > 0){
pluginNode.getDependNodeNameList().forEach(dependNodeName -> {
Integer nodeId = nameIdRel.get(pluginNode.getName());
Integer dependNodeId = nameIdRel.get(dependNodeName);
ValidationUtil.isTrueValidation(null == nodeId , pluginNode.getName() + "节点不存在!");
ValidationUtil.isTrueValidation(null == dependNodeId , "依赖的节点" + dependNodeName + "不存在!");
nodeDependencyMapper.insert(nodeId, dependNodeId);
});
}
}
}
......@@ -295,7 +301,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
flowDagCheck.initDag(flowNameSet, fromFlowSet, toFlowSet, lineMap);
//校验是否存在环路
DagCheckEnum loopCheck = flowDagCheck.checkDag();
ValidationUtil.isTrueValidation(DagCheckEnum.PASS.getCode().equals(loopCheck.getCode()), loopCheck.getMsg());
ValidationUtil.isTrueValidation(!DagCheckEnum.PASS.getCode().equals(loopCheck.getCode()), loopCheck.getMsg());
return workspace;
}
......@@ -345,16 +351,16 @@ public class ApiFlowServiceImpl implements ApiFlowService {
nodeDagCheck.initDag(nodeList);
//校验开始节点名称
DagCheckEnum checkStart = nodeDagCheck.checkStart();
ValidationUtil.isTrueValidation(DagCheckEnum.PASS.getCode().equals(checkStart.getCode()), checkStart.getCode() == 0 ? checkStart.getMsg() : checkStart.getMsg() + "start");
ValidationUtil.isTrueValidation(!DagCheckEnum.PASS.getCode().equals(checkStart.getCode()), checkStart.getCode() == 0 ? checkStart.getMsg() : checkStart.getMsg() + "start");
//校验结束节点名称
DagCheckEnum endCheck = nodeDagCheck.checkEnd();
ValidationUtil.isTrueValidation(DagCheckEnum.PASS.getCode().equals(endCheck.getCode()), endCheck.getCode() == 0 ? endCheck.getMsg() : endCheck.getMsg() + "end");
ValidationUtil.isTrueValidation(!DagCheckEnum.PASS.getCode().equals(endCheck.getCode()), endCheck.getCode() == 0 ? endCheck.getMsg() : endCheck.getMsg() + "end");
//校验是否有游离节点
DagCheckEnum freeCheck = nodeDagCheck.checkFreeNode();
ValidationUtil.isTrueValidation(DagCheckEnum.PASS.getCode().equals(freeCheck.getCode()), freeCheck.getMsg());
ValidationUtil.isTrueValidation(!DagCheckEnum.PASS.getCode().equals(freeCheck.getCode()), freeCheck.getMsg());
//校验是否存在环路
DagCheckEnum loopCheck = nodeDagCheck.checkDag();
ValidationUtil.isTrueValidation(DagCheckEnum.PASS.getCode().equals(loopCheck.getCode()), loopCheck.getMsg());
ValidationUtil.isTrueValidation(!DagCheckEnum.PASS.getCode().equals(loopCheck.getCode()), loopCheck.getMsg());
}
@Override
......@@ -365,7 +371,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
ValidationUtil.dataNotBank(pluginFlow.getConfig().getExecType(), "工作流的调度类型不允许为空!");
if (FlowPropertyEnum.SCHEDULE_MODE.getCode().equals(pluginFlow.getConfig().getExecType())){
ValidationUtil.dataNotBank(pluginFlow.getConfig().getFlowCron(), "工作流cron表达式不允许为空!");
ValidationUtil.isTrueValidation(CronExpression.isValidExpression(pluginFlow.getConfig().getFlowCron()), "工作流cron表达式不符合规范!");
ValidationUtil.isTrueValidation(!CronExpression.isValidExpression(pluginFlow.getConfig().getFlowCron()), "工作流cron表达式不符合规范!");
}
if (!FlowPropertyEnum.NO_ALARML.getCode().equals(pluginFlow.getConfig().getAlarmlAction())){
ValidationUtil.dataNotBank(pluginFlow.getConfig().getAlarmEmail(), "设置告警时机时告警邮箱不允许为空!");
......@@ -374,9 +380,9 @@ public class ApiFlowServiceImpl implements ApiFlowService {
//判断是否是重发
//是重发
if (pluginFlow.isRePublish()){
ValidationUtil.dataNotNull(flow, "工作流【"+ flow.getFlowName() + "】不存在!");
ValidationUtil.dataNotNull(flow, "工作流【"+ pluginFlow.getName() + "】不存在!");
}else {//不是重发
ValidationUtil.isTrueValidation(null != flow, "工作流【"+ flow.getFlowName() + "】已存在!");
ValidationUtil.isTrueValidation(null != flow, "工作流【"+ pluginFlow.getName() + "】已存在!");
}
}
......@@ -420,11 +426,12 @@ public class ApiFlowServiceImpl implements ApiFlowService {
NodeVersion nodeVersion = new NodeVersion();
BeanUtils.copyProperties(node, nodeVersion);
nodeVersion.setAddTime(currentDate);
nodeVersion.setFlowVersionId(flowVersion.getFlowVersionId());
nodeVersion.setVersionMark(FlowPropertyEnum.IS_CURRENTVERSION.getCode());
if (null != node.getIsVirtual() && NodePropertyEnum.IS_VIRTUAL.equals(node.getIsVirtual())){
if (null != node.getIsVirtual() && NodePropertyEnum.IS_VIRTUAL.getCode().equals(node.getIsVirtual())){
Flow innerFlow = flowMapper.getById(node.getMapFlowId());
FlowVersion innerFlowVersion = saveFlowVersion(innerFlow);
node.setMapFlowId(innerFlowVersion.getFlowVersionId());
nodeVersion.setMapFlowId(innerFlowVersion.getFlowVersionId());
}
nodeVersionMapper.insertSelective(nodeVersion);
idVersionIdRel.put(node.getNodeId(), nodeVersion.getNodeVersionId());
......
......@@ -26,7 +26,7 @@ public class ApiWorkspaceServiceImpl implements ApiWorkspaceService {
public void add(String workspaceName) {
ValidationUtil.dataNotBank(workspaceName, "工作空间名称为空!");
Workspace workspace = workspaceMapper.getByName(workspaceName);
ValidationUtil.dataNotNull(workspace, "工作空间已存在!");
ValidationUtil.isTrueValidation(null != workspace, "工作空间已存在!");
workspace = new Workspace();
workspace.setWorkspaceName(workspaceName);
workspace.setAddTime(new Date());
......
......@@ -34,7 +34,7 @@
<insert id="insert">
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into node_dependency (node_id, dependency_id)
values (#{nodeId,jdbcType=INTEGER}, #{dependencyId,jdbcType=INTEGER})
values (#{nodeId,jdbcType=INTEGER}, #{dependNodeId,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.byit.model.NodeDependencyKey">
<!-- generated @mbg.generated date: 2019-12-31 -->
......
......@@ -72,7 +72,7 @@
where node_version_id = #{nodeVersionId,jdbcType=INTEGER}
</delete>
<insert id="insertSelective" parameterType="com.byit.model.NodeVersion">
<insert id="insertSelective" useGeneratedKeys="true" keyProperty="nodeVersionId" parameterType="com.byit.model.NodeVersion">
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into node_version
<trim prefix="(" suffix=")" suffixOverrides=",">
......
......@@ -2,7 +2,6 @@ package com.byit.job.dto.plugin;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
......@@ -12,7 +11,7 @@ import java.util.List;
*/
@Data
public class PluginBaseNode implements Serializable {
public class PluginBaseNode {
/**
* 名称
*/
......@@ -37,7 +36,4 @@ public class PluginBaseNode implements Serializable {
* 依赖的任务节点名称集合,只能是节点的名称,如果不是内嵌工作流不允许设置依赖
*/
private List<String> dependNodeNameList;
private static final long serialVersionUID = 1L;
}
......@@ -2,6 +2,7 @@ package com.byit.job.dto.plugin;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
......@@ -10,7 +11,7 @@ import java.util.List;
* @create: 2019-12-30 10:44
*/
@Data
public class PluginFlow extends PluginBaseNode {
public class PluginFlow extends PluginBaseNode implements Serializable {
/**
* 责任人
......@@ -32,5 +33,5 @@ public class PluginFlow extends PluginBaseNode {
*/
private PluginFlowConfig config;
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 3L;
}
......@@ -2,13 +2,15 @@ package com.byit.job.dto.plugin;
import lombok.Data;
import java.io.Serializable;
/**
* @description: 插件端的任务节点
* @author: gml
* @create: 2019-12-30 10:45
*/
@Data
public class PluginNode extends PluginBaseNode {
public class PluginNode extends PluginBaseNode implements Serializable {
/**
* 当前任务的类型 JAVA PYTHON SHELL SQL SCRIPT
......@@ -49,5 +51,5 @@ public class PluginNode extends PluginBaseNode {
*/
private PluginNodeConfig config;
private static final long serialVersionUID = 2L;
}
......@@ -2,13 +2,15 @@ package com.byit.job.dto.plugin;
import lombok.Data;
import java.io.Serializable;
/**
* @description: 插件段的发布包
* @author: gml
* @create: 2020-01-02 14:38
*/
@Data
public class PluginPackage {
public class PluginPackage implements Serializable {
/**
* 工作空间名称
......@@ -20,4 +22,5 @@ public class PluginPackage {
*/
private PluginFlow flow;
private static final long serialVersionUID = 11L;
}
......@@ -2,11 +2,11 @@ package com.byit.utils;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.byit.job.dto.PluginBeanJobInfo;
import com.byit.job.dto.plugin.PluginPackage;
import com.byit.job.enums.plugin.PluginEnum;
import com.byit.job.exceptions.plugin.PluginException;
import com.byit.job.handler.interfaces.IJobHandler;
import com.byit.job.dto.PluginBeanJobInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -15,6 +15,8 @@ import java.net.URLDecoder;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
/**
* @program: byit-myth-job->JobFactory
* @description: 创建任务的工具类
......@@ -67,7 +69,8 @@ public class JobUtils {
//请求的路径
String requestUrl = REQUEST_PREFIX + "127.0.0.1" + ":" + "8080" + REQUEST_FLOW_PUBLISH;
//发送请求 添加任务
String addRequestResult = HttpUtil.post(requestUrl, "pluginPackageParam=" + JSON.toJSONString(pluginPackage));
String addRequestResult = HttpUtil.post(requestUrl, "param=" + JSON.toJSONString(pluginPackage, WriteClassName));
// String addRequestResult = HttpUtil.post(requestUrl, JSON.toJSONString(pluginPackage, WriteClassName));
log.info("--------------------添加任务完成,添加结果为:{}------------------------",addRequestResult);
return addRequestResult;
}
......
......@@ -29,7 +29,7 @@ public class Test {
PluginFlow flow = new PluginFlow();
flow.setName(name);
flow.setRePublish(false);
flow.setRePublish(true);
flow.setPrincipal("admin");
PluginFlowConfig flowConfig = new PluginFlowConfig();
......@@ -42,6 +42,40 @@ public class Test {
PluginNode start = getNode("start", "echo start", "echo start", null);
PluginNode center = getNode("center", "echo center", "echo center", "start");
PluginFlow innerFlow = getInnerFlow("inner", "start");
PluginNode end = getNode("end", "echo end", "echo end", "center,inner");
List<PluginBaseNode> nodeList = new ArrayList<>();
nodeList.add(start);
nodeList.add(center);
nodeList.add(end);
nodeList.add(innerFlow);
flow.setConfig(flowConfig);
flow.setNodeList(nodeList);
return flow;
}
public static PluginFlow getInnerFlow(String name, String dependNames){
PluginFlow flow = new PluginFlow();
flow.setName(name);
flow.setRePublish(true);
flow.setPrincipal("admin");
flow.setType("flow");
PluginFlowConfig flowConfig = new PluginFlowConfig();
flowConfig.setAlarmlAction("1");
flowConfig.setExecType("1");
flowConfig.setFlowCron("0 0 2 * * ? *");
flowConfig.setPriority("1");
flowConfig.setScheduleFollow("1");
flowConfig.setAlarmEmail("qwe@qq.com");
PluginNode start = getNode("start", "echo start", "echo start", null);
PluginNode center = getNode("center", "echo center", "echo center", "start");
PluginNode end = getNode("end", "echo end", "echo end", "center");
List<PluginBaseNode> nodeList = new ArrayList<>();
......@@ -52,6 +86,9 @@ public class Test {
flow.setConfig(flowConfig);
flow.setNodeList(nodeList);
if (StringUtils.isNotEmpty(dependNames)) {
flow.setDependNodeNameList(Arrays.asList(dependNames));
}
return flow;
}
......@@ -69,7 +106,7 @@ public class Test {
nodeConfig.setPriority("1");
node.setConfig(nodeConfig);
if (StringUtils.isNotEmpty(dependNames)) {
node.setDependNodeNameList(Arrays.asList(dependNames));
node.setDependNodeNameList(Arrays.asList(dependNames.split(",")));
}
return node;
......
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