Search in sources :

Example 1 with MigrationRequest

use of com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest 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;
}
Also used : ClusterMigratingNow(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterMigratingNow) LinkedList(java.util.LinkedList) ClusterNotFoundException(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException) TryMigrateResult(com.ctrip.xpipe.redis.console.service.migration.impl.TryMigrateResult) ClusterNotFoundException(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException) ClusterActiveDcNotRequest(com.ctrip.xpipe.redis.console.service.migration.exception.ClusterActiveDcNotRequest) MigrationRequest(com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest)

Example 2 with MigrationRequest

use of com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest in project x-pipe by ctripcorp.

the class MigrationEventModel method createMigrationRequest.

public MigrationRequest createMigrationRequest(String userInfo, String tag) {
    MigrationRequest migrationRequest = new MigrationRequest(userInfo);
    migrationRequest.setTag(tag);
    event.getMigrationClusters().forEach((migrationCluster) -> {
        MigrationRequest.ClusterInfo clusterInfo = new MigrationRequest.ClusterInfo(migrationCluster);
        migrationRequest.addClusterInfo(clusterInfo);
    });
    return migrationRequest;
}
Also used : MigrationRequest(com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest)

Example 3 with MigrationRequest

use of com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest in project x-pipe by ctripcorp.

the class MigrationServiceTest method createEventDemo.

private MigrationRequest createEventDemo(long clusterId, long destDcId) {
    MigrationRequest migrationRequest = new MigrationRequest("unit test");
    migrationRequest.setTag("unit test-" + getTestName());
    MigrationRequest.ClusterInfo clusterInfo = new MigrationRequest.ClusterInfo();
    clusterInfo.setClusterId(clusterId);
    clusterInfo.setToDcId(destDcId);
    migrationRequest.addClusterInfo(clusterInfo);
    return migrationRequest;
}
Also used : MigrationRequest(com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest)

Aggregations

MigrationRequest (com.ctrip.xpipe.redis.console.service.migration.impl.MigrationRequest)3 ClusterActiveDcNotRequest (com.ctrip.xpipe.redis.console.service.migration.exception.ClusterActiveDcNotRequest)1 ClusterMigratingNow (com.ctrip.xpipe.redis.console.service.migration.exception.ClusterMigratingNow)1 ClusterNotFoundException (com.ctrip.xpipe.redis.console.service.migration.exception.ClusterNotFoundException)1 TryMigrateResult (com.ctrip.xpipe.redis.console.service.migration.impl.TryMigrateResult)1 LinkedList (java.util.LinkedList)1