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;
}
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("=====================================");
}
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);
}
}
}
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;
}
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);
}
}
Aggregations