From 75713a46567909accce1a44581d998b348c42343 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Fri, 12 Apr 2024 09:40:38 +0800 Subject: [PATCH 01/40] cache: Use cache to store cluster and runtime in the database because they are frequently used. --- .../dashboard/console/cache/ClusterCache.java | 99 +++++++++++++++++++ .../dashboard/console/cache/RuntimeCache.java | 60 +++++++++++ 2 files changed, 159 insertions(+) create mode 100644 eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/ClusterCache.java create mode 100644 eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/RuntimeCache.java diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/ClusterCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/ClusterCache.java new file mode 100644 index 00000000..bde19f9b --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/ClusterCache.java @@ -0,0 +1,99 @@ +/* + * 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.cache; + + +import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import lombok.Getter; + +public class ClusterCache { + + @Getter + private static final ClusterCache INSTANCE = new ClusterCache(); + + //cluster name + private HashMap clusterNameMap = new HashMap<>(); + + private HashMap clusterIdMap = new HashMap<>(); + + private static final Object lock = new Object(); + + public ClusterEntity getClusterById(Long id) { + return INSTANCE.clusterIdMap.get(id); + } + + public ClusterEntity getClusterByName(String name) { + return INSTANCE.clusterNameMap.get(name); + } + + public ClusterEntity getClusterByRegistryAddress(String registryAddress) { + for (ClusterEntity clusterEntity : INSTANCE.clusterIdMap.values()) { + if (clusterEntity.getRegistryAddress().equals(registryAddress)) { + return clusterEntity; + } + } + return null; + } + + public List getClusters() { + return new ArrayList<>(INSTANCE.clusterIdMap.values()); + } + + public void addCluster(ClusterEntity clusterEntity) { + synchronized (lock) { + if (INSTANCE.clusterIdMap.containsKey(clusterEntity.getId()) + || INSTANCE.clusterNameMap.containsKey(clusterEntity.getName())) { + return; + } + INSTANCE.clusterIdMap.put(clusterEntity.getId(), clusterEntity); + INSTANCE.clusterNameMap.put(clusterEntity.getName(), clusterEntity); + } + } + + public void deleteClusterById(Long id) { + synchronized (lock) { + ClusterEntity clusterEntity = INSTANCE.clusterIdMap.get(id); + INSTANCE.clusterIdMap.remove(id); + INSTANCE.clusterNameMap.remove(clusterEntity.getName()); + } + } + + public void deleteClusterByName(String name) { + synchronized (lock) { + ClusterEntity clusterEntity = INSTANCE.clusterNameMap.get(name); + INSTANCE.clusterNameMap.remove(name); + INSTANCE.clusterIdMap.remove(clusterEntity.getId()); + } + } + + public void syncClusters(List clusters) { + synchronized (lock) { + INSTANCE.clusterIdMap.clear(); + INSTANCE.clusterNameMap.clear(); + for (ClusterEntity clusterEntity : clusters) { + INSTANCE.clusterIdMap.put(clusterEntity.getId(), clusterEntity); + INSTANCE.clusterNameMap.put(clusterEntity.getName(), clusterEntity); + } + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/RuntimeCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/RuntimeCache.java new file mode 100644 index 00000000..d179847f --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/cache/RuntimeCache.java @@ -0,0 +1,60 @@ +/* + * 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.cache; + +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class RuntimeCache { + + private static final RuntimeCache INSTANCE = new RuntimeCache(); + + public static final RuntimeCache getInstance() { + return INSTANCE; + } + + // ip:port -> runtime + private Map runtimeMap = new ConcurrentHashMap<>(); + + private RuntimeCache() { + } + + public void addRuntime(RuntimeEntity runtimeEntity) { + runtimeMap.put(runtimeEntity.getHost() + ":" + runtimeEntity.getPort(), runtimeEntity); + } + + public Collection getRuntimeList() { + return runtimeMap.values(); + } + + public void deleteRuntime(RuntimeEntity runtimeEntity) { + runtimeMap.remove(runtimeEntity.getHost() + ":" + runtimeEntity.getPort()); + } + + public void replaceAllRuntime(List runtimeEntities) { + Map newRuntimeList = new ConcurrentHashMap<>(); + runtimeEntities.forEach(runtimeEntity -> { + newRuntimeList.put(runtimeEntity.getHost() + ":" + runtimeEntity.getPort(), runtimeEntity); + }); + runtimeMap = newRuntimeList; + } +} From 93aab64937c4a28275fac4a9f9fe65c73312f24c Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Fri, 12 Apr 2024 10:01:47 +0800 Subject: [PATCH 02/40] remove HealthCheckConfig, it's useless --- .../console/config/HealthCheckConfig.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java deleted file mode 100644 index bbf05719..00000000 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/config/HealthCheckConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.config; - -import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class HealthCheckConfig { - private List checkObjectConfigList; -} From 088a5e473dd51552a0921efe90bdc5657589d693 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Fri, 12 Apr 2024 10:10:05 +0800 Subject: [PATCH 03/40] entities modified --- .../console/entity/acl/AclEntity.java | 2 ++ .../console/entity/base/BaseEntity.java | 8 +++++ .../console/entity/client/ClientEntity.java | 4 +++ .../console/entity/cluster/ClusterEntity.java | 17 ++++------- .../console/entity/config/ConfigEntity.java | 9 +++++- .../entity/connection/ConnectionEntity.java | 30 ++++--------------- .../entity/connector/ConnectorEntity.java | 12 +++++--- .../console/entity/group/GroupEntity.java | 4 +++ .../entity/groupmember/GroupMemberEntity.java | 4 +++ .../health/HealthCheckResultEntity.java | 6 +++- .../instanceuser/InstanceUserEntity.java | 2 ++ .../console/entity/log/LogEntity.java | 2 ++ .../console/entity/meta/MetaEntity.java | 8 +++-- .../console/entity/runtime/RuntimeEntity.java | 8 ++--- .../console/entity/storage/StoreEntity.java | 13 ++++---- .../console/entity/topic/TopicEntity.java | 13 +++++++- 16 files changed, 88 insertions(+), 54 deletions(-) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/acl/AclEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/acl/AclEntity.java index 78b7d7da..18ca26c7 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/acl/AclEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/acl/AclEntity.java @@ -23,11 +23,13 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class AclEntity extends BaseEntity { private static final long serialVersionUID = 6057071983428111947L; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java index 5d0984d6..c7022f34 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/base/BaseEntity.java @@ -22,13 +22,21 @@ import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; /** * Base Entity provide some basic fields that every Eventmesh Dashboard Entity would have */ @Data +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false, exclude = {"createTime", "updateTime"}) @Schema(name = "BaseEntity", description = "Base entity") +@SuperBuilder public class BaseEntity implements Serializable { private static final long serialVersionUID = -2697805837923579585L; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/client/ClientEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/client/ClientEntity.java index e6cec83c..cfdbe0a3 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/client/ClientEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/client/ClientEntity.java @@ -26,11 +26,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class ClientEntity extends BaseEntity { private static final long serialVersionUID = 8204133370609215856L; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java index eafbd2f1..c5ff7b1f 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/cluster/ClusterEntity.java @@ -19,22 +19,22 @@ import org.apache.eventmesh.dashboard.console.entity.base.BaseEntity; -import java.sql.Timestamp; - import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@SuperBuilder +@EqualsAndHashCode(callSuper = true, exclude = "status") public class ClusterEntity extends BaseEntity { - private Long id; - private String name; - private String registryNameList; + private String registryAddress; private String bootstrapServers; @@ -54,12 +54,5 @@ public class ClusterEntity extends BaseEntity { private Integer status; - private Timestamp createTime; - - private Timestamp updateTime; - - /** - * @See StoreType - */ private Integer storeType; } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java index 40e766e8..c4702814 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/config/ConfigEntity.java @@ -23,11 +23,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +@Data +@EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor -@Data +@SuperBuilder public class ConfigEntity extends BaseEntity { private Long id; @@ -36,6 +40,9 @@ public class ConfigEntity extends BaseEntity { private String businessType; + /** + * config type 0:runtime,1:storage,2:connector,3:topic + */ private Integer instanceType; private Long instanceId; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java index 8283cbbb..1637dcdc 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connection/ConnectionEntity.java @@ -21,13 +21,14 @@ import org.apache.eventmesh.dashboard.console.entity.base.BaseEntity; import java.sql.Timestamp; -import java.util.Objects; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; /** @@ -36,6 +37,8 @@ @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = {"status", "endTime"}) +@SuperBuilder public class ConnectionEntity extends BaseEntity { private static final long serialVersionUID = 6565578252656944905L; @@ -83,28 +86,7 @@ public class ConnectionEntity extends BaseEntity { private String description; - public void setDataStatus(RecordStatus dataStatus) { - this.status = dataStatus.getNumber(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ConnectionEntity that = (ConnectionEntity) o; - return Objects.equals(sourceType, that.sourceType) - && Objects.equals(sourceId, that.sourceId) - - && Objects.equals(sinkType, that.sinkType) - && Objects.equals(sinkId, that.sinkId) - - && Objects.equals(runtimeId, that.runtimeId) - && Objects.equals(status, that.status) - - && Objects.equals(description, that.description); + public void setStatusEnum(RecordStatus statusEnum) { + this.status = statusEnum.getNumber(); } } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java index 0b888be7..64655726 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/connector/ConnectorEntity.java @@ -25,11 +25,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class ConnectorEntity extends BaseEntity { private static final long serialVersionUID = -8226303660232951326L; @@ -67,11 +71,11 @@ public class ConnectorEntity extends BaseEntity { */ private String configIds; - public void setDataStatus(RecordStatus dataStatus) { - this.status = dataStatus.getNumber(); + public void setStatusEnum(RecordStatus statusEnum) { + this.status = statusEnum.getNumber(); } - public void setKubernetesPodDataStatus(KubernetesPodStatus kubernetesPodDataStatus) { - this.podState = kubernetesPodDataStatus.getNumber(); + public void setKubernetesPodStatusEnum(KubernetesPodStatus kubernetesPodStatusEnum) { + this.podState = kubernetesPodStatusEnum.getNumber(); } } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/group/GroupEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/group/GroupEntity.java index 52d15d20..dc62d489 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/group/GroupEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/group/GroupEntity.java @@ -23,11 +23,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @NoArgsConstructor @AllArgsConstructor @Data +@SuperBuilder +@EqualsAndHashCode(callSuper = true, exclude = "status") public class GroupEntity extends BaseEntity { private Long id; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/groupmember/GroupMemberEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/groupmember/GroupMemberEntity.java index 9b56cbe1..9e2f6011 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/groupmember/GroupMemberEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/groupmember/GroupMemberEntity.java @@ -23,11 +23,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class GroupMemberEntity extends BaseEntity { private Long id; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java index f2b65ad3..017a9470 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/health/HealthCheckResultEntity.java @@ -23,11 +23,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data +@SuperBuilder @AllArgsConstructor @NoArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "resultDesc") @Schema(name = "HealthCheckResultEntity", description = "Health check result entity") public class HealthCheckResultEntity extends BaseEntity { @@ -44,7 +48,7 @@ public class HealthCheckResultEntity extends BaseEntity { private String resultDesc; - @Schema(description = "state of a health check, 0: failed, 1: passed, 2: doing check, 3: out of time") + @Schema(description = "state of a health check, 0: failed, 1: passed, 2: doing check, 3: out of time, 4: not connected") private Integer state; } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/instanceuser/InstanceUserEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/instanceuser/InstanceUserEntity.java index 8ca85b42..bce60c15 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/instanceuser/InstanceUserEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/instanceuser/InstanceUserEntity.java @@ -23,12 +23,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class InstanceUserEntity extends BaseEntity { private Integer instanceType; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/log/LogEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/log/LogEntity.java index f2483f5f..48c0efbe 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/log/LogEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/log/LogEntity.java @@ -23,11 +23,13 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = {"endTime", "operationUser", "result"}) public class LogEntity extends BaseEntity { private Long id; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java index fb004425..3a0b13d0 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/meta/MetaEntity.java @@ -24,11 +24,15 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class MetaEntity extends BaseEntity { private static final long serialVersionUID = 7176263169716424469L; @@ -59,7 +63,7 @@ public class MetaEntity extends BaseEntity { @Schema(name = "status", defaultValue = "0", allowableValues = {"0", "1"}, description = "0:inactive, 1:active") private Integer status; - public void setDataStatus(RecordStatus dataStatus) { - this.status = dataStatus.getNumber(); + public void setStatusEnum(RecordStatus statusEnum) { + this.status = statusEnum.getNumber(); } } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java index c4a7be5e..b4703b99 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/runtime/RuntimeEntity.java @@ -23,16 +23,16 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor - +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class RuntimeEntity extends BaseEntity { - - private Long id; - private Long clusterId; private String host; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java index 78156f50..ba0781e0 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/storage/StoreEntity.java @@ -24,20 +24,23 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class StoreEntity extends BaseEntity { - private Long id; - private Long clusterId; - private Integer storeId; - - private String storeType; + /** + * @see org.apache.eventmesh.dashboard.common.enums.StoreType + */ + private Integer storeType; private String host; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/topic/TopicEntity.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/topic/TopicEntity.java index 85ae80e6..e96a460d 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/topic/TopicEntity.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/entity/topic/TopicEntity.java @@ -21,13 +21,19 @@ import java.sql.Timestamp; +import io.swagger.v3.oas.annotations.media.Schema; + import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true, exclude = "status") +@SuperBuilder public class TopicEntity extends BaseEntity { private Long id; @@ -36,10 +42,15 @@ public class TopicEntity extends BaseEntity { private String topicName; - private String storageId; + private Long storageId; + @Schema(description = "time to live in milliseconds, -2 unknown, -1 no limit;", example = "1000") private Long retentionMs; + /** + * topic type, 0: normal, 1: EventMesh internal; + */ + @Schema(description = "topic type, 0: normal, 1: EventMesh internal;", example = "0") private Integer type; private String description; From 36c7ca3bfa0aa99bcd02184aa1c6c69856c00b53 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Fri, 12 Apr 2024 10:10:23 +0800 Subject: [PATCH 04/40] mappers modified --- .../console/mapper/client/ClientMapper.java | 8 +++- .../console/mapper/cluster/ClusterMapper.java | 13 +++--- .../console/mapper/config/ConfigMapper.java | 12 ++++-- .../mapper/connection/ConnectionMapper.java | 12 +++--- .../mapper/connector/ConnectorMapper.java | 9 +++-- .../health/HealthCheckResultMapper.java | 40 +++++++++++++------ .../console/mapper/meta/MetaMapper.java | 8 ++-- .../console/mapper/runtime/RuntimeMapper.java | 5 ++- .../console/mapper/storage/StoreMapper.java | 3 ++ 9 files changed, 71 insertions(+), 39 deletions(-) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java index 94e3eda2..a2692848 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/client/ClientMapper.java @@ -65,10 +65,14 @@ public interface ClientMapper { + "`status`, `config_ids`, `description`) " + "VALUES (#{clusterId}, #{name}, #{platform}," + "#{language}, #{pid}, #{host}, #{port}, #{protocol}," - + "#{status}, #{configIds}, #{description})") - void insert(ClientEntity clientEntity); + + "#{status}, #{configIds}, #{description})" + + "ON DUPLICATE KEY UPDATE `status` = 1, `pid` = #{pid}, `config_ids` = #{configIds}, `host` = #{host}, `port` = #{port}") + Long insert(ClientEntity clientEntity); @Update("UPDATE `client` SET status = 0, end_time = NOW() WHERE id = #{id}") void deactivate(ClientEntity clientEntity); + @Update("UPDATE `client` SET status = 0, end_time = NOW() WHERE `host` = #{host} AND `port` = #{port}") + void deActiveByHostPort(ClientEntity clientEntity); + } 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 7e1c3af3..e9850e57 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 @@ -41,10 +41,10 @@ public interface ClusterMapper { @Insert({ ""}) @@ -54,17 +54,18 @@ public interface ClusterMapper { @Select("SELECT * FROM cluster WHERE id=#{id} AND status=1") ClusterEntity selectClusterById(ClusterEntity cluster); - @Insert("INSERT INTO cluster (name, registry_name_list, bootstrap_servers, eventmesh_version, client_properties, " - + "jmx_properties, reg_properties, description, auth_type, run_state,store_type) VALUES (#{name},#{registryNameList}," + @Insert("INSERT INTO cluster (name, registry_address, bootstrap_servers, eventmesh_version, client_properties, " + + "jmx_properties, reg_properties, description, auth_type, run_state,store_type) VALUES (#{name},#{registryAddress}," + "#{bootstrapServers},#{eventmeshVersion},#{clientProperties},#{jmxProperties},#{regProperties},#{description},#{authType}," - + "#{runState},#{storeType})") + + "#{runState},#{storeType})" + + "ON DUPLICATE KEY UPDATE status = 1") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void addCluster(ClusterEntity cluster); @Update("UPDATE cluster SET name =#{name},reg_properties=#{regProperties},bootstrap_servers=#{bootstrapServers}," + "eventmesh_version=#{eventmeshVersion},client_properties=#{clientProperties},jmx_properties=#{jmxProperties}," + "reg_properties=#{regProperties},description=#{description},auth_type=#{authType},run_state=#{runState} ," - + "registry_name_list=#{registryNameList} WHERE id=#{id}") + + "registry_address=#{registryAddress} WHERE id=#{id}") void updateClusterById(ClusterEntity cluster); @Update("UPDATE cluster SET status=0 WHERE id=#{id}") diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java index 838e95f8..2a6c9a1c 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java @@ -61,6 +61,9 @@ public interface ConfigMapper { @Select("SELECT * FROM config WHERE status=1 AND is_default=0") List selectAll(); + @Select("SELECT * FROM config WHERE instance_type=#{instanceType} AND instance_id=#{instanceId}") + List selectConfigsByInstance(ConfigEntity configEntity); + @Insert({ ""}) void batchInsert(List connectionEntityList); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java index 5958b6a4..910884fa 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/connector/ConnectorMapper.java @@ -34,7 +34,7 @@ public interface ConnectorMapper { @Select("SELECT * FROM connector WHERE status=1") - ConnectorEntity selectAll(); + List selectAll(); @Select("SELECT * FROM connector WHERE id = #{id} AND status=1") ConnectorEntity selectById(ConnectorEntity connectorEntity); @@ -47,8 +47,9 @@ public interface ConnectorMapper { @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Insert("INSERT INTO connector (cluster_id,name, class_name, type, status, pod_state, config_ids, host, port) " - + "VALUES (#{clusterId}, #{name}, #{className}, #{type}, #{status}, #{podState}, #{configIds}, #{host}, #{port})") - void insert(ConnectorEntity connectorEntity); + + "VALUES (#{clusterId}, #{name}, #{className}, #{type}, #{status}, #{podState}, #{configIds}, #{host}, #{port})" + + "ON DUPLICATE KEY UPDATE status = 1, pod_state = #{podState}, config_ids = #{configIds}, host = #{host}, port = #{port}") + Long insert(ConnectorEntity connectorEntity); @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Insert({ @@ -66,7 +67,7 @@ public interface ConnectorMapper { void active(ConnectorEntity connectorEntity); @Update("UPDATE connector SET status = 0 WHERE id = #{id}") - void deactivate(ConnectorEntity connectorEntity); + void deActive(ConnectorEntity connectorEntity); @Update("UPDATE connector SET pod_state = #{podState} WHERE id = #{id}") void updatePodState(ConnectorEntity connectorEntity); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java index b14b1a16..59b5fb56 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/health/HealthCheckResultMapper.java @@ -61,22 +61,35 @@ List selectByClusterIdAndCreateTimeRange(@Param("cluste @Insert({ "" }) void batchInsert(List healthCheckResultEntityList); + @Insert({ + "" + }) + void insertNewChecks(List healthCheckResultEntityList); + @Update("UPDATE health_check_result SET state = #{state}, result_desc = #{resultDesc} WHERE id = #{id}") void update(HealthCheckResultEntity healthCheckResultEntity); @@ -92,10 +105,13 @@ List selectByClusterIdAndCreateTimeRange(@Param("cluste @Select({ "" }) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java index c3102724..6d4f8d6a 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/meta/MetaMapper.java @@ -40,11 +40,11 @@ public interface MetaMapper { ""}) @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") - void batchInsert(List metaEntities); + List batchInsert(List metaEntities); @Select("SELECT * FROM meta WHERE id = #{id}") MetaEntity selectById(MetaEntity metaEntity); @@ -54,8 +54,8 @@ public interface MetaMapper { @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Insert("INSERT INTO meta (name, type, version, cluster_id, host, port, role, username, params, status)" - + " VALUES ( #{name}, #{type}, #{version}, #{clusterId}, #{host}, #{port}, #{role}, #{username}, #{params}, #{status})") - void insert(MetaEntity metaEntity); + + " VALUES ( #{name}, #{type}, #{version}, #{clusterId}, #{host}, #{port}, #{role}, #{username}, #{params}, 1)") + Long insert(MetaEntity metaEntity); @Update("UPDATE meta SET status = 0 WHERE id = #{id}") void deactivate(MetaEntity metaEntity); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java index c6453309..c1e910f5 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/runtime/RuntimeMapper.java @@ -44,14 +44,15 @@ public interface RuntimeMapper { ""}) @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void batchInsert(List runtimeEntities); @Insert("INSERT INTO runtime (cluster_id, host, storage_cluster_id, port, jmx_port, start_timestamp, rack, status, " - + "endpoint_map) VALUES(#{clusterId},#{host},#{storageClusterId},#{port},#{jmxPort},#{startTimestamp},#{rack},#{status},#{endpointMap})") + + "endpoint_map) VALUES(#{clusterId},#{host},#{storageClusterId},#{port},#{jmxPort},NOW(),#{rack},#{status},#{endpointMap})" + + " ON DUPLICATE KEY UPDATE status=1,start_timestamp = now()") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void addRuntime(RuntimeEntity runtimeEntity); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java index 5e5ee418..2449a106 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java @@ -39,6 +39,9 @@ public interface StoreMapper { @Select("SELECT * FROM store WHERE id=#{id} AND status=1") StoreEntity selectById(StoreEntity storeEntity); + @Select("SELECT * FROM store WHERE host=#{host} AND port=#{port} AND status=1 LIMIT 1") + StoreEntity selectByHostPort(StoreEntity storeEntity); + @Insert({ "