Merge remote-tracking branch 'upstream/dev' into instacne-spi

This commit is contained in:
jay li
2024-12-31 19:38:20 +08:00
35 changed files with 606 additions and 8 deletions

View File

@@ -50,6 +50,11 @@ public class CommonBenchmark {
flowExecutor.execute2Resp("chain2");
}
@Benchmark
public void test3(){
flowExecutor.execute2Resp("chain3");
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()

View File

@@ -0,0 +1,15 @@
package com.yomahub.liteflow.benchmark.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import java.util.Iterator;
@LiteflowComponent("d")
public class DCmp extends NodeIteratorComponent {
@Override
public Iterator<?> processIterator() throws Exception {
return ListUtil.toList("1","2","3").iterator();
}
}

View File

@@ -1,2 +1,5 @@
liteflow.rule-source=flow.xml
liteflow.print-execution-log=false
liteflow.print-execution-log=false
liteflow.global-thread-pool-size=500
liteflow.global-thread-pool-queue-size=1000

View File

@@ -30,4 +30,8 @@
<chain name="chain2">
THEN(a,b,s1);
</chain>
<chain name="chain3">
ITERATOR(d).parallel(true).DO(THEN(a,b,c));
</chain>
</flow>

View File

@@ -576,7 +576,8 @@ public class FlowExecutor {
List<Tuple> routeTupleList = new ArrayList<>();
for (Chain routeChain : routeChainList){
CompletableFuture<Slot> f = CompletableFuture.supplyAsync(
() -> doExecute(routeChain.getChainId(), param, finalRequestId, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE, ChainExecuteModeEnum.ROUTE)
() -> doExecute(routeChain.getChainId(), param, finalRequestId, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE, ChainExecuteModeEnum.ROUTE),
ExecutorHelper.loadInstance().buildWhenExecutor()
);
routeTupleList.add(new Tuple(routeChain, f));
@@ -612,7 +613,8 @@ public class FlowExecutor {
List<CompletableFuture<Slot>> executeChainCfList = new ArrayList<>();
for (Chain chain : matchedRouteChainList){
CompletableFuture<Slot> cf = CompletableFuture.supplyAsync(
() -> doExecute(chain.getChainId(), param, finalRequestId, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE, ChainExecuteModeEnum.BODY)
() -> doExecute(chain.getChainId(), param, finalRequestId, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE, ChainExecuteModeEnum.BODY),
ExecutorHelper.loadInstance().buildWhenExecutor()
);
executeChainCfList.add(cf);
}

View File

@@ -99,6 +99,8 @@ public abstract class NodeComponent{
stopWatch.start();
try {
LOG.info("[O]start component[{}] execution", self.getDisplayName());
// 前置处理
self.beforeProcess();

View File

@@ -14,6 +14,7 @@ import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.enums.ConditionTypeEnum;
import com.yomahub.liteflow.enums.ExecuteableTypeEnum;
import com.yomahub.liteflow.exception.ChainEndException;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.element.condition.ConditionKey;
import com.yomahub.liteflow.slot.DataBus;
import com.yomahub.liteflow.slot.Slot;
@@ -116,6 +117,8 @@ public abstract class Condition implements Executable{
executableList.forEach(executable -> {
if (executable instanceof Condition){
resultList.addAll(((Condition)executable).getAllNodeInCondition());
}else if(executable instanceof Chain){
resultList.addAll(FlowBus.getNodesByChainId(executable.getId()));
}else if(executable instanceof Node){
resultList.add((Node)executable);
}

View File

@@ -180,8 +180,6 @@ public class Node implements Executable, Cloneable, Rollbackable{
// 判断是否可执行所以isAccess经常作为一个组件进入的实际判断要素用作检查slot里的参数的完备性
if (getAccessResult() || instance.isAccess()) {
LOG.info("[O]start component[{}] execution", instance.getDisplayName());
// 这里开始进行重试的逻辑和主逻辑的运行
NodeExecutor nodeExecutor = NodeExecutorHelper.loadInstance()
.buildNodeExecutor(instance.getNodeExecutorClass());

View File

@@ -94,7 +94,7 @@ public class JavaxExecutor extends ScriptExecutor {
.replaceAll("protected class", "class");
//分析出class的具体名称
String className = ReUtil.getGroup1("class\\s+(\\w+)\\s+implements", script1);
String className = ReUtil.getGroup1("class\\s+(\\w+)\\s+(implements|extends)", script1);
if (StrUtil.isBlank(className)){
throw new RuntimeException("cannot find class defined");

View File

@@ -0,0 +1,8 @@
package com.yomahub.liteflow.test.script.javax.scriptExtends;
public class DemoClass {
public String sayHello(String name) {
return "hello " + name;
}
}

View File

@@ -0,0 +1,33 @@
package com.yomahub.liteflow.test.script.javax.scriptExtends;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.junit.jupiter.SpringExtension;
import javax.annotation.Resource;
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/scriptExtends/application.properties")
@SpringBootTest(classes = ScriptJavaxScriptExtendsELTest.class)
@EnableAutoConfiguration
public class ScriptJavaxScriptExtendsELTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 测试普通脚本节点
@Test
public void testCommon1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,2 @@
liteflow.rule-source=scriptExtends/flow.xml
liteflow.script-setting.javax-is-cache=false

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
<flow>
<nodes>
<node id="s1" name="普通脚本1" type="script" language="java">
<![CDATA[
import com.yomahub.liteflow.script.body.CommonScriptBody;
import com.yomahub.liteflow.script.ScriptExecuteWrap;
public class Demo implements CommonScriptBody {
public Void body(ScriptExecuteWrap wrap) {
System.out.println("hello world");
return null;
}
}
]]>
</node>
</nodes>
<chain name="chain1">
THEN(s1);
</chain>
</flow>

View File

@@ -0,0 +1,55 @@
package com.yomahub.liteflow.test.getnodes;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
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 javax.annotation.Resource;
import java.util.List;
/**
* springboot环境FlowBus.getNodesByChainId的例子测试
*
* @author Bryan.Zhang
*/
@TestPropertySource(value = "classpath:/getnodes/application.properties")
@SpringBootTest(classes = GetNodesELSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.getnodes.cmp" })
public class GetNodesELSpringbootTest extends BaseTest {
// 从简单到复杂
@Test
public void testGetNodes1() throws Exception {
List<Node> nodeList1 = FlowBus.getNodesByChainId("chain1");
Assertions.assertEquals(4, nodeList1.size());
List<Node> nodeList2 = FlowBus.getNodesByChainId("chain2");
Assertions.assertEquals(5, nodeList2.size());
List<Node> nodeList3 = FlowBus.getNodesByChainId("chain3");
Assertions.assertEquals(7, nodeList3.size());
List<Node> nodeList4 = FlowBus.getNodesByChainId("chain4");
Assertions.assertEquals(15, nodeList4.size());
}
// 测试有子变量的情况
@Test
public void testGetNodes2() throws Exception {
List<Node> nodeList = FlowBus.getNodesByChainId("chain5");
Assertions.assertEquals(15, nodeList.size());
}
// 测试有子chain的情况
@Test
public void testGetNodes3() throws Exception {
List<Node> nodeList = FlowBus.getNodesByChainId("chain6");
Assertions.assertEquals(6, nodeList.size());
}
}

View File

@@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.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!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.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!");
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.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!");
}
@Override
public boolean isAccess() {
System.out.println("hello");
return true;
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ESwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "d";
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("f")
public class FCmp extends NodeComponent {
@Override
public void process() {
System.out.println("FCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("g")
public class GSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "then_1001";
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("h")
public class HCmp extends NodeComponent {
@Override
public void process() {
System.out.println("HCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("i")
public class ICmp extends NodeComponent {
@Override
public void process() {
System.out.println("ICmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("j")
public class JCmp extends NodeComponent {
@Override
public void process() {
System.out.println("JCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("k")
public class KCmp extends NodeComponent {
@Override
public void process() {
System.out.println("KCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("m")
public class MCmp extends NodeComponent {
@Override
public void process() {
System.out.println("MCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("n")
public class NCmp extends NodeComponent {
@Override
public void process() {
System.out.println("NCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("p")
public class PCmp extends NodeComponent {
@Override
public void process() {
System.out.println("PCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("q")
public class QCmp extends NodeComponent {
@Override
public void process() {
System.out.println("QCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("r")
public class RCmp extends NodeComponent {
@Override
public void process() {
System.out.println("RCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("x")
public class XSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "w01";
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getnodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("z")
public class ZCmp extends NodeComponent {
@Override
public void process() {
System.out.println("ZCmp executed!");
}
}

View File

@@ -38,8 +38,12 @@ public class ParallelLoopELSpringbootTest extends BaseTest {
//测试并行FOR循环循环次数直接在el中定义
@Test
public void testParallelLoop1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assertions.assertTrue(response.isSuccess());
for (int i = 0; i < 10; i++) {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assertions.assertTrue(response.isSuccess());
}
}
//测试并行FOR循环循环次数由For组件定义

View File

@@ -0,0 +1 @@
liteflow.rule-source=getnodes/flow.el.xml

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
<flow>
<chain name="chain1">
THEN(a,b,b,a);
</chain>
<chain name="chain2">
THEN(
a,b,
SWITCH(e).to(d,f)
);
</chain>
<chain name="chain3">
THEN(
a,
WHEN(
c,
SWITCH(g).to(b, d, THEN(h,i).id("then_1001"))
)
);
</chain>
<chain name="chain4">
THEN(
a,b,
WHEN(
THEN(c, WHEN(j,k)),
d,
THEN(h, i)
),
SWITCH(x).to(
m,
n,
WHEN(q, THEN(p, r)).id("w01")
),
z
);
</chain>
<chain name="chain5">
t1 = THEN(c, WHEN(j,k));
w1 = WHEN(q, THEN(p, r)).id("w01");
t2 = THEN(h, i);
THEN(
a,b,
WHEN(t1, d, t2 ),
SWITCH(x).to(m, n, w1),
z
);
</chain>
<chain name="chain6">
THEN(j,k,chain1);
</chain>
</flow>