feat #I6O2YE zk 外置存储支持多脚本混合调用

This commit is contained in:
gaibu
2023-03-21 22:26:30 +08:00
parent 775f5ec791
commit 7d3d07ba28
3 changed files with 67 additions and 11 deletions

View File

@@ -36,7 +36,9 @@ public class ZkParserHelper {
private final String NODE_XML_PATTERN = "<nodes>{}</nodes>";
private final String NODE_ITEM_XML_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\" language=\"{}\"><![CDATA[{}]]></node>";
private final String NODE_ITEM_XML_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\"><![CDATA[{}]]></node>";
private final String NODE_ITEM_XML_WITH_LANGUAGE_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\" language=\"{}\"><![CDATA[{}]]></node>";
private final String XML_PATTERN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow>{}{}</flow>";
@@ -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);

View File

@@ -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"));
}
}

View File

@@ -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();