Search in sources :

Example 1 with ClusterListClusterModel

use of com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel in project x-pipe by ctripcorp.

the class ClusterServiceImpl method richClusterInfo.

@VisibleForTesting
protected List<ClusterListClusterModel> richClusterInfo(Map<String, ClusterListClusterModel> clusters) {
    if (clusters.isEmpty()) {
        return Collections.emptyList();
    }
    List<String> clusterNames = Lists.newArrayListWithExpectedSize(clusters.size());
    clusterNames.addAll(clusters.keySet());
    List<ClusterTbl> clusterTbls = clusterDao.findClustersWithName(clusterNames);
    List<ClusterListClusterModel> result = Lists.newArrayListWithExpectedSize(clusterTbls.size());
    for (ClusterTbl clusterTbl : clusterTbls) {
        ClusterListClusterModel cluster = clusters.get(clusterTbl.getClusterName());
        cluster.setActivedcId(clusterTbl.getActivedcId()).setClusterAdminEmails(clusterTbl.getClusterAdminEmails()).setClusterDescription(clusterTbl.getClusterDescription());
        result.add(cluster);
    }
    return result;
}
Also used : ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 2 with ClusterListClusterModel

use of com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel 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 3 with ClusterListClusterModel

use of com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel in project x-pipe by ctripcorp.

the class ClusterServiceImplTest2 method testFindUnhealthyClusters.

@Test
public void testFindUnhealthyClusters() throws Exception {
    when(delayService.getDelay(any())).thenReturn(10L);
    when(delayService.getDelay(new HostPort("127.0.0.2", 6379))).thenReturn(DefaultDelayMonitor.SAMPLE_LOST_BUT_PONG);
    when(clusterDao.findClustersWithName(Lists.newArrayList("cluster1"))).thenReturn(Lists.newArrayList(new ClusterTbl().setClusterName("cluster1")));
    List<ClusterListClusterModel> clusterTbls = clusterService.findUnhealthyClusters();
    Assert.assertEquals(1, clusterTbls.size());
    Assert.assertEquals("cluster1", clusterTbls.get(0).getClusterName());
}
Also used : ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel) HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test)

Example 4 with ClusterListClusterModel

use of com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel in project x-pipe by ctripcorp.

the class ClusterServiceImplTest2 method testFindUnhealthyClusters2.

@Test
public void testFindUnhealthyClusters2() throws Exception {
    when(delayService.getDelay(any())).thenReturn(10L);
    when(delayService.getDelay(new HostPort("127.0.0.2", 6379))).thenReturn(DefaultDelayMonitor.SAMPLE_LOST_BUT_PONG);
    when(delayService.getDelay(new HostPort("127.0.0.4", 6380))).thenReturn(DefaultDelayMonitor.SAMPLE_LOST_AND_NO_PONG);
    when(clusterDao.findClustersWithName(anyList())).then(new Answer<List<ClusterTbl>>() {

        @Override
        public List<ClusterTbl> answer(InvocationOnMock invocation) throws Throwable {
            List<String> clusterNames = (List<String>) invocation.getArguments()[0];
            return Lists.transform(clusterNames, new Function<String, ClusterTbl>() {

                @Override
                public ClusterTbl apply(String input) {
                    return new ClusterTbl().setClusterName(input);
                }
            });
        }
    });
    List<ClusterListClusterModel> clusterTbls = clusterService.findUnhealthyClusters();
    Assert.assertEquals(2, clusterTbls.size());
    Assert.assertEquals("cluster1", clusterTbls.get(0).getClusterName());
    Assert.assertEquals("cluster2", clusterTbls.get(1).getClusterName());
}
Also used : Function(com.google.common.base.Function) ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HostPort(com.ctrip.xpipe.endpoint.HostPort) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) Test(org.junit.Test)

Aggregations

ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)4 HostPort (com.ctrip.xpipe.endpoint.HostPort)3 Test (org.junit.Test)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 Function (com.google.common.base.Function)1 List (java.util.List)1 Matchers.anyList (org.mockito.Matchers.anyList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 DalException (org.unidal.dal.jdbc.DalException)1