use of com.ctrip.xpipe.redis.console.service.RedisService 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);
}
Aggregations