From b703a13a423ea819532747fc0401d59131df0f8b Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 4 Nov 2021 22:06:59 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#I4EXCP=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=85=B3=E9=97=AD/=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=20Banner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/property/LiteflowConfig.java | 20 ++++++++- .../liteflow/spring/ComponentScanner.java | 15 ++++++- .../liteflow/springboot/LiteflowProperty.java | 11 +++++ .../config/LiteflowMainAutoConfiguration.java | 4 +- .../LiteflowPropertyAutoConfiguration.java | 1 + ...itional-spring-configuration-metadata.json | 12 ++++++ .../META-INF/liteflow-default.properties | 3 +- .../BannerPrintSpringbootTest.java | 41 +++++++++++++++++++ .../liteflow/test/bannerPrint/cmp/ACmp.java | 20 +++++++++ .../liteflow/test/bannerPrint/cmp/BCmp.java | 21 ++++++++++ .../liteflow/test/bannerPrint/cmp/CCmp.java | 21 ++++++++++ .../bannerPrint/application.properties | 2 + .../src/test/resources/bannerPrint/flow.xml | 6 +++ 13 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/BannerPrintSpringbootTest.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/ACmp.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/BCmp.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/CCmp.java create mode 100644 liteflow-testcase-springboot/src/test/resources/bannerPrint/application.properties create mode 100644 liteflow-testcase-springboot/src/test/resources/bannerPrint/flow.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index d27742bce..209615c56 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -17,6 +17,7 @@ import com.sun.org.apache.xpath.internal.operations.Bool; * 这个类中的属性为什么不用基本类型,而用包装类型呢 * 是因为这个类是springboot和spring的最终参数获取器,考虑到spring的场景,有些参数不是必须配置。基本类型就会出现默认值的情况。 * 所以为了要有null值出现,这里采用包装类型 + * * @author Bryan.Zhang */ public class LiteflowConfig { @@ -67,6 +68,9 @@ public class LiteflowConfig { //重试次数 private Integer retryCount; + //是否打印liteflow banner + private Boolean printBanner; + public Boolean getEnable() { if (ObjectUtil.isNull(enable)) { return true; @@ -220,9 +224,9 @@ public class LiteflowConfig { } public String getZkNode() { - if (StrUtil.isBlank(zkNode)){ + if (StrUtil.isBlank(zkNode)) { return "/lite-flow/flow"; - }else{ + } else { return zkNode; } } @@ -230,4 +234,16 @@ public class LiteflowConfig { public void setZkNode(String zkNode) { this.zkNode = zkNode; } + + public Boolean getPrintBanner() { + if (ObjectUtil.isNull(printBanner)) { + return Boolean.TRUE; + } else { + return printBanner; + } + } + + public void setPrintBanner(Boolean printBanner) { + this.printBanner = printBanner; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java index 4ed751143..18ee60915 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java @@ -10,6 +10,8 @@ package com.yomahub.liteflow.spring; import com.yomahub.liteflow.aop.ICmpAroundAspect; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.util.LOGOPrinter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,13 +30,22 @@ public class ComponentScanner implements BeanPostProcessor { public static Map nodeComponentMap = new HashMap<>(); + private LiteflowConfig liteflowConfig; + public static ICmpAroundAspect cmpAroundAspect; - static { - // 打印liteflow的LOGO + public ComponentScanner() { LOGOPrinter.print(); } + public ComponentScanner(LiteflowConfig liteflowConfig) { + this.liteflowConfig = liteflowConfig; + if(liteflowConfig.getPrintBanner()){ + // 打印liteflow的LOGO + LOGOPrinter.print(); + } + } + @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 7e887b11d..98e180f7d 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -41,6 +41,9 @@ public class LiteflowProperty { //重试次数 private int retryCount; + //是否打印liteflow banner + private boolean printBanner; + public boolean isEnable() { return enable; } @@ -120,4 +123,12 @@ public class LiteflowProperty { public void setZkNode(String zkNode) { this.zkNode = zkNode; } + + public boolean isPrintBanner() { + return printBanner; + } + + public void setPrintBanner(boolean printBanner) { + this.printBanner = printBanner; + } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java index 6f79a72b2..399f79d99 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java @@ -29,8 +29,8 @@ import org.springframework.context.annotation.Import; public class LiteflowMainAutoConfiguration { @Bean - public ComponentScanner componentScanner(){ - return new ComponentScanner(); + public ComponentScanner componentScanner(LiteflowConfig liteflowConfig){ + return new ComponentScanner(liteflowConfig); } @Bean diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index 3f5253558..5967f9d6e 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -39,6 +39,7 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); liteflowConfig.setRetryCount(property.getRetryCount()); liteflowConfig.setZkNode(property.getZkNode()); + liteflowConfig.setPrintBanner(property.isPrintBanner()); return liteflowConfig; } } diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index f4e2f2e4e..e63b086c7 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -6,6 +6,12 @@ "description": "Whether to turn on liteflow.", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" }, + { + "name": "liteflow.print-banner", + "type": "java.lang.Boolean", + "description": "Whether to print liteflow banner.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" + }, { "name": "liteflow.rule-source", "type": "java.lang.String", @@ -18,6 +24,12 @@ "description": "Set concurrent data slot size.", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" }, + { + "name": "liteflow.zk-node", + "type": "java.lang.String", + "description": "Node definition for ZK configuration.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" + }, { "name": "liteflow.when-max-wait-seconds", "type": "java.lang.Integer", diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 8c353c9bb..8dd42950b 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -1,4 +1,5 @@ liteflow.enable=true +liteflow.print-banner=true liteflow.rule-source=config/flow.xml liteflow.zk-node=/lite-flow/flow liteflow.slot-size=1024 @@ -11,4 +12,4 @@ liteflow.support-multiple-type=false liteflow.monitor.enable-log=false liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 -liteflow.monitor.period=300000 +liteflow.monitor.period=300000 \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/BannerPrintSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/BannerPrintSpringbootTest.java new file mode 100644 index 000000000..e3d42aef6 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/BannerPrintSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.bannerPrint; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +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.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/bannerPrint/application.properties") +@SpringBootTest(classes = BannerPrintSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.bannerPrint.cmp"}) +public class BannerPrintSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testRefresh() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/ACmp.java new file mode 100644 index 000000000..ed0c8a824 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/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.bannerPrint.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-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/BCmp.java new file mode 100644 index 000000000..2d4c7778b --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/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.bannerPrint.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-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/CCmp.java new file mode 100644 index 000000000..e8ea232e9 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/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.bannerPrint.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-springboot/src/test/resources/bannerPrint/application.properties b/liteflow-testcase-springboot/src/test/resources/bannerPrint/application.properties new file mode 100644 index 000000000..589d44e7b --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/bannerPrint/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=bannerPrint/flow.xml +liteflow.print-banner=true \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/bannerPrint/flow.xml b/liteflow-testcase-springboot/src/test/resources/bannerPrint/flow.xml new file mode 100644 index 000000000..22870d94f --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/bannerPrint/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file