diff --git a/README.zh-CN.md b/README.zh-CN.md index ea1ae6f0..bc964799 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -66,7 +66,7 @@ crontab -e ``` cd eventmesh-dashboard -./mvnw clean package +./mvnw -Prelease-package -Dmaven.test.skip=true clean install -U ``` > TODO download mysql-connector-j manually diff --git a/eventmesh-dashboard-common/pom.xml b/eventmesh-dashboard-common/pom.xml index 00578711..074849a7 100644 --- a/eventmesh-dashboard-common/pom.xml +++ b/eventmesh-dashboard-common/pom.xml @@ -26,7 +26,6 @@ 0.0.1-SNAPSHOT - org.apache.eventmesh.dashboard.common eventmesh-dashboard-common diff --git a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterSyncMetadataEnum.java b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterSyncMetadataEnum.java index dac75f9e..6d71aad8 100644 --- a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterSyncMetadataEnum.java +++ b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterSyncMetadataEnum.java @@ -31,6 +31,7 @@ /** * 集群的特性 */ +@Getter public enum ClusterSyncMetadataEnum { @@ -81,7 +82,6 @@ public enum ClusterSyncMetadataEnum { ; private static final Map SYNC_METADATA_CONCURRENT_HASH_MAP = new ConcurrentHashMap<>(); - @Getter private ClusterSyncMetadata clusterSyncMetadata; ClusterSyncMetadataEnum(ClusterSyncMetadata clusterSyncMetadata) { diff --git a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterType.java b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterType.java index af16214a..103d5a7e 100644 --- a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterType.java +++ b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/ClusterType.java @@ -18,11 +18,15 @@ package org.apache.eventmesh.dashboard.common.enums; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.reflect.FieldUtils; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; import lombok.Getter; @@ -103,26 +107,26 @@ public enum ClusterType { EVENTMESH_CLUSTER(EVENTMESH, EVENTMESH, CLUSTER, DEFINITION, RemotingType.EVENT_MESH_RUNTIME), - EVENTMESH_RUNTIME(EVENTMESH, EVENTMESH, RUNTIME, DEFAULT, RemotingType.EVENT_MESH_RUNTIME), + EVENTMESH_RUNTIME(EVENTMESH, EVENTMESH_CLUSTER, RUNTIME, DEFAULT, RemotingType.EVENT_MESH_RUNTIME), - EVENTMESH_META_ETCD(EVENTMESH, EVENTMESH, META, META_TYPE_ETCD, RemotingType.EVENT_MESH_ETCD), + EVENTMESH_META_ETCD(EVENTMESH, EVENTMESH_CLUSTER, META, META_TYPE_ETCD, RemotingType.EVENT_MESH_ETCD), - EVENTMESH_META_NACOS(EVENTMESH, EVENTMESH, META, META_TYPE_NACOS, RemotingType.EVENT_MESH_NACOS), + EVENTMESH_META_NACOS(EVENTMESH, EVENTMESH_CLUSTER, META, META_TYPE_NACOS, RemotingType.EVENT_MESH_NACOS), - EVENTMESH_JVM_CLUSTER(EVENTMESH, EVENTMESH_JVM, CLUSTER, DEFINITION, RemotingType.EVENT_MESH_RUNTIME), + EVENTMESH_JVM_CLUSTER(EVENTMESH, EVENTMESH_JVM, CLUSTER, DEFINITION, RemotingType.JVM), - EVENTMESH_JVM_RUNTIME(EVENTMESH, EVENTMESH_JVM, RUNTIME, DEFAULT, RemotingType.EVENT_MESH_RUNTIME), + EVENTMESH_JVM_RUNTIME(EVENTMESH, EVENTMESH_JVM_CLUSTER, RUNTIME, DEFAULT, RemotingType.JVM), - EVENTMESH_JVM_META(EVENTMESH, EVENTMESH_JVM, META, META_TYPE_JVM, RemotingType.JVM), + EVENTMESH_JVM_META(EVENTMESH, EVENTMESH_JVM_CLUSTER, META, META_TYPE_JVM, RemotingType.JVM), STORAGE_ROCKETMQ(ClusterType.STORAGE.code + 1), STORAGE_ROCKETMQ_CLUSTER(STORAGE, STORAGE_ROCKETMQ, CLUSTER, DEFINITION, RemotingType.ROCKETMQ), - STORAGE_ROCKETMQ_NAMESERVER(STORAGE, STORAGE_ROCKETMQ, META, DEFAULT, RemotingType.ROCKETMQ_NAMESERVER), + STORAGE_ROCKETMQ_NAMESERVER(STORAGE, STORAGE_ROCKETMQ_CLUSTER, META, DEFAULT, RemotingType.ROCKETMQ_NAMESERVER), - STORAGE_ROCKETMQ_BROKER(STORAGE, STORAGE_ROCKETMQ, RUNTIME, DEFINITION, RemotingType.ROCKETMQ), + STORAGE_ROCKETMQ_BROKER(STORAGE, STORAGE_ROCKETMQ_CLUSTER, RUNTIME, DEFINITION, RemotingType.ROCKETMQ), STORAGE_ROCKETMQ_BROKER_MAIN_SLAVE(STORAGE, STORAGE_ROCKETMQ_BROKER, RUNTIME, DEFAULT, RemotingType.ROCKETMQ), @@ -133,34 +137,34 @@ public enum ClusterType { STORAGE_KAFKA_CLUSTER(STORAGE, STORAGE_KAFKA, CLUSTER, DEFINITION, RemotingType.KAFKA), - STORAGE_KAFKA_ZK(STORAGE, STORAGE_KAFKA, META, META_TYPE_ZK, RemotingType.ZK), + STORAGE_KAFKA_ZK(STORAGE, STORAGE_KAFKA_CLUSTER, META, META_TYPE_ZK, RemotingType.ZK), - STORAGE_KAFKA_RAFT(STORAGE, STORAGE_KAFKA, META_AND_RUNTIME, STORAGE_KAFKA, RemotingType.KAFKA), + STORAGE_KAFKA_RAFT(STORAGE, STORAGE_KAFKA_CLUSTER, META_AND_RUNTIME, STORAGE_KAFKA, RemotingType.KAFKA), - STORAGE_KAFKA_BROKER(STORAGE, STORAGE_KAFKA, RUNTIME, DEFAULT, RemotingType.KAFKA), + STORAGE_KAFKA_BROKER(STORAGE, STORAGE_KAFKA_CLUSTER, RUNTIME, DEFAULT, RemotingType.KAFKA), STORAGE_REDIS(STORAGE_KAFKA.code + 1), STORAGE_REDIS_CLUSTER(STORAGE, STORAGE_REDIS, CLUSTER, DEFINITION, RemotingType.REDIS), - STORAGE_REDIS_BROKER(STORAGE, STORAGE_REDIS, RUNTIME, DEFAULT, RemotingType.REDIS), + STORAGE_REDIS_BROKER(STORAGE, STORAGE_REDIS_CLUSTER, RUNTIME, DEFAULT, RemotingType.REDIS), STORAGE_JVM(STORAGE_REDIS.code + 1), STORAGE_JVM_CLUSTER(STORAGE, STORAGE_JVM, CLUSTER, DEFINITION, RemotingType.JVM), - STORAGE_JVM_META(STORAGE, STORAGE_JVM, META, DEFAULT, RemotingType.JVM), + STORAGE_JVM_META(STORAGE, STORAGE_JVM_CLUSTER, META, DEFAULT, RemotingType.JVM), - STORAGE_JVM_BROKER(STORAGE, STORAGE_JVM, RUNTIME, DEFAULT, RemotingType.JVM), + STORAGE_JVM_BROKER(STORAGE, STORAGE_JVM_CLUSTER, RUNTIME, DEFAULT, RemotingType.JVM), STORAGE_JVM_CAP(STORAGE_REDIS.code + 1), STORAGE_JVM_CAP_CLUSTER(STORAGE, STORAGE_JVM_CAP, CLUSTER, DEFINITION, RemotingType.JVM), - STORAGE_JVM_CAP_BROKER(STORAGE, STORAGE_JVM_CAP, META_AND_RUNTIME, DEFAULT, RemotingType.JVM), + STORAGE_JVM_CAP_BROKER(STORAGE, STORAGE_JVM_CAP_CLUSTER, META_AND_RUNTIME, DEFAULT, RemotingType.JVM), - STORAGE_JVM_CAP_META(STORAGE, STORAGE_JVM_CAP, META, DEFAULT, RemotingType.JVM), + STORAGE_JVM_CAP_META(STORAGE, STORAGE_JVM_CAP_CLUSTER, META, DEFAULT, RemotingType.JVM), ; @@ -172,8 +176,27 @@ public enum ClusterType { private static final List STORAGE_META_RUNTIME_TYPE_LIST = new ArrayList<>(); + private static final Map CLUSTER_TYPE_CLUSTER_TYPE_CHILD_MAP = new HashMap<>(); + static { for (ClusterType clusterType : ClusterType.values()) { + if (Objects.isNull(clusterType.assemblyName)) { + continue; + } + ClusterTypeChild clusterTypeChild = + CLUSTER_TYPE_CLUSTER_TYPE_CHILD_MAP.computeIfAbsent(clusterType.assemblyName, k -> new ClusterTypeChild()); + clusterType.assemblyName.clusterTypeChild = clusterTypeChild; + + clusterType.clusterTypeChild = CLUSTER_TYPE_CLUSTER_TYPE_CHILD_MAP.computeIfAbsent(clusterType, k -> new ClusterTypeChild()); + if (clusterType.isMeta()) { + clusterTypeChild.metaClusterType.add(clusterType); + } else if (clusterType.isRuntime()) { + clusterTypeChild.runtimeClusterType.add(clusterType); + } else if (clusterType.isDefinition()) { + clusterTypeChild.definitionClusterType.add(clusterType); + } else if (clusterType.isCluster()) { + clusterTypeChild.clusterType.add(clusterType); + } if (clusterType.isStorageCluster()) { STORAGE_MAIN_CLUSTER_TYPE_LIST.add(clusterType); } @@ -186,6 +209,11 @@ public enum ClusterType { if (clusterType.isMetaAndRuntime()) { STORAGE_META_RUNTIME_TYPE_LIST.add(clusterType); } + + } + for (ClusterType clusterType : ClusterType.values()) { + clusterType.getHigher(); + clusterType.injection(); } } @@ -217,6 +245,9 @@ public enum ClusterType { @Getter private int code; private ClusterType higherType; + + private ClusterTypeChild clusterTypeChild; + private List mainClusterType; private List metaClusterType; private List runtimeClusterType; @@ -274,6 +305,13 @@ public boolean isMeta() { return this.assemblyNodeType.equals(META); } + public boolean isCluster() { + if (Objects.isNull(this.assemblyNodeType)) { + return false; + } + return this.assemblyNodeType.equals(CLUSTER); + } + public boolean isMetaAndRuntime() { if (Objects.isNull(this.eventmeshNodeType)) { return false; @@ -338,6 +376,18 @@ public List getMetaClusterInStorage() { return list; } + public List getThisInAllRuntimeCluster() { + return this.clusterTypeChild.allRuntimeClusterType; + } + + public List getFrameworkInAllMetaCluster() { + return this.higherType.clusterTypeChild.allMetaClusterType; + } + + public List getFrameworkInAllRuntimeCluster() { + return this.higherType.clusterTypeChild.allRuntimeClusterType; + } + public List getMainClusterType() { return this.getThisClusterType(CLUSTER, this.mainClusterType, "mainClusterType"); @@ -351,30 +401,74 @@ public List getRuntimeClusterType() { return this.getThisClusterType(RUNTIME, this.runtimeClusterType, "runtimeClusterType"); } + void injection() { + if (Objects.isNull(this.clusterTypeChild)) { + return; + } + if (Objects.isNull(this.higherType)) { + return; + } + if (this.clusterTypeChild.isRuntimeAdd.get()) { + return; + } + if (Objects.equals(this.higherType, this)) { + this.clusterTypeChild.isRuntimeAdd.set(true); + return; + } + this.clusterTypeChild.isRuntimeAdd.set(true); + this.assemblyName.injection(List.of(this), this.assemblyNodeType); + } + + + void injection(List list, ClusterType clusterType) { + if (CollectionUtils.isEmpty(list)) { + return; + } + if (Objects.equals(clusterType, META)) { + this.clusterTypeChild.allMetaClusterType.addAll(list); + return; + } + if (Objects.equals(clusterType, CLUSTER)) { + this.clusterTypeChild.allClusterType.addAll(list); + return; + } + if (Objects.equals(clusterType, RUNTIME)) { + this.clusterTypeChild.allRuntimeClusterType.addAll(list); + } + if (Objects.equals(this.higherType, this)) { + return; + } + this.assemblyName.injection(list, clusterType); + } + /** * */ public ClusterType getHigher() { - if (Objects.isNull(this.higherType)) { - for (ClusterType allClusterType : ClusterType.values()) { - if (!Objects.equals(allClusterType.eventmeshNodeType, this.eventmeshNodeType) - || !Objects.equals(allClusterType.assemblyName, this.assemblyName)) { - continue; - } - if (!Objects.equals(allClusterType.assemblyNodeType, CLUSTER)) { - continue; - } - if (!Objects.equals(allClusterType.assemblyBusiness, DEFINITION)) { - continue; - } - this.higherType = allClusterType; + if (Objects.nonNull(this.higherType)) { + return this.higherType; + } + if (this.code != 0) { + this.higherType = this; + return this.higherType; + } + if (this.eventmeshNodeType == DEFAULT) { + this.higherType = this; + return this.higherType; + } + if (Objects.isNull(this.assemblyName)) { + return this; + } + ClusterType assemblyName = this.assemblyName; + ClusterType lastAssemblyName = this; + for (; ; ) { + if (Objects.isNull(assemblyName.assemblyName)) { + this.higherType = lastAssemblyName; break; } - if (Objects.isNull(this.higherType)) { - throw new RuntimeException("higher type is null, current type:" + this); - } + lastAssemblyName = assemblyName; + assemblyName = assemblyName.assemblyName; } - return this.higherType; } @@ -414,4 +508,24 @@ private List getThisClusterType(ClusterType assemblyNodeType, List< } + static class ClusterTypeChild { + + List metaClusterType = new ArrayList<>(); + + List runtimeClusterType = new ArrayList<>(); + + AtomicBoolean isRuntimeAdd = new AtomicBoolean(false); + + List definitionClusterType = new ArrayList<>(); + + List clusterType = new ArrayList<>(); + + List allClusterType = new ArrayList<>(); + + List allMetaClusterType = new ArrayList<>(); + + List allRuntimeClusterType = new ArrayList<>(); + + } + } diff --git a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/DeployStatusType.java b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/DeployStatusType.java index 79c047ee..30e2a734 100644 --- a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/DeployStatusType.java +++ b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/enums/DeployStatusType.java @@ -112,6 +112,12 @@ public enum DeployStatusType { UPDATE_FULL_FAIL, + CHECKING, + + CHECK_WAIT, + + CHECKING_FAILED, + PAUSE, PAUSE_WAIT, diff --git a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/util/ClasspathScanner.java b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/util/ClasspathScanner.java index d57291b7..2d92dbdf 100644 --- a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/util/ClasspathScanner.java +++ b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/util/ClasspathScanner.java @@ -120,7 +120,7 @@ private boolean includeInterface(Class clazz) throws Exception { } private String createLocationPattern() { - StringBuffer stringBuffer = new StringBuffer(); + StringBuilder stringBuffer = new StringBuilder(); stringBuffer.append("classpath*:./"); this.baseString = base.getPackage().getName().replace('.', '/'); stringBuffer.append(this.baseString); diff --git a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/utils/ClusterTypeRelationship.java b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/utils/ClusterTypeRelationship.java index 3159cf34..8c7e03f2 100644 --- a/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/utils/ClusterTypeRelationship.java +++ b/eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/utils/ClusterTypeRelationship.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Objects; +@Deprecated public class ClusterTypeRelationship { private static final ClusterTypeRelationship INSTANCE = new ClusterTypeRelationship(); diff --git a/eventmesh-dashboard-console/pom.xml b/eventmesh-dashboard-console/pom.xml index 0ac59e57..7ec18a07 100644 --- a/eventmesh-dashboard-console/pom.xml +++ b/eventmesh-dashboard-console/pom.xml @@ -27,7 +27,6 @@ 0.0.1-SNAPSHOT - org.apache.eventmesh.dashboard.console eventmesh-dashboard-console @@ -41,17 +40,17 @@ - org.apache.eventmesh.dashboard.core + org.apache.eventmesh.dashboard eventmesh-dashboard-core 0.0.1-SNAPSHOT - org.apache.eventmesh.dashboard.common + org.apache.eventmesh.dashboard eventmesh-dashboard-common 0.0.1-SNAPSHOT - org.apache.eventmesh.dashboard.service + org.apache.eventmesh.dashboard eventmesh-dashboard-service 0.0.1-SNAPSHOT @@ -219,23 +218,6 @@ - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot.version} - - org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication - - - - repackage - - repackage - - - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentActionController.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentActionController.java index eaae3466..56b2744b 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentActionController.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentActionController.java @@ -22,19 +22,29 @@ import org.apache.eventmesh.dashboard.common.enums.ClusterSyncMetadataEnum; import org.apache.eventmesh.dashboard.common.enums.ClusterType; import org.apache.eventmesh.dashboard.common.enums.MetadataType; +import org.apache.eventmesh.dashboard.console.domain.ClusterAndRuntimeDomain; import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; import org.apache.eventmesh.dashboard.console.entity.cluster.RuntimeEntity; import org.apache.eventmesh.dashboard.console.entity.function.ConfigEntity; -import org.apache.eventmesh.dashboard.console.model.DO.runtime.QueryRuntimeByBigExpandClusterDO; +import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.ClusterAndRuntimeOfRelationshipDO; +import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.QueryTreeByChildClusterIdDO; import org.apache.eventmesh.dashboard.console.model.dto.agent.AgentStartActionDTO; import org.apache.eventmesh.dashboard.console.service.cluster.ClusterService; import org.apache.eventmesh.dashboard.console.service.cluster.RuntimeService; import org.apache.eventmesh.dashboard.console.service.function.ConfigService; +import org.apache.eventmesh.dashboard.console.spring.support.address.AddressManage; +import org.apache.eventmesh.dashboard.console.spring.support.address.AddressService; +import org.apache.eventmesh.dashboard.console.spring.support.address.AddressServiceIPDO; +import org.apache.eventmesh.dashboard.console.spring.support.address.AddressServiceResult; +import org.apache.eventmesh.dashboard.console.utils.data.controller.agent.AgentActionControllerUtils; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import javax.validation.Valid; @@ -60,6 +70,17 @@ public class AgentActionController { @Autowired private RuntimeService runtimeService; + @Autowired + private ClusterAndRuntimeDomain clusterAndRuntimeDomain; + + @Autowired + private AddressManage addressManage; + + /** + * TODO + * 启动时,无法确认其他服务是否启动 + * 只有在不停地 check 时,可以确认依赖服务已经启动 + */ @PostMapping("agentStartAction") public AgentStartActionVO agentStartAction(@RequestBody @Valid AgentStartActionDTO data) { @@ -82,37 +103,20 @@ public AgentStartActionVO agentStartAction(@RequestBody @Valid AgentStartActionD updateRuntimeEntity.setHost(data.getNodeAddress()); updateRuntimeEntity.setPodHost(data.getLocalAddress()); this.runtimeService.updateAddressByRuntimeId(updateRuntimeEntity); - // 识别架构,修改 需要 修改 config 相关配置 , 端口 - - // TODO 识别 架构方式,修改 cap 架构配置 , - - // 依赖组件,在 agentCheckRuntime , - - // 识别架构, 获得 AgentStartActionVO agentStartActionVO = new AgentStartActionVO(); agentStartActionVO.setClusterType(clusterEntity.getClusterType().toString()); - agentStartActionVO.setCheck(clusterEntity.getClusterType().isMeta()); - - ConfigEntity configEntity = new ConfigEntity(); - configEntity.setInstanceId(clusterEntity.getId()); - configEntity.setInstanceType(MetadataType.CLUSTER); - List configEntityList = this.configService.queryByInstanceId(configEntity); - Map configMap = new HashMap(); - configEntityList.forEach(config -> { - configMap.put(config.getConfigName(), config.getConfigValue()); - }); - - configEntity = new ConfigEntity(); - configEntity.setInstanceId(runtimeEntity.getId()); - configEntity.setInstanceType(MetadataType.RUNTIME); - this.configService.queryByInstanceId(configEntity); - configEntityList.forEach(config -> { - configMap.put(config.getConfigName(), config.getConfigValue()); - }); - - agentStartActionVO.setConfigMap(configMap); - + ClusterType clusterType = clusterEntity.getClusterType(); + ClusterSyncMetadataEnum.getClusterFramework(clusterType); + if (!clusterType.isMeta()) { + return agentStartActionVO; + } + ClusterFramework clusterFramework = ClusterSyncMetadataEnum.getClusterFramework(clusterType); + if (!clusterFramework.isAP()) { + return agentStartActionVO; + } + agentStartActionVO.setCheck(true); + agentStartActionVO.setConfigMap(this.queryConfig(runtimeEntity, clusterEntity)); return agentStartActionVO; } @@ -124,33 +128,85 @@ public AgentCheckRuntimeVO agentCheckRuntime(@RequestBody @Valid AgentStartActio clusterEntity.setId(data.getClusterId()); clusterEntity = this.clusterService.queryClusterById(clusterEntity); - AgentCheckRuntimeVO agentCheckRuntimeVO = new AgentCheckRuntimeVO(); - - QueryRuntimeByBigExpandClusterDO queryRuntimeByBigExpandClusterDO = - QueryRuntimeByBigExpandClusterDO.builder().followClusterId(clusterEntity.getId()) - .queryClusterTypeList(clusterEntity.getClusterType().getMetaClusterType()).build(); + ClusterType clusterType = clusterEntity.getClusterType(); - List runtimeEntityList = this.runtimeService.queryMetaRuntimeByStorageClusterId(queryRuntimeByBigExpandClusterDO); + AddressService addressService = addressManage.getAddressService(clusterType); + RuntimeEntity remoteRuntimeEntity = new RuntimeEntity(); + remoteRuntimeEntity.setClusterId(clusterEntity.getId()); - ClusterType clusterType = clusterEntity.getClusterType(); + AddressServiceResult addressServiceResult = new AddressServiceResult(); if (clusterType.isEventMethRuntime()) { - queryRuntimeByBigExpandClusterDO = QueryRuntimeByBigExpandClusterDO.builder().followClusterId(clusterEntity.getId()) - .storageMetaClusterTypeList(ClusterType.getStorageMetaRuntimeCluster()).build(); - //如果是 eventmesh 集群,name需要查询 存储集群的 runtime 是否启动 - // 如果识别 meta 的可用度 - runtimeEntityList = this.runtimeService.queryRuntimeByBigExpandCluster(queryRuntimeByBigExpandClusterDO); + // + this.clusterAndRuntimeDomain.getAllClusterAndRuntimeByCluster(null); } else { ClusterFramework clusterFramework = ClusterSyncMetadataEnum.getClusterFramework(clusterType); - if (clusterFramework.isCAP() && clusterType.isMeta()) { - // + if ((clusterFramework.isCAP() && clusterType.isMeta())) { + List runtimeEntities = this.runtimeService.queryRuntimeToFrontByClusterId(remoteRuntimeEntity); + addressServiceResult = addressService.createCapAddress(AgentActionControllerUtils.byRuntimeList(runtimeEntities)); } else if (clusterType.isMetaAndRuntime()) { - // + List runtimeEntities = this.runtimeService.queryRuntimeToFrontByClusterId(remoteRuntimeEntity); + addressServiceResult = addressService.createCapAddress(AgentActionControllerUtils.byRuntimeList(runtimeEntities)); } else if (clusterType.isRuntime()) { - // + // 需要 得到 集群的依赖组件检查依赖 runtime 是否运行 + // 检查依赖 runtime 是否运行 + QueryTreeByChildClusterIdDO queryTreeByChildClusterIdDO = new QueryTreeByChildClusterIdDO(); + queryTreeByChildClusterIdDO.setClusterEntity(clusterEntity); + queryTreeByChildClusterIdDO.setRootClusterTypeList(Set.of(clusterType.getHigher())); + queryTreeByChildClusterIdDO.setOnlyClusterTypeList(new HashSet<>(clusterType.getHigher().getMetaClusterType())); + + ClusterAndRuntimeOfRelationshipDO clusterAndRuntimeOfRelationshipDo = + this.clusterAndRuntimeDomain.queryTreeByChildClusterId(queryTreeByChildClusterIdDO); + AddressServiceIPDO addressServiceDo = + AgentActionControllerUtils.byClusterAndRuntimeOfRelationshipDO(clusterAndRuntimeOfRelationshipDo); + addressServiceResult = addressService.createRegisterAddress(addressServiceDo); } - } - + AgentCheckRuntimeVO agentCheckRuntimeVO = new AgentCheckRuntimeVO(); + if (!addressServiceResult.isCheckSuccess()) { + agentCheckRuntimeVO.setSuccess(false); + } else { + ClusterEntity tmpClusterEntity = clusterEntity; + // TODO 这个有一个问题,这些配置地址,是写入 cluster ,还是 写入 runtime, 写入 cluster + List configEntityList = addressServiceResult.getConfigEntities().stream().filter((value) -> { + if (Objects.isNull(value.getConfigName())) { + return false; + } else { + value.setInstanceId(tmpClusterEntity.getId()); + value.setInstanceType(MetadataType.CLUSTER); + return true; + } + }).toList(); + this.configService.updateValueByConfigList(configEntityList); + agentCheckRuntimeVO.setConfigMap(this.queryConfig(remoteRuntimeEntity, clusterEntity)); + } return agentCheckRuntimeVO; } + + + private Map queryConfig(RuntimeEntity runtimeEntity, ClusterEntity clusterEntity) { + List queryConfigConfigList = new ArrayList<>(2); + + ConfigEntity configEntity = new ConfigEntity(); + configEntity.setInstanceId(clusterEntity.getId()); + configEntity.setInstanceType(MetadataType.CLUSTER); + + queryConfigConfigList.add(configEntity); + + configEntity = new ConfigEntity(); + configEntity.setInstanceId(runtimeEntity.getId()); + configEntity.setInstanceType(MetadataType.RUNTIME); + + queryConfigConfigList.add(configEntity); + + Map configMap = new HashMap<>(); + queryConfigConfigList.forEach(value -> { + List configEntityList = this.configService.queryByInstanceId(value); + configEntityList.forEach(config -> { + configMap.put(config.getConfigName(), config.getConfigValue()); + }); + }); + + return configMap; + } + } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentCheckRuntimeVO.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentCheckRuntimeVO.java index 09fdf5df..43ee2c6f 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentCheckRuntimeVO.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/agent/AgentCheckRuntimeVO.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.dashboard.console.controller.agent; +import java.util.Map; + import lombok.Data; @Data @@ -24,4 +26,6 @@ public class AgentCheckRuntimeVO { private boolean success; + private Map configMap; + } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/ClusterCycleController.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/ClusterCycleController.java index 619fa106..c0172ee8 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/ClusterCycleController.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/ClusterCycleController.java @@ -150,7 +150,7 @@ public void createClusterByCopy(@RequestBody @Validated CreateClusterByCopyDTO d } /** - * 这里应该上传一个文件 + * 这里应该上传一个文件,可以通过前端把文件数据读出来,然后写入字段里面 */ @PostMapping("createClusterByFullMetadata") public void createClusterByFullMetadata(@RequestBody @Validated CreateClusterByFullMetadataDTO dto) { diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/CreateCycleService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/CreateCycleService.java index 1dd887d1..c9e6df05 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/CreateCycleService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/CreateCycleService.java @@ -29,6 +29,7 @@ import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; import org.apache.eventmesh.dashboard.console.entity.cluster.RuntimeEntity; import org.apache.eventmesh.dashboard.console.mapstruct.cluster.ClusterControllerMapper; +import org.apache.eventmesh.dashboard.console.model.DO.service.function.config.CopyConfigDO; import org.apache.eventmesh.dashboard.console.model.dto.cluster.CreateClusterByCompleteDataDTO; import org.apache.eventmesh.dashboard.console.model.dto.cluster.CreateClusterBySimpleDataDTO; import org.apache.eventmesh.dashboard.console.service.cluster.ClusterRelationshipService; @@ -132,7 +133,9 @@ private void createCluster(Long configGatherId) { this.verifyName(); this.clusterService.createCluster(clusterEntity); if (Objects.nonNull(configGatherId)) { - this.configService.copyConfig(configGatherId, clusterEntity.getId()); + CopyConfigDO copyConfigDO = new CopyConfigDO(); + + //this.configService.copyConfig(configGatherId, clusterEntity.getId()); } } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/create/CreateClusterByDeployScriptHandler.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/create/CreateClusterByDeployScriptHandler.java index 237e67d9..c254e43c 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/create/CreateClusterByDeployScriptHandler.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/deploy/create/CreateClusterByDeployScriptHandler.java @@ -24,11 +24,13 @@ import org.apache.eventmesh.dashboard.common.enums.ClusterTrusteeshipType.FirstToWhom; import org.apache.eventmesh.dashboard.common.enums.ClusterType; import org.apache.eventmesh.dashboard.common.enums.DeployStatusType; +import org.apache.eventmesh.dashboard.common.enums.MetadataType; import org.apache.eventmesh.dashboard.common.enums.ReplicationType; import org.apache.eventmesh.dashboard.console.controller.deploy.handler.UpdateHandler; import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; import org.apache.eventmesh.dashboard.console.entity.cluster.RuntimeEntity; import org.apache.eventmesh.dashboard.console.mapstruct.deploy.ClusterCycleControllerMapper; +import org.apache.eventmesh.dashboard.console.model.DO.service.function.config.CopyConfigDO; import org.apache.eventmesh.dashboard.console.model.deploy.create.CreateClusterByDeployScriptDO; import org.apache.eventmesh.dashboard.console.service.cluster.ClusterRelationshipService; import org.apache.eventmesh.dashboard.console.service.cluster.ClusterService; @@ -79,14 +81,21 @@ public void handler(CreateClusterByDeployScriptDO createClusterByDeployScriptDO) this.clusterService.insertCluster(this.clusterEntity); this.handlerMetadata(this.clusterEntity); - if (Objects.nonNull(createClusterByDeployScriptDO.getConfigGatherId())) { - configService.copyConfig(createClusterByDeployScriptDO.getConfigGatherId(), this.clusterEntity.getId()); - } + if (this.clusterFramework.isMainSlave()) { this.mainSlaveHandler(createClusterByDeployScriptDO, this.clusterEntity); } else { this.ordinaryRuntime(createClusterByDeployScriptDO); } + // TODO #1111 + if (Objects.nonNull(createClusterByDeployScriptDO.getConfigGatherId())) { + CopyConfigDO copyConfigDO = new CopyConfigDO(); + copyConfigDO.setSourceId(createClusterByDeployScriptDO.getConfigGatherId()); + copyConfigDO.setSourceType(createClusterByDeployScriptDO.getConfigGatherType()); + copyConfigDO.setTargetId(createClusterByDeployScriptDO.getConfigGatherId()); + copyConfigDO.setTargetType(MetadataType.CLUSTER); + configService.copyConfig(copyConfigDO); + } this.runtimeService.batchInsert(this.runtimeEntityList); } @@ -109,6 +118,7 @@ private void mainSlaveHandler(CreateClusterByDeployScriptDO createClusterByDeplo ClusterEntity newClusterEntity = ClusterCycleControllerMapper.INSTANCE.createClusterByDeployScript(createClusterByDeployScriptDO); clusterEntityList.add(newClusterEntity); } + // TODO 添加失败,如何处理 this.clusterService.batchInsert(clusterEntityList, clusterEntity); clusterEntityList.forEach(entity -> { this.createRuntimeEntity(clusterEntity, ReplicationType.MAIN, 0); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/ClusterAndRuntimeDomain.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/ClusterAndRuntimeDomain.java index 9138fa6a..1a2e1459 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/ClusterAndRuntimeDomain.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/ClusterAndRuntimeDomain.java @@ -25,10 +25,12 @@ import org.apache.eventmesh.dashboard.common.model.metadata.RuntimeMetadata; import org.apache.eventmesh.dashboard.console.entity.base.BaseRuntimeIdEntity; import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; +import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.ClusterAndRuntimeDomainQO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.ClusterAndRuntimeOfRelationshipDO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.GetClusterInSyncReturnDO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.QueryClusterInSyncDO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.QueryClusterTreeDO; +import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.QueryTreeByChildClusterIdDO; import org.apache.eventmesh.dashboard.console.model.vo.cluster.ClusterTreeVO; import java.util.ArrayList; @@ -50,6 +52,12 @@ public interface ClusterAndRuntimeDomain { ClusterAndRuntimeOfRelationshipDO getAllClusterAndRuntimeByCluster(ClusterEntity clusterEntity, DeployStatusType deployStatusType); + ClusterAndRuntimeOfRelationshipDO getAllClusterAndRuntimeByCluster(ClusterAndRuntimeDomainQO data); + + + ClusterAndRuntimeOfRelationshipDO queryTreeByChildClusterId(QueryTreeByChildClusterIdDO data); + + GetClusterInSyncReturnDO queryClusterInSync(ClusterEntity clusterEntity, List syncClusterTypeList); default T queryClusterInSync(QueryClusterInSyncDO data) { diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/Impl/ClusterAndRuntimeDomainImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/Impl/ClusterAndRuntimeDomainImpl.java index 8ff44639..f74e3185 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/Impl/ClusterAndRuntimeDomainImpl.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/domain/Impl/ClusterAndRuntimeDomainImpl.java @@ -30,24 +30,31 @@ import org.apache.eventmesh.dashboard.console.mapstruct.model.entity.ClusterEntityMapstruct; import org.apache.eventmesh.dashboard.console.mapstruct.model.entity.RuntimeEntityMapstruct; import org.apache.eventmesh.dashboard.console.model.DO.clusterRelationship.QueryListByClusterIdAndTypeDO; +import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.ClusterAndRuntimeDomainQO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.ClusterAndRuntimeOfRelationshipDO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.GetClusterInSyncReturnDO; import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.QueryClusterTreeDO; -import org.apache.eventmesh.dashboard.console.model.QO.cluster.QueryRelationClusterByClusterIdListAndType; +import org.apache.eventmesh.dashboard.console.model.DO.domain.clusterAndRuntimeDomain.QueryTreeByChildClusterIdDO; +import org.apache.eventmesh.dashboard.console.model.QO.cluster.QueryRelationClusterByClusterIdListAndTypeQO; import org.apache.eventmesh.dashboard.console.model.vo.cluster.ClusterTreeVO; import org.apache.eventmesh.dashboard.console.service.cluster.ClusterRelationshipService; import org.apache.eventmesh.dashboard.console.service.cluster.ClusterService; import org.apache.eventmesh.dashboard.console.service.cluster.RuntimeService; import org.apache.eventmesh.dashboard.console.service.connector.ResourcesConfigService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -68,6 +75,7 @@ * 1. 部署 需要整体关系 * 2. 运维 只需要 可操作节点 * 3. 关系可视化 需要整体关系 + * 4. address 生产 */ @Component public class ClusterAndRuntimeDomainImpl implements ClusterAndRuntimeDomain { @@ -104,7 +112,9 @@ public List queryClusterTree(QueryClusterTreeDO data) { } /** - * 这个方法是否放到 controller 层 + * 这个方法是否放到 controller 层, + * TODO + * 还需要反向 tree */ public List queryClusterTree(ClusterAndRuntimeOfRelationshipDO data) { Map clusterIdMap = data.getClusterEntityList().stream().collect(Collectors.toMap(ClusterEntity::getId, @@ -133,10 +143,13 @@ public List queryClusterTree(ClusterAndRuntimeOfRelationshipDO da } /** - * 运维操作使用列表:

+ * 网络地址组操作

+ * + * @see org.apache.eventmesh.dashboard.console.controller.agent.AgentActionController + *

+ * 运维操作使用列表: *

* 部署操作使用列表:

- * * @see org.apache.eventmesh.dashboard.console.controller.deploy.uninstall.UninstallClusterHandler * @see org.apache.eventmesh.dashboard.console.controller.deploy.create.CreateClusterByCopyHandler * @see org.apache.eventmesh.dashboard.console.controller.deploy.relationship.RelationshipHandler @@ -151,6 +164,27 @@ public ClusterAndRuntimeOfRelationshipDO getAllClusterAndRuntimeByCluster(Cluste return getSyncObjectHandler.deploy(); } + @Override + public ClusterAndRuntimeOfRelationshipDO getAllClusterAndRuntimeByCluster(ClusterAndRuntimeDomainQO data) { + GetSyncObjectHandler getSyncObjectHandler = new GetSyncObjectHandler(); + getSyncObjectHandler.setClusterEntity(data.getClusterEntity()); + getSyncObjectHandler.setDeployStatusType(data.getDeployStatusType()); + getSyncObjectHandler.setSyncClusterTypeList(data.getOnlyClusterTypeList()); + return getSyncObjectHandler.deploy(); + } + + @Override + public ClusterAndRuntimeOfRelationshipDO queryTreeByChildClusterId(QueryTreeByChildClusterIdDO data) { + ReverseSearchHandler reverseSearchHandler = new ReverseSearchHandler(); + reverseSearchHandler.queryTreeByChildClusterIdDO = data; + List clusterEntityList = reverseSearchHandler.doReverseSearch(); + + GetSyncObjectHandler getSyncObjectHandler = new GetSyncObjectHandler(); + getSyncObjectHandler.setQueryClusterEntityList(clusterEntityList); + getSyncObjectHandler.setSyncClusterTypeList(new ArrayList<>(data.getOnlyClusterTypeList())); + return getSyncObjectHandler.deploy(); + } + /** * 修改配置只能在一个维度的进行操作 topic 需要对 eventmesh 与 存储同时进行操作, acl 需要多维度操作,还是? offset 的操作 按照具体 offset,只能操作 队列 级别 按照 最大或则最小 和 时间,可以 是 大集群 或则 全域操作 定义操作域 @@ -164,20 +198,100 @@ public GetClusterInSyncReturnDO queryClusterInSync(ClusterEntity clusterEntity, return getSyncObjectHandler.sync(); } + private class ReverseSearchHandler { + + private QueryTreeByChildClusterIdDO queryTreeByChildClusterIdDO; + + private List tmpList; + + private void reverseSearch() { + List list = this.doReverseSearch(); + + } + + + private List doReverseSearch() { + + List clusterRelationshipEntityList = this.queryAllClusterRelationshipEntity(); + + Map> clusterRelationshipMap = + clusterRelationshipEntityList.stream().collect(Collectors.groupingBy(ClusterRelationshipEntity::getRelationshipId)); + List idList = new ArrayList<>(); + Consumer clusterRelationshipConsumer = + this.createHandlerClusterRelationshipEntityConsumer(clusterRelationshipMap, idList); + + List newList = clusterRelationshipMap.get(queryTreeByChildClusterIdDO.getClusterEntity().getId()); + while (CollectionUtils.isNotEmpty(newList)) { + tmpList = new ArrayList<>(); + newList.forEach(clusterRelationshipConsumer); + newList = tmpList; + } + return idList; + } + + private Consumer createHandlerClusterRelationshipEntityConsumer( + Map> clusterRelationshipMap, + List idList) { + Set rootClusterTypeList = queryTreeByChildClusterIdDO.getRootClusterTypeList(); + return (value) -> { + if (Objects.nonNull(rootClusterTypeList) && rootClusterTypeList.contains(value.getClusterType())) { + ClusterEntity clusterEntity = new ClusterEntity(); + clusterEntity.setId(value.getClusterId()); + clusterEntity.setClusterType(value.getClusterType()); + idList.add(clusterEntity); + return; + } + List list = clusterRelationshipMap.get(value.getClusterId()); + if (CollectionUtils.isEmpty(list)) { + ClusterEntity clusterEntity = new ClusterEntity(); + clusterEntity.setId(value.getClusterId()); + clusterEntity.setClusterType(value.getClusterType()); + idList.add(clusterEntity); + } else { + tmpList.addAll(list); + } + }; + } + + private List queryAllClusterRelationshipEntity() { + QueryListByClusterIdAndTypeDO queryListByClusterIdAndTypeDO = new QueryListByClusterIdAndTypeDO(); + queryListByClusterIdAndTypeDO.setClusterIdList(List.of(this.queryTreeByChildClusterIdDO.getClusterEntity().getId())); + List clusterRelationshipEntityList = new ArrayList<>(); + for (; ; ) { + List newList = clusterRelationshipService.queryListByRelationshipList(queryListByClusterIdAndTypeDO); + if (CollectionUtils.isEmpty(newList)) { + break; + } + clusterRelationshipEntityList.addAll(newList); + List idList = newList.stream().map(ClusterRelationshipEntity::getClusterId).toList(); + queryListByClusterIdAndTypeDO.setClusterIdList(idList); + } + return clusterRelationshipEntityList; + } + } + class GetSyncObjectHandler { - private final List clusterRelationshipEntityList = new ArrayList<>(); + private List clusterRelationshipEntityList = new ArrayList<>(); + @Setter private ClusterEntity clusterEntity; + + @Setter + private List queryClusterEntityList; + @Setter private DeployStatusType deployStatusType; + private ClusterType clusterType; /** * 修改 eventmesh 空间下 所有 存储集群 */ @Setter private List syncClusterTypeList; - private List independenceClusterList = new ArrayList<>(); + + private final List independenceClusterList = new ArrayList<>(); + private List clusterEntityList = new ArrayList<>(); private List capClusterList = new ArrayList<>(); @@ -185,15 +299,17 @@ class GetSyncObjectHandler { private List runtimeList; private void base(boolean isSync) { - this.clusterEntity = clusterService.queryClusterById(clusterEntity); - this.clusterType = clusterEntity.getClusterType(); - ClusterFramework clusterFramework = ClusterSyncMetadataEnum.getClusterFramework(clusterEntity.getClusterType()); - if (clusterFramework.isCAP() && isSync) { - return; - } - if (this.clusterType.isRuntime()) { - this.queryRuntimeByClusterId(); - return; + if (Objects.nonNull(clusterEntity)) { + this.clusterEntity = clusterService.queryClusterById(clusterEntity); + this.clusterType = clusterEntity.getClusterType(); + ClusterFramework clusterFramework = ClusterSyncMetadataEnum.getClusterFramework(clusterEntity.getClusterType()); + if (clusterFramework.isCAP() && isSync) { + return; + } + if (this.clusterType.isRuntime()) { + this.queryRuntimeByClusterId(); + return; + } } this.queryClusterRelationship(); this.queryClusterByRelationship(); @@ -219,7 +335,7 @@ public ClusterAndRuntimeOfRelationshipDO queryClusterAndRuntime() { public ClusterAndRuntimeOfRelationshipDO deploy() { this.base(false); - if (this.clusterType.isRuntime()) { + if (Objects.nonNull(this.clusterType) && this.clusterType.isRuntime()) { ClusterAndRuntimeOfRelationshipDO clusterAndRuntimeOfRelationshipDO = this.createClusterAndRuntimeOfRelationshipDO(); clusterAndRuntimeOfRelationshipDO.getRuntimeEntityPairList().add(Pair.of(this.clusterEntity, this.runtimeList)); return clusterAndRuntimeOfRelationshipDO; @@ -229,7 +345,6 @@ public ClusterAndRuntimeOfRelationshipDO deploy() { return this.structureRelationship(); } - public GetClusterInSyncReturnDO sync() { this.base(true); if (this.clusterType.isRuntime()) { @@ -327,6 +442,7 @@ private void copy(ClusterAndRuntimeOfRelationshipDO clusterAndRuntimeOfRelations } + @Deprecated public void getEventSpace() { /* 查询 eventmesh 集群 里面 eventmesh 相关集群 @@ -343,6 +459,7 @@ public void getEventSpace() { List clusterEntityList = clusterService.queryStorageClusterByEventMeshId(clusterEntity); } + @Deprecated public void getDefinition() { // 查询是否存 List reationClusterList = clusterService.queryRelationClusterByClusterIdAndType(clusterEntity); @@ -360,8 +477,8 @@ public void getDefinition() { } }); if (definitionClusterList.isEmpty()) { - QueryRelationClusterByClusterIdListAndType queryRelationClusterByClusterIdListAndType = - new QueryRelationClusterByClusterIdListAndType(); + QueryRelationClusterByClusterIdListAndTypeQO queryRelationClusterByClusterIdListAndType = + new QueryRelationClusterByClusterIdListAndTypeQO(); queryRelationClusterByClusterIdListAndType.setClusterEntityList(definitionClusterList); queryRelationClusterByClusterIdListAndType.setClusterTypeList(syncClusterTypeList); List definitionQueryRelustClusternList = @@ -417,16 +534,23 @@ private void queryClusterByRelationship() { private void queryClusterRelationship() { QueryListByClusterIdAndTypeDO queryListByClusterIdAndTypeDO = new QueryListByClusterIdAndTypeDO(); - queryListByClusterIdAndTypeDO.setClusterId(this.clusterEntity.getId()); - queryListByClusterIdAndTypeDO.setClusterTypeList(this.syncClusterTypeList); - - /* - * TODO 只能通过 代码 过滤需要的 clusterType, 除非 能从 syncClusterTypeList 得到 DEFINITION 与 目标类型 - * 前端如何操作, - */ - List relationshipEntityList = - clusterRelationshipService.queryListByClusterIdAndType(queryListByClusterIdAndTypeDO); - this.clusterRelationshipEntityList.addAll(relationshipEntityList); + List relationshipEntityList; + if (Objects.nonNull(this.clusterEntity)) { + queryListByClusterIdAndTypeDO.setClusterId(this.clusterEntity.getId()); + /* + * TODO 只能通过 代码 过滤需要的 clusterType, 除非 能从 syncClusterTypeList 得到 DEFINITION 与 目标类型 + * 前端如何操作, + */ + relationshipEntityList = + clusterRelationshipService.queryListByClusterIdAndType(queryListByClusterIdAndTypeDO); + this.clusterRelationshipEntityList.addAll(relationshipEntityList); + } else { + relationshipEntityList = new LinkedList<>(); + this.queryClusterEntityList.forEach(value -> { + ClusterRelationshipEntity clusterRelationshipEntity = new ClusterRelationshipEntity(); + clusterRelationshipEntity.setRelationshipId(value.getId()); + }); + } for (; ; ) { List idList = relationshipEntityList.stream().map(ClusterRelationshipEntity::getRelationshipId).toList(); queryListByClusterIdAndTypeDO.setClusterIdList(idList); @@ -436,6 +560,18 @@ private void queryClusterRelationship() { } this.clusterRelationshipEntityList.addAll(relationshipEntityList); } + if (Objects.isNull(this.syncClusterTypeList)) { + return; + } + Set clusterTypeSet = new HashSet<>(this.syncClusterTypeList); + List newList = new ArrayList<>(); + this.clusterRelationshipEntityList.forEach(value -> { + if (clusterTypeSet.contains(value.getRelationshipType())) { + newList.add(value); + } + }); + this.clusterRelationshipEntityList = newList; + } /** @@ -444,8 +580,8 @@ private void queryClusterRelationship() { */ private void queryCluster() { // 构建第一次查询对象 - QueryRelationClusterByClusterIdListAndType queryRelationClusterByClusterIdListAndType = - new QueryRelationClusterByClusterIdListAndType(); + QueryRelationClusterByClusterIdListAndTypeQO queryRelationClusterByClusterIdListAndType = + new QueryRelationClusterByClusterIdListAndTypeQO(); queryRelationClusterByClusterIdListAndType.setClusterTypeList(syncClusterTypeList); List clusterEntityList = new ArrayList<>(); queryRelationClusterByClusterIdListAndType.setClusterEntityList(clusterEntityList); @@ -467,7 +603,7 @@ private void queryCluster() { /* *目前来说 definition 的 storage 集群 只有 rocketmq(还有关系型数据库), *如果认为 definition 即 主从集群,那么认 definition - */ + */ definitionClusterList.add(value); } else { ClusterFramework clusterFramework = ClusterSyncMetadataEnum.getClusterFramework(value.getClusterType()); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigEntity.java index 43bfb031..f9a20808 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigEntity.java @@ -35,6 +35,7 @@ public class ConfigEntity extends BaseRuntimeIdEntity { /** * config type 0:runtime,1:storage,2:connector,3:topic + * CONFIG is ConfigTemplate */ private MetadataType instanceType; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigTemplateEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigTemplateEntity.java new file mode 100644 index 00000000..5e17710f --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/function/ConfigTemplateEntity.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.dashboard.console.entity.function; + +import org.apache.eventmesh.dashboard.common.enums.ClusterType; +import org.apache.eventmesh.dashboard.common.enums.MetadataType; +import org.apache.eventmesh.dashboard.console.entity.base.BaseOrganizationEntity; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +public class ConfigTemplateEntity extends BaseOrganizationEntity { + + private ClusterType clusterType; + + private String version; + + private MetadataType metadataType; + + private String name; + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java index 048b557d..52ce7ee1 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterMapper.java @@ -20,7 +20,7 @@ import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; import org.apache.eventmesh.dashboard.console.model.ClusterIdDTO; -import org.apache.eventmesh.dashboard.console.model.QO.cluster.QueryRelationClusterByClusterIdListAndType; +import org.apache.eventmesh.dashboard.console.model.QO.cluster.QueryRelationClusterByClusterIdListAndTypeQO; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; @@ -80,7 +80,7 @@ public interface ClusterMapper { """) List queryRelationClusterByClusterIdListAndType( - QueryRelationClusterByClusterIdListAndType queryRelationClusterByClusterIdListAndType); + QueryRelationClusterByClusterIdListAndTypeQO queryRelationClusterByClusterIdListAndType); @Select(""" diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterRelationshipMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterRelationshipMapper.java index 2a32b64d..c194df7a 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterRelationshipMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/cluster/ClusterRelationshipMapper.java @@ -62,7 +62,7 @@ public interface ClusterRelationshipMapper { @Select(""" + """) + List queryListByRelationshipList(QueryListByClusterIdAndTypeDO data); + + + @Select(""" + + """) + List queryListByClusterIdListAndType(QueryListByClusterIdAndTypeDO data); + @Select("""