use of com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd in project x-pipe by ctripcorp.
the class DefaultSentinelManager method addSentinel.
@Override
public void addSentinel(String clusterId, String shardId, HostPort redisMaster, ExecutionLog executionLog) {
String sentinelMonitorName = dcMetaCache.getSentinelMonitorName(clusterId, shardId);
String allSentinels = dcMetaCache.getSentinel(clusterId, shardId).getAddress();
executionLog.info(String.format("[addSentinel]%s,%s,%s, monitorName:%s, master:%s:%d", clusterId, shardId, allSentinels, sentinelMonitorName, redisMaster.getHost(), redisMaster.getPort()));
if (checkEmpty(sentinelMonitorName, allSentinels, executionLog)) {
return;
}
int quorum = DEFAULT_SENTINEL_QUORUM;
List<InetSocketAddress> sentinels = IpUtils.parse(allSentinels);
if (sentinels.size() < quorum) {
throw new IllegalStateException(String.format("sentinel size < quorum, %d < %d", sentinels.size(), quorum));
}
int addSize = Math.min(sentinels.size(), DEFAULT_SENTINEL_ADD_SIZE);
for (int i = 0; i < addSize; i++) {
InetSocketAddress sentinelAddress = sentinels.get(i);
SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
SentinelAdd command = new SentinelAdd(clientPool, sentinelMonitorName, redisMaster.getHost(), redisMaster.getPort(), quorum, scheduled);
try {
String result = command.execute().get();
executionLog.info(String.format("add to sentinel %s : %s", sentinelAddress, result));
} catch (InterruptedException | ExecutionException e) {
throw new AddSentinelException(sentinelAddress, clusterId, shardId, redisMaster.getHost(), redisMaster.getPort(), e);
}
}
}
use of com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd 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);
}
}
Aggregations