OCT REM: 1. workflow设计主要流程完成

This commit is contained in:
HuangXin 2025-03-08 09:21:24 +08:00
parent f8ab1e3b80
commit 9243d2a081
5 changed files with 111 additions and 54 deletions

View File

@ -0,0 +1,11 @@
package com.cmcc.magent.service.workflow;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
public class DeploymentShellService implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
}
}

View File

@ -5,10 +5,11 @@ import com.cmcc.magent.config.DroolsConfig;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.bpmn.behavior.BusinessRuleTaskActivityBehavior;
import org.flowable.engine.impl.context.Context;
import org.kie.api.runtime.KieSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@ -24,6 +25,9 @@ public class RuleProcessService extends BusinessRuleTaskActivityBehavior {
Map<MiddlewareManagerCommand, String> results = new HashMap<>(10);
kieSession.setGlobal("results", results);
List<String> retCommand = new ArrayList<>();
kieSession.setGlobal("returnCommand", retCommand);
// 3. 插入事实对象从流程变量获取命令数据
kieSession.insert(execution.getVariable("execCommand"));
@ -34,8 +38,7 @@ public class RuleProcessService extends BusinessRuleTaskActivityBehavior {
// 5. 回收结果到流程变量增强版
if (resultVariable != null && !resultVariable.isEmpty()) {
// 将结果同时存入显式指定的变量和默认变量
execution.setVariable(resultVariable, results);
Context.getProcessEngineConfiguration().getRuntimeService().setVariable(execution.getId(), resultVariable, results);
execution.setVariable(resultVariable, retCommand);
}
kieSession.dispose();

View File

@ -1,105 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.8.0">
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.8.0">
<process id="deployment" name="deployment" isExecutable="true">
<startEvent id="startTask" name="startTask"/>
<startEvent id="startTask" name="workflowBegin"/>
<exclusiveGateway id="checkCommandType" name="checkCommandType"/>
<endEvent id="endTask"/>
<serviceTask id="writeShellService" flowable:exclusive="false" name="writeShellService" flowable:async="true" flowable:class="com.cmcc.magent.service.workflow.WriteLocalShellAsyncService">
<endEvent id="endTask" name="workflowFinished"/>
<serviceTask id="writeShellService" flowable:exclusive="false" name="writeShellService" flowable:async="true"
flowable:class="com.cmcc.magent.service.workflow.WriteLocalShellAsyncService">
<multiInstanceLoopCharacteristics flowable:collection="taskDataList" flowable:elementVariable="middlewareManagerCommand"/>
</serviceTask>
<serviceTask id="downloadShellService" flowable:exclusive="false" name="downloadShellService" flowable:async="true" flowable:class="com.cmcc.magent.service.workflow.WriteLocalShellAsyncService">
<serviceTask id="downloadShellService" flowable:exclusive="false" name="downloadShellService" flowable:async="true"
flowable:class="com.cmcc.magent.service.workflow.WriteLocalShellAsyncService">
<multiInstanceLoopCharacteristics flowable:collection="taskDataList" flowable:elementVariable="middlewareManagerCommand"/>
</serviceTask>
<serviceTask id="downloadConfigService" flowable:exclusive="false" name="downloadConfigService" flowable:async="true" flowable:class="com.cmcc.magent.service.workflow.DownloadFileAsyncService">
<serviceTask id="downloadConfigService" flowable:exclusive="false" name="downloadConfigService" flowable:async="true"
flowable:class="com.cmcc.magent.service.workflow.DownloadFileAsyncService">
<multiInstanceLoopCharacteristics flowable:collection="remoteFileList" flowable:elementVariable="downloadInfo"/>
</serviceTask>
<businessRuleTask id="depolymentRuleService" name="depolymentRuleService" flowable:resultVariable="rulesOutput" flowable:ruleVariablesInput="${execCommand}" flowable:class="com.cmcc.magent.service.workflow.RuleProcessService"/>
<exclusiveGateway id="checkConfigDownload" name="checkConfigDownload"/>
<businessRuleTask id="depolymentRuleService" name="depolymentRuleService" flowable:resultVariable="rulesOutput"
flowable:ruleVariablesInput="${execCommand}" flowable:class="com.cmcc.magent.service.workflow.RuleProcessService"/>
<serviceTask id="execDeploymentShellService" flowable:exclusive="true" name="execDeploymentShellService"
flowable:class="com.cmcc.magent.service.workflow.DeploymentShellService">
<multiInstanceLoopCharacteristics flowable:collection="rulesOutput" flowable:elementVariable="execRules"/>
</serviceTask>
<sequenceFlow id="sid-d2d76406-2d81-4b89-b3e3-90635916c64e" sourceRef="startTask" targetRef="checkCommandType"/>
<sequenceFlow id="sid-fc6d41ca-61ee-4e12-9c3e-df0ba488a3ae" sourceRef="checkCommandType" targetRef="downloadShellService">
<sequenceFlow id="sid-fc6d41ca-61ee-4e12-9c3e-df0ba488a3ae" sourceRef="checkCommandType" targetRef="downloadShellService"
name="downloadCommand">
<conditionExpression xsi:type="tFormalExpression">${commandWithInLocal == false}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-8edc54d6-7c17-4e8f-af24-164dbf3ba7de" sourceRef="checkCommandType" targetRef="writeShellService">
<sequenceFlow id="sid-8edc54d6-7c17-4e8f-af24-164dbf3ba7de" sourceRef="checkCommandType" targetRef="writeShellService"
name="writeCmdToFile">
<conditionExpression xsi:type="tFormalExpression">${commandWithInLocal == true}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-fbff4952-245d-4585-8389-9a60fc964970" sourceRef="writeShellService" targetRef="checkConfigDownload"/>
<sequenceFlow id="sid-e8128af9-f2d9-4fd9-8cc9-8b493cc7ad72" sourceRef="downloadShellService" targetRef="checkConfigDownload"/>
<sequenceFlow id="sid-74d36e64-17a8-4559-adea-5e9f5a5344c4" sourceRef="checkConfigDownload" targetRef="downloadConfigService">
<sequenceFlow id="sid-fbff4952-245d-4585-8389-9a60fc964970" sourceRef="writeShellService" targetRef="checkConfigDownload"
name="writeFinished"/>
<sequenceFlow id="sid-e8128af9-f2d9-4fd9-8cc9-8b493cc7ad72" sourceRef="downloadShellService" targetRef="checkConfigDownload"
name="downloadFinished"/>
<sequenceFlow id="sid-74d36e64-17a8-4559-adea-5e9f5a5344c4" sourceRef="checkConfigDownload" targetRef="downloadConfigService"
name="downloadConfigFile">
<conditionExpression xsi:type="tFormalExpression">${downloadConfigFiles == true}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-da28d222-a4ff-4e6f-8884-198ff179f8d6" sourceRef="downloadConfigService" targetRef="depolymentRuleService"/>
<sequenceFlow id="sid-a9acd95d-23e9-4a18-b1e9-9e289881d521" sourceRef="checkConfigDownload" targetRef="depolymentRuleService">
<sequenceFlow id="sid-da28d222-a4ff-4e6f-8884-198ff179f8d6" sourceRef="downloadConfigService" targetRef="depolymentRuleService"
name="downloadConfigFileFinished"/>
<sequenceFlow id="sid-a9acd95d-23e9-4a18-b1e9-9e289881d521" sourceRef="checkConfigDownload" targetRef="depolymentRuleService"
name="skipDownloadConfigFile">
<documentation/>
<conditionExpression xsi:type="tFormalExpression">${downloadConfigFiles == false}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-71d269db-11af-4e76-b091-c8805abe6e4e" sourceRef="depolymentRuleService" targetRef="execDeploymentShellService"
name="applyRulesFinished"/>
<sequenceFlow id="sid-6a285660-8a50-4f0a-89b2-8e8bc773f80d" sourceRef="execDeploymentShellService" targetRef="endTask"
name="deploymentFinished"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_deployment">
<bpmndi:BPMNPlane bpmnElement="deployment" id="BPMNPlane_deployment">
<bpmndi:BPMNShape id="shape-abca481a-3f25-48bb-8684-c95045705599" bpmnElement="startTask">
<omgdc:Bounds x="-2815.0" y="85.0" width="30.0" height="30.0"/>
<omgdc:Bounds x="-2350.0" y="-240.0" width="30.0" height="30.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-67d9b776-3612-4f9b-9fdc-5a05ac03cdcb" bpmnElement="checkCommandType">
<omgdc:Bounds x="-2730.0" y="80.0" width="40.0" height="40.0"/>
<omgdc:Bounds x="-2265.0" y="-245.0" width="40.0" height="40.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-ddf4873b-d546-4820-8b08-3407f5b8275c" bpmnElement="writeShellService">
<omgdc:Bounds x="-2645.0" y="-35.0" width="100.0" height="80.0"/>
<omgdc:Bounds x="-2180.0" y="-360.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-de6ab90a-1470-43c2-acfd-b0d3cb8cc94d" bpmnElement="downloadShellService">
<omgdc:Bounds x="-2645.0" y="155.0" width="100.0" height="80.0"/>
<omgdc:Bounds x="-2180.0" y="-170.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-4b91bb71-fd69-4c59-a00e-d6ce1add95a0" bpmnElement="endTask">
<omgdc:Bounds x="-2545.0" y="-180.0" width="30.0" height="30.0"/>
<omgdc:Bounds x="-1210.0" y="-239.99998" width="30.0" height="30.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge-9948d0c6-8084-4ff5-98d0-616d68895040" bpmnElement="sid-d2d76406-2d81-4b89-b3e3-90635916c64e">
<omgdi:waypoint x="-2785.0" y="100.0"/>
<omgdi:waypoint x="-2730.0" y="100.0"/>
<omgdi:waypoint x="-2320.0" y="-225.0"/>
<omgdi:waypoint x="-2265.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-708efee7-b65f-43d6-84e5-155068dceec7" bpmnElement="sid-fc6d41ca-61ee-4e12-9c3e-df0ba488a3ae">
<omgdi:waypoint x="-2710.0" y="120.0"/>
<omgdi:waypoint x="-2710.0" y="189.99998"/>
<omgdi:waypoint x="-2652.5" y="189.99998"/>
<omgdi:waypoint x="-2645.0" y="190.0"/>
<omgdi:waypoint x="-2245.0" y="-205.0"/>
<omgdi:waypoint x="-2245.0" y="-135.0"/>
<omgdi:waypoint x="-2187.5" y="-135.0"/>
<omgdi:waypoint x="-2180.0" y="-135.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-bd4cb437-d098-46d0-a5bb-66464d7b7039" bpmnElement="sid-8edc54d6-7c17-4e8f-af24-164dbf3ba7de">
<omgdi:waypoint x="-2710.0" y="80.0"/>
<omgdi:waypoint x="-2710.0" y="5.0"/>
<omgdi:waypoint x="-2645.0" y="5.0"/>
<omgdi:waypoint x="-2245.0" y="-245.0"/>
<omgdi:waypoint x="-2245.0" y="-320.0"/>
<omgdi:waypoint x="-2180.0" y="-320.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-26a4d014-7ca1-4b27-8409-1c10e0d14301" bpmnElement="sid-fbff4952-245d-4585-8389-9a60fc964970">
<omgdi:waypoint x="-2545.0" y="5.0"/>
<omgdi:waypoint x="-2477.5" y="5.0"/>
<omgdi:waypoint x="-2477.5" y="100.000015"/>
<omgdi:waypoint x="-2405.0" y="100.00001"/>
<omgdi:waypoint x="-2080.0" y="-320.0"/>
<omgdi:waypoint x="-2012.5" y="-320.0"/>
<omgdi:waypoint x="-2012.5" y="-225.0"/>
<omgdi:waypoint x="-1940.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-92cc6bbe-2b2a-4559-a78e-80bf1ee859e8" bpmnElement="sid-e8128af9-f2d9-4fd9-8cc9-8b493cc7ad72">
<omgdi:waypoint x="-2545.0" y="195.0"/>
<omgdi:waypoint x="-2477.5" y="195.00002"/>
<omgdi:waypoint x="-2477.5" y="100.00001"/>
<omgdi:waypoint x="-2405.0" y="100.00001"/>
<omgdi:waypoint x="-2080.0" y="-130.0"/>
<omgdi:waypoint x="-2012.5" y="-130.0"/>
<omgdi:waypoint x="-2012.5" y="-225.0"/>
<omgdi:waypoint x="-1940.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="shape-1860cc98-3c72-40fc-9f5f-621cc7a0cfee" bpmnElement="checkConfigDownload">
<omgdc:Bounds x="-2405.0" y="80.0" width="40.0" height="40.0"/>
<omgdc:Bounds x="-1940.0" y="-245.0" width="40.0" height="40.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-03300fc2-d7a7-43b2-820c-0a6543d69552" bpmnElement="downloadConfigService">
<omgdc:Bounds x="-2315.0" y="60.0" width="100.0" height="80.0"/>
<omgdc:Bounds x="-1850.0" y="-265.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-1153a8d0-310f-4fb8-ae09-f9b1febb0450" bpmnElement="depolymentRuleService">
<omgdc:Bounds x="-2115.0" y="60.0" width="100.0" height="80.0"/>
<omgdc:Bounds x="-1650.0" y="-265.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge-962565b8-13de-4f1c-be53-78740775bc62" bpmnElement="sid-74d36e64-17a8-4559-adea-5e9f5a5344c4">
<omgdi:waypoint x="-2365.0" y="100.0"/>
<omgdi:waypoint x="-2315.0" y="100.0"/>
<omgdi:waypoint x="-1900.0" y="-225.0"/>
<omgdi:waypoint x="-1850.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-fcfdce67-5528-47fe-8525-574a3d22071f" bpmnElement="sid-da28d222-a4ff-4e6f-8884-198ff179f8d6">
<omgdi:waypoint x="-2215.0" y="100.0"/>
<omgdi:waypoint x="-2115.0" y="100.0"/>
<omgdi:waypoint x="-1750.0" y="-225.0"/>
<omgdi:waypoint x="-1650.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-513e469f-6dc4-4fbf-88d5-9821310ad4ab" bpmnElement="sid-a9acd95d-23e9-4a18-b1e9-9e289881d521">
<omgdi:waypoint x="-2365.0" y="100.0"/>
<omgdi:waypoint x="-2365.0" y="165.00002"/>
<omgdi:waypoint x="-2170.0007" y="165.0"/>
<omgdi:waypoint x="-2170.0007" y="165.0"/>
<omgdi:waypoint x="-2170.0005" y="100.0"/>
<omgdi:waypoint x="-2115.0" y="100.0"/>
<omgdi:waypoint x="-1920.0" y="-205.0"/>
<omgdi:waypoint x="-1920.0002" y="-160.0"/>
<omgdi:waypoint x="-1705.0007" y="-160.0"/>
<omgdi:waypoint x="-1705.0007" y="-160.0"/>
<omgdi:waypoint x="-1705.0005" y="-225.0"/>
<omgdi:waypoint x="-1650.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="shape-f4e655f2-6d33-470b-9355-9df1ddfbcec1" bpmnElement="execDeploymentShellService">
<omgdc:Bounds x="-1455.0" y="-265.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge-d24ed054-e9ba-4ed4-a0ba-885d1773a070" bpmnElement="sid-71d269db-11af-4e76-b091-c8805abe6e4e">
<omgdi:waypoint x="-1550.0" y="-225.0"/>
<omgdi:waypoint x="-1455.0" y="-225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-804f4c3b-511b-4a79-9e59-f338ddb7f95f" bpmnElement="sid-6a285660-8a50-4f0a-89b2-8e8bc773f80d">
<omgdi:waypoint x="-1355.0" y="-225.0"/>
<omgdi:waypoint x="-1210.0" y="-224.99998"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

View File

@ -5,6 +5,14 @@ import java.util.Map
import java.util.List;
global Map results;
global List<String> returnCommand;
rule "collectResult"
when
eval(!results.isEmpty())
then
returnCommand.addAll(results.values());
end
rule "ruleHasAllStart"
salience 1000

View File

@ -19,8 +19,8 @@ spring.h2.console.path=/h2-console
spring.h2.server.enable=false
spring.h2.server.port=18090
# auto init
#spring.sql.init.mode=always
#spring.sql.init.schema-locations=classpath:sql/schema.sql
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath:sql/schema.sql
# flowable configure
flowable.async-executor-activate=true