Commit f87321bc by tiger

快照状态梳理

1 parent a0fd5f51
......@@ -32,9 +32,7 @@ public class SopInstExecuteJobHandler {
// 创建执行批次
SopInstBatch batch = sopService.createBatch(sop.getInst());
sop.setBatch(batch);
sop.getInst().setBatchNo(batch.getBatchNo());
// 创建所有节点任务
SopXxlJobUtil.initSopNodesJob(sop);
......
......@@ -12,6 +12,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.job.xxljob.param.SopInstNodeParam;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstBatch;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopInstNodeBatch;
......@@ -23,6 +24,7 @@ import cn.com.glsx.process.modules.sop.execute.SnapshotStruct;
import cn.com.glsx.process.modules.sop.execute.SopNodeExecutor;
import cn.com.glsx.process.modules.sop.execute.SopNodeExecutorFactory;
import cn.com.glsx.process.modules.sop.execute.SopNodeType;
import cn.com.glsx.process.util.JacksonUtils;
import cn.hutool.core.lang.Pair;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -67,8 +69,8 @@ public class SopInstNodeExecuteJobHandler {
* @return
*/
private boolean checkPreIds(SopStruct sop, SopInstNode node, SopInstNodeParam param) {
log.info("sop:{}", sop);
log.info("node:{}", node);
log.info("sop:{}", JacksonUtils.nodefaultMapper.toJson(sop));
log.info("node:{}", JacksonUtils.nodefaultMapper.toJson(node));
Pair<Set<Integer>, Set<Integer>> pair = sop.getInstLinkMap().get(node.getNodeId());
// 前置任务为空,直接执行
......@@ -139,17 +141,23 @@ public class SopInstNodeExecuteJobHandler {
}
private void updateBatch(SopStruct sop, SopInstNode node, SnapshotStruct result) {
// TODO 这里需要考虑合并结果
String snapshot = JacksonUtils.nodefaultMapper.toJson(result);
// 刷新实例快照
SopInst inst = sop.getInst();
inst.setInstSnapshot(snapshot);
// 刷新实例批次快照
SopInstBatch batch = sop.getBatch();
batch.setSnapshot(JSONUtil.toJsonStr(result));
sop.getInst().setInstSnapshot(batch.getSnapshot());
sopService.updateInstBatch(sop.getInst(), batch);
batch.setSnapshot(snapshot);
batch.setUpdateTime(new Date());
// 刷新实例节点批次快照
SopInstNodeBatch nodeBatch = sop.getNodeBatch();
nodeBatch.setSnapshot(JSONUtil.toJsonStr(result));
nodeBatch.setSnapshot(snapshot);
nodeBatch.setUpdateTime(new Date());
sopService.updateInstNodeBatch(nodeBatch);
sopService.updateNodeBatch(inst, batch, nodeBatch);
}
private SopStruct reloadAndCreateBatch(SopStruct sop, SopInstNode node) {
......
......@@ -148,62 +148,13 @@ public class SopService {
return sop;
}
public void execute() {
// String flowInstanceId = Tools.genFlowInstanceId(session.getId(), webStruct.getFlowId());
//
// ConcurrentHashMap<String, RunResult> runResultMap = new ConcurrentHashMap<String, RunResult>();
// FlowRunSort flowRunSort = new FlowRunSort();
// ExecuteStruct executeStruct = new ExecuteStruct();
// executeStruct.setMcgWebScoketCode(webStruct.getMcgWebScoketCode());
// executeStruct.setFlowId(webStruct.getFlowId());
// executeStruct.setFlowInstanceId(flowInstanceId);
// executeStruct.setDataMap(flowRunSort.init(flowStruct));
// executeStruct.setOrders(flowRunSort.getFlowSort());
// executeStruct.setRunResultMap(runResultMap);
// executeStruct.setSession(session);
// executeStruct.setTopology(curTopology);
// executeStruct.setSubFlag(subFlag);
// executeStruct.setRunStatus(runStatus);
//
// notifyBody.setContent("【" + curTopology.getName() + "】流程执行开始!");
// notifyBody.setType(LogTypeEnum.INFO.getValue());
// message.setBody(notifyBody);
// MessagePlugin.push(webStruct.getMcgWebScoketCode(), session.getId(), message);
//
// try {
// FlowTask flowTask = new FlowTask(webStruct.getMcgWebScoketCode(), session.getId(), executeStruct, subFlag);
//
// FlowInstancesUtils.executeStructMap.put(flowInstanceId, executeStruct);
// Future<RunStatus> future = ThreadPoolUtils.FLOW_WORK_EXECUTOR.submit(flowTask);
//
// FlowInstancesUtils.executeStructMap.get(flowInstanceId).getFlowTaskFutureList().add(future);
// if(subFlag) {
//
// String subFlowInstanceId = Tools.genFlowInstanceId(session.getId(), parentFlowId);
// ExecuteStruct parentExecuteStruct = FlowInstancesUtils.executeStructMap.get(subFlowInstanceId);
// executeStruct.setParentParam(parentParam);
// parentExecuteStruct.setChildExecuteStruct(executeStruct);
// }
// runStatus = future.get();
// logger.debug("流程:{}, 执行结果:{}", JSON.toJSONString(curTopology), JSON.toJSONString(runStatus));
// return runStatus;
//
// } catch(CancellationException e) {
// executeStruct.getRunStatus().setInterrupt(true);
// logger.error("流程执行中断,抛出CancellationException,异常信息:", e);
// } catch (InterruptedException e) {
// executeStruct.getRunStatus().setInterrupt(true);
// logger.error("流程执行中断,抛出InterruptedException,异常信息:", e);
// }
}
public SopInstBatch createBatch(SopInst sopInst) {
SopInstBatch batch = new SopInstBatch();
batch.setBatchNo(SnowFlake.nextSerialNumber());
batch.setCreateTime(new Date());
batch.setUpdateTime(new Date());
batch.setInstId(sopInst.getInstId());
batch.setSnapshot(sopInst.getInstSnapshot());
batch.setSnapshot(StrUtil.blankToDefault(sopInst.getInstSnapshot(), "{}"));
instBatchMapper.insert(batch);
......@@ -219,21 +170,20 @@ public class SopService {
curBatch.setCreateTime(new Date());
curBatch.setUpdateTime(new Date());
curBatch.setInstNodeId(instNodeId);
curBatch.setSnapshot(sopInst.getInstSnapshot());
curBatch.setSnapshot(StrUtil.blankToDefault(sopInst.getInstSnapshot(), "{}"));
instNodeBatchMapper.insert(curBatch);
return curBatch;
}
public void updateInstNodeBatch(SopInstNodeBatch nodeBatch) {
instNodeBatchMapper.updateByPrimaryKey(nodeBatch);
}
public void updateInstBatch(SopInst sopInst, SopInstBatch batch) {
instMapper.updateByPrimaryKey(sopInst);
public void updateNodeBatch(SopInst sopInst, SopInstBatch batch, SopInstNodeBatch nodeBatch) {
instNodeBatchMapper.updateByPrimaryKey(nodeBatch);
instBatchMapper.updateByPrimaryKey(batch);
instMapper.updateByPrimaryKey(sopInst);
}
}
......@@ -38,9 +38,9 @@ public interface SopNodeExecutor {
*/
default SnapshotStruct prepare(SopStruct sop, SopInstNode node) {
SnapshotStruct es = new SnapshotStruct();
if (StrUtil.length(sop.getBatch().getSnapshot()) > 3) {
if (StrUtil.length(sop.getInst().getInstSnapshot()) > 3) {
// 继承参数
es = JacksonUtils.fromJson(sop.getBatch().getSnapshot(), SnapshotStruct.class);
es = JacksonUtils.fromJson(sop.getInst().getInstSnapshot(), SnapshotStruct.class);
} else {
// 启动参数
if (StrUtil.isNotEmpty(sop.getInst().getInstParam())) {
......@@ -82,18 +82,16 @@ public interface SopNodeExecutor {
* @return
*/
default SnapshotStruct handleResult(SopStruct sop, SopInstNode node, SnapshotStruct es, RunResult result) {
// 启动参数
if (StrUtil.isNotEmpty(sop.getInst().getInstParam())) {
JSONObject paramObj = JSONUtil.parseObj(sop.getInst().getInstParam());
es.getInitMap().putAll(paramObj);
if (result == null) {
return es;
}
// 当前节点需要的参数
if (StrUtil.isNotEmpty(node.getNodeParam())) {
JSONObject nodeParamObj = JSONUtil.parseObj(node.getNodeParam());
es.getParamMap().putAll(nodeParamObj);
if (StrUtil.isNotEmpty(node.getNodeKey())) {
es.getParamMap().put(node.getNodeKey(), result);
} else {
log.warn("【{}】nodeKey 为空!!!", node.getInstId() + "-" + node.getNodeId());
}
return es;
}
}
......@@ -8,8 +8,8 @@ import org.springframework.stereotype.Service;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopService;
import cn.com.glsx.process.modules.sop.execute.SnapshotStruct;
import cn.com.glsx.process.modules.sop.execute.RunResult;
import cn.com.glsx.process.modules.sop.execute.SnapshotStruct;
import cn.com.glsx.process.modules.sop.execute.SopNodeExecutor;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
......@@ -26,14 +26,13 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
@Service
public class StartExecutor extends JavaExecutor implements SopNodeExecutor {
public class StartExecutor implements SopNodeExecutor {
@Resource
private SopService sopService;
@Override
public RunResult execute(SopStruct sop, SopInstNode node, SnapshotStruct executeStruct) throws Exception {
super.execute(sop, node, executeStruct);
return null;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!