Search in sources :

Example 1 with RedisKeeperRuntimeException

use of com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException 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 RedisKeeperRuntimeException

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

the class KeeperContainerServiceTest method testAddKeeperWithError.

@Test
public void testAddKeeperWithError() throws Exception {
    Exception someException = new Exception("some error happened");
    when(componentRegistry.add(any(RedisKeeperServer.class))).thenThrow(someException);
    Exception cause = null;
    try {
        keeperContainerService.add(someKeeperTransMeta);
    } catch (RedisKeeperRuntimeException ex) {
        cause = (Exception) ex.getCause();
    }
    assertEquals(someException, cause);
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) Test(org.junit.Test)

Example 3 with RedisKeeperRuntimeException

use of com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException 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 4 with RedisKeeperRuntimeException

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

the class DefaultRedisSlave method beginWriteCommands.

@Override
public void beginWriteCommands(long beginOffset) {
    closeState.makeSureOpen();
    try {
        if (partialState == PARTIAL_STATE.UNKNOWN) {
            partialState = PARTIAL_STATE.PARTIAL;
        }
        logger.info("[beginWriteCommands]{}, {}", this, beginOffset);
        slaveState = SLAVE_STATE.REDIS_REPL_ONLINE;
        getRedisKeeperServer().getReplicationStore().addCommandsListener(beginOffset, this);
    } catch (IOException e) {
        throw new RedisKeeperRuntimeException("[beginWriteCommands]" + beginOffset + "," + this, e);
    }
}
Also used : RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) IOException(java.io.IOException)

Example 5 with RedisKeeperRuntimeException

use of com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException 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)

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