Skip to content

Commit

Permalink
Merge pull request #903 from wangqifan/bugfix/dcmeata_disable_db
Browse files Browse the repository at this point in the history
get dcmeta without cache
  • Loading branch information
LanternLee authored Oct 29, 2024
2 parents 74ec15b + 21eadcf commit 8138daa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -274,6 +275,22 @@ public String call() {

}

public DcMeta getDcMeta(String dcName, Set<String> 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<DcMeta> resp = exchange(comp.toUriString(), HttpMethod.GET, null, DcMeta.class, "getDcMeta");
return resp.getBody();
}

<T> ResponseEntity<T> exchange(String url, HttpMethod var2, HttpEntity<?> httpEntity, Class<T> type, String name) {
try {
return catTransactionMonitor.logTransaction("ConsoleForwardAPI", name, new Callable<ResponseEntity<T>>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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<String> allowTypes) throws Exception {
// 大小写

Set<String> 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<String, ClusterMeta> 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
Expand Down

0 comments on commit 8138daa

Please sign in to comment.