use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class MetaServerPrepareResourcesAndStart method setupZkNodes.
private void setupZkNodes(CuratorFramework client, DcMeta dcMeta) throws Exception {
for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
String path = MetaZkConfig.getKeeperLeaderLatchPath(clusterMeta.getId(), shardMeta.getId());
client.createContainers(path);
}
}
String metaPath = MetaZkConfig.getMetaRootPath();
client.createContainers(metaPath);
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class BaseSampleMonitor method generatePlan.
@Override
public Collection<BaseSamplePlan<T>> generatePlan(List<DcMeta> dcMetas) {
Map<Pair<String, String>, BaseSamplePlan<T>> plans = new HashMap<>();
for (DcMeta dcMeta : dcMetas) {
for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
if (!addCluster(dcMeta.getId(), clusterMeta)) {
continue;
}
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
Pair<String, String> cs = new Pair<>(clusterMeta.getId(), shardMeta.getId());
BaseSamplePlan<T> plan = plans.get(cs);
if (plan == null) {
plan = createPlan(dcMeta.getId(), clusterMeta.getId(), shardMeta.getId());
plans.put(cs, plan);
}
for (RedisMeta redisMeta : shardMeta.getRedises()) {
log.debug("[generatePlan]{}", redisMeta.desc());
addRedis(plan, dcMeta.getId(), redisMeta);
}
if (plan.isEmpty()) {
plans.remove(cs);
}
}
}
}
return plans.values();
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class DefaultRedisSessionManager method getInUseRedises.
private Set<HostPort> getInUseRedises() {
Set<HostPort> redisInUse = new HashSet<>();
List<DcMeta> dcMetas = new LinkedList<>(metaCache.getXpipeMeta().getDcs().values());
if (dcMetas.isEmpty())
return null;
for (DcMeta dcMeta : dcMetas) {
if (dcMeta == null)
break;
for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
for (RedisMeta redisMeta : shardMeta.getRedises()) {
redisInUse.add(new HostPort(redisMeta.getIp(), redisMeta.getPort()));
}
}
}
}
return redisInUse;
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class ClusterMetaServiceImpl method loadClusterMeta.
@Override
public ClusterMeta loadClusterMeta(DcMeta dcMeta, ClusterTbl clusterTbl, DcMetaQueryVO dcMetaQueryVO) {
ClusterMeta clusterMeta = new ClusterMeta();
clusterTbl.setActivedcId(getClusterMetaCurrentPrimaryDc(dcMetaQueryVO.getCurrentDc(), clusterTbl));
clusterMeta.setId(clusterTbl.getClusterName());
for (DcClusterTbl dcCluster : dcMetaQueryVO.getAllDcClusterMap().get(clusterTbl.getId())) {
if (dcCluster.getDcId() == clusterTbl.getActivedcId()) {
clusterMeta.setActiveDc(dcMetaQueryVO.getAllDcs().get(dcCluster.getDcId()).getDcName());
} else {
if (Strings.isNullOrEmpty(clusterMeta.getBackupDcs())) {
clusterMeta.setBackupDcs(dcMetaQueryVO.getAllDcs().get(dcCluster.getDcId()).getDcName());
} else {
clusterMeta.setBackupDcs(clusterMeta.getBackupDcs() + "," + dcMetaQueryVO.getAllDcs().get(dcCluster.getDcId()).getDcName());
}
}
}
clusterMeta.setParent(dcMeta);
for (ShardTbl shard : dcMetaQueryVO.getShardMap().get(clusterTbl.getClusterName())) {
clusterMeta.addShard(shardMetaService.loadShardMeta(clusterMeta, clusterTbl, shard, dcMetaQueryVO));
}
return clusterMeta;
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class ClusterMetaServiceImpl method getClusterMeta.
@Override
public ClusterMeta getClusterMeta(final String dcName, final String clusterName) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {
@Override
public DcTbl call() throws Exception {
return dcService.find(dcName);
}
});
Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {
@Override
public ClusterTbl call() throws Exception {
return clusterService.find(clusterName);
}
});
Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {
@Override
public DcClusterTbl call() throws Exception {
return dcClusterService.find(dcName, clusterName);
}
});
Future<List<ShardTbl>> future_shardsInfo = fixedThreadPool.submit(new Callable<List<ShardTbl>>() {
@Override
public List<ShardTbl> call() throws Exception {
return shardService.findAllByClusterName(clusterName);
}
});
Future<List<DcTbl>> future_clusterRelatedDc = fixedThreadPool.submit(new Callable<List<DcTbl>>() {
@Override
public List<DcTbl> call() throws Exception {
return dcService.findClusterRelatedDc(clusterName);
}
});
ClusterMeta clusterMeta = new ClusterMeta();
clusterMeta.setId(clusterName);
try {
DcTbl dcInfo = future_dcInfo.get();
ClusterTbl clusterInfo = future_clusterInfo.get();
DcClusterTbl dcClusterInfo = future_dcClusterInfo.get();
List<DcTbl> clusterRelatedDc = future_clusterRelatedDc.get();
if (null == dcInfo || null == clusterInfo || null == dcClusterInfo)
return clusterMeta;
clusterMeta.setId(clusterInfo.getClusterName());
clusterInfo.setActivedcId(getClusterMetaCurrentPrimaryDc(dcInfo, clusterInfo));
for (DcTbl dc : clusterRelatedDc) {
if (dc.getId() == clusterInfo.getActivedcId()) {
clusterMeta.setActiveDc(dc.getDcName());
} else {
if (Strings.isNullOrEmpty(clusterMeta.getBackupDcs())) {
clusterMeta.setBackupDcs(dc.getDcName());
} else {
clusterMeta.setBackupDcs(clusterMeta.getBackupDcs() + "," + dc.getDcName());
}
}
}
List<ShardTbl> shards = future_shardsInfo.get();
if (null != shards) {
for (ShardTbl shard : shards) {
clusterMeta.addShard(shardMetaService.getShardMeta(dcInfo, clusterInfo, shard));
}
}
} catch (ExecutionException e) {
throw new DataNotFoundException("Cannot construct cluster-meta", e);
} catch (InterruptedException e) {
throw new ServerException("Concurrent execution failed.", e);
} finally {
fixedThreadPool.shutdown();
}
return clusterMeta;
}
Aggregations