use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DefaultSentinelCollector method collect.
@Override
public void collect(SentinelSample sentinelSample) {
Set<SentinelHello> hellos = sentinelSample.getHellos();
String clusterId = sentinelSample.getSamplePlan().getClusterId();
String shardId = sentinelSample.getSamplePlan().getShardId();
String sentinelMonitorName = metaCache.getSentinelMonitorName(clusterId, shardId);
Set<HostPort> masterDcSentinels = metaCache.getActiveDcSentinels(clusterId, shardId);
QuorumConfig quorumConfig = consoleConfig.getDefaultSentinelQuorumConfig();
HostPort masterAddr = null;
try {
masterAddr = metaCache.findMaster(clusterId, shardId);
} catch (MasterNotFoundException e) {
logger.error("[collect]" + e.getMessage(), e);
}
logger.debug("[collect]{},{},{}", clusterId, shardId, hellos);
// check delete
Set<SentinelHello> toDelete = checkAndDelete(sentinelMonitorName, masterDcSentinels, hellos, quorumConfig);
// checkReset
checkReset(clusterId, shardId, sentinelMonitorName, hellos);
// check add
Set<SentinelHello> toAdd = checkToAdd(clusterId, shardId, sentinelMonitorName, masterDcSentinels, hellos, masterAddr, quorumConfig);
doAction(toDelete, toAdd, quorumConfig);
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DefaultSentinelCollector method doAction.
private void doAction(Set<SentinelHello> toDelete, Set<SentinelHello> toAdd, QuorumConfig quorumConfig) {
if ((toDelete == null || toDelete.size() == 0) && (toAdd == null || toAdd.size() == 0)) {
return;
}
if (toAdd != null && toAdd.size() > 0) {
logger.info("[doAction][add]{}", toAdd);
}
if (toDelete != null && toDelete.size() > 0) {
logger.info("[doAction][del]{}", toDelete);
}
if (toDelete != null) {
toDelete.forEach((hello -> {
HostPort sentinelAddr = hello.getSentinelAddr();
RedisClient redisConnection = null;
try {
CatEventMonitor.DEFAULT.logEvent(SENTINEL_TYPE, "[del]" + hello);
redisConnection = sessionManager.findRedisConnection(sentinelAddr.getHost(), sentinelAddr.getPort());
redisConnection.connectSentinel().sync().remove(hello.getMonitorName());
} catch (Exception e) {
logger.error("[doAction][delete]" + hello, e);
} finally {
if (redisConnection != null) {
redisConnection.shutdown();
}
}
}));
}
if (toAdd != null) {
toAdd.forEach((hello) -> {
HostPort sentinelAddr = hello.getSentinelAddr();
RedisClient redisConnection = null;
try {
// TODO: Re-use connection instead of creating them each time
redisConnection = sessionManager.findRedisConnection(sentinelAddr.getHost(), sentinelAddr.getPort());
boolean doAdd = true;
try {
Map<String, String> map = redisConnection.connectSentinel().sync().master(hello.getMonitorName());
if (equals(hello.getMonitorName(), hello.getMasterAddr(), map)) {
doAdd = false;
logger.info("[doAction][already exist]{}, {}", map, hello.getSentinelAddr());
} else {
redisConnection.connectSentinel().sync().remove(hello.getMonitorName());
}
} catch (Exception e) {
// ingnore
}
if (doAdd) {
CatEventMonitor.DEFAULT.logEvent(SENTINEL_TYPE, "[add]" + hello);
redisConnection.connectSentinel().sync().monitor(hello.getMonitorName(), hello.getMasterAddr().getHost(), hello.getMasterAddr().getPort(), quorumConfig.getQuorum());
}
} catch (Exception e) {
logger.error("[doAction][add]" + hello, e);
} finally {
if (redisConnection != null) {
redisConnection.shutdown();
}
}
});
}
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class AbstractSentinelMonitorsCheck method doCheck.
@Override
public void doCheck() {
logger.info("[doCheck] check sentinel monitors");
Collection<DcMeta> dcMetas = metaCache.getXpipeMeta().getDcs().values();
for (DcMeta dcMeta : dcMetas) {
Collection<SentinelMeta> sentinelMetas = dcMeta.getSentinels().values();
for (SentinelMeta sentinelMeta : sentinelMetas) {
List<HostPort> sentinels = IpUtils.parseAsHostPorts(sentinelMeta.getAddress());
for (HostPort hostPort : sentinels) {
checkSentinel(sentinelMeta, hostPort);
}
}
}
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class ConfigRewriteMonitor method addRedis.
@Override
protected void addRedis(BaseSamplePlan<InstanceRedisConfResult> plan, String dcId, RedisMeta redisMeta) {
HostPort hostPort = new HostPort(redisMeta.getIp(), redisMeta.getPort());
if (goodRedises.contains(hostPort)) {
return;
}
log.debug("[addRedis]{}", hostPort);
plan.addRedis(dcId, redisMeta, new InstanceRedisConfResult());
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DefaultPingMonitor method samplePing.
private void samplePing(final long startNanoTime, BaseSamplePlan<InstancePingResult> plan) {
for (Entry<HostPort, InstancePingResult> entry : plan.getHostPort2SampleResult().entrySet()) {
final HostPort hostPort = entry.getKey();
log.debug("[ping]{}", hostPort);
try {
RedisSession session = findRedisSession(hostPort.getHost(), hostPort.getPort());
session.ping(new PingCallback() {
@Override
public void pong(String pongMsg) {
addInstanceSuccess(startNanoTime, hostPort.getHost(), hostPort.getPort(), null);
}
@Override
public void fail(Throwable th) {
addInstanceFail(startNanoTime, hostPort.getHost(), hostPort.getPort(), th);
}
});
} catch (Exception e) {
log.error("[samplePing]" + hostPort, e);
}
}
}
Aggregations