Search in sources :

Example 1 with ErrorMessage

use of com.ctrip.xpipe.exception.ErrorMessage in project x-pipe by ctripcorp.

the class KeeperContainerService method remove.

public void remove(String clusterId, String shardId) {
    String keeperServerKey = assembleKeeperServerKey(clusterId, shardId);
    RedisKeeperServer keeperServer = redisKeeperServers.get(keeperServerKey);
    if (keeperServer == null) {
        return;
    }
    try {
        // 1. stop and dispose keeper server
        deRegister(keeperServer);
        // 2. remove keeper
        removeKeeperCache(keeperServerKey);
        // 3. clean external resources, such as replication stores
        keeperServer.destroy();
    } catch (Throwable ex) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Remove keeper failed for cluster %s shard %s", clusterId, shardId)), ex);
    }
}
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)

Example 2 with ErrorMessage

use of com.ctrip.xpipe.exception.ErrorMessage in project x-pipe by ctripcorp.

the class KeeperContainerService method stop.

public void stop(String clusterId, String shardId) {
    String keeperServerKey = assembleKeeperServerKey(clusterId, shardId);
    RedisKeeperServer keeperServer = redisKeeperServers.get(keeperServerKey);
    if (keeperServer == null) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_NOT_EXIST, String.format("Stop keeper for cluster %s shard %s failed since keeper doesn't exist", clusterId, shardId)), null);
    }
    if (keeperServer.getLifecycleState().isStopped()) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_STOPPED, String.format("Keeper for cluster %s shard %s already stopped", clusterId, shardId)), null);
    }
    try {
        keeperServer.stop();
    } catch (Throwable ex) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Stop keeper failed for cluster %s shard %s", clusterId, shardId)), ex);
    }
}
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)

Example 3 with ErrorMessage

use of com.ctrip.xpipe.exception.ErrorMessage in project x-pipe by ctripcorp.

the class KeeperContainerService method start.

public void start(String clusterId, String shardId) {
    String keeperServerKey = assembleKeeperServerKey(clusterId, shardId);
    RedisKeeperServer keeperServer = redisKeeperServers.get(keeperServerKey);
    if (keeperServer == null) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_NOT_EXIST, String.format("Start keeper for cluster %s shard %s failed since keeper doesn't exist", clusterId, shardId)), null);
    }
    if (keeperServer.getLifecycleState().isStarted()) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_STARTED, String.format("Keeper for cluster %s shard %s already started", clusterId, shardId)), null);
    }
    try {
        keeperServer.start();
    } catch (Throwable ex) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Start keeper failed for cluster %s shard %s", clusterId, shardId)), ex);
    }
}
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)

Example 4 with ErrorMessage

use of com.ctrip.xpipe.exception.ErrorMessage 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

ErrorMessage (com.ctrip.xpipe.exception.ErrorMessage)4 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)4 RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)4 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)1