Search in sources :

Example 31 with HostPort

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);
}
Also used : QuorumConfig(com.ctrip.xpipe.redis.core.meta.QuorumConfig) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException) HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 32 with HostPort

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();
                }
            }
        });
    }
}
Also used : AlertManager(com.ctrip.xpipe.redis.console.alert.AlertManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AtomicReference(java.util.concurrent.atomic.AtomicReference) Server(com.ctrip.xpipe.api.server.Server) HashSet(java.util.HashSet) QuorumConfig(com.ctrip.xpipe.redis.core.meta.QuorumConfig) DefaultRedisSessionManager(com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager) Map(java.util.Map) HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) EventMonitor(com.ctrip.xpipe.api.monitor.EventMonitor) ConsoleConfig(com.ctrip.xpipe.redis.console.config.ConsoleConfig) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException) StatefulRedisSentinelConnection(com.lambdaworks.redis.sentinel.api.StatefulRedisSentinelConnection) Logger(org.slf4j.Logger) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting) Set(java.util.Set) RedisClient(com.lambdaworks.redis.RedisClient) Sets(com.google.common.collect.Sets) RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession) Pair(com.ctrip.xpipe.tuple.Pair) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Component(org.springframework.stereotype.Component) List(java.util.List) ObjectUtils(com.ctrip.xpipe.utils.ObjectUtils) StringUtil(com.ctrip.xpipe.utils.StringUtil) CatEventMonitor(com.ctrip.xpipe.monitor.CatEventMonitor) Lazy(org.springframework.context.annotation.Lazy) MetaCache(com.ctrip.xpipe.redis.console.resources.MetaCache) RedisClient(com.lambdaworks.redis.RedisClient) HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)

Example 33 with HostPort

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);
            }
        }
    }
}
Also used : DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) SentinelMeta(com.ctrip.xpipe.redis.core.entity.SentinelMeta) HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 34 with 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());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 35 with HostPort

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);
        }
    }
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort)

Aggregations

HostPort (com.ctrip.xpipe.endpoint.HostPort)79 Test (org.junit.Test)31 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)7 LinkedList (java.util.LinkedList)7 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)6 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)6 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)6 ClusterShardHostPort (com.ctrip.xpipe.endpoint.ClusterShardHostPort)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)4 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)4 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)4 Set (java.util.Set)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)3 AlertManager (com.ctrip.xpipe.redis.console.alert.AlertManager)3 DefaultRedisSessionManager (com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager)3 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)3