Search in sources :

Example 11 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.

the class DefaultDcMetaCache method changeDcMeta.

@VisibleForTesting
protected void changeDcMeta(DcMeta current, DcMeta future) {
    DcMetaComparator dcMetaComparator = new DcMetaComparator(current, future);
    dcMetaComparator.compare();
    if (dcMetaComparator.totalChangedCount() > META_MODIFY_PROTECT_COUNT) {
        logger.error("[run][modify count size too big]{}, {}, {}", META_MODIFY_PROTECT_COUNT, dcMetaComparator.totalChangedCount(), dcMetaComparator);
        EventMonitor.DEFAULT.logAlertEvent("remove too many:" + dcMetaComparator.totalChangedCount());
        return;
    }
    logger.info("[run][change dc meta]");
    dcMetaManager.set(DefaultDcMetaManager.buildFromDcMeta(future));
    if (dcMetaComparator.totalChangedCount() > 0) {
        logger.info("[run][change]{}", dcMetaComparator);
        EventMonitor.DEFAULT.logEvent(META_CHANGE_TYPE, String.format("[add:%s, del:%s, mod:%s]", StringUtil.join(",", (clusterMeta) -> clusterMeta.getId(), dcMetaComparator.getAdded()), StringUtil.join(",", (clusterMeta) -> clusterMeta.getId(), dcMetaComparator.getRemoved()), StringUtil.join(",", (comparator) -> comparator.idDesc(), dcMetaComparator.getMofified())));
        notifyObservers(dcMetaComparator);
    }
}
Also used : DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 12 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting 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

VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)12 RedisSession (com.ctrip.xpipe.redis.console.health.RedisSession)2 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 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 SetinelTbl (com.ctrip.xpipe.redis.console.model.SetinelTbl)1 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)1 ShardDeleteEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent)1 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)1 ResourceNotFoundException (com.ctrip.xpipe.redis.console.service.exception.ResourceNotFoundException)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)1 DcMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)1