From 21eadcf458f506ee4a3d29b89147ee051c350523 Mon Sep 17 00:00:00 2001 From: qifanwang Date: Mon, 28 Oct 2024 19:15:08 +0800 Subject: [PATCH] get dcmeta without cache --- .../resources/ConsolePortalService.java | 17 +++++++++++ .../meta/impl/DcMetaServiceWithoutDB.java | 30 +++++++------------ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/resources/ConsolePortalService.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/resources/ConsolePortalService.java index 9fae76c086..17dc1806e8 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/resources/ConsolePortalService.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/resources/ConsolePortalService.java @@ -11,6 +11,7 @@ import com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo; import com.ctrip.xpipe.redis.console.model.*; import com.ctrip.xpipe.redis.core.console.ConsoleCheckerPath; +import com.ctrip.xpipe.redis.core.entity.DcMeta; import com.ctrip.xpipe.redis.core.entity.KeeperMeta; import com.ctrip.xpipe.redis.core.entity.XpipeMeta; import com.ctrip.xpipe.redis.core.service.AbstractService; @@ -274,6 +275,22 @@ public String call() { } + public DcMeta getDcMeta(String dcName, Set allowTypes) { + UriComponents comp; + if (null == allowTypes) { + comp = UriComponentsBuilder + .fromHttpUrl(config.getConsoleNoDbDomain() + "/api/dc/{dcId}") + .buildAndExpand(dcName); + } else { + comp = UriComponentsBuilder + .fromHttpUrl(config.getConsoleNoDbDomain() + "/api/dc/{dcId}") + .queryParam("types", allowTypes.toArray()) + .buildAndExpand(dcName); + } + ResponseEntity resp = exchange(comp.toUriString(), HttpMethod.GET, null, DcMeta.class, "getDcMeta"); + return resp.getBody(); + } + ResponseEntity exchange(String url, HttpMethod var2, HttpEntity httpEntity, Class type, String name) { try { return catTransactionMonitor.logTransaction("ConsoleForwardAPI", name, new Callable>() { diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/service/meta/impl/DcMetaServiceWithoutDB.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/service/meta/impl/DcMetaServiceWithoutDB.java index f6c999607e..b2f4c2e1fd 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/service/meta/impl/DcMetaServiceWithoutDB.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/service/meta/impl/DcMetaServiceWithoutDB.java @@ -1,6 +1,7 @@ package com.ctrip.xpipe.redis.console.service.meta.impl; -import org.apache.commons.lang3.SerializationUtils; +import com.ctrip.xpipe.redis.console.config.ConsoleConfig; +import com.ctrip.xpipe.redis.console.resources.ConsolePortalService; import com.ctrip.xpipe.redis.checker.spring.ConsoleDisableDbCondition; import com.ctrip.xpipe.redis.checker.spring.DisableDbMode; import com.ctrip.xpipe.redis.console.service.meta.DcMetaService; @@ -10,10 +11,8 @@ import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Service; -import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; @Service @Conditional(ConsoleDisableDbCondition.class) @@ -23,29 +22,20 @@ public class DcMetaServiceWithoutDB implements DcMetaService { @Autowired private MetaCache metaCache; + @Autowired + private ConsoleConfig consoleConfig; + + @Autowired + private ConsolePortalService consolePortalService; + @Override public DcMeta getDcMeta(String dcName) throws Exception { - return metaCache.getXpipeMeta().getDcs().get(dcName); + return getDcMeta(dcName, consoleConfig.getOwnClusterType()); } @Override public DcMeta getDcMeta(String dcName, Set allowTypes) throws Exception { - // 大小写 - - Set upperCaseAllowTypes = allowTypes.stream() - .map(String::toUpperCase) - .collect(Collectors.toSet()); - - DcMeta dcMeta = metaCache.getXpipeMeta().getDcs().get(dcName); - DcMeta result = SerializationUtils.clone(dcMeta); - result.getClusters().clear(); - Map clusterMetas = dcMeta.getClusters(); - for(ClusterMeta clusterMeta : clusterMetas.values()) { - if(upperCaseAllowTypes.contains(clusterMeta.getType().toUpperCase())) { - result.addCluster(SerializationUtils.clone(clusterMeta)); - } - } - return result; + return consolePortalService.getDcMeta(dcName, allowTypes); } @Override