From daa36d40a0dc052320e8229c3e5d1b498bca32c3 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sun, 27 Nov 2022 17:27:18 +0800 Subject: [PATCH] =?UTF-8?q?ETCD=E5=AD=98=E5=82=A8=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/etcd/util/EtcdParserHelper.java | 58 ++++++++++--------- .../graaljs/GraalJavaScriptExecutor.java | 10 +++- .../script/javascript/JavaScriptExecutor.java | 1 - .../test/sql/SQLWithXmlELSpringbootTest.java | 2 +- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java index ecc89e757..62807de88 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java @@ -131,11 +131,7 @@ public class EtcdParserHelper { try{ //存在这个节点,但是子节点不存在 List 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){ diff --git a/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java index 28bf96b3c..f7d48fd89 100644 --- a/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java @@ -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(); diff --git a/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java index 25783eeb9..fff27366c 100644 --- a/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java @@ -86,7 +86,6 @@ public class JavaScriptExecutor implements ScriptExecutor { //往脚本上下文里放入元数据 bindings.put("_meta", metaMap); - //放入用户自己定义的bean //放入用户自己定义的bean ScriptBeanManager.getScriptBeanMap().forEach(bindings::putIfAbsent); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java index 4f7c68bec..46ac7164a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java @@ -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());