use of com.ctrip.xpipe.redis.console.model.RedisTbl in project x-pipe by ctripcorp.
the class DefaultRedisMasterCollectorTest method testDoCorrection.
@Test
public void testDoCorrection() throws Exception {
when(redisService.findAllByDcClusterShard(any(), any(), any())).then(new Answer<List<RedisTbl>>() {
@Override
public List<RedisTbl> answer(InvocationOnMock invocation) throws Throwable {
return Lists.newArrayList(new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(6379).setMaster(false), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(6380).setMaster(false));
}
});
when(redisSessionManager.findOrCreateSession("127.0.0.1", 6380)).thenReturn(redisSession);
when(redisSession.roleSync()).thenReturn("master");
collector.doCorrection(plan);
verify(redisService).updateBatchMaster(any());
}
use of com.ctrip.xpipe.redis.console.model.RedisTbl in project x-pipe by ctripcorp.
the class RedisServiceImplTest method checkAllInstances.
private void checkAllInstances(List<RedisTbl> allByDcClusterShard) {
Assert.assertEquals(4, allByDcClusterShard.size());
int masterCount = 0;
for (RedisTbl redisTbl : allByDcClusterShard) {
logger.debug("{}", redisTbl);
if (redisTbl.isMaster()) {
masterCount++;
}
}
Assert.assertEquals(1, masterCount);
}
use of com.ctrip.xpipe.redis.console.model.RedisTbl in project x-pipe by ctripcorp.
the class RedisServiceImplTest method testInter.
@Test
public void testInter() {
List<Pair<String, Integer>> first = Lists.newArrayList(Pair.from("127.0.0.1", 1111), Pair.from("127.0.0.1", 1112), Pair.from("127.0.0.1", 1113));
List<RedisTbl> second = Lists.newArrayList(new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(1111), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(1112), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(9999));
List<RedisTbl> inter = redisService.inter(first, second);
Assert.assertEquals(2, inter.size());
}
use of com.ctrip.xpipe.redis.console.model.RedisTbl in project x-pipe by ctripcorp.
the class MigrationPublishState method updateRedisMaster.
private void updateRedisMaster() throws ResourceNotFoundException {
List<RedisTbl> toUpdate = new LinkedList<>();
MigrationCluster migrationCluster = getHolder();
RedisService redisService = migrationCluster.getRedisService();
String fromDc = migrationCluster.fromDc();
String destDc = migrationCluster.destDc();
String clusterName = migrationCluster.clusterName();
List<RedisTbl> prevDcRedises = redisService.findAllRedisesByDcClusterName(fromDc, clusterName);
for (RedisTbl redis : prevDcRedises) {
if (redis.isMaster()) {
redis.setMaster(false);
toUpdate.add(redis);
}
}
List<RedisTbl> newDcRedises = redisService.findAllRedisesByDcClusterName(destDc, clusterName);
for (InetSocketAddress newMasterAddress : getNewMasters()) {
for (RedisTbl redis : newDcRedises) {
if (redis.getRedisIp().equals(newMasterAddress.getHostString()) && redis.getRedisPort() == newMasterAddress.getPort()) {
redis.setMaster(true);
toUpdate.add(redis);
}
}
}
logger.info("[UpdateMaster]{}", toUpdate);
migrationCluster.getRedisService().updateBatchMaster(toUpdate);
}
use of com.ctrip.xpipe.redis.console.model.RedisTbl in project x-pipe by ctripcorp.
the class KeepercontainerDcController method findAvailableKeepers.
@RequestMapping(value = "/dcs/{dcName}/availablekeepers", method = RequestMethod.POST)
public List<RedisTbl> findAvailableKeepers(@PathVariable String dcName, @RequestBody(required = false) ShardModel shardModel) {
logger.debug("[findAvailableKeepers]{}, {}", dcName, shardModel);
int beginPort = findBeginPort(shardModel);
String clusterName = getShardClusterName(shardModel);
List<KeeperBasicInfo> bestKeepers = keeperAdvancedService.findBestKeepers(dcName, beginPort, (ip, port) -> {
if (shardModel != null && existOnConsole(ip, port, shardModel.getKeepers())) {
return false;
}
return true;
}, clusterName);
List<RedisTbl> result = new LinkedList<>();
bestKeepers.forEach(keeperSelected -> result.add(new RedisTbl().setKeepercontainerId(keeperSelected.getKeeperContainerId()).setRedisIp(keeperSelected.getHost()).setRedisPort(keeperSelected.getPort())));
return result;
}
Aggregations