Search in sources :

Example 6 with MigrationCluster

use of com.ctrip.xpipe.redis.console.migration.model.MigrationCluster in project x-pipe by ctripcorp.

the class AbstractMigrationMigratingState method doMigrateOtherDc.

protected void doMigrateOtherDc() {
    logger.debug("[doMigrateOtherDc]{}", this);
    MigrationCluster migrationCluster = getHolder();
    String clusterName = migrationCluster.clusterName();
    for (MigrationShard migrationShard : migrationCluster.getMigrationShards()) {
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            public void doRun() {
                String shardName = migrationShard.shardName();
                logger.info("[doOtherDcMigrate][start]{},{}", clusterName, shardName);
                migrationShard.doMigrateOtherDc();
                logger.info("[doOtherDcMigrate][done]{},{}", clusterName, shardName);
            }
        });
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)

Example 7 with MigrationCluster

use of com.ctrip.xpipe.redis.console.migration.model.MigrationCluster in project x-pipe by ctripcorp.

the class DefaultMigrationEvent method isDone.

@Override
public boolean isDone() {
    int successCnt = 0;
    List<MigrationCluster> migrationClusters = getMigrationClusters();
    for (MigrationCluster cluster : migrationClusters) {
        if (cluster.getStatus().isTerminated()) {
            ++successCnt;
        }
    }
    if (successCnt == migrationClusters.size()) {
        logger.info("[isDone][true]{}, success:{}", getMigrationEventId(), successCnt);
        return true;
    }
    return false;
}
Also used : MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)

Example 8 with MigrationCluster

use of com.ctrip.xpipe.redis.console.migration.model.MigrationCluster in project x-pipe by ctripcorp.

the class DefaultMigrationEvent method rollbackCluster.

@Override
public MigrationCluster rollbackCluster(String clusterName) throws ClusterNotFoundException {
    MigrationCluster cluster = getMigrationCluster(clusterName);
    if (cluster == null) {
        throw new ClusterNotFoundException(clusterName);
    }
    cluster.rollback();
    return cluster;
}
Also used : ClusterNotFoundException(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)

Example 9 with MigrationCluster

use of com.ctrip.xpipe.redis.console.migration.model.MigrationCluster in project x-pipe by ctripcorp.

the class MigrationApi method rollback.

@RequestMapping(value = "/rollback", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
public RollbackResponse rollback(@RequestBody(required = true) RollbackRequest request) {
    logger.info("[rollback]{}", request);
    long tickedId = request.getTicketId();
    if (request.getClusters() == null || request.getClusters().size() == 0) {
        return new RollbackResponse();
    }
    RollbackResponse rollbackResponse = new RollbackResponse();
    for (String clusterName : request.getClusters()) {
        MigrationCluster migrationCluster = null;
        try {
            migrationCluster = migrationService.rollbackMigrationCluster(tickedId, clusterName);
            rollbackResponse.addResult(new RollbackClusterResponse(true, clusterName, migrationCluster.fromDc(), migrationCluster.destDc(), "success"));
        } catch (ClusterNotFoundException e) {
            logger.error("[rollback]" + clusterName, e);
            rollbackResponse.addResult(new RollbackClusterResponse(false, clusterName, e.getMessage()));
        } catch (Exception e) {
            logger.error("[rollback]" + clusterName, e);
            if (migrationCluster == null) {
                rollbackResponse.addResult(new RollbackClusterResponse(false, clusterName, e.getMessage()));
            } else {
                rollbackResponse.addResult(new RollbackClusterResponse(false, clusterName, migrationCluster.fromDc(), migrationCluster.destDc(), e.getMessage()));
            }
        }
    }
    mapResponseIdc(rollbackResponse.getResults());
    return rollbackResponse;
}
Also used : ClusterNotFoundException(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) ClusterNotFoundException(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException)

Example 10 with MigrationCluster

use of com.ctrip.xpipe.redis.console.migration.model.MigrationCluster 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)10 ClusterNotFoundException (com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException)3 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)1 ClusterStepResult (com.ctrip.xpipe.redis.console.migration.model.ClusterStepResult)1 MigrationEvent (com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)1 MigrationShard (com.ctrip.xpipe.redis.console.migration.model.MigrationShard)1 DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)1 DefaultMigrationEvent (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)1 DefaultMigrationShard (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard)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