enhancement 支持etcd分离chain以及脚本的存储结构

This commit is contained in:
zendwang 2022-11-07 22:51:47 +08:00
parent c71efffa6a
commit b05aba0e1d
2 changed files with 21 additions and 20 deletions

View File

@ -68,11 +68,6 @@ public class EtcdParserHelper {
public String getContent(){
try{
//检查zk上有没有chainPath节点
// if (client.get(etcdParserVO.getChainPath()) == null) {
// throw new EtcdException(StrUtil.format("etcd node[{}] is not exist", etcdParserVO.getChainPath()));
// }
//检查chainPath路径下有没有子节点
List<String> chainNameList = client.getChildrenKeys(etcdParserVO.getChainPath(), SEPARATOR);
if (CollectionUtil.isEmpty(chainNameList)){
@ -128,11 +123,6 @@ public class EtcdParserHelper {
}
try{
//配置了但是不存在这个节点
// if (client.get(etcdParserVO.getScriptPath()) == null){
// return false;
// }
//存在这个节点但是子节点不存在
List<String> chainNameList = client.getChildrenKeys(etcdParserVO.getScriptPath(), SEPARATOR);
if (CollUtil.isEmpty(chainNameList)){
@ -151,13 +141,19 @@ public class EtcdParserHelper {
*/
public void listen(Consumer<String> parseConsumer) {
this.client.watchChildChange(this.etcdParserVO.getChainPath(), (updatePath, updateValue) -> {
LOG.info("starting load flow config....");
parseConsumer.accept(updateValue);
}, null);
LOG.info("update path={} value={},starting reload flow config...", updatePath, updateValue);
parseConsumer.accept(getContent());
}, (deletePath) -> {
LOG.info("delete path={},starting reload flow config...", deletePath);
parseConsumer.accept(getContent());
});
this.client.watchChildChange(this.etcdParserVO.getScriptPath(), (updatePath, updateValue) -> {
LOG.info("starting load flow config....");
parseConsumer.accept(updateValue);
}, null);
LOG.info("update path={} value={},starting reload flow config...", updatePath, updateValue);
parseConsumer.accept(getContent());
}, (deletePath) -> {
LOG.info("delete path={},starting reload flow config....", deletePath);
parseConsumer.accept(getContent());
});
}
public NodeSimpleVO convert(String str){

View File

@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.etcd;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ReflectUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.enums.FlowParserTypeEnum;
@ -65,7 +66,7 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr());
Assert.assertEquals("a==>b==>s1[脚本s1]", response.getExecuteStepStr());
Assert.assertEquals("hello", context.getData("test"));
}
@ -77,13 +78,17 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest {
//
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr());
Assert.assertEquals("a==>b==>s1[脚本s1]", response.getExecuteStepStr());
int i=0;
while (i <= 100000) {
i++;
}
// 手动触发一次 模拟节点数据变更
//FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML,changedFlowXml);
Thread.sleep(9000);
LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response2.isSuccess());
Assert.assertEquals("a==>b==>s1[脚本s1]", response2.getExecuteStepStr());
Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr());
}
}