Search in sources :

Example 1 with RedisService

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);
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) InetSocketAddress(java.net.InetSocketAddress) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) RedisService(com.ctrip.xpipe.redis.console.service.RedisService) LinkedList(java.util.LinkedList)

Aggregations

MigrationCluster (com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)1 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 RedisService (com.ctrip.xpipe.redis.console.service.RedisService)1 InetSocketAddress (java.net.InetSocketAddress)1 LinkedList (java.util.LinkedList)1