use of com.ctrip.xpipe.redis.core.entity.ShardMeta in project x-pipe by ctripcorp.
the class GeneratePlanTest method testGeneratePlan.
@Test
public void testGeneratePlan() {
List<DcMeta> dcMetas = Lists.newArrayList(new DcMeta("SHAJQ").addCluster(new ClusterMeta("cluster1").setActiveDc("SHAJQ").setBackupDcs("SHAOY").addShard(new ShardMeta("shard1"))), new DcMeta("SHAOY").addCluster(new ClusterMeta("cluster1").setActiveDc("SHAJQ").setBackupDcs("SHAOY").addShard(new ShardMeta("shard1"))));
Collection result = monitor.generatePlan(dcMetas);
Assert.assertEquals(0, result.size());
}
use of com.ctrip.xpipe.redis.core.entity.ShardMeta in project x-pipe by ctripcorp.
the class ClientConfigMonitor method fromXPipe.
private CheckCluster fromXPipe(XpipeMeta xpipeMeta, String checkCluster) {
XpipeMetaManager xpm = new DefaultXpipeMetaManager(xpipeMeta);
CheckCluster result = new CheckCluster(checkCluster);
for (String dc : xpipeMeta.getDcs().keySet()) {
ClusterMeta clusterMeta = xpm.getClusterMeta(dc, checkCluster);
if (clusterMeta == null) {
continue;
}
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
CheckShard orShard = result.getOrCreate(shardMeta.getId());
shardMeta.getRedises().forEach(redis -> {
orShard.addRedis(new CheckRedis(redis.getIp(), redis.getPort(), dc));
});
}
}
return result;
}
use of com.ctrip.xpipe.redis.core.entity.ShardMeta in project x-pipe by ctripcorp.
the class DefaultDynamicStateManager method add.
@Override
public void add(ClusterMeta clusterMeta) {
clusterMetas.put(clusterMeta.getId(), clusterMeta);
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
for (KeeperMeta keeperMeta : shardMeta.getKeepers()) {
final KeeperKey keeperKey = createKeeperKey(clusterMeta.getId(), shardMeta.getId(), keeperMeta);
@SuppressWarnings("unused") KeeperHeartBeatManager keeperHeartBeatManager = MapUtils.getOrCreate(keepers, keeperKey, new ObjectFactory<KeeperHeartBeatManager>() {
@Override
public KeeperHeartBeatManager create() {
KeeperHeartBeatManager keeperHeartBeatManager = new DefaultKeeperHeartBeatManager(keeperKey, scheduled);
keeperHeartBeatManager.addObserver(DefaultDynamicStateManager.this);
return keeperHeartBeatManager;
}
});
}
}
}
use of com.ctrip.xpipe.redis.core.entity.ShardMeta in project x-pipe by ctripcorp.
the class BackupDcClusterRedisStateAjust method doRun.
@Override
protected void doRun() throws Exception {
ClusterMeta clusterMeta = currentMetaManager.getClusterMeta(clusterId);
if (clusterMeta == null) {
logger.warn("[doRun][cluster null]{}", clusterId);
return;
}
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
logger.debug("[doRun]{}, {}", clusterId, shardMeta.getId());
KeeperMeta keeperActive = currentMetaManager.getKeeperActive(clusterId, shardMeta.getId());
if (keeperActive == null) {
logger.debug("[doRun][keeper active null]{}, {}", clusterId, shardMeta.getId());
continue;
}
List<RedisMeta> redisesNeedChange = getRedisesNeedToChange(shardMeta, keeperActive);
if (redisesNeedChange.size() == 0) {
continue;
}
logger.info("[doRun][change state]{}, {}, {}", clusterId, keeperActive, redisesNeedChange);
new DefaultSlaveOfJob(redisesNeedChange, keeperActive.getIp(), keeperActive.getPort(), pool, scheduled, executors).execute().addListener(new CommandFutureListener<Void>() {
@Override
public void operationComplete(CommandFuture<Void> commandFuture) throws Exception {
if (!commandFuture.isSuccess()) {
logger.error("[operationComplete][fail]" + commandFuture.command(), commandFuture.cause());
}
}
});
}
}
use of com.ctrip.xpipe.redis.core.entity.ShardMeta in project x-pipe by ctripcorp.
the class ClusterMetaComparatorTest method testAdded.
@Test
public void testAdded() {
ShardMeta shard = differentShard(current);
future.addShard(shard);
ClusterMetaComparator clusterMetaComparator = new ClusterMetaComparator(current, future);
clusterMetaComparator.compare();
Assert.assertEquals(1, clusterMetaComparator.getAdded().size());
Assert.assertEquals(shard, clusterMetaComparator.getAdded().toArray()[0]);
Assert.assertEquals(0, clusterMetaComparator.getRemoved().size());
Assert.assertEquals(0, clusterMetaComparator.getMofified().size());
}
Aggregations