From 7a2887ac03614482132968837de2afebefc8b9a9 Mon Sep 17 00:00:00 2001 From: zhanghua <964552300@qq.com> Date: Sun, 4 Dec 2022 01:41:15 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=20=E6=94=AF=E6=8C=81apollo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow-rule-apollo/pom.xml | 45 ++++++++++ .../parser/apollo/ApolloXmlELParser.java | 65 ++++++++++++++ .../apollo/exception/ApolloException.java | 21 +++++ .../parser/apollo/util/ApolloParseHelper.java | 87 +++++++++++++++++++ .../apollo/vo/ApolloParserConfigVO.java | 34 ++++++++ .../spi/apollo/ApolloParserClassNameSpi.java | 17 ++++ ...hub.liteflow.parser.spi.ParserClassNameSpi | 1 + .../pom.xml | 38 ++++++++ pom.xml | 9 ++ 9 files changed, 317 insertions(+) create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/pom.xml create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java create mode 100644 liteflow-rule-plugin/liteflow-rule-apollo/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml b/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml new file mode 100644 index 000000000..f69b5075f --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml @@ -0,0 +1,45 @@ + + + + liteflow-rule-plugin + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-rule-apollo + + + 8 + 8 + + + + + com.yomahub + liteflow-core + ${revision} + true + provided + + + + com.alibaba.nacos + nacos-client + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + com.ctrip.framework.apollo + apollo-client + + + + + \ No newline at end of file diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java new file mode 100644 index 000000000..9401af7c9 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java @@ -0,0 +1,65 @@ +package com.yomahub.liteflow.parser.apollo; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.parser.apollo.exception.ApolloException; +import com.yomahub.liteflow.parser.apollo.util.ApolloParseHelper; +import com.yomahub.liteflow.parser.apollo.vo.ApolloParserConfigVO; +import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.util.JsonUtil; + +import java.util.Objects; +import java.util.function.Consumer; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 13:38 + */ +public class ApolloXmlELParser extends ClassXmlFlowELParser { + + private final ApolloParseHelper apolloParseHelper; + + public ApolloXmlELParser() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + try { + ApolloParserConfigVO apolloParserConfigVO = null; + if (MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))) { + apolloParserConfigVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), ApolloParserConfigVO.class, CopyOptions.create()); + } else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { + apolloParserConfigVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ApolloParserConfigVO.class); + } + if (Objects.isNull(apolloParserConfigVO)) { + throw new ApolloException("ruleSourceExtData or map is empty"); + } + + apolloParseHelper = new ApolloParseHelper(apolloParserConfigVO); + } catch (Exception e) { + throw new ApolloException(e.getMessage()); + } + } + + @Override + public String parseCustom() { + Consumer parseConsumer = t -> { + try { + parse(t); + } catch (Exception e) { + throw new ApolloException(e.getMessage()); + } + }; + try { + String content = apolloParseHelper.getContent(); + apolloParseHelper.checkContent(content); + apolloParseHelper.listen(parseConsumer); + return content; + + } catch (Exception e) { + throw new ApolloException(e.getMessage()); + } + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java new file mode 100644 index 000000000..f8aa53ec9 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.parser.apollo.exception; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 13:45 + */ +public class ApolloException extends RuntimeException { + + private String message; + + public ApolloException(String message) { + super(); + this.message = message; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java new file mode 100644 index 000000000..a275e80ef --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java @@ -0,0 +1,87 @@ +package com.yomahub.liteflow.parser.apollo.util; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.client.config.NacosConfigService; +import com.ctrip.framework.apollo.Config; +import com.ctrip.framework.apollo.ConfigFile; +import com.ctrip.framework.apollo.ConfigFileChangeListener; +import com.ctrip.framework.apollo.ConfigService; +import com.ctrip.framework.apollo.core.dto.ApolloConfig; +import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; +import com.ctrip.framework.apollo.model.ConfigFileChangeEvent; +import com.yomahub.liteflow.exception.ParseException; +import com.yomahub.liteflow.parser.apollo.exception.ApolloException; +import com.yomahub.liteflow.parser.apollo.vo.ApolloParserConfigVO; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; +import java.util.Properties; +import java.util.function.Consumer; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 13:47 + */ +public class ApolloParseHelper { + + + private static final Logger LOG = LoggerFactory.getLogger(ApolloParseHelper.class); + + private final ApolloParserConfigVO apolloParserConfigVO; + + private ConfigFile liteflowConfigFile; + + public ApolloParseHelper(ApolloParserConfigVO apolloParserConfigVO) { + this.apolloParserConfigVO = apolloParserConfigVO; + try { + liteflowConfigFile = ConfigService.getConfigFile(apolloParserConfigVO.getNamespace(), ConfigFileFormat.XML); + } catch (Exception e) { + LOG.error("[ApolloParseHelper] liteflowConfigFile get init error, apolloParserConfigVO:{}", apolloParserConfigVO); + throw new ApolloException(e.getMessage()); + } + } + + public String getContent() { + try { + ConfigFile configFile = ConfigService.getConfigFile(apolloParserConfigVO.getNamespace(), ConfigFileFormat.XML); + String content; + if (Objects.isNull(configFile) || StrUtil.isBlank(content = configFile.getContent())) { + throw new ApolloException(String.format("not find config file, namespace:%s", apolloParserConfigVO.getNamespace())); + } + return content; + } catch (Exception e) { + throw new ApolloException(e.getMessage()); + } + } + + /** + * 检查 content 是否合法 + */ + public void checkContent(String content) { + if (StrUtil.isBlank(content)) { + String error = StrUtil.format("the node[{}] value is empty", apolloParserConfigVO.toString()); + throw new ParseException(error); + } + } + + /** + * 监听 apollo 数据变化 + */ + public void listen(Consumer parseConsumer) { + try { + liteflowConfigFile.addChangeListener(configFileChangeEvent -> { + String newContext = configFileChangeEvent.getNewValue(); + parseConsumer.accept(newContext); + }); + } catch (Exception e) { + throw new ApolloException(e.getMessage()); + } + } + + +} diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java new file mode 100644 index 000000000..ed79f75e2 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.parser.apollo.vo; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 13:45 + */ +public class ApolloParserConfigVO { + + private String namespace; + + + public ApolloParserConfigVO() { + } + + public ApolloParserConfigVO(String namespace) { + this.namespace = namespace; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @Override + public String toString() { + return "ApolloParserConfigVO{" + + "namespace='" + namespace + '\'' + + '}'; + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java new file mode 100644 index 000000000..d83a7eca1 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.parser.spi.apollo; + +import com.yomahub.liteflow.parser.apollo.ApolloXmlELParser; +import com.yomahub.liteflow.parser.spi.ParserClassNameSpi; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 13:40 + */ +public class ApolloParserClassNameSpi implements ParserClassNameSpi { + + @Override + public String getSpiClassName() { + return ApolloXmlELParser.class.getName(); + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi new file mode 100644 index 000000000..b5c5af6bd --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi @@ -0,0 +1 @@ +com.yomahub.liteflow.parser.spi.apollo.ApolloParserClassNameSpi \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml new file mode 100644 index 000000000..c7cc3c43d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml @@ -0,0 +1,38 @@ + + + + liteflow + com.yomahub + 2.9.4 + + 4.0.0 + + liteflow-testcase-el-apollo-springboot + + + 8 + 8 + + + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + + org.springframework.boot + spring-boot-starter-test + + + + com.yomahub + liteflow-rule-apollo + ${revision} + test + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9ece2bb5f..36d2115cc 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,7 @@ 31.1-jre 4.5.13 1.9.4 + 1.7.0 @@ -259,6 +260,12 @@ provided true + + com.ctrip.framework.apollo + apollo-client + ${apollo.version} + + @@ -370,6 +377,8 @@ liteflow-spring-boot-starter liteflow-spring liteflow-testcase-el + liteflow-rule-apollo + liteflow-testcase-el-apollo-springboot From cebc731296413ba73b772174cad50c804e48d09f Mon Sep 17 00:00:00 2001 From: zhanghua <964552300@qq.com> Date: Sun, 4 Dec 2022 01:41:26 +0800 Subject: [PATCH 2/5] =?UTF-8?q?1.=20apollo=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yomahub/liteflow/test/BaseTest.java | 28 +++++++++ .../apollo/ApolloWithXmlELSpringbootTest.java | 57 +++++++++++++++++++ .../liteflow/test/apollo/cmp/ACmp.java | 20 +++++++ .../liteflow/test/apollo/cmp/BCmp.java | 21 +++++++ .../liteflow/test/apollo/cmp/CCmp.java | 21 +++++++ .../apollo/application-xml.properties | 2 + 6 files changed, 149 insertions(+) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 000000000..dbad4a0e5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test; + +import com.yomahub.liteflow.core.FlowInitHook; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.AfterClass; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 15:22 + */ +public class BaseTest { + + @AfterClass + public static void cleanScanCache(){ + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java new file mode 100644 index 000000000..e158cf7c7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java @@ -0,0 +1,57 @@ +package com.yomahub.liteflow.test.apollo; + +import com.alibaba.nacos.client.config.NacosConfigService; +import com.ctrip.framework.apollo.Config; +import com.ctrip.framework.apollo.ConfigService; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +/** + * @Description: + * @Author: zhanghua + * @Date: 2022/12/3 15:22 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/apollo/application-xml.properties") +@SpringBootTest(classes = ApolloWithXmlELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.apollo.cmp"}) +public class ApolloWithXmlELSpringbootTest { + + + @Resource + private FlowExecutor flowExecutor; + + @After + public void after() { + FlowBus.cleanCache(); + } + + + @Test + public void testApolloWithXml1() throws InterruptedException { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Thread.sleep(2000l); + Assert.assertEquals("a==>b==>c==>c==>b==>a", response.getExecuteStepStrWithoutTime()); + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java new file mode 100644 index 000000000..8ad342958 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.apollo.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java new file mode 100644 index 000000000..24a392e13 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.apollo.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java new file mode 100644 index 000000000..f40763850 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.apollo.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties new file mode 100644 index 000000000..fbc7690ee --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties @@ -0,0 +1,2 @@ +liteflow.rule-source-ext-data={"namespace":"liteflowConfig"} +liteflow.parse-on-start=false \ No newline at end of file From 82028d33c47fcd1f546f86f702717c5a2a11a90c Mon Sep 17 00:00:00 2001 From: zhanghua <964552300@qq.com> Date: Sun, 4 Dec 2022 01:53:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?1.=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/parser/apollo/util/ApolloParseHelper.java | 9 --------- .../test/java/com/yomahub/liteflow/test/BaseTest.java | 2 +- .../test/apollo/ApolloWithXmlELSpringbootTest.java | 9 --------- .../java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java | 1 + .../java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java | 1 + .../java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java | 1 + 6 files changed, 4 insertions(+), 19 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java index a275e80ef..699a3214f 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java @@ -1,25 +1,16 @@ package com.yomahub.liteflow.parser.apollo.util; import cn.hutool.core.util.StrUtil; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.client.config.NacosConfigService; -import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.ConfigFile; -import com.ctrip.framework.apollo.ConfigFileChangeListener; import com.ctrip.framework.apollo.ConfigService; -import com.ctrip.framework.apollo.core.dto.ApolloConfig; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; -import com.ctrip.framework.apollo.model.ConfigFileChangeEvent; import com.yomahub.liteflow.exception.ParseException; import com.yomahub.liteflow.parser.apollo.exception.ApolloException; import com.yomahub.liteflow.parser.apollo.vo.ApolloParserConfigVO; -import com.yomahub.liteflow.spi.holder.ContextAwareHolder; -import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Objects; -import java.util.Properties; import java.util.function.Consumer; /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index dbad4a0e5..785bc391b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -16,7 +16,7 @@ import org.junit.AfterClass; public class BaseTest { @AfterClass - public static void cleanScanCache(){ + public static void cleanScanCache() { ComponentScanner.cleanCache(); FlowBus.cleanCache(); ExecutorHelper.loadInstance().clearExecutorServiceMap(); diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java index e158cf7c7..80de48c80 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java @@ -1,10 +1,6 @@ package com.yomahub.liteflow.test.apollo; -import com.alibaba.nacos.client.config.NacosConfigService; -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.ConfigService; import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.enums.FlowParserTypeEnum; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.LiteflowResponse; import org.junit.After; @@ -13,17 +9,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - /** * @Description: * @Author: zhanghua diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java index 8ad342958..871f8144b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java @@ -1,6 +1,7 @@ /** *

Title: liteflow

*

Description: 轻量级的组件式流程框架

+ * * @author Bryan.Zhang * @email weenyc31@163.com * @Date 2020/4/1 diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java index 24a392e13..482e2c2a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/BCmp.java @@ -1,6 +1,7 @@ /** *

Title: liteflow

*

Description: 轻量级的组件式流程框架

+ * * @author Bryan.Zhang * @email weenyc31@163.com * @Date 2020/4/1 diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java index f40763850..79b305837 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/CCmp.java @@ -1,6 +1,7 @@ /** *

Title: liteflow

*

Description: 轻量级的组件式流程框架

+ * * @author Bryan.Zhang * @email weenyc31@163.com * @Date 2020/4/1 From 7e2e0c337c0bfceb22690ca2644713e9e63ed2f5 Mon Sep 17 00:00:00 2001 From: zhanghua <964552300@qq.com> Date: Mon, 5 Dec 2022 01:18:05 +0800 Subject: [PATCH 4/5] =?UTF-8?q?1.=20chain=E3=80=81script=E5=88=86=E7=A6=BB?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=94=AF=E6=8C=81Apollo=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow-rule-apollo/pom.xml | 4 - .../parser/apollo/ApolloXmlELParser.java | 23 +- .../parser/apollo/util/ApolloParseHelper.java | 212 +++++++++++++++--- .../apollo/vo/ApolloParserConfigVO.java | 28 ++- pom.xml | 2 - 5 files changed, 215 insertions(+), 54 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml b/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml index f69b5075f..23c2643b8 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml +++ b/liteflow-rule-plugin/liteflow-rule-apollo/pom.xml @@ -26,10 +26,6 @@ provided - - com.alibaba.nacos - nacos-client - org.apache.httpcomponents httpclient diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java index 9401af7c9..f47ec4848 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java @@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.FlowInitHook; import com.yomahub.liteflow.parser.apollo.exception.ApolloException; import com.yomahub.liteflow.parser.apollo.util.ApolloParseHelper; import com.yomahub.liteflow.parser.apollo.vo.ApolloParserConfigVO; @@ -13,7 +14,6 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.util.JsonUtil; import java.util.Objects; -import java.util.function.Consumer; /** * @Description: @@ -33,29 +33,32 @@ public class ApolloXmlELParser extends ClassXmlFlowELParser { } else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { apolloParserConfigVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ApolloParserConfigVO.class); } + + // check config if (Objects.isNull(apolloParserConfigVO)) { throw new ApolloException("ruleSourceExtData or map is empty"); } + if (StrUtil.isBlank(apolloParserConfigVO.getChainNamespace())) { + throw new ApolloException("chainNamespace is empty, you must configure the chainNamespace property"); + } + apolloParseHelper = new ApolloParseHelper(apolloParserConfigVO); } catch (Exception e) { throw new ApolloException(e.getMessage()); } } + @Override public String parseCustom() { - Consumer parseConsumer = t -> { - try { - parse(t); - } catch (Exception e) { - throw new ApolloException(e.getMessage()); - } - }; + try { String content = apolloParseHelper.getContent(); - apolloParseHelper.checkContent(content); - apolloParseHelper.listen(parseConsumer); + FlowInitHook.addHook(() -> { + apolloParseHelper.listenApollo(); + return true; + }); return content; } catch (Exception e) { diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java index 699a3214f..11e2557c8 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java @@ -1,17 +1,26 @@ package com.yomahub.liteflow.parser.apollo.util; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; -import com.ctrip.framework.apollo.ConfigFile; +import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.ConfigService; -import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; -import com.yomahub.liteflow.exception.ParseException; +import com.ctrip.framework.apollo.enums.PropertyChangeType; +import com.ctrip.framework.apollo.model.ConfigChange; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.parser.apollo.exception.ApolloException; import com.yomahub.liteflow.parser.apollo.vo.ApolloParserConfigVO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; import java.util.Objects; -import java.util.function.Consumer; +import java.util.Set; +import java.util.stream.Collectors; /** * @Description: @@ -23,54 +32,197 @@ public class ApolloParseHelper { private static final Logger LOG = LoggerFactory.getLogger(ApolloParseHelper.class); + private final String CHAIN_XML_PATTERN = "{}"; + + private final String NODE_XML_PATTERN = "{}"; + + private final String NODE_ITEM_XML_PATTERN = ""; + + private final String XML_PATTERN = "{}{}"; + private final ApolloParserConfigVO apolloParserConfigVO; - private ConfigFile liteflowConfigFile; + private Config chainConfig; + + private Config scriptConfig; + public ApolloParseHelper(ApolloParserConfigVO apolloParserConfigVO) { this.apolloParserConfigVO = apolloParserConfigVO; try { - liteflowConfigFile = ConfigService.getConfigFile(apolloParserConfigVO.getNamespace(), ConfigFileFormat.XML); + chainConfig = ConfigService.getConfig(apolloParserConfigVO.getChainNamespace()); + String scriptNamespace; + // scriptConfig is optional + if (StrUtil.isNotBlank(scriptNamespace = apolloParserConfigVO.getScriptNamespace())) { + scriptConfig = ConfigService.getConfig(scriptNamespace); + } } catch (Exception e) { - LOG.error("[ApolloParseHelper] liteflowConfigFile get init error, apolloParserConfigVO:{}", apolloParserConfigVO); throw new ApolloException(e.getMessage()); } } public String getContent() { + try { - ConfigFile configFile = ConfigService.getConfigFile(apolloParserConfigVO.getNamespace(), ConfigFileFormat.XML); - String content; - if (Objects.isNull(configFile) || StrUtil.isBlank(content = configFile.getContent())) { - throw new ApolloException(String.format("not find config file, namespace:%s", apolloParserConfigVO.getNamespace())); + // 1. handle chain + Set propertyNames = chainConfig.getPropertyNames(); + if (CollectionUtil.isEmpty(propertyNames)) { + throw new ApolloException(StrUtil.format("There are no chains in namespace : {}", apolloParserConfigVO.getChainNamespace())); } - return content; + List chainItemContentList = propertyNames.stream() + .map(item -> StrUtil.format(CHAIN_XML_PATTERN, item, chainConfig.getProperty(item, StrUtil.EMPTY))) + .collect(Collectors.toList()); + // merge all chain content + String chainAllContent = CollUtil.join(chainItemContentList, StrUtil.EMPTY); + + // 2. handle script if needed + String scriptAllContent = StrUtil.EMPTY; + Set scriptNamespaces; + if (Objects.nonNull(scriptConfig) && CollectionUtil.isNotEmpty(scriptNamespaces = scriptConfig.getPropertyNames())) { + + List scriptItemContentList = scriptNamespaces.stream() + .map(item -> convert(item, scriptConfig.getProperty(item, StrUtil.EMPTY))) + .filter(Objects::nonNull) + .map(item -> StrUtil.format(NODE_ITEM_XML_PATTERN, item.getNodeId(), item.getName(), item.getType(), item.getScript())) + .collect(Collectors.toList()); + + scriptAllContent = StrUtil.format(NODE_XML_PATTERN, CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); + } + + return StrUtil.format(XML_PATTERN, scriptAllContent, chainAllContent); } catch (Exception e) { throw new ApolloException(e.getMessage()); } } - /** - * 检查 content 是否合法 - */ - public void checkContent(String content) { - if (StrUtil.isBlank(content)) { - String error = StrUtil.format("the node[{}] value is empty", apolloParserConfigVO.toString()); - throw new ParseException(error); - } - } /** - * 监听 apollo 数据变化 + * listen apollo config change */ - public void listen(Consumer parseConsumer) { - try { - liteflowConfigFile.addChangeListener(configFileChangeEvent -> { - String newContext = configFileChangeEvent.getNewValue(); - parseConsumer.accept(newContext); - }); - } catch (Exception e) { - throw new ApolloException(e.getMessage()); + public void listenApollo() { + + // chain + chainConfig.addChangeListener(changeEvent -> + changeEvent.changedKeys().forEach(changeKey -> { + ConfigChange configChange = changeEvent.getChange(changeKey); + String newValue = configChange.getNewValue(); + PropertyChangeType changeType = configChange.getChangeType(); + switch (changeType) { + case ADDED: + case MODIFIED: + LOG.info("starting reload flow config... {} key={} value={},", changeType.name(), changeKey, newValue); + LiteFlowChainELBuilder.createChain() + .setChainId(changeKey) + .setEL(newValue) + .build(); + break; + case DELETED: + LOG.info("starting reload flow config... delete key={}", changeKey); + FlowBus.removeChain(changeKey); + + } + })); + + // script + if (Objects.isNull(scriptConfig)) { + // no script config + return; + } + scriptConfig.addChangeListener(changeEvent -> + changeEvent.changedKeys().forEach(changeKey -> { + ConfigChange configChange = changeEvent.getChange(changeKey); + String newValue = configChange.getNewValue(); + + PropertyChangeType changeType = configChange.getChangeType(); + + NodeSimpleVO nodeSimpleVO; + switch (changeType) { + case ADDED: + case MODIFIED: + LOG.info("starting reload flow config... {} key={} value={},", changeType.name(), changeKey, newValue); + nodeSimpleVO = convert(changeKey, newValue); + LiteFlowNodeBuilder.createScriptNode() + .setId(nodeSimpleVO.getNodeId()) + .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.getType())) + .setName(nodeSimpleVO.getName()) + .setScript(nodeSimpleVO.getScript()) + .build(); + break; + case DELETED: + LOG.info("starting reload flow config... delete key={}", changeKey); + nodeSimpleVO = convert(changeKey, null); + FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId()); + } + })); + + } + + + private NodeSimpleVO convert(String key, String value) { + //不需要去理解这串正则,就是一个匹配冒号的 + //一定得是a:b,或是a:b:c...这种完整类型的字符串的 + List matchItemList = ReUtil.findAllGroup0("(?<=[^:]:)[^:]+|[^:]+(?=:[^:])", key); + if (CollUtil.isEmpty(matchItemList)) { + return null; + } + + NodeSimpleVO nodeSimpleVO = new NodeSimpleVO(); + if (matchItemList.size() > 1) { + nodeSimpleVO.setNodeId(matchItemList.get(0)); + nodeSimpleVO.setType(matchItemList.get(1)); + } + + if (matchItemList.size() > 2) { + nodeSimpleVO.setName(matchItemList.get(2)); + } + + // set script + nodeSimpleVO.setScript(value); + + return nodeSimpleVO; + } + + + private static class NodeSimpleVO { + + private String nodeId; + + private String type; + + private String name = StrUtil.EMPTY; + + private String script; + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; } } diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java index ed79f75e2..311fd3bd7 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java @@ -7,28 +7,40 @@ package com.yomahub.liteflow.parser.apollo.vo; */ public class ApolloParserConfigVO { - private String namespace; + private String chainNamespace; + + private String scriptNamespace; public ApolloParserConfigVO() { } - public ApolloParserConfigVO(String namespace) { - this.namespace = namespace; + public ApolloParserConfigVO(String chainNamespace, String scriptNamespace) { + this.chainNamespace = chainNamespace; + this.scriptNamespace = scriptNamespace; } - public String getNamespace() { - return namespace; + public String getChainNamespace() { + return chainNamespace; } - public void setNamespace(String namespace) { - this.namespace = namespace; + public void setChainNamespace(String chainNamespace) { + this.chainNamespace = chainNamespace; + } + + public String getScriptNamespace() { + return scriptNamespace; + } + + public void setScriptNamespace(String scriptNamespace) { + this.scriptNamespace = scriptNamespace; } @Override public String toString() { return "ApolloParserConfigVO{" + - "namespace='" + namespace + '\'' + + "chainNamespace='" + chainNamespace + '\'' + + ", scriptNamespace='" + scriptNamespace + '\'' + '}'; } } diff --git a/pom.xml b/pom.xml index 36d2115cc..3d91f3510 100644 --- a/pom.xml +++ b/pom.xml @@ -377,8 +377,6 @@ liteflow-spring-boot-starter liteflow-spring liteflow-testcase-el - liteflow-rule-apollo - liteflow-testcase-el-apollo-springboot From 3a85cc36a4d45aa11f96e7332cb0cfab37dd2249 Mon Sep 17 00:00:00 2001 From: zhanghua <964552300@qq.com> Date: Mon, 5 Dec 2022 01:18:24 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1.=20=E6=B5=8B=E8=AF=95Apollo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 17 +++++++++++++++-- .../apollo/ApolloWithXmlELSpringbootTest.java | 12 ++++++++++-- .../resources/apollo/application-xml.properties | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml index c7cc3c43d..d47c6904e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/pom.xml @@ -3,9 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - liteflow + liteflow-testcase-el com.yomahub - 2.9.4 + ${revision} + ../pom.xml 4.0.0 @@ -34,5 +35,17 @@ ${revision} test + + + cn.hutool + hutool-core + ${hutool-core.version} + + + + com.yomahub + liteflow-script-groovy + ${revision} + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java index 80de48c80..fa9e229c8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java @@ -40,9 +40,17 @@ public class ApolloWithXmlELSpringbootTest { @Test public void testApolloWithXml1() throws InterruptedException { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Thread.sleep(2000l); - Assert.assertEquals("a==>b==>c==>c==>b==>a", response.getExecuteStepStrWithoutTime()); + Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStrWithoutTime()); } + @Test + public void testApolloWithXml2() throws InterruptedException { + while (true) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + System.out.println("liteflow step : " + response.getExecuteStepStrWithoutTime()); + Thread.sleep(2000l); + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties index fbc7690ee..366b1dc36 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/resources/apollo/application-xml.properties @@ -1,2 +1,2 @@ -liteflow.rule-source-ext-data={"namespace":"liteflowConfig"} +liteflow.rule-source-ext-data={"chainNamespace":"chainConfig","scriptNamespace":"scriptConfig"} liteflow.parse-on-start=false \ No newline at end of file