|
@@ -5,7 +5,7 @@ import cn.hutool.crypto.digest.MD5;
|
|
|
import com.yomahub.liteflow.flow.element.Chain;
|
|
|
import com.yomahub.liteflow.flow.element.Condition;
|
|
|
import com.yomahub.liteflow.flow.element.Node;
|
|
|
-import com.yomahub.liteflow.flow.entity.InstanceIdDto;
|
|
|
+import com.yomahub.liteflow.flow.entity.InstanceInfoDto;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
@@ -25,16 +25,13 @@ public abstract class BaseNodeInstanceIdManageSpi implements NodeInstanceIdManag
|
|
|
if (StringUtils.isBlank(chainId) || StringUtils.isBlank(instanceId)) {
|
|
|
return "";
|
|
|
}
|
|
|
-
|
|
|
+ // 第一行为elMd5 第二行为实例id json格式信息
|
|
|
List<String> instanceIdFile = readInstanceIdFile(chainId);
|
|
|
|
|
|
for (int i = 1; i < instanceIdFile.size(); i++) {
|
|
|
- List<InstanceIdDto> instanceIdDtos = parseList(instanceIdFile.get(i), InstanceIdDto.class);
|
|
|
- if (instanceIdDtos == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ List<InstanceInfoDto> instanceInfos = parseList(instanceIdFile.get(i), InstanceInfoDto.class);
|
|
|
|
|
|
- for (InstanceIdDto dto : instanceIdDtos) {
|
|
|
+ for (InstanceInfoDto dto : instanceInfos) {
|
|
|
if (Objects.equals(dto.getInstanceId(), instanceId)) {
|
|
|
return dto.getNodeId() + "(" + dto.getIndex() + ")";
|
|
|
}
|
|
@@ -50,18 +47,19 @@ public abstract class BaseNodeInstanceIdManageSpi implements NodeInstanceIdManag
|
|
|
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
|
|
|
|
|
String elMd5 = MD5.create().digestHex(chain.getEl());
|
|
|
- List<String> instanceIdFile = nodeInstanceIdManageSpi.readInstanceIdFile(chain.getChainId());
|
|
|
+ String chainId = chain.getChainId();
|
|
|
+ List<String> instanceIdFile = nodeInstanceIdManageSpi.readInstanceIdFile(chainId);
|
|
|
|
|
|
// 如果文件不存在,或者文件内容不是当前el,则写入
|
|
|
if (CollUtil.isEmpty(instanceIdFile) || !instanceIdFile.get(0).equals(elMd5)) {
|
|
|
- nodeInstanceIdManageSpi.writeInstanceIdFile(writeNodeInstanceId(condition), elMd5, chain.getChainId());
|
|
|
+ nodeInstanceIdManageSpi.writeInstanceIdFile(writeNodeInstanceId(condition, chainId), elMd5, chainId);
|
|
|
} else {
|
|
|
// 文件存在,则直接读取
|
|
|
- List<InstanceIdDto> instanceIdDtos = new ArrayList<>();
|
|
|
+ List<InstanceInfoDto> instanceInfoDtos = new ArrayList<>();
|
|
|
for (int i = 1; i < instanceIdFile.size(); i++) {
|
|
|
- List<InstanceIdDto> instanceIdDtos1 = parseList(instanceIdFile.get(i), InstanceIdDto.class);
|
|
|
- if (instanceIdDtos1 != null) {
|
|
|
- instanceIdDtos.addAll(instanceIdDtos1);
|
|
|
+ List<InstanceInfoDto> instanceInfoDtos1 = parseList(instanceIdFile.get(i), InstanceInfoDto.class);
|
|
|
+ if (instanceInfoDtos1 != null) {
|
|
|
+ instanceInfoDtos.addAll(instanceInfoDtos1);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -72,7 +70,7 @@ public abstract class BaseNodeInstanceIdManageSpi implements NodeInstanceIdManag
|
|
|
Node node = (Node) executable;
|
|
|
idCntMap.put(node.getId(), idCntMap.getOrDefault(node.getId(), -1) + 1);
|
|
|
|
|
|
- for (InstanceIdDto dto : instanceIdDtos) {
|
|
|
+ for (InstanceInfoDto dto : instanceInfoDtos) {
|
|
|
if (Objects.equals(dto.getNodeId(), node.getId())
|
|
|
&& Objects.equals(dto.getChainId(), node.getCurrChainId())
|
|
|
&& Objects.equals(dto.getIndex(), idCntMap.get(node.getId()))) {
|
|
@@ -90,18 +88,19 @@ public abstract class BaseNodeInstanceIdManageSpi implements NodeInstanceIdManag
|
|
|
// 写入时第一行为el的md5,第二行为json格式的groupKey和对应的nodeId 和实例id
|
|
|
// instanceId a_XXX_0
|
|
|
// {"chainId":"chain1","nodeId":"a","instanceId":"XXXX","index":0},
|
|
|
- private List<InstanceIdDto> writeNodeInstanceId(Condition condition) {
|
|
|
- ArrayList<InstanceIdDto> instanceIdDtos = new ArrayList<>();
|
|
|
+ private List<InstanceInfoDto> writeNodeInstanceId(Condition condition, String chainId) {
|
|
|
+ ArrayList<InstanceInfoDto> instanceInfos = new ArrayList<>();
|
|
|
|
|
|
condition.getExecutableGroup().forEach((key, executables) -> {
|
|
|
+ // 统计每个nodeId的索引
|
|
|
Map<String, Integer> idCntMap = new HashMap<>();
|
|
|
executables.forEach(executable -> {
|
|
|
if (executable instanceof Node) {
|
|
|
Node node = (Node) executable;
|
|
|
- InstanceIdDto instanceIdDto = new InstanceIdDto();
|
|
|
+ InstanceInfoDto instanceInfoDto = new InstanceInfoDto();
|
|
|
|
|
|
- instanceIdDto.setChainId(node.getCurrChainId());
|
|
|
- instanceIdDto.setNodeId(node.getId());
|
|
|
+ instanceInfoDto.setChainId(chainId);
|
|
|
+ instanceInfoDto.setNodeId(node.getId());
|
|
|
|
|
|
String shortUUID = generateShortUUID();
|
|
|
|
|
@@ -110,15 +109,15 @@ public abstract class BaseNodeInstanceIdManageSpi implements NodeInstanceIdManag
|
|
|
String instanceId = node.getId() + "_" + shortUUID + "_" + idCntMap.get(node.getId());
|
|
|
|
|
|
node.setInstanceId(instanceId);
|
|
|
- instanceIdDto.setInstanceId(instanceId);
|
|
|
- instanceIdDto.setIndex(idCntMap.get(node.getId()));
|
|
|
+ instanceInfoDto.setInstanceId(instanceId);
|
|
|
+ instanceInfoDto.setIndex(idCntMap.get(node.getId()));
|
|
|
|
|
|
- instanceIdDtos.add(instanceIdDto);
|
|
|
+ instanceInfos.add(instanceInfoDto);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- return instanceIdDtos;
|
|
|
+ return instanceInfos;
|
|
|
}
|
|
|
|
|
|
}
|