use of com.ctrip.xpipe.redis.core.entity.ShardMeta 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.ShardMeta 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.ShardMeta 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.ShardMeta in project x-pipe by ctripcorp.
the class MetaServiceTest method generateClusterMetaMockData.
private void generateClusterMetaMockData() {
when(mockedDcService.find("ntgxh")).thenReturn(new DcTbl().setId(1L).setDcName("ntgxh").setDcLastModifiedTime("1234567"));
when(mockedDcService.find(1L)).thenReturn(new DcTbl().setId(1L).setDcName("ntgxh").setDcLastModifiedTime("1234567"));
when(mockedClusterService.find("cluster1")).thenReturn(new ClusterTbl().setId(1).setClusterName("cluster1").setActivedcId(1L).setClusterLastModifiedTime("1234567"));
when(mockedDcClusterService.find("ntgxh", "cluster1")).thenReturn(new DcClusterTbl().setDcClusterId(1L).setDcClusterPhase(1));
when(mockedShardService.findAllByClusterName("cluster1")).thenReturn(Arrays.asList(new ShardTbl().setId(1L).setShardName("shard1").setSetinelMonitorName("cluster1-shard1")));
when(mockedShardMetaService.getShardMeta(any(DcTbl.class), any(ClusterTbl.class), any(ShardTbl.class))).thenReturn(new ShardMeta().setId("shard1").setPhase(1).setSentinelId(1L).setSentinelMonitorName("cluster1-shard1"));
}
use of com.ctrip.xpipe.redis.core.entity.ShardMeta in project x-pipe by ctripcorp.
the class ShardMetaServiceImpl method getShardMeta.
@Override
public ShardMeta getShardMeta(final String dcName, final String clusterName, final String shardName) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {
@Override
public DcTbl call() throws DalException {
return dcService.find(dcName);
}
});
Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {
@Override
public ClusterTbl call() throws DalException {
return clusterService.find(clusterName);
}
});
Future<ShardTbl> future_shardInfo = fixedThreadPool.submit(new Callable<ShardTbl>() {
@Override
public ShardTbl call() throws DalException {
return shardService.find(clusterName, shardName);
}
});
Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {
@Override
public DcClusterTbl call() throws DalException {
return dcClusterService.find(dcName, clusterName);
}
});
Future<DcClusterShardTbl> future_dcClusterShardInfo = fixedThreadPool.submit(new Callable<DcClusterShardTbl>() {
@Override
public DcClusterShardTbl call() throws DalException {
return dcClusterShardService.find(dcName, clusterName, shardName);
}
});
try {
if (null == future_dcInfo.get() || null == future_clusterInfo.get() || null == future_shardInfo.get() || null == future_dcClusterInfo.get() || null == future_dcClusterShardInfo.get()) {
return new ShardMeta().setId(shardName);
}
return getShardMeta(future_dcInfo.get(), future_clusterInfo.get(), future_shardInfo.get(), future_dcClusterInfo.get(), future_dcClusterShardInfo.get());
} catch (ExecutionException e) {
throw new DataNotFoundException("Cannot construct shard-meta", e);
} catch (InterruptedException e) {
throw new ServerException("Concurrent execution failed.", e);
} finally {
fixedThreadPool.shutdown();
}
}
Aggregations