Search in sources :

Example 1 with Sentinel

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

the class DefaultSentinelManager method getRealSentinels.

private List<Sentinel> getRealSentinels(List<InetSocketAddress> sentinels, String sentinelMonitorName, ExecutionLog executionLog) {
    List<Sentinel> realSentinels = null;
    for (InetSocketAddress sentinelAddress : sentinels) {
        SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
        Sentinels sentinelsCommand = new Sentinels(clientPool, sentinelMonitorName, scheduled);
        try {
            realSentinels = sentinelsCommand.execute().get();
            executionLog.info(String.format("get sentinels from %s : %s", sentinelAddress, realSentinels));
            if (realSentinels.size() > 0) {
                realSentinels.add(new Sentinel(sentinelAddress.toString(), sentinelAddress.getHostString(), sentinelAddress.getPort()));
                break;
            }
        } catch (InterruptedException | ExecutionException e) {
            logger.warn("[getRealSentinels]get sentinels from " + sentinelAddress, e);
            executionLog.warn("[getRealSentinels]get sentinels from " + sentinelAddress + "," + e.getMessage());
        }
    }
    return realSentinels;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) InetSocketAddress(java.net.InetSocketAddress) ExecutionException(java.util.concurrent.ExecutionException) Sentinels(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.Sentinels)

Example 2 with Sentinel

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

the class DefaultSentinelManagerTest method infoSentinel.

// manual test
@Test
public void infoSentinel() throws Exception {
    String info = manager.infoSentinel(new Sentinel("test", "10.2.48.234", 5000));
    logger.info("=====================================");
    SentinelMonitors.parseFromString(info).getMonitors().forEach(monitor -> logger.info(monitor));
    logger.info("=====================================");
}
Also used : Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 3 with Sentinel

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

the class DefaultSentinelMonitorsCheck method checkSentinel.

@Override
public void checkSentinel(SentinelMeta sentinelMeta, HostPort sentinelHostPort) {
    Sentinel sentinel = new Sentinel(sentinelHostPort.toString(), sentinelHostPort.getHost(), sentinelHostPort.getPort());
    String infoSentinel = sentinelManager.infoSentinel(sentinel);
    if (infoSentinel == null) {
        logger.warn("[checkSentinel] info sentinel empty: {}", sentinel);
        return;
    }
    SentinelMonitors sentinelMonitors = SentinelMonitors.parseFromString(infoSentinel);
    // master0:name=cluster_mengshard1,status=ok,address=10.2.58.242:6399,slaves=1,sentinels=3
    for (String monitorName : sentinelMonitors.getMonitors()) {
        if (metaCache.findClusterShardBySentinelMonitor(monitorName) == null) {
            sentinelManager.removeSentinelMonitor(sentinel, monitorName);
            String message = String.format("Sentinel monitor: %s not exist in XPipe", monitorName);
            alertManager.alert(null, null, null, ALERT_TYPE.SENTINEL_MONITOR_INCONSIS, message);
        }
    }
}
Also used : Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel)

Example 4 with Sentinel

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

the class DefaultSentinelManager method getRealSentinels.

@VisibleForTesting
protected List<Sentinel> getRealSentinels(List<InetSocketAddress> sentinels, String sentinelMonitorName) {
    List<Sentinel> realSentinels = null;
    for (InetSocketAddress sentinelAddress : sentinels) {
        SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
        AbstractSentinelCommand.Sentinels sentinelsCommand = new AbstractSentinelCommand.Sentinels(clientPool, sentinelMonitorName, scheduled);
        try {
            realSentinels = sentinelsCommand.execute().get();
            logger.info("[getRealSentinels]get sentinels from {} : {}", sentinelAddress, realSentinels);
            if (realSentinels.size() > 0) {
                realSentinels.add(new Sentinel(sentinelAddress.toString(), sentinelAddress.getHostString(), sentinelAddress.getPort()));
                logger.info("[getRealSentinels]sentinels for monitor {}, list as: {}", sentinelMonitorName, realSentinels);
                break;
            }
        } catch (Exception e) {
            logger.warn("[getRealSentinels]get sentinels from " + sentinelAddress, e);
        }
    }
    return realSentinels;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) InetSocketAddress(java.net.InetSocketAddress) AbstractSentinelCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 5 with Sentinel

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

the class DefaultSentinelManager method removeShardSentinelMonitors.

@Override
public void removeShardSentinelMonitors(ShardEvent shardEvent) {
    String clusterId = shardEvent.getClusterName(), shardId = shardEvent.getShardName();
    String sentinelMonitorName = shardEvent.getShardMonitorName();
    String allSentinels = shardEvent.getShardSentinels();
    logger.info("[removeShardSentinelMonitors]removeSentinelMonitor cluster:{}, shard:{}, masterName:{}, sentinelAddress:{}", clusterId, shardId, sentinelMonitorName, allSentinels);
    if (checkEmpty(sentinelMonitorName, allSentinels)) {
        return;
    }
    List<InetSocketAddress> sentinels = IpUtils.parse(allSentinels);
    List<Sentinel> realSentinels = getRealSentinels(sentinels, sentinelMonitorName);
    if (realSentinels == null) {
        logger.warn("[removeShardSentinelMonitors]get real sentinels null");
        return;
    }
    logger.info("[removeShardSentinelMonitors]removeSentinelMonitor realSentinels: {}", realSentinels);
    for (Sentinel sentinel : realSentinels) {
        removeSentinelMonitor(sentinel, sentinelMonitorName);
    }
}
Also used : Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) InetSocketAddress(java.net.InetSocketAddress)

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