Commit a99c4b7e by huangfusuper

删除所有的公共参数替换,发布工作流的时候保存工作流的内嵌层级

parent d5ac8f22
......@@ -14,7 +14,6 @@ import com.byit.dto.specials.RepairFlow;
import com.byit.dto.specials.RepairTimeParam;
import com.byit.enums.*;
import com.byit.enums.plugin.PluginNodeTypeEnum;
import com.byit.enums.task.RunResultEnum;
import com.byit.job.utils.CronExpression;
import com.byit.job.utils.CurrentUserUtils;
import com.byit.job.utils.PlaceholderUtils;
......@@ -132,7 +131,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
Workspace workspace = validate(pluginPackage);
//保存工作流
log.debug("保存工作流和节点信息");
Flow flow = saveFlow(pluginPackage.getFlow(), workspace.getWorkspaceId(), false);
Flow flow = saveFlow(pluginPackage.getFlow(), workspace.getWorkspaceId(), false, "");
//生成工作流版本
log.debug("生成版本");
FlowVersion flowVersion = saveFlowVersion(flow);
......@@ -149,10 +148,10 @@ public class ApiFlowServiceImpl implements ApiFlowService {
* @param isInnner
* @param workspaceId
*/
private Flow saveFlow(PluginFlow pluginFlow, Integer workspaceId, boolean isInnner) throws Exception {
private Flow saveFlow(PluginFlow pluginFlow, Integer workspaceId, boolean isInnner, String upFlowName) throws Exception {
//拼装工作流名称
upFlowName = String.format("%s:%s",upFlowName,pluginFlow.getName());
Flow flow = new Flow();
flow.setExtendedConfiguration(JSON.toJSONString(pluginFlow.getConfig().getExtendedConfiguration()));
flow.setFlowName(pluginFlow.getName());
flow.setIsInner(isInnner ? "0" : "1");
flow.setFlowNodeCount(pluginFlow.getNodeList().size());
......@@ -167,8 +166,6 @@ public class ApiFlowServiceImpl implements ApiFlowService {
flow.setAlarmlAction(pluginFlow.getConfig().getAlarmlAction());
flow.setAlarmEmail(pluginFlow.getConfig().getAlarmEmail());
flow.setScanMark("1");
Map<String, String> publicParamMap = pluginFlow.getConfig().getPublicParam();
flow.setFlowDesc(JSON.toJSONString(publicParamMap));
//设置可执行次数
//若没设置或者设置为-1,则响应设置剩余的执行次数
if (null != pluginFlow.getConfig().getRepeatCount() && !"-1".equals(pluginFlow.getConfig().getRepeatCount())) {
......@@ -197,7 +194,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
flow.setVersionName(versionName);
}
flowMapper.updateByIdSelective(flow);
updateNodeByFlow(pluginFlow.getNodeList(), flow, publicParamMap);
updateNodeByFlow(pluginFlow.getNodeList(), flow, upFlowName);
} else {
String versionName = pluginFlow.getVersionName();
......@@ -208,9 +205,11 @@ public class ApiFlowServiceImpl implements ApiFlowService {
}
Integer flowId = flowMapper.insertSelective(flow);
saveNode(pluginFlow.getNodeList(), flow, publicParamMap);
saveNode(pluginFlow.getNodeList(), flow, upFlowName);
}
FlowExtendedConfiguration extendedConfiguration = pluginFlow.getConfig().getExtendedConfiguration();
extendedConfiguration.setFlowEmbedLogo(upFlowName);
flow.setExtendedConfiguration(JSON.toJSONString(extendedConfiguration));
return flow;
}
......@@ -220,7 +219,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
* @param pluginNodeList
* @param flow
*/
private void updateNodeByFlow(List<PluginBaseNode> pluginNodeList, Flow flow, Map<String, String> publicParamMap) throws Exception {
private void updateNodeByFlow(List<PluginBaseNode> pluginNodeList, Flow flow, String upFlowName) throws Exception {
//将工作流下的所有节点设为不在工作流调度上
log.debug("将工作流【{}】所有的节点移下调度,并删除相关的依赖关系", flow.getFlowName());
......@@ -250,7 +249,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
//保存节点信息
for (PluginBaseNode pluginNode : pluginNodeList) {
Node node = new Node();
buildNode(pluginNode, flow, node, publicParamMap);
buildNode(pluginNode, flow, node, upFlowName);
Integer nodeId = nodeMapper.insertSelective(node);
nameIdRel.put(node.getNodeName(), node.getNodeId());
......@@ -265,12 +264,12 @@ public class ApiFlowServiceImpl implements ApiFlowService {
* @param nodeList
* @param flow
*/
private void saveNode(List<PluginBaseNode> nodeList, Flow flow, Map<String, String> publicParamMap) throws Exception {
private void saveNode(List<PluginBaseNode> nodeList, Flow flow, String upFlowName) throws Exception {
HashMap<String, Integer> nameIdRel = new HashMap<>();
//保存节点信息
for (PluginBaseNode pluginNode : nodeList) {
Node node = new Node();
buildNode(pluginNode, flow, node, publicParamMap);
buildNode(pluginNode, flow, node, upFlowName);
node.setNodeId(null);
Integer nodeId = nodeMapper.insertSelective(node);
nameIdRel.put(node.getNodeName(), node.getNodeId());
......@@ -286,7 +285,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
* @param node
* @throws Exception
*/
private void buildNode(PluginBaseNode pluginNode, Flow flow, Node node, Map<String, String> publicParamMap) throws Exception {
private void buildNode(PluginBaseNode pluginNode, Flow flow, Node node, String upFlowName) throws Exception {
node.setVersionName(flow.getVersionName());
node.setFlowId(flow.getFlowId());
......@@ -299,7 +298,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
PluginFlow pluginFlow = (PluginFlow) pluginNode;
pluginFlow.getConfig().setFlowCron(flow.getFlowCron());
//如果是内嵌工作流先保存工作流信息
Flow innerFlow = saveFlow(pluginFlow, flow.getWorkspaceId(), true);
Flow innerFlow = saveFlow(pluginFlow, flow.getWorkspaceId(), true, upFlowName);
node.setIsVirtual(NodePropertyEnum.IS_VIRTUAL.getCode());
node.setMapFlowId(innerFlow.getFlowId());
node.setVersionName(pluginFlow.getVersionName());
......@@ -342,11 +341,6 @@ public class ApiFlowServiceImpl implements ApiFlowService {
node.setSuperSuccessRun("0");
}
node.setIsVirtual(NodePropertyEnum.ISNOT_VIRTUAL.getCode());
RunParamWrapped runParamWrapped = new RunParamWrapped();
runParamWrapped.setPrivateParam(node.getRunParam());
runParamWrapped.setPublicParamMap(publicParamMap);
node.setRunParam(JSON.toJSONString(runParamWrapped));
}
}
......@@ -809,7 +803,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
}
}
return runRecordingMapper.findByStartAndEndTime(loadScheduleCondition,flowIds);
return runRecordingMapper.findByStartAndEndTime(loadScheduleCondition, flowIds);
}
......@@ -1669,7 +1663,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
StringBuffer runids = new StringBuffer();
//暂停工作流调度
recordingList.forEach(runRecording -> {
if(RunRecordingEnum.FLOW_STATUS_IS_END.getCode().equals(runRecording.getFlowStatus())){
if (RunRecordingEnum.FLOW_STATUS_IS_END.getCode().equals(runRecording.getFlowStatus())) {
throw new RuntimeException(String.format("实例%s是完结状态", runRecording.getFlowName()));
}
//runRecordingMapper.stopByRunIdAndFlowId(runRecording.getRunId(), runRecording.getFlowId());
......@@ -1694,7 +1688,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
List<RunRecording> runRecordList = runRecordingMapper.findStopRunCordByRunId(runId);
//ValidationUtil.isTrueValidation(CollectionUtil.isEmpty(runRecordList), "该工作流不是暂停状态!");
if(CollectionUtil.isEmpty(runRecordList)){
if (CollectionUtil.isEmpty(runRecordList)) {
log.warn("---------运行记录{},不存在暂停记录中!---", runId);
return;
}
......
package com.byit.enums;
/**
* @author huangfu
*/
public enum RedisKeyNameEnum {
/**
* 调度中心公共参数
*/
REDIS_PUBLIC_PARAM_KEY("myth:param:public:%s"),
;
private final String keyName;
RedisKeyNameEnum(String keyName) {
this.keyName = keyName;
}
public String getKeyName() {
return keyName;
}
}
......@@ -88,7 +88,7 @@ public class RunRecording implements Serializable {
/**
* 本次任务的执行时间
*/
@ApiModelProperty("本次任务的执行时间")
@ApiModelProperty("计划本次任务开始的时间")
private Long triggerTime;
/**
......@@ -106,13 +106,13 @@ public class RunRecording implements Serializable {
/**
* 开始时间
*/
@ApiModelProperty("开始时间")
@ApiModelProperty("实际开始时间")
private Date startTime;
/**
* 结束时间
*/
@ApiModelProperty("结束时间")
@ApiModelProperty("实际结束时间")
private Date endTime;
/**
......
package com.byit.service.impl;
import com.byit.dto.RunRecordingWrapped;
import com.byit.enums.NodeNameEnum;
import com.byit.enums.RunRecordingEnum;
import com.byit.enums.ScheduleTypeEnum;
......@@ -32,7 +31,7 @@ import java.util.*;
* @author huangfu
*/
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Slf4j
public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublisherAware {
private final RunRecordingService runRecordingService;
......@@ -56,16 +55,17 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
/**
* 保存到运行记录一份 将节点保存到job_task表
* @param flow 工作流
*
* @param flow 工作流
* @param nodes 节点
*/
@Override
public void saveRunRec(Flow flow, List<Node> nodes) {
log.info("---------saveRunRecAndTask start------【保存工作流:{}和节点:{}】-----------------------",flow,nodes);
log.info("---------saveRunRecAndTask start------【保存工作流:{}和节点:{}】-----------------------", flow, nodes);
String runId = IDGenerationStrategy.runIdGenerationStrategy(serverPort);
log.info("-------------【开始保存运行记录runId为:{}】------------------",runId);
log.info("-------------【开始保存运行记录runId为:{}】------------------", runId);
RunRecording build = new RunRecording();
BeanUtils.copyProperties(flow,build);
BeanUtils.copyProperties(flow, build);
build.setRunId(runId);
//TODO 这个不解释 不知道干嘛的 后续需要修改
build.setDispatchIp("0.0.0.0");
......@@ -73,19 +73,17 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
build.setTriggerTime(flow.getTriggerNextTime());
boolean isScheduleFollow = "1".equals(flow.getScheduleFollow());
log.info("-------------【开始保存节点信息,任务是否为跟随工作流,{}】---------------",isScheduleFollow);
log.info("-------------【开始保存节点信息,任务是否为跟随工作流,{}】---------------", isScheduleFollow);
List<JobTask> jobTasks = new ArrayList<>(32);
for (Node node : nodes) {
JobTask jobTask = new JobTask();
jobTask.setScheduleType(1);
jobTask.setTriggerStatus("1");
BeanUtils.copyProperties(node,jobTask);
if(isScheduleFollow){
BeanUtils.copyProperties(node, jobTask);
if (isScheduleFollow) {
jobTask.setTriggerTime(flow.getTriggerNextTime());
}else {
} else {
jobTask.setTriggerTime(node.getTriggerNextTime());
try {
node.setTriggerNextTime(new CronExpression(node.getNodeCron()).getNextValidTimeAfter(new Date(node.getTriggerNextTime())).getTime());
......@@ -98,7 +96,7 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
jobTask.setFlowName(flow.getFlowName());
jobTask.setScheduleType(ScheduleTypeEnum.NORMAL.getCode());
//如果不是开始节点
if(!NodeNameEnum.START_NODE.getNodeName().equals(jobTask.getNodeName())){
if (!NodeNameEnum.START_NODE.getNodeName().equals(jobTask.getNodeName())) {
List<Integer> dependIdByNodeId = nodeDependencyService.findDependIdByNodeId(jobTask.getNodeId());
String parentIds = StringUtils.join(dependIdByNodeId, ",");
jobTask.setNodeDepend(parentIds);
......@@ -112,12 +110,13 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
//回调生命周期
try {
for (Map.Entry<String, InstanceRunTheLifeCycleCallback> entry : entries) {
log.info("-------------【开始回调周期{}前置】---------------",entry.getKey());
RunRecordingWrapped runRecordingWrapped = entry.getValue().postProcessAfterInitialization(build, jobTasks);
build = runRecordingWrapped.getRunRecording();
jobTasks = runRecordingWrapped.getNodeList();
log.info("-------------【开始回调周期{}前置】---------------", entry.getKey());
RunRecording runRecording = entry.getValue().postProcessAfterInitialization(build);
if (runRecording != null) {
build = runRecording;
}
}
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
build.setFlowStatus(RunRecordingEnum.FLOW_STATUS_IS_END.getCode());
build.setFlowRunResult(RunResultEnum.RUN_ERROR.getCode());
......@@ -130,7 +129,7 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
jobTaskService.saveJobTasks(jobTasks);
log.info("-------------【开始修改工作流{}的下次运行时间,以及各种状态】---------------",flow);
log.info("-------------【开始修改工作流{}的下次运行时间,以及各种状态】---------------", flow);
try {
Long triggerNextTime = flow.getTriggerNextTime();
flow.setTriggerNextTime(new CronExpression(flow.getFlowCron()).getNextValidTimeAfter(new Date(triggerNextTime)).getTime());
......@@ -140,26 +139,27 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
e.printStackTrace();
}
updateFlow(flow);
applicationEventPublisher.publishEvent(new FlowScanEndEvent(this,build));
applicationEventPublisher.publishEvent(new FlowScanEndEvent(this, build));
log.info("-------saveRunRecAndTaskAndUpdate end-----------【运行结束】-----------------");
}
/**
* 修改工作流的信息
*
* @param flow 工作流
*/
private void updateFlow(Flow flow){
if (flow.getRemainingCount()>0) {
flow.setRemainingCount(flow.getRemainingCount()-1);
private void updateFlow(Flow flow) {
if (flow.getRemainingCount() > 0) {
flow.setRemainingCount(flow.getRemainingCount() - 1);
}
flowService.updateByIdSelective(flow);
}
/**
* 设置时间发布器
*
* @param applicationEventPublisher
*/
@Override
......
......@@ -274,9 +274,11 @@ public class RunRecordingAndJobTaskServiceImpl implements RunRecordingAndJobTask
//回调生命周期
for (Map.Entry<String, InstanceRunTheLifeCycleCallback> entry : entries) {
log.info("-------------【开始回调周期{}前置】---------------",entry.getKey());
RunRecordingWrapped runRecordingWrapped = entry.getValue().postProcessAfterInitialization(runRecording, jobTasks);
runRecording = runRecordingWrapped.getRunRecording();
jobTasks = runRecordingWrapped.getNodeList();
RunRecording runRecordingLi = entry.getValue().postProcessAfterInitialization(runRecording);
if(runRecordingLi != null) {
runRecording = runRecordingLi;
}
}
}catch (Exception e) {
e.printStackTrace();
......
......@@ -17,14 +17,15 @@ public interface InstanceRunTheLifeCycleCallback {
/**
* 实例执行前
* @param runRecording 运行实例
* @param jobTaskList 节点
* @return 两者的包装对象
*/
RunRecordingWrapped postProcessAfterInitialization(RunRecording runRecording, List<JobTask> jobTaskList);
default RunRecording postProcessAfterInitialization(RunRecording runRecording){
return runRecording;
}
/**
* 后置处理器
* @param runRecording 实例
*/
void postProcessBeforeInitialization(RunRecording runRecording);
default void postProcessBeforeInitialization(RunRecording runRecording){}
}
package com.byit.strategy.impl;
import com.byit.enums.RedisKeyNameEnum;
import com.byit.model.RunRecording;
import com.byit.strategy.InstanceRunTheLifeCycleCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
/**
* 关于公共参数的redis数据删除
*
* @author huangfu
* @date 2020年12月14日11:55:37
*/
@Component
@Slf4j
public class RunRecordingRunRedisRemoveTheLifeCycleCallback implements InstanceRunTheLifeCycleCallback {
private final StringRedisTemplate stringRedisTemplate;
public RunRecordingRunRedisRemoveTheLifeCycleCallback(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
}
/**
* 后置处理器 清除实例执行中产生的各种redis信息
*
* @param runRecording 实例
*/
@Override
public void postProcessBeforeInitialization(RunRecording runRecording) {
//删除本次实例的公共参数
String runId = runRecording.getRunId();
String publicRedisName = String.format(RedisKeyNameEnum.REDIS_PUBLIC_PARAM_KEY.getKeyName(), runId);
stringRedisTemplate.delete(publicRedisName);
}
}
......@@ -229,8 +229,8 @@
select
<include refid="Base_Column_List" />
from run_recording
where UNIX_TIMESTAMP(start_time) * 1000 &gt;= #{loadScheduleCondition.startTime}
and UNIX_TIMESTAMP(start_time) * 1000 &lt;= #{loadScheduleCondition.endTime}
where trigger_time &gt;= #{loadScheduleCondition.startTime}
and trigger_time &lt;= #{loadScheduleCondition.endTime}
and schedule_type != 4
<if test="flowIds != null">
and flow_id in (
......
......@@ -19,4 +19,5 @@ public class CallbackDto implements Serializable {
private String versionName;
private String runId;
private String data;
private Boolean runRecordingStatus = false;
}
......@@ -23,4 +23,9 @@ public class FlowExtendedConfiguration {
* 公共参数
*/
public String publicParam;
/**
* 节点嵌入标记 a:b:c
*/
private String flowEmbedLogo;
}
......@@ -20,11 +20,6 @@ import java.util.Map;
public class PluginFlowConfig {
/**
* 公共参数
*/
private Map<String,String> publicParam;
/**
* 当前工作流版本的告警的时机(0 不告警, 1 完成时告警, 2 失败时告警, 3 成功时告警)
*/
private String alarmlAction;
......
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