Skip to content

Commit

Permalink
fix: get runtimes by 3 protocols from meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambert-Rao committed Apr 15, 2024
1 parent da15ab4 commit 22bf6d9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class RuntimeMetadata extends MetadataConfig {

private String host;
Expand All @@ -43,6 +45,4 @@ public class RuntimeMetadata extends MetadataConfig {
private Long startTimestamp;

private String clusterName;

private String clusterRegistryAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class RuntimeMetadataHandlerToDbImpl implements MetadataHandler<RuntimeMe

@Override
public void addMetadata(RuntimeMetadata meta) {
ClusterEntity cluster = ClusterCache.getINSTANCE().getClusterByRegistryAddress(meta.getClusterRegistryAddress());
ClusterEntity cluster = ClusterCache.getINSTANCE().getClusterByRegistryAddress(meta.getRegistryAddress());
if (Objects.isNull(cluster)) {
log.info("new cluster detected syncing runtime, adding cluster to db, cluster:{}", meta.getClusterName());
ClusterEntity clusterEntity = new ClusterEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ CREATE TABLE `topic`
`description` varchar(1024) DEFAULT '' COMMENT '备注信息',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(尽量与Topic实际创建时间一致)',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间(尽量与Topic实际创建时间一致)',
`status` int NOT NULL DEFAULT '1',
`status` int NOT NULL DEFAULT 1,
create_progress int NOT NULL DEFAULT 1 COMMENT '0:创建成功,1:创建中,2:创建失败',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_cluster_phy_id_topic_name` (`cluster_id`, `topic_name`),
Expand Down Expand Up @@ -403,7 +403,7 @@ CREATE TABLE `meta`
`role` varchar(16) NOT NULL DEFAULT '-1' COMMENT '角色, leader follower observer',
`username` varchar(192) NOT NULL DEFAULT '' COMMENT '注册中心用户名',
`params` varchar(192) NOT NULL DEFAULT '' COMMENT '注册中心启动参数',
`status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '状态: 1启用,0未启用',
`status` tinyint(4) unsigned NOT NULL DEFAULT 1 COMMENT '状态: 1启用,0未启用',

`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import org.apache.eventmesh.dashboard.service.remoting.MetaRemotingService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

Expand All @@ -47,24 +50,32 @@ public GetRuntimeResult getRuntime(GetRuntimeRequest getRuntimeRequest) {

CompletableFuture<GetRuntimeResponse> future = CompletableFuture.supplyAsync(() -> {
try {
List<Instance> instances =
nacosNamingService.getAllInstances("EVENTMESH-runtime-GRPC", "GRPC-GROUP");
List<RuntimeMetadata> runtimeMetadataList = new ArrayList<>();
instances.forEach(instance -> {
RuntimeMetadata runtimeMetadata = RuntimeMetadata.builder()
.host(instance.getIp())
.port(instance.getPort())
.rack(instance.getClusterName())
.storageClusterId(0L)
.clusterName(Objects.isNull(instance.getClusterName()) ? instance.getClusterName() : "NORMAL")
.clusterRegistryAddress(getRuntimeRequest.getRegistryAddress())
.jmxPort(0)
.endpointMap("")
.build();
runtimeMetadata.setRegistryAddress(getRuntimeRequest.getRegistryAddress());
runtimeMetadataList.add(runtimeMetadata);
});
return new GetRuntimeResponse(runtimeMetadataList);
Map<String, RuntimeMetadata> runtimeMetadataMap = new HashMap<>();
//If service name or group name is changed, please modify the following code
List<String> protocols = Arrays.asList("GRPC", "HTTP", "TCP");

for (String protocol : protocols) {
List<Instance> instances =
nacosNamingService.getAllInstances("EVENTMESH-runtime-" + protocol, protocol + "-GROUP");
instances.forEach(instance -> {
if (!runtimeMetadataMap.containsKey(instance.getIp())) {
RuntimeMetadata runtimeMetadata = RuntimeMetadata.builder()
.host(instance.getIp())
.port(instance.getPort())
.rack(instance.getClusterName())
.storageClusterId(0L)
.clusterName(Objects.isNull(instance.getClusterName()) ? instance.getClusterName() : "NORMAL")
.registryAddress(getRuntimeRequest.getRegistryAddress())
.jmxPort(0)
.endpointMap("")
.build();
runtimeMetadata.setRegistryAddress(getRuntimeRequest.getRegistryAddress());
runtimeMetadataMap.put(instance.getIp(), runtimeMetadata);
}
});
}

return new GetRuntimeResponse(new ArrayList<>(runtimeMetadataMap.values()));
} catch (NacosException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 22bf6d9

Please sign in to comment.