Search in sources :

Example 1 with RetryNTimesOnCondition

use of com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition in project x-pipe by ctripcorp.

the class DefaultMigrationCluster method updateStorageClusterStatus.

@VisibleForTesting
protected void updateStorageClusterStatus() throws Exception {
    MigrationStatus migrationStatus = this.currentState.getStatus();
    ClusterStatus clusterStatus = migrationStatus.getClusterStatus();
    logger.info("[updateStat][updatedb]{}, {}", clusterName(), clusterStatus);
    RetryTemplate<String> retryTemplate = new RetryNTimesOnCondition<>(new RetryCondition.AbstractRetryCondition<String>() {

        @Override
        public boolean isSatisfied(String s) {
            return ClusterStatus.isSameClusterStatus(s, clusterStatus);
        }

        @Override
        public boolean isExceptionExpected(Throwable th) {
            if (th instanceof TimeoutException)
                return true;
            return false;
        }
    }, 3);
    retryTemplate.execute(new AbstractCommand<String>() {

        @Override
        protected void doExecute() throws Exception {
            try {
                getClusterService().updateStatusById(clusterId(), clusterStatus);
                ClusterTbl newCluster = getClusterService().find(clusterName());
                future().setSuccess(newCluster.getStatus());
            } catch (Exception e) {
                future().setFailure(e.getCause());
            }
        }

        @Override
        protected void doReset() {
        }

        @Override
        public String getName() {
            return "update cluster status";
        }
    });
    ClusterTbl newCluster = getClusterService().find(clusterName());
    logger.info("[updateStat][getdb]{}, {}", clusterName(), newCluster != null ? newCluster.getStatus() : null);
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) RetryNTimesOnCondition(com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) TimeoutException(java.util.concurrent.TimeoutException) RetryCondition(com.ctrip.xpipe.redis.console.job.retry.RetryCondition) TimeoutException(java.util.concurrent.TimeoutException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Aggregations

ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 RetryCondition (com.ctrip.xpipe.redis.console.job.retry.RetryCondition)1 RetryNTimesOnCondition (com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition)1 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)1 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 TimeoutException (java.util.concurrent.TimeoutException)1