Search in sources :

Example 36 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class ClusterServiceImpl method findUnhealthyClusters.

@Override
public List<ClusterListClusterModel> findUnhealthyClusters() {
    try {
        XpipeMeta xpipeMeta = metaCache.getXpipeMeta();
        if (xpipeMeta == null || xpipeMeta.getDcs() == null) {
            return Collections.emptyList();
        }
        String prefix = "健康监测有问题的shard及redis:\n";
        Map<String, ClusterListClusterModel> unhealthyClusters = Maps.newHashMap();
        for (DcMeta dcMeta : xpipeMeta.getDcs().values()) {
            for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
                StringBuffer sb = new StringBuffer();
                for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
                    boolean shardLogged = false;
                    for (RedisMeta redisMeta : shardMeta.getRedises()) {
                        HostPort hostPort = new HostPort(redisMeta.getIp(), redisMeta.getPort());
                        long delay = delayService.getDelay(hostPort);
                        if (delay == TimeUnit.NANOSECONDS.toMillis(DefaultDelayMonitor.SAMPLE_LOST_AND_NO_PONG) || delay == TimeUnit.NANOSECONDS.toMillis(DefaultDelayMonitor.SAMPLE_LOST_BUT_PONG)) {
                            String clusterName = clusterMeta.getId();
                            unhealthyClusters.putIfAbsent(clusterName, new ClusterListClusterModel(clusterMeta.getId()));
                            if (!shardLogged) {
                                shardLogged = true;
                                sb.append(shardMeta.getId()).append(": ");
                            }
                            sb.append(hostPort.toString()).append(", ");
                        }
                    }
                    if (shardLogged) {
                        sb.append(";\n");
                    }
                }
                ClusterListClusterModel cluster = unhealthyClusters.get(clusterMeta.getId());
                if (cluster != null) {
                    String message = cluster.getMessage() == null ? "" : cluster.getMessage();
                    message += sb.toString();
                    if (!message.startsWith(prefix)) {
                        message = prefix + message;
                    }
                    cluster.setMessage(message);
                }
            }
        }
        return richClusterInfo(unhealthyClusters);
    } catch (Exception e) {
        logger.error("[findUnhealthyClusters]{}", e);
        return Collections.emptyList();
    }
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) DalException(org.unidal.dal.jdbc.DalException) ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)

Example 37 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class SenderManagerTest method testSenderManager.

@Test
public void testSenderManager() {
    HostPort hostPort = new HostPort("192.168.1.10", 6379);
    Map<ALERT_TYPE, Set<AlertEntity>> alerts = new ConcurrentHashMap<>();
    AlertEntity alert = new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID);
    Set<AlertEntity> set = new ConcurrentSet<>();
    set.add(alert);
    alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, set);
    new Thread(new Runnable() {

        @Override
        public void run() {
            alerts.get(ALERT_TYPE.XREDIS_VERSION_NOT_VALID).remove(alert);
        }
    }).start();
    List<Map<ALERT_TYPE, Set<AlertEntity>>> result = senderManager.getGroupedAlerts(alerts);
    logger.info("result: {}", result.get(0));
    if (!result.isEmpty()) {
        Set<AlertEntity> alertEntities = result.get(0).getOrDefault(alert.getAlertType(), null);
        if (alertEntities != null) {
            Assert.assertFalse(alertEntities.isEmpty());
        }
    }
}
Also used : ConcurrentSet(io.netty.util.internal.ConcurrentSet) ConcurrentSet(io.netty.util.internal.ConcurrentSet) HostPort(com.ctrip.xpipe.endpoint.HostPort) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 38 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DiskLessCollectorTest method testCheckRedisVersion.

@Test
public void testCheckRedisVersion() {
    RedisConf redisConf = new RedisConf(new HostPort(host, port), clusterId, shardId);
    redisConf.setRedisVersion("3.0.7");
    redisConf.setXredisVersion("0.0.4");
    when(confManager.findOrCreateConfig(host, port)).thenReturn(redisConf);
    when(config.getReplDisklessMinRedisVersion()).thenReturn("2.8.22");
    HostPort hostPort = new HostPort(host, port);
    Assert.assertTrue(collector.isReplDiskLessSync(diskLess));
    Assert.assertFalse(collector.versionMatches(hostPort));
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisConf(com.ctrip.xpipe.redis.console.health.redisconf.RedisConf) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 39 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultSentinelCollectorTest method beforeDefaultSentinelCollectorTest.

@Before
public void beforeDefaultSentinelCollectorTest() {
    sentinelCollector = new DefaultSentinelCollector();
    sentinelCollector.setSessionManager(new DefaultRedisSessionManager(1, Executors.newFixedThreadPool(1), Executors.newFixedThreadPool(1)));
    masterSentinels = Sets.newHashSet(new HostPort("127.0.0.1", 5000), new HostPort("127.0.0.1", 5001), new HostPort("127.0.0.1", 5002), new HostPort("127.0.0.1", 5003), new HostPort("127.0.0.1", 5004));
}
Also used : DefaultRedisSessionManager(com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager) HostPort(com.ctrip.xpipe.endpoint.HostPort) Before(org.junit.Before)

Example 40 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class SentinelHelloTest method testFormat.

@Test
public void testFormat() {
    SentinelHello sentinelHello = SentinelHello.fromString("10.15.95.133,33322," + "642d5452b3ffd243fdfc31a2ccf5b0b5963c161f,1942," + "FlightIntlGDSCacheGroup1," + "10.15.94.178,6379,0");
    Assert.assertEquals(new HostPort("10.15.95.133", 33322), sentinelHello.getSentinelAddr());
    Assert.assertEquals(new HostPort("10.15.94.178", 6379), sentinelHello.getMasterAddr());
    Assert.assertEquals("FlightIntlGDSCacheGroup1", sentinelHello.getMonitorName());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

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