mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
ETCD存储代码优化
This commit is contained in:
@@ -131,11 +131,7 @@ public class EtcdParserHelper {
|
||||
try{
|
||||
//存在这个节点,但是子节点不存在
|
||||
List<String> chainNameList = client.getChildrenKeys(etcdParserVO.getScriptPath(), SEPARATOR);
|
||||
if (CollUtil.isEmpty(chainNameList)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !CollUtil.isEmpty(chainNameList);
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
@@ -146,29 +142,35 @@ public class EtcdParserHelper {
|
||||
* 监听 etcd 节点
|
||||
*/
|
||||
public void listen() {
|
||||
this.client.watchChildChange(this.etcdParserVO.getChainPath(), (updatePath, updateValue) -> {
|
||||
LOG.info("starting reload flow config... update path={} value={},", updatePath, updateValue);
|
||||
String chainName = updatePath.replace(this.etcdParserVO.getChainPath() + SEPARATOR, "");
|
||||
LiteFlowChainELBuilder.createChain().setChainName(chainName).setEL(updateValue).build();
|
||||
}, (deletePath) -> {
|
||||
LOG.info("starting reload flow config... delete path={}", deletePath);
|
||||
String chainName = deletePath.replace(this.etcdParserVO.getChainPath() + SEPARATOR, "");
|
||||
FlowBus.removeChain(chainName);
|
||||
});
|
||||
this.client.watchChildChange(this.etcdParserVO.getScriptPath(), (updatePath, updateValue) -> {
|
||||
LOG.info("starting reload flow config... update path={} value={}", updatePath, updateValue);
|
||||
String scriptNodeValue = updatePath.replace(this.etcdParserVO.getScriptPath() + SEPARATOR, "");;
|
||||
NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue);
|
||||
LiteFlowNodeBuilder.createScriptNode().setId(nodeSimpleVO.getNodeId())
|
||||
.setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type))
|
||||
.setName(nodeSimpleVO.getName())
|
||||
.setScript(updateValue).build();
|
||||
}, (deletePath) -> {
|
||||
LOG.info("starting reload flow config... delete path={}", deletePath);
|
||||
String scriptNodeValue = deletePath.replace(this.etcdParserVO.getScriptPath() + SEPARATOR, "");;
|
||||
NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue);
|
||||
FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId());
|
||||
});
|
||||
this.client.watchChildChange(this.etcdParserVO.getChainPath(),
|
||||
(updatePath, updateValue) -> {
|
||||
LOG.info("starting reload flow config... update path={} value={},", updatePath, updateValue);
|
||||
String chainName = updatePath.replace(this.etcdParserVO.getChainPath() + SEPARATOR, "");
|
||||
LiteFlowChainELBuilder.createChain().setChainId(chainName).setEL(updateValue).build();
|
||||
},
|
||||
(deletePath) -> {
|
||||
LOG.info("starting reload flow config... delete path={}", deletePath);
|
||||
String chainName = deletePath.replace(this.etcdParserVO.getChainPath() + SEPARATOR, "");
|
||||
FlowBus.removeChain(chainName);
|
||||
}
|
||||
);
|
||||
this.client.watchChildChange(this.etcdParserVO.getScriptPath(),
|
||||
(updatePath, updateValue) -> {
|
||||
LOG.info("starting reload flow config... update path={} value={}", updatePath, updateValue);
|
||||
String scriptNodeValue = updatePath.replace(this.etcdParserVO.getScriptPath() + SEPARATOR, "");
|
||||
NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue);
|
||||
LiteFlowNodeBuilder.createScriptNode().setId(nodeSimpleVO.getNodeId())
|
||||
.setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type))
|
||||
.setName(nodeSimpleVO.getName())
|
||||
.setScript(updateValue).build();
|
||||
},
|
||||
(deletePath) -> {
|
||||
LOG.info("starting reload flow config... delete path={}", deletePath);
|
||||
String scriptNodeValue = deletePath.replace(this.etcdParserVO.getScriptPath() + SEPARATOR, "");
|
||||
NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue);
|
||||
FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public NodeSimpleVO convert(String str){
|
||||
|
||||
@@ -71,7 +71,7 @@ public class GraalJavaScriptExecutor implements ScriptExecutor {
|
||||
metaMap.put("requestData", slot.getRequestData());
|
||||
|
||||
//如果有隐式流程,则放入隐式流程的流程参数
|
||||
Object subRequestData = slot.getChainReqData(wrap.getCurrChainName());
|
||||
Object subRequestData = slot.getChainReqData(wrap.getCurrChainId());
|
||||
if (ObjectUtil.isNotNull(subRequestData)){
|
||||
metaMap.put("subRequestData", subRequestData);
|
||||
}
|
||||
@@ -80,9 +80,13 @@ public class GraalJavaScriptExecutor implements ScriptExecutor {
|
||||
bindings.putMember("_meta", metaMap);
|
||||
|
||||
//放入用户自己定义的bean
|
||||
ScriptBeanManager.getScriptBeanMap().entrySet().stream().forEach( e ->{
|
||||
bindings.putMember(e.getKey(), e.getValue());
|
||||
ScriptBeanManager.getScriptBeanMap().forEach((key, value) -> {
|
||||
if (!bindings.hasMember(key)) {
|
||||
bindings.putMember(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Value value = context.eval("js", scriptMap.get(wrap.getNodeId()));
|
||||
if (value.isBoolean()) {
|
||||
return value.asBoolean();
|
||||
|
||||
@@ -86,7 +86,6 @@ public class JavaScriptExecutor implements ScriptExecutor {
|
||||
//往脚本上下文里放入元数据
|
||||
bindings.put("_meta", metaMap);
|
||||
|
||||
//放入用户自己定义的bean
|
||||
//放入用户自己定义的bean
|
||||
ScriptBeanManager.getScriptBeanMap().forEach(bindings::putIfAbsent);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SQLWithXmlELSpringbootTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSQLWithScriptXml() {
|
||||
public void testSQLWithScriptXml() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime());
|
||||
|
||||
Reference in New Issue
Block a user