From 7d3d07ba28f887ba5fe361257bd72b2847f3bb4d Mon Sep 17 00:00:00 2001
From: gaibu <1016771049@qq.com>
Date: Tue, 21 Mar 2023 22:26:30 +0800
Subject: [PATCH] =?UTF-8?q?feat=20#I6O2YE=20zk=20=E5=A4=96=E7=BD=AE?=
=?UTF-8?q?=E5=AD=98=E5=82=A8=E6=94=AF=E6=8C=81=E5=A4=9A=E8=84=9A=E6=9C=AC?=
=?UTF-8?q?=E6=B7=B7=E5=90=88=E8=B0=83=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../parser/zk/util/ZkParserHelper.java | 42 +++++++++++++++----
.../ZkClusterWithXmlELSpringbootTest.java | 18 +++++++-
.../ZkNodeWithXmlELSpringbootTest.java | 18 +++++++-
3 files changed, 67 insertions(+), 11 deletions(-)
diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java
index 3620c1c08..c994b2b56 100644
--- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java
+++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java
@@ -36,7 +36,9 @@ public class ZkParserHelper {
private final String NODE_XML_PATTERN = "{}";
- private final String NODE_ITEM_XML_PATTERN = "";
+ private final String NODE_ITEM_XML_PATTERN = "";
+
+ private final String NODE_ITEM_XML_WITH_LANGUAGE_PATTERN = "";
private final String XML_PATTERN = "{}{}";
@@ -92,8 +94,17 @@ public class ZkParserHelper {
String scriptData = new String(client.getData()
.forPath(StrUtil.format("{}/{}", zkParserVO.getScriptPath(), scriptNodeValue)));
- scriptItemContentList.add(StrUtil.format(NODE_ITEM_XML_PATTERN, nodeSimpleVO.getNodeId(),
- nodeSimpleVO.getName(), nodeSimpleVO.getType(), nodeSimpleVO.getLanguage(), scriptData));
+ // 有语言类型
+ if (StrUtil.isNotBlank(nodeSimpleVO.getLanguage())) {
+ scriptItemContentList.add(StrUtil.format(NODE_ITEM_XML_WITH_LANGUAGE_PATTERN,
+ nodeSimpleVO.getNodeId(), nodeSimpleVO.getName(), nodeSimpleVO.getType(),
+ nodeSimpleVO.getLanguage(), scriptData));
+ }
+ // 没有语言类型
+ else {
+ scriptItemContentList.add(StrUtil.format(NODE_ITEM_XML_PATTERN, nodeSimpleVO.getNodeId(),
+ nodeSimpleVO.getName(), nodeSimpleVO.getType(), scriptData));
+ }
}
scriptAllContent = StrUtil.format(NODE_XML_PATTERN,
@@ -169,12 +180,25 @@ public class ZkParserHelper {
LOG.info("starting reload flow config... {} path={} value={},", type.name(), path, value);
String scriptNodeValue = FileNameUtil.getName(path);
NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue);
- LiteFlowNodeBuilder.createScriptNode()
- .setId(nodeSimpleVO.getNodeId())
- .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type))
- .setName(nodeSimpleVO.getName())
- .setScript(value)
- .build();
+ // 有语言类型
+ if (StrUtil.isNotBlank(nodeSimpleVO.getLanguage())) {
+ LiteFlowNodeBuilder.createScriptNode()
+ .setId(nodeSimpleVO.getNodeId())
+ .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type))
+ .setName(nodeSimpleVO.getName())
+ .setScript(value)
+ .setLanguage(nodeSimpleVO.getLanguage())
+ .build();
+ }
+ // 没有语言类型
+ else {
+ LiteFlowNodeBuilder.createScriptNode()
+ .setId(nodeSimpleVO.getNodeId())
+ .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type))
+ .setName(nodeSimpleVO.getName())
+ .setScript(value)
+ .build();
+ }
}
else if (CuratorCacheListener.Type.NODE_DELETED.equals(type)) {
LOG.info("starting reload flow config... delete path={}", path);
diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java
index ebcfd24c2..05415a7c8 100644
--- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java
+++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java
@@ -68,6 +68,10 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest {
zkClient.createPersistent(chain1Path, true);
zkClient.writeData(chain1Path, "THEN(a, b, c, s1, s2);");
+ String chain2Path = ZK_CHAIN_PATH + "/chain2";
+ zkClient.createPersistent(chain2Path, true);
+ zkClient.writeData(chain2Path, "THEN(a, b, c, s3);");
+
String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1:groovy";
zkClient.createPersistent(script1Path, true);
zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");");
@@ -76,11 +80,15 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest {
zkClient.createPersistent(script2Path, true);
zkClient.writeData(script2Path, "defaultContext.setData(\"test1\",\"hello\");");
+ String script3Path = ZK_SCRIPT_PATH + "/s3:script:脚本s3";
+ zkClient.createPersistent(script3Path, true);
+ zkClient.writeData(script3Path, "defaultContext.setData(\"test\",\"hello\");");
+
Thread.sleep(2000L);
}
@Test
- public void testZkNodeWithXml() {
+ public void testZkNodeWithXmlWithLanguage() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
@@ -88,4 +96,12 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest {
Assert.assertEquals("hello", context.getData("test1"));
}
+ @Test
+ public void testZkNodeWithXml() {
+ LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+ DefaultContext context = response.getFirstContextBean();
+ Assert.assertTrue(response.isSuccess());
+ Assert.assertEquals("hello", context.getData("test"));
+ }
+
}
diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java
index 8cf6f71b0..2dc833d3c 100644
--- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java
+++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java
@@ -63,6 +63,10 @@ public class ZkNodeWithXmlELSpringbootTest extends BaseTest {
zkClient.createPersistent(chain1Path, true);
zkClient.writeData(chain1Path, "THEN(a, b, c, s1, s2);");
+ String chain2Path = ZK_CHAIN_PATH + "/chain2";
+ zkClient.createPersistent(chain2Path, true);
+ zkClient.writeData(chain2Path, "THEN(a, b, c, s3);");
+
String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1:groovy";
zkClient.createPersistent(script1Path, true);
zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");");
@@ -70,10 +74,14 @@ public class ZkNodeWithXmlELSpringbootTest extends BaseTest {
String script2Path = ZK_SCRIPT_PATH + "/s2:script:脚本s2:js";
zkClient.createPersistent(script2Path, true);
zkClient.writeData(script2Path, "defaultContext.setData(\"test1\",\"hello\");");
+
+ String script3Path = ZK_SCRIPT_PATH + "/s3:script:脚本s3";
+ zkClient.createPersistent(script3Path, true);
+ zkClient.writeData(script3Path, "defaultContext.setData(\"test\",\"hello\");");
}
@Test
- public void testZkNodeWithXml() {
+ public void testZkNodeWithXmlWithLanguage() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
@@ -81,6 +89,14 @@ public class ZkNodeWithXmlELSpringbootTest extends BaseTest {
Assert.assertEquals("hello", context.getData("test1"));
}
+ @Test
+ public void testZkNodeWithXml() {
+ LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+ DefaultContext context = response.getFirstContextBean();
+ Assert.assertTrue(response.isSuccess());
+ Assert.assertEquals("hello", context.getData("test"));
+ }
+
@AfterClass
public static void tearDown() throws Exception {
zkServer.stop();