use of com.ctrip.xpipe.redis.console.service.migration.impl.TryMigrateResult 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