Search in sources :

Example 6 with Sentinel

use of com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel in project x-pipe by ctripcorp.

the class DefaultSentinelManager method removeSentinel.

@Override
public void removeSentinel(String clusterId, String shardId, ExecutionLog executionLog) {
    String sentinelMonitorName = dcMetaCache.getSentinelMonitorName(clusterId, shardId);
    String allSentinels = dcMetaCache.getSentinel(clusterId, shardId).getAddress();
    executionLog.info(String.format("removeSentinel cluster:%s, shard:%s, masterName:%s, sentinelAddress:%s", clusterId, shardId, sentinelMonitorName, allSentinels));
    if (checkEmpty(sentinelMonitorName, allSentinels, executionLog)) {
        return;
    }
    List<InetSocketAddress> sentinels = IpUtils.parse(allSentinels);
    List<Sentinel> realSentinels = getRealSentinels(sentinels, sentinelMonitorName, executionLog);
    if (realSentinels == null) {
        executionLog.warn("get real sentinels null");
        return;
    }
    executionLog.info(String.format("removeSentinel realSentinels:%s", realSentinels));
    for (Sentinel sentinel : realSentinels) {
        SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(new InetSocketAddress(sentinel.getIp(), sentinel.getPort()));
        SentinelRemove sentinelRemove = new SentinelRemove(clientPool, sentinelMonitorName, scheduled);
        try {
            String result = sentinelRemove.execute().get();
            executionLog.info(String.format("removeSentinel %s from %s : %s", sentinelMonitorName, sentinel, result));
        } catch (InterruptedException | ExecutionException e) {
            executionLog.info(String.format("removeSentinel %s from %s : %s", sentinelMonitorName, sentinel, e.getMessage()));
            logger.warn("[removeSentinel]" + sentinel, e);
        }
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) InetSocketAddress(java.net.InetSocketAddress) SentinelRemove(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Sentinel (com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel)6 InetSocketAddress (java.net.InetSocketAddress)4 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)3 ExecutionException (java.util.concurrent.ExecutionException)2 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 AbstractSentinelCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand)1 SentinelRemove (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove)1 Sentinels (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.Sentinels)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 Test (org.junit.Test)1