Skip to content

Commit

Permalink
feat: add from registry nacos
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambert-Rao committed Apr 5, 2024
1 parent 752aa15 commit 04bf2ab
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void addMetadata(RuntimeMetadata meta) {
ClusterEntity cluster = ClusterCache.getINSTANCE().getClusterByRegistryAddress(meta.getClusterRegistryAddress());
if (Objects.isNull(cluster)) {
log.info("new cluster detected syncing runtime, adding cluster to db, cluster:{}", meta.getClusterName());
ClusterEntity clusterEntity = new ClusterEntity(meta.getClusterName(), cluster.getRegistryAddress(), "", "", "", "", "", "", 0, 0, 1,
ClusterEntity clusterEntity = new ClusterEntity(meta.getClusterName(), meta.getRegistryAddress(), "", "", "", "", "", "", 0, 0, 1,
null, null, 0);
clusterService.addCluster(clusterEntity);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import org.apache.eventmesh.dashboard.common.model.metadata.RuntimeMetadata;
import org.apache.eventmesh.dashboard.common.model.remoting.runtime.GetRuntimeRequest;
import org.apache.eventmesh.dashboard.console.cache.ClusterCache;
import org.apache.eventmesh.dashboard.console.entity.meta.MetaEntity;
import org.apache.eventmesh.dashboard.console.function.metadata.syncservice.SyncDataService;
import org.apache.eventmesh.dashboard.console.service.registry.RegistryDataService;
import org.apache.eventmesh.dashboard.core.meta.runtime.NacosRuntimeCore;
import org.apache.eventmesh.dashboard.service.remoting.MetaRemotingService;

Expand All @@ -32,6 +33,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;
Expand All @@ -42,15 +44,21 @@ public class RuntimeSyncFromClusterService implements SyncDataService<RuntimeMet

private final MetaRemotingService metaRemotingService = new NacosRuntimeCore();

@Autowired
private RegistryDataService registryDataService;

@Override
public List<RuntimeMetadata> getData() {
List<GetRuntimeRequest> requestList = new ArrayList<>();
ConcurrentLinkedDeque<RuntimeMetadata> runtimeMetadata = new ConcurrentLinkedDeque<>();
ClusterCache.getINSTANCE().getClusters().forEach(cluster -> {
GetRuntimeRequest request = new GetRuntimeRequest();
request.setRegistryAddress(cluster.getRegistryAddress());
requestList.add(request);
});
List<MetaEntity> metaEntityList = registryDataService.selectAll();
registryDataService.selectAll().forEach(
metaEntity -> {
GetRuntimeRequest request = new GetRuntimeRequest();
request.setRegistryAddress(metaEntity.getHost() + ":" + metaEntity.getPort());
requestList.add(request);
}
);
if (requestList.isEmpty()) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface MetaMapper {
"<script>",
" INSERT INTO meta (name, type, version, cluster_id, host, port, role, username, params,status) VALUES ",
" <foreach collection='list' item='c' index='index' separator=','>",
" (#{c.name}, #{c.type}, #{c.version}, #{c.clusterId}, #{c.host}, #{c.port}, #{c.role}, #{c.username}, #{c.params}, #{c.status})",
" (#{c.name}, #{c.type}, #{c.version}, #{c.clusterId}, #{c.host}, #{c.port}, #{c.role}, #{c.username}, #{c.params}, 1)",
"</foreach>",
"</script>"})
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
Expand All @@ -54,7 +54,7 @@ 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})")
+ " VALUES ( #{name}, #{type}, #{version}, #{clusterId}, #{host}, #{port}, #{role}, #{username}, #{params}, 1)")
Long insert(MetaEntity metaEntity);

@Update("UPDATE meta SET status = 0 WHERE id = #{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.eventmesh.dashboard.console;

import org.apache.eventmesh.dashboard.common.enums.RecordStatus;

import java.sql.Timestamp;

import static org.mockito.ArgumentMatchers.any;
Expand All @@ -27,8 +29,10 @@
import org.apache.eventmesh.dashboard.common.model.remoting.runtime.GetRuntimeResult;
import org.apache.eventmesh.dashboard.console.cache.ClusterCache;
import org.apache.eventmesh.dashboard.console.entity.cluster.ClusterEntity;
import org.apache.eventmesh.dashboard.console.entity.meta.MetaEntity;
import org.apache.eventmesh.dashboard.console.function.metadata.syncservice.cluster.RuntimeSyncFromClusterService;
import org.apache.eventmesh.dashboard.console.service.cluster.ClusterService;
import org.apache.eventmesh.dashboard.console.service.registry.RegistryDataService;
import org.apache.eventmesh.dashboard.service.remoting.MetaRemotingService;

import java.util.ArrayList;
Expand Down Expand Up @@ -60,31 +64,26 @@
class EventMeshDashboardApplicationTest {

@Autowired
private ClusterService clusterService;
private RegistryDataService registryDataService;

@Test
public void IntegrationTest() throws InterruptedException {
ClusterEntity newCluster = new ClusterEntity();
newCluster.setName("");
newCluster.setRegistryAddress("175.27.155.139:8848");
newCluster.setBootstrapServers("175.27.155.139:10000");
newCluster.setEventmeshVersion("");
newCluster.setClientProperties("");
newCluster.setJmxProperties("");
newCluster.setRegProperties("");
newCluster.setDescription("");
newCluster.setAuthType(0);
newCluster.setRunState(0);
newCluster.setStatus(0);
newCluster.setCreateTime(new Timestamp(new java.util.Date().getTime()));
newCluster.setUpdateTime(new Timestamp(new java.util.Date().getTime()));
newCluster.setStoreType(0);
newCluster.setId(0L);
newCluster.setClusterId(0L);
newCluster.setCreateTime(new Timestamp(new java.util.Date().getTime()));
newCluster.setUpdateTime(new Timestamp(new java.util.Date().getTime()));
MetaEntity metaEntity = new MetaEntity();
metaEntity.setStatusEnum(RecordStatus.INACTIVE);
metaEntity.setName("");
metaEntity.setType("");
metaEntity.setVersion("");
metaEntity.setClusterId(0L);
metaEntity.setHost("175.27.155.139");
metaEntity.setPort(8848);
metaEntity.setRole("");
metaEntity.setUsername("");
metaEntity.setParams("");
metaEntity.setStatus(0);
metaEntity.setId(0L);
metaEntity.setClusterId(0L);

clusterService.addCluster(newCluster);
registryDataService.insert(metaEntity);

if (Objects.equals(System.getenv("APPLICATION_TEST"), "on")) {
Thread.sleep(1000 * 60 * 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public GetRuntimeResult getRuntime(GetRuntimeRequest getRuntimeRequest) {
nacosNamingService.getAllInstances("EVENTMESH-runtime-GRPC", "GRPC-GROUP");
List<RuntimeMetadata> runtimeMetadataList = new ArrayList<>();
instances.forEach(instance -> {
runtimeMetadataList.add(RuntimeMetadata.builder()
RuntimeMetadata runtimeMetadata = RuntimeMetadata.builder()
.host(instance.getIp())
.port(instance.getPort())
.rack(instance.getClusterName())
Expand All @@ -60,7 +60,9 @@ public GetRuntimeResult getRuntime(GetRuntimeRequest getRuntimeRequest) {
.clusterRegistryAddress(getRuntimeRequest.getRegistryAddress())
.jmxPort(0)
.endpointMap("")
.build());
.build();
runtimeMetadata.setRegistryAddress(getRuntimeRequest.getRegistryAddress());
runtimeMetadataList.add(runtimeMetadata);
});
return new GetRuntimeResponse(runtimeMetadataList);
} catch (NacosException e) {
Expand Down

0 comments on commit 04bf2ab

Please sign in to comment.