feature #I9DQDU 允许对不存在的组件增加全局参数

This commit is contained in:
everywhere.z 2024-04-09 14:53:57 +08:00
parent e3cfe56308
commit 59f67bc546
21 changed files with 76 additions and 71 deletions

View File

@ -10,6 +10,7 @@ import com.ql.util.express.InstructionSet;
import com.ql.util.express.exception.QLException; import com.ql.util.express.exception.QLException;
import com.yomahub.liteflow.builder.el.operator.*; import com.yomahub.liteflow.builder.el.operator.*;
import com.yomahub.liteflow.common.ChainConstant; import com.yomahub.liteflow.common.ChainConstant;
import com.yomahub.liteflow.enums.ParseModeEnum;
import com.yomahub.liteflow.exception.*; import com.yomahub.liteflow.exception.*;
import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.element.Chain; import com.yomahub.liteflow.flow.element.Chain;
@ -184,7 +185,7 @@ public class LiteFlowChainELBuilder {
this.chain.setEl(elStr); this.chain.setEl(elStr);
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
// 如果设置了不检查Node是否存在那么这里是不解析的 // 如果设置了不检查Node是否存在那么这里是不解析的
if (BooleanUtil.isFalse(liteflowConfig.getCheckNodeExists())){ if (liteflowConfig.getParseMode().equals(ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC)){
this.chain.setCompiled(false); this.chain.setCompiled(false);
return this; return this;
} }

View File

@ -15,6 +15,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.*; import cn.hutool.core.util.*;
import com.yomahub.liteflow.enums.ChainExecuteModeEnum; import com.yomahub.liteflow.enums.ChainExecuteModeEnum;
import com.yomahub.liteflow.enums.InnerChainTypeEnum; import com.yomahub.liteflow.enums.InnerChainTypeEnum;
import com.yomahub.liteflow.enums.ParseModeEnum;
import com.yomahub.liteflow.exception.*; import com.yomahub.liteflow.exception.*;
import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.LiteflowResponse;
@ -72,7 +73,7 @@ public class FlowExecutor {
LiteflowConfigGetter.setLiteflowConfig(liteflowConfig); LiteflowConfigGetter.setLiteflowConfig(liteflowConfig);
// 设置FlowExecutor的Holder虽然大部分地方都可以通过Spring上下文获取到但放入Holder还是为了某些地方能方便的取到 // 设置FlowExecutor的Holder虽然大部分地方都可以通过Spring上下文获取到但放入Holder还是为了某些地方能方便的取到
FlowExecutorHolder.setHolder(this); FlowExecutorHolder.setHolder(this);
if (BooleanUtil.isTrue(liteflowConfig.isParseOnStart())) { if (!liteflowConfig.getParseMode().equals(ParseModeEnum.PARSE_ALL_ON_FIRST_EXEC)) {
this.init(true); this.init(true);
} }
// 初始化DataBus // 初始化DataBus

View File

@ -0,0 +1,17 @@
package com.yomahub.liteflow.enums;
/**
* 解析模式
* PARSE_ALL_ON_START 启动时解析所有的规则
* PARSE_ALL_ON_FIRST_EXEC 第一次执行链路时解析所有的规则
* PARSE_ONE_ON_FIRST_EXEC 第一次执行相关链路时解析当前的规则
*
* @author Bryan.Zhang
* @since 2.12.0
*/
public enum ParseModeEnum {
PARSE_ALL_ON_START,
PARSE_ALL_ON_FIRST_EXEC,
PARSE_ONE_ON_FIRST_EXEC
}

View File

@ -10,6 +10,7 @@ package com.yomahub.liteflow.property;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.enums.ParseModeEnum;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -71,9 +72,8 @@ public class LiteflowConfig {
// 异步线程池最大队列数量 // 异步线程池最大队列数量
private Integer whenQueueLimit; private Integer whenQueueLimit;
// 是否在启动时解析规则文件 // 解析模式一共有三种具体看其定义
// 这个参数主要给编码式注册元数据的场景用的结合FlowBus.addNode一起用 private ParseModeEnum parseMode;
private Boolean parseOnStart;
// 这个属性为true则支持多种不同的类型的配置 // 这个属性为true则支持多种不同的类型的配置
// 但是要注意不能将主流程和子流程分配在不同类型配置文件中 // 但是要注意不能将主流程和子流程分配在不同类型配置文件中
@ -118,9 +118,6 @@ public class LiteflowConfig {
//是否快速加载规则如果快速加载规则意味着不用copyOnWrite机制了 //是否快速加载规则如果快速加载规则意味着不用copyOnWrite机制了
private Boolean fastLoad; private Boolean fastLoad;
//检查node是否存在
private Boolean checkNodeExists;
public Boolean getEnableMonitorFile() { public Boolean getEnableMonitorFile() {
return enableMonitorFile; return enableMonitorFile;
} }
@ -254,19 +251,6 @@ public class LiteflowConfig {
this.whenQueueLimit = whenQueueLimit; this.whenQueueLimit = whenQueueLimit;
} }
public Boolean isParseOnStart() {
if (ObjectUtil.isNull(parseOnStart)) {
return Boolean.TRUE;
}
else {
return parseOnStart;
}
}
public void setParseOnStart(Boolean parseOnStart) {
this.parseOnStart = parseOnStart;
}
public Boolean isSupportMultipleType() { public Boolean isSupportMultipleType() {
if (ObjectUtil.isNull(supportMultipleType)) { if (ObjectUtil.isNull(supportMultipleType)) {
return Boolean.FALSE; return Boolean.FALSE;
@ -494,15 +478,15 @@ public class LiteflowConfig {
this.fastLoad = fastLoad; this.fastLoad = fastLoad;
} }
public Boolean getCheckNodeExists() { public ParseModeEnum getParseMode() {
if (ObjectUtil.isNull(checkNodeExists)){ if (ObjectUtil.isNull(parseMode)) {
return Boolean.TRUE; return ParseModeEnum.PARSE_ALL_ON_START;
}else{ }else{
return checkNodeExists; return parseMode;
} }
} }
public void setCheckNodeExists(Boolean checkNodeExists) { public void setParseMode(ParseModeEnum parseMode) {
this.checkNodeExists = checkNodeExists; this.parseMode = parseMode;
} }
} }

View File

@ -36,7 +36,7 @@ public class LiteflowAutoConfiguration {
liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod());
liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers());
liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit());
liteflowConfig.setParseOnStart(property.isParseOnStart()); liteflowConfig.setParseMode(property.getParseMode());
liteflowConfig.setEnable(property.isEnable()); liteflowConfig.setEnable(property.isEnable());
liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); liteflowConfig.setSupportMultipleType(property.isSupportMultipleType());
liteflowConfig.setRetryCount(property.getRetryCount()); liteflowConfig.setRetryCount(property.getRetryCount());

View File

@ -1,5 +1,6 @@
package com.yomahub.liteflow.solon.config; package com.yomahub.liteflow.solon.config;
import com.yomahub.liteflow.enums.ParseModeEnum;
import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject; import org.noear.solon.annotation.Inject;
@ -44,9 +45,8 @@ public class LiteflowProperty {
// 异步线程池最大队列数量 // 异步线程池最大队列数量
private int whenQueueLimit; private int whenQueueLimit;
// 是否在启动时解析规则文件 // 解析模式一共有三种具体看其定义
// 这个参数主要给编码式注册元数据的场景用的结合FlowBus.addNode一起用 private ParseModeEnum parseMode;
private boolean parseOnStart;
// 这个属性为true则支持多种不同的类型的配置 // 这个属性为true则支持多种不同的类型的配置
// 但是要注意不能将主流程和子流程分配在不同类型配置文件中 // 但是要注意不能将主流程和子流程分配在不同类型配置文件中
@ -132,14 +132,6 @@ public class LiteflowProperty {
this.whenQueueLimit = whenQueueLimit; this.whenQueueLimit = whenQueueLimit;
} }
public boolean isParseOnStart() {
return parseOnStart;
}
public void setParseOnStart(boolean parseOnStart) {
this.parseOnStart = parseOnStart;
}
public boolean isSupportMultipleType() { public boolean isSupportMultipleType() {
return supportMultipleType; return supportMultipleType;
} }
@ -251,4 +243,12 @@ public class LiteflowProperty {
public void setFallbackCmpEnable(Boolean fallbackCmpEnable) { public void setFallbackCmpEnable(Boolean fallbackCmpEnable) {
this.fallbackCmpEnable = fallbackCmpEnable; this.fallbackCmpEnable = fallbackCmpEnable;
} }
public ParseModeEnum getParseMode() {
return parseMode;
}
public void setParseMode(ParseModeEnum parseMode) {
this.parseMode = parseMode;
}
} }

View File

@ -1,5 +1,6 @@
package com.yomahub.liteflow.springboot; package com.yomahub.liteflow.springboot;
import com.yomahub.liteflow.enums.ParseModeEnum;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Map; import java.util.Map;
@ -54,9 +55,8 @@ public class LiteflowProperty {
// 异步线程池是否隔离 // 异步线程池是否隔离
private boolean whenThreadPoolIsolate; private boolean whenThreadPoolIsolate;
// 是否在启动时解析规则文件 // 解析模式一共有三种具体看其定义
// 这个参数主要给编码式注册元数据的场景用的结合FlowBus.addNode一起用 private ParseModeEnum parseMode;
private boolean parseOnStart;
// 这个属性为true则支持多种不同的类型的配置 // 这个属性为true则支持多种不同的类型的配置
// 但是要注意不能将主流程和子流程分配在不同类型配置文件中 // 但是要注意不能将主流程和子流程分配在不同类型配置文件中
@ -155,12 +155,12 @@ public class LiteflowProperty {
this.whenQueueLimit = whenQueueLimit; this.whenQueueLimit = whenQueueLimit;
} }
public boolean isParseOnStart() { public ParseModeEnum getParseMode() {
return parseOnStart; return parseMode;
} }
public void setParseOnStart(boolean parseOnStart) { public void setParseMode(ParseModeEnum parseMode) {
this.parseOnStart = parseOnStart; this.parseMode = parseMode;
} }
public boolean isSupportMultipleType() { public boolean isSupportMultipleType() {

View File

@ -51,9 +51,17 @@ public class LiteflowMainAutoConfiguration {
} }
// FlowExecutor的初始化工作和实例化分开来 // FlowExecutor的初始化工作和实例化分开来
// 这里写2个几乎一样的是因为无论是在PARSE_ALL_ON_START或者PARSE_ONE_ON_FIRST_EXEC模式下都需要初始化工作
// 换句话说这两个只可能被执行一个
@Bean @Bean
@ConditionalOnProperty(prefix = "liteflow", name = "parse-on-start", havingValue = "true") @ConditionalOnProperty(prefix = "liteflow", name = "parse-mode", havingValue = "PARSE_ALL_ON_START")
public LiteflowExecutorInit liteflowExecutorInit(FlowExecutor flowExecutor) { public LiteflowExecutorInit liteflowExecutorInit1(FlowExecutor flowExecutor) {
return new LiteflowExecutorInit(flowExecutor);
}
@Bean
@ConditionalOnProperty(prefix = "liteflow", name = "parse-mode", havingValue = "PARSE_ONE_ON_FIRST_EXEC")
public LiteflowExecutorInit liteflowExecutorInit2(FlowExecutor flowExecutor) {
return new LiteflowExecutorInit(flowExecutor); return new LiteflowExecutorInit(flowExecutor);
} }

View File

@ -33,7 +33,7 @@ public class LiteflowPropertyAutoConfiguration {
liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers());
liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit());
liteflowConfig.setWhenThreadPoolIsolate(property.isWhenThreadPoolIsolate()); liteflowConfig.setWhenThreadPoolIsolate(property.isWhenThreadPoolIsolate());
liteflowConfig.setParseOnStart(property.isParseOnStart()); liteflowConfig.setParseMode(property.getParseMode());
liteflowConfig.setEnable(property.isEnable()); liteflowConfig.setEnable(property.isEnable());
liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); liteflowConfig.setSupportMultipleType(property.isSupportMultipleType());
liteflowConfig.setRetryCount(property.getRetryCount()); liteflowConfig.setRetryCount(property.getRetryCount());
@ -49,7 +49,6 @@ public class LiteflowPropertyAutoConfiguration {
liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass()); liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass());
liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable()); liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable());
liteflowConfig.setFastLoad(property.isFastLoad()); liteflowConfig.setFastLoad(property.isFastLoad());
liteflowConfig.setCheckNodeExists(property.isCheckNodeExists());
liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog());
liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit());
liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); liteflowConfig.setDelay(liteflowMonitorProperty.getDelay());

View File

@ -111,9 +111,9 @@
"defaultValue": false "defaultValue": false
}, },
{ {
"name": "liteflow.parse-on-start", "name": "liteflow.parse-mode",
"type": "java.lang.Boolean", "type": "com.yomahub.liteflow.enums.ParseModeEnum",
"description": "Set whether the rule file needs to be parsed at startup.", "description": "Set parse mode at startup.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty",
"defaultValue": true "defaultValue": true
}, },
@ -159,13 +159,6 @@
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty",
"defaultValue": false "defaultValue": false
}, },
{
"name": "liteflow.check-node-exists",
"type": "java.lang.Boolean",
"description": "Whether to check the existence of a node or not.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty",
"defaultValue": true
},
{ {
"name": "liteflow.monitor.enable-log", "name": "liteflow.monitor.enable-log",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",

View File

@ -10,7 +10,7 @@ liteflow.when-max-wait-time-unit=MILLISECONDS
liteflow.when-max-workers=16 liteflow.when-max-workers=16
liteflow.when-queue-limit=512 liteflow.when-queue-limit=512
liteflow.when-thread-pool-isolate=false liteflow.when-thread-pool-isolate=false
liteflow.parse-on-start=true liteflow.parse-mode=PARSE_ALL_ON_START
liteflow.retry-count=0 liteflow.retry-count=0
liteflow.support-multiple-type=false liteflow.support-multiple-type=false
liteflow.node-executor-class=com.yomahub.liteflow.flow.executor.DefaultNodeExecutor liteflow.node-executor-class=com.yomahub.liteflow.flow.executor.DefaultNodeExecutor

View File

@ -1,2 +1,2 @@
liteflow.rule-source-ext-data={"chainNamespace":"chainConfig","scriptNamespace":"scriptConfig"} liteflow.rule-source-ext-data={"chainNamespace":"chainConfig","scriptNamespace":"scriptConfig"}
liteflow.parse-on-start=false liteflow.parse-mode=PARSE_ALL_ON_FIRST_EXEC

View File

@ -3,4 +3,4 @@ liteflow.rule-source-ext-data={\
"chainPath": "/liteflow/chain",\ "chainPath": "/liteflow/chain",\
"scriptPath": "/liteflow/script"\ "scriptPath": "/liteflow/script"\
} }
liteflow.parse-on-start=false liteflow.parse-mode=PARSE_ALL_ON_FIRST_EXEC

View File

@ -3,4 +3,4 @@ liteflow.rule-source-ext-data={\
"chainPath": "/liteflow/chain",\ "chainPath": "/liteflow/chain",\
"scriptPath": "/liteflow/script"\ "scriptPath": "/liteflow/script"\
} }
liteflow.parse-on-start=false liteflow.parse-mode=PARSE_ALL_ON_FIRST_EXEC

View File

@ -1,2 +1,2 @@
liteflow.rule-source-ext-data={"serverAddr":"192.168.10.147:8848","dataId":"LiteFlow","group":"LITE_FLOW_GROUP","namespace":"","username":"","password":""} liteflow.rule-source-ext-data={"serverAddr":"192.168.10.147:8848","dataId":"LiteFlow","group":"LITE_FLOW_GROUP","namespace":"","username":"","password":""}
liteflow.parse-on-start=false liteflow.parse-mode=PARSE_ALL_ON_FIRST_EXEC

View File

@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.config;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder; import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.enums.ParseModeEnum;
import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.property.LiteflowConfigGetter;
@ -43,7 +44,7 @@ public class LiteflowConfigTest1 extends BaseTest {
Assertions.assertFalse(config.getEnableLog()); Assertions.assertFalse(config.getEnableLog());
Assertions.assertEquals(16, config.getWhenMaxWorkers().longValue()); Assertions.assertEquals(16, config.getWhenMaxWorkers().longValue());
Assertions.assertEquals(512, config.getWhenQueueLimit().longValue()); Assertions.assertEquals(512, config.getWhenQueueLimit().longValue());
Assertions.assertEquals(true, config.isParseOnStart()); Assertions.assertEquals(ParseModeEnum.PARSE_ALL_ON_START, config.getParseMode());
} }
} }

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.test.flowmeta;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder; import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.enums.NodeTypeEnum;
import com.yomahub.liteflow.enums.ParseModeEnum;
import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfig;
@ -20,7 +21,7 @@ public class FlowMetaTest extends BaseTest {
public static void init() { public static void init() {
LiteflowConfig config = new LiteflowConfig(); LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("flowmeta/flow.el.xml"); config.setRuleSource("flowmeta/flow.el.xml");
config.setParseOnStart(false); config.setParseMode(ParseModeEnum.PARSE_ALL_ON_FIRST_EXEC);
flowExecutor = FlowExecutorHolder.loadInstance(config); flowExecutor = FlowExecutorHolder.loadInstance(config);
} }

View File

@ -8,4 +8,4 @@ liteflow.rule-source-ext-data={\
"scriptDataBase":1,\ "scriptDataBase":1,\
"scriptKey":"pollScriptKey"\ "scriptKey":"pollScriptKey"\
} }
liteflow.parse-on-start=false liteflow.parse-mode=PARSE_ALL_ON_FIRST_EXEC

View File

@ -7,4 +7,4 @@ liteflow.rule-source-ext-data={\
"scriptDataBase":1,\ "scriptDataBase":1,\
"scriptKey":"testScriptKey"\ "scriptKey":"testScriptKey"\
} }
liteflow.parse-on-start=false liteflow.parse-mode=PARSE_ALL_ON_FIRST_EXEC

View File

@ -1,2 +1,2 @@
liteflow.rule-source=uncheckNode/flow.el.xml liteflow.rule-source=uncheckNode/flow.el.xml
liteflow.check-node-exists=false liteflow.parse-mode=PARSE_ONE_ON_FIRST_EXEC

View File

@ -15,7 +15,7 @@
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig"> <bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="flowmeta/flow.el.xml"/> <property name="ruleSource" value="flowmeta/flow.el.xml"/>
<property name="parseOnStart" value="false"/> <property name="parseMode" value="PARSE_ALL_ON_FIRST_EXEC"/>
</bean> </bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor"> <bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">