use of com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException in project x-pipe by ctripcorp.
the class DefaultMigrationEvent method rollbackCluster.
@Override
public MigrationCluster rollbackCluster(long clusterId) throws ClusterNotFoundException {
MigrationCluster migrationCluster = getMigrationCluster(clusterId);
if (migrationCluster == null) {
throw new ClusterNotFoundException(clusterId);
}
migrationCluster.rollback();
return migrationCluster;
}
use of com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException 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;
}
use of com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException 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;
}
use of com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException in project x-pipe by ctripcorp.
the class MigrationApi method checkAndPrepare.
@RequestMapping(value = "/checkandprepare", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
public CheckPrepareResponse checkAndPrepare(@RequestBody(required = true) CheckPrepareRequest checkMeta) {
mapRequestIdc(checkMeta);
logger.info("[checkAndPrepare]{}", checkMeta);
CheckPrepareResponse checkRetMeta = new CheckPrepareResponse();
List<TryMigrateResult> maySuccessClusters = new LinkedList<>();
List<CheckPrepareClusterResponse> failClusters = new LinkedList<>();
String fromIdc = checkMeta.getFromIdc();
for (String clusterName : checkMeta.getClusters()) {
try {
TryMigrateResult tryMigrateResult = migrationService.tryMigrate(clusterName, fromIdc, checkMeta.getToIdc());
maySuccessClusters.add(tryMigrateResult);
logger.info("[checkAndPrepare]{}", tryMigrateResult);
} catch (ClusterNotFoundException e) {
failClusters.add(CheckPrepareClusterResponse.createFailResponse(clusterName, fromIdc, CHECK_FAIL_STATUS.CLUSTER_NOT_FOUND, e.getMessage()));
logger.error("[checkAndPrepare]" + clusterName, e);
} catch (ClusterActiveDcNotRequest e) {
failClusters.add(CheckPrepareClusterResponse.createFailResponse(clusterName, fromIdc, CHECK_FAIL_STATUS.ACTIVE_DC_ALREADY_NOT_REQUESTED, e.getMessage()));
logger.error("[checkAndPrepare]" + clusterName, e);
} catch (ClusterMigratingNow e) {
failClusters.add(CheckPrepareClusterResponse.createFailResponse(clusterName, fromIdc, CHECK_FAIL_STATUS.ALREADY_MIGRATING, String.valueOf(e.getEventId())));
logger.error("[checkAndPrepare]" + clusterName, e);
} catch (Exception e) {
logger.error("[checkAndPrepare]" + clusterName, e);
failClusters.add(CheckPrepareClusterResponse.createFailResponse(clusterName, fromIdc, CHECK_FAIL_STATUS.OTHERS, e.getMessage()));
}
}
Long eventId = -1L;
if (maySuccessClusters.size() > 0) {
MigrationRequest request = new MigrationRequest("api_call");
request.setTag("api_call");
maySuccessClusters.forEach((tryMigrateResult) -> request.addClusterInfo(new MigrationRequest.ClusterInfo(tryMigrateResult)));
eventId = migrationService.createMigrationEvent(request);
}
checkRetMeta.setTicketId(eventId);
failClusters.forEach((failCluster) -> checkRetMeta.addCheckPrepareClusterResponse(failCluster));
maySuccessClusters.forEach((successCluster) -> checkRetMeta.addCheckPrepareClusterResponse(CheckPrepareClusterResponse.createSuccessResponse(successCluster.getClusterName(), successCluster.getFromDcName(), successCluster.getToDcName())));
mapResponseIdc(checkRetMeta.getResults());
return checkRetMeta;
}
Aggregations