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;
}
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();
}
}
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());
}
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());
}
Aggregations