mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-13 11:14:38 +08:00
bug #I88U0Q SQL插件当eldata字段为空时,启动失败
This commit is contained in:
@@ -40,6 +40,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -58,6 +59,8 @@ public class FlowBus {
|
||||
|
||||
private static final Map<NodeTypeEnum, Node> fallbackNodeMap = new CopyOnWriteHashMap<>();
|
||||
|
||||
private static AtomicBoolean initStat = new AtomicBoolean(false);
|
||||
|
||||
private FlowBus() {
|
||||
}
|
||||
|
||||
@@ -82,7 +85,7 @@ public class FlowBus {
|
||||
}
|
||||
|
||||
public static boolean needInit() {
|
||||
return MapUtil.isEmpty(chainMap);
|
||||
return initStat.compareAndSet(false, true);
|
||||
}
|
||||
|
||||
public static boolean containNode(String nodeId) {
|
||||
@@ -297,4 +300,8 @@ public class FlowBus {
|
||||
fallbackNodeMap.put(nodeType, node);
|
||||
}
|
||||
|
||||
public static void clearStat(){
|
||||
initStat.set(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,10 +80,6 @@ public class ApolloParseHelper {
|
||||
try {
|
||||
// 1. handle chain
|
||||
Set<String> propertyNames = chainConfig.getPropertyNames();
|
||||
if (CollectionUtil.isEmpty(propertyNames)) {
|
||||
throw new ApolloException(StrUtil.format("There are no chains in namespace : {}",
|
||||
apolloParserConfigVO.getChainNamespace()));
|
||||
}
|
||||
List<String> chainItemContentList = propertyNames.stream()
|
||||
.map(item -> StrUtil.format(CHAIN_XML_PATTERN, item, chainConfig.getProperty(item, StrUtil.EMPTY)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -77,10 +77,6 @@ public class EtcdParserHelper {
|
||||
try {
|
||||
// 检查chainPath路径下有没有子节点
|
||||
List<String> chainNameList = client.getChildrenKeys(etcdParserVO.getChainPath(), SEPARATOR);
|
||||
if (CollectionUtil.isEmpty(chainNameList)) {
|
||||
throw new EtcdException(
|
||||
StrUtil.format("There are no chains in path [{}]", etcdParserVO.getChainPath()));
|
||||
}
|
||||
|
||||
// 获取chainPath路径下的所有子节点内容List
|
||||
List<String> chainItemContentList = new ArrayList<>();
|
||||
|
||||
@@ -121,9 +121,6 @@ public class RedisParserPollingMode implements RedisParserHelper {
|
||||
// 检查chainKey下有没有子节点
|
||||
String chainKey = redisParserVO.getChainKey();
|
||||
Set<String> chainNameSet = chainClient.hkeys(chainKey);
|
||||
if (CollectionUtil.isEmpty(chainNameSet)) {
|
||||
throw new RedisException(StrUtil.format("There are no chains in key [{}]", chainKey));
|
||||
}
|
||||
chainNum = chainNameSet.size();
|
||||
// 获取chainKey下的所有子节点内容List
|
||||
List<String> chainItemContentList = new ArrayList<>();
|
||||
@@ -131,6 +128,8 @@ public class RedisParserPollingMode implements RedisParserHelper {
|
||||
String chainData = chainClient.hget(chainKey, chainName);
|
||||
if (StrUtil.isNotBlank(chainData)) {
|
||||
chainItemContentList.add(StrUtil.format(CHAIN_XML_PATTERN, chainName, chainData));
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
|
||||
//计算该chainData的SHA值
|
||||
|
||||
@@ -86,10 +86,6 @@ public class RedisParserSubscribeMode implements RedisParserHelper {
|
||||
try {
|
||||
// 检查chainKey下有没有子节点
|
||||
Map<String, String> chainMap = chainClient.getMap(redisParserVO.getChainKey());
|
||||
if (CollectionUtil.isEmpty(chainMap)) {
|
||||
throw new RedisException(StrUtil.format("There are no chains in key [{}]",
|
||||
redisParserVO.getChainKey()));
|
||||
}
|
||||
// 获取chainKey下的所有子节点内容List
|
||||
List<String> chainItemContentList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : chainMap.entrySet()) {
|
||||
|
||||
@@ -87,10 +87,14 @@ public abstract class AbstractSqlRead implements SqlRead {
|
||||
}
|
||||
|
||||
|
||||
public String getStringFromResultSet(ResultSet rs, String field) throws SQLException {
|
||||
String data = rs.getString(field);
|
||||
public String getStringFromRs(ResultSet rs, String field) throws SQLException {
|
||||
return rs.getString(field);
|
||||
}
|
||||
|
||||
public String getStringFromRsWithCheck(ResultSet rs, String field) throws SQLException {
|
||||
String data = getStringFromRs(rs, field);
|
||||
if (StrUtil.isBlank(data)) {
|
||||
throw new ELSQLException(StrUtil.format("exist {} field value is empty", field));
|
||||
throw new ELSQLException(StrUtil.format("field[{}] value is empty", field));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -39,24 +39,22 @@ public class ChainRead extends AbstractSqlRead {
|
||||
throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property");
|
||||
}
|
||||
|
||||
String sqlCmd = StrUtil.format(SqlReadConstant.SQL_PATTERN, chainNameField, elDataField, chainTableName,
|
||||
return StrUtil.format(SqlReadConstant.SQL_PATTERN, chainNameField, elDataField, chainTableName,
|
||||
chainApplicationNameField);
|
||||
|
||||
return sqlCmd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildXmlElement(ResultSet rs) throws SQLException {
|
||||
String elDataField = super.config.getElDataField();
|
||||
|
||||
return getStringFromResultSet(rs, elDataField);
|
||||
return getStringFromRs(rs, elDataField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildXmlElementUniqueKey(ResultSet rs) throws SQLException {
|
||||
String chainNameField = super.config.getChainNameField();
|
||||
|
||||
return getStringFromResultSet(rs, chainNameField);
|
||||
return getStringFromRsWithCheck(rs, chainNameField);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ScriptRead extends AbstractSqlRead {
|
||||
public String buildXmlElement(ResultSet rs) throws SQLException {
|
||||
String scriptDataField = super.config.getScriptDataField();
|
||||
|
||||
return getStringFromResultSet(rs, scriptDataField);
|
||||
return getStringFromRs(rs, scriptDataField);
|
||||
|
||||
}
|
||||
|
||||
@@ -93,10 +93,10 @@ public class ScriptRead extends AbstractSqlRead {
|
||||
String scriptTypeField = super.config.getScriptTypeField();
|
||||
String scriptLanguageField = super.config.getScriptLanguageField();
|
||||
|
||||
String id = getStringFromResultSet(rs, scriptIdField);
|
||||
String name = getStringFromResultSet(rs, scriptNameField);
|
||||
String type = getStringFromResultSet(rs, scriptTypeField);
|
||||
String language = withLanguage() ? getStringFromResultSet(rs, scriptLanguageField) : null;
|
||||
String id = getStringFromRsWithCheck(rs, scriptIdField);
|
||||
String name = getStringFromRsWithCheck(rs, scriptNameField);
|
||||
String type = getStringFromRsWithCheck(rs, scriptTypeField);
|
||||
String language = withLanguage() ? getStringFromRs(rs, scriptLanguageField) : null;
|
||||
|
||||
NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type);
|
||||
if (Objects.isNull(nodeTypeEnum)) {
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.yomahub.liteflow.parser.constant.SqlReadConstant.*;
|
||||
|
||||
@@ -91,9 +93,13 @@ public class JDBCHelper {
|
||||
// 获取 chain 数据
|
||||
Map<String, String> chainMap = chainRead.read();
|
||||
List<String> chainList = new ArrayList<>();
|
||||
chainMap.forEach((chainName, elData) -> {
|
||||
chainList.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainName), elData));
|
||||
});
|
||||
|
||||
chainMap.entrySet().stream()
|
||||
.filter(entry -> StrUtil.isNotBlank(entry.getValue()))
|
||||
.forEach(
|
||||
entry -> chainList.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(entry.getKey()), entry.getValue()))
|
||||
);
|
||||
|
||||
String chainsContent = CollUtil.join(chainList, StrUtil.EMPTY);
|
||||
|
||||
// 获取脚本数据
|
||||
|
||||
@@ -66,15 +66,14 @@ public class ZkParserHelper {
|
||||
|
||||
// 检查chainPath路径下有没有子节点
|
||||
List<String> chainNameList = client.getChildren().forPath(zkParserVO.getChainPath());
|
||||
if (CollectionUtil.isEmpty(chainNameList)) {
|
||||
throw new ZkException(StrUtil.format("There are no chains in path [{}]", zkParserVO.getChainPath()));
|
||||
}
|
||||
|
||||
// 获取chainPath路径下的所有子节点内容List
|
||||
List<String> chainItemContentList = new ArrayList<>();
|
||||
for (String chainName : chainNameList) {
|
||||
String chainData = new String(
|
||||
client.getData().forPath(StrUtil.format("{}/{}", zkParserVO.getChainPath(), chainName)));
|
||||
if (StrUtil.isBlank(chainData)){
|
||||
continue;
|
||||
}
|
||||
chainItemContentList.add(StrUtil.format(CHAIN_XML_PATTERN, chainName, chainData));
|
||||
}
|
||||
// 合并成所有chain的xml内容
|
||||
|
||||
@@ -23,6 +23,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest {
|
||||
@AfterEach
|
||||
public void after() {
|
||||
FlowBus.cleanCache();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,6 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class NacosWithXmlELSpringbootTest extends BaseTest {
|
||||
@AfterEach
|
||||
public void after() {
|
||||
FlowBus.cleanCache();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,17 +56,17 @@ public class NacosWithXmlELSpringbootTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testNacosWithXml2() throws Exception {
|
||||
String flowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, b, c);</chain></flow>";
|
||||
String changedFlowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, c);</chain></flow>";
|
||||
String flowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain2\">THEN(a, b, c);</chain></flow>";
|
||||
String changedFlowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain2\">THEN(a, c);</chain></flow>";
|
||||
when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml)
|
||||
.thenReturn(changedFlowXml);
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime());
|
||||
|
||||
FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, changedFlowXml);
|
||||
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowExecutorHolder.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BaseTest {
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user