Search in sources :

Example 1 with VisibleForTesting

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

the class DefaultDiskLessCollector method versionMatches.

@VisibleForTesting
protected boolean versionMatches(HostPort hostPort) {
    RedisConf redisConf = redisConfManager.findOrCreateConfig(hostPort.getHost(), hostPort.getPort());
    String targetVersion = consoleConfig.getReplDisklessMinRedisVersion();
    String version = redisConf.getRedisVersion();
    logger.debug("[versionMatches]Redis {} version is {}", hostPort, version);
    logger.debug("[versionMatches]Redis {} alert version is {}", hostPort, targetVersion);
    return version != null && StringUtil.compareVersion(version, targetVersion) < 1;
}
Also used : RedisConf(com.ctrip.xpipe.redis.console.health.redisconf.RedisConf) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 2 with VisibleForTesting

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

the class ClusterServiceImpl method richClusterInfo.

@VisibleForTesting
protected List<ClusterListClusterModel> richClusterInfo(Map<String, ClusterListClusterModel> clusters) {
    if (clusters.isEmpty()) {
        return Collections.emptyList();
    }
    List<String> clusterNames = Lists.newArrayListWithExpectedSize(clusters.size());
    clusterNames.addAll(clusters.keySet());
    List<ClusterTbl> clusterTbls = clusterDao.findClustersWithName(clusterNames);
    List<ClusterListClusterModel> result = Lists.newArrayListWithExpectedSize(clusterTbls.size());
    for (ClusterTbl clusterTbl : clusterTbls) {
        ClusterListClusterModel cluster = clusters.get(clusterTbl.getClusterName());
        cluster.setActivedcId(clusterTbl.getActivedcId()).setClusterAdminEmails(clusterTbl.getClusterAdminEmails()).setClusterDescription(clusterTbl.getClusterDescription());
        result.add(cluster);
    }
    return result;
}
Also used : ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 3 with VisibleForTesting

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

the class SentinelUpdateController method convert2SentinelTbl.

@VisibleForTesting
protected SetinelTbl convert2SentinelTbl(SentinelModel sentinelModel) {
    StringBuilder sb = new StringBuilder();
    for (HostPort hostPort : sentinelModel.getSentinels()) {
        sb.append(hostPort.getHost()).append(':').append(hostPort.getPort()).append(',');
    }
    String sentinels = sb.deleteCharAt(sb.length() - 1).toString();
    SetinelTbl proto = new SetinelTbl();
    proto.setSetinelAddress(sentinels);
    proto.setDeleted(false);
    proto.setSetinelDescription(sentinelModel.getDesc());
    proto.setDcId(dcService.find(sentinelModel.getDcName()).getId());
    return proto;
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 4 with VisibleForTesting

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

the class DefaultSentinelCollector method isKeeperOrDead.

@VisibleForTesting
protected boolean isKeeperOrDead(String host, int port) {
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<Object> role = new AtomicReference<>();
    try {
        RedisSession redisSession = sessionManager.findOrCreateSession(host, port);
        redisSession.role(new RedisSession.RollCallback() {

            @Override
            public void role(String roleDesc) {
                role.set(roleDesc);
                latch.countDown();
            }

            @Override
            public void fail(Throwable e) {
                logger.error("[isKeeperOrDead][fail]" + host + ":" + port, e);
                role.set(e);
                latch.countDown();
            }
        });
    } catch (Exception e) {
        role.set(e);
        logger.error("[isKeeperOrDead]" + host + ":" + port, e);
    }
    try {
        latch.await(2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        logger.error("[isKeeperOrDead]latch await error: {}", e);
    }
    if (role.get() instanceof String && Server.SERVER_ROLE.KEEPER.sameRole((String) role.get())) {
        return true;
    }
    if (role.get() instanceof RedisConnectionException) {
        return true;
    }
    logger.info("[isKeeperOrDead] role: {}", role.get());
    return false;
}
Also used : RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession) AtomicReference(java.util.concurrent.atomic.AtomicReference) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) CountDownLatch(java.util.concurrent.CountDownLatch) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 5 with VisibleForTesting

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

the class ClusterServiceImpl method balanceCluster.

// Add transaction for one cluster update, rollback if one 'DcClusterShard' update fails
@VisibleForTesting
@DalTransaction
protected void balanceCluster(Map<String, List<SetinelTbl>> dcToSentinels, final String cluster) {
    for (String dcName : dcToSentinels.keySet()) {
        List<DcClusterShardTbl> dcClusterShards = dcClusterShardService.findAllByDcCluster(dcName, cluster);
        List<SetinelTbl> sentinels = dcToSentinels.get(dcName);
        if (dcClusterShards == null || sentinels == null) {
            throw new XpipeRuntimeException("DcClusterShard | Sentinels should not be null");
        }
        long randomlySelectedSentinelId = randomlyChoseSentinels(sentinels);
        dcClusterShards.forEach(dcClusterShard -> {
            dcClusterShard.setSetinelId(randomlySelectedSentinelId);
            try {
                dcClusterShardService.updateDcClusterShard(dcClusterShard);
            } catch (DalException e) {
                throw new XpipeRuntimeException(e.getMessage());
            }
        });
    }
}
Also used : DalException(org.unidal.dal.jdbc.DalException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

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