Search in sources :

Example 6 with RedisKeeperRuntimeException

use of com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException in project x-pipe by ctripcorp.

the class KeeperContainerService method add.

public RedisKeeperServer add(KeeperTransMeta keeperTransMeta) {
    KeeperMeta keeperMeta = keeperTransMeta.getKeeperMeta();
    enrichKeeperMetaFromKeeperTransMeta(keeperMeta, keeperTransMeta);
    String keeperServerKey = assembleKeeperServerKey(keeperTransMeta);
    if (!redisKeeperServers.containsKey(keeperServerKey)) {
        synchronized (this) {
            if (!redisKeeperServers.containsKey(keeperServerKey)) {
                if (runningPorts.contains(keeperMeta.getPort())) {
                    throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Add keeper for cluster %s shard %s failed since port %d is already used", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId(), keeperMeta.getPort())), null);
                }
                try {
                    RedisKeeperServer redisKeeperServer = doAdd(keeperTransMeta, keeperMeta);
                    cacheKeeper(keeperServerKey, redisKeeperServer);
                    return redisKeeperServer;
                } catch (Throwable ex) {
                    throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Add keeper for cluster %s shard %s failed", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), ex);
                }
            }
        }
    }
    throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Keeper already exists for cluster %s shard %s", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), null);
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) ErrorMessage(com.ctrip.xpipe.exception.ErrorMessage) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Aggregations

RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)6 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)5 ErrorMessage (com.ctrip.xpipe.exception.ErrorMessage)4 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)1 IOException (java.io.IOException)1 Test (org.junit.Test)1