Search in sources :

Example 1 with SentinelRemove

use of com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove 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)

Example 2 with SentinelRemove

use of com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove in project x-pipe by ctripcorp.

the class SentinelCommandTest method testSentinelMaster.

@Test
public void testSentinelMaster() throws InterruptedException, ExecutionException {
    try {
        String addResult = new SentinelAdd(clientPool, masterName, "127.0.0.1", 6379, 3, scheduled).execute().get();
        logger.info("{}", addResult);
    } catch (Exception ignore) {
    }
    try {
        HostPort master = new AbstractSentinelCommand.SentinelMaster(clientPool, scheduled, masterName).execute().get();
        logger.info("[master]{}", master);
        Assert.assertEquals("127.0.0.1", master.getHost());
        Assert.assertEquals(6379, master.getPort());
    } catch (Exception e) {
        logger.error("[testSentinelMaster]", e);
    }
    try {
        new SentinelRemove(clientPool, masterName, scheduled).execute().get();
    } catch (Exception e) {
        logger.error("[testRemove]", e);
    }
}
Also used : SentinelRemove(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove) HostPort(com.ctrip.xpipe.endpoint.HostPort) SentinelAdd(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

SentinelRemove (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove)2 ExecutionException (java.util.concurrent.ExecutionException)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 SentinelAdd (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd)1 Sentinel (com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.Test)1