DefaultMetaCache implements MetaCache { @Override public List<HostPort> getAllActiveRedisOfDc(String activeDc, String dcId) { List<HostPort> result = Lists.newLinkedList(); boolean isDcActiveDc = activeDc.equalsIgnoreCase(dcId); try { for(ClusterMeta clusterMeta : meta.getKey().findDc(dcId).getClusters().values()) { ClusterType clusterType = ClusterType.lookup(clusterMeta.getType()); if (clusterType.supportSingleActiveDC() && !clusterMeta.getActiveDc().equalsIgnoreCase(activeDc)) { continue; } if (clusterType.supportMultiActiveDC() && !isDcActiveDc) { continue; } for (ShardMeta shardMeta : clusterMeta.getShards().values()) { for(RedisMeta redis : shardMeta.getRedises()) { result.add(new HostPort(redis.getIp(), redis.getPort())); } } } } catch (Exception e) { logger.error("[getRedisNumOfDc]", e); } return result; } DefaultMetaCache(); @PostConstruct void postConstruct(); @PreDestroy void shutdown(); @Override XpipeMeta getXpipeMeta(); @Override boolean inBackupDc(HostPort hostPort); @Override HostPort findMasterInSameShard(HostPort hostPort); @Override Pair<String, String> findClusterShard(HostPort hostPort); @Override String getActiveDc(HostPort hostPort); @Override long getLastUpdateTime(); @Override RouteMeta getRouteIfPossible(HostPort hostPort); @Override boolean isCrossRegion(String activeDc, String backupDc); @Override List<HostPort> getAllActiveRedisOfDc(String activeDc, String dcId); @Override Set<HostPort> getAllKeepers(); @Override String getSentinelMonitorName(String clusterId, String shardId); @Override Set<HostPort> getActiveDcSentinels(String clusterId, String shardId); @Override HostPort findMaster(String clusterId, String shardId); @Override String getDc(HostPort hostPort); @Override Pair<String, String> findClusterShardBySentinelMonitor(String monitor); @Override String getActiveDc(String clusterId, String shardId); @Override ClusterType getClusterType(String clusterId);  }
@Test public void testGetAllActiveRedisOfDc() { List<HostPort> redises = metaCache.getAllActiveRedisOfDc("jq", "jq"); Assert.assertEquals(4, redises.size()); Assert.assertTrue(redises.contains(new HostPort("10.0.0.1", 6379))); Assert.assertTrue(redises.contains(new HostPort("127.0.0.1", 6379))); redises = metaCache.getAllActiveRedisOfDc("jq", "oy"); Assert.assertEquals(2, redises.size()); Assert.assertTrue(redises.contains(new HostPort("127.0.0.1", 8100))); Assert.assertTrue(redises.contains(new HostPort("127.0.0.1", 8101))); redises = metaCache.getAllActiveRedisOfDc("oy", "oy"); Assert.assertEquals(4, redises.size()); Assert.assertTrue(redises.contains(new HostPort("127.0.0.2", 8100))); Assert.assertTrue(redises.contains(new HostPort("127.0.0.2", 8101))); Assert.assertTrue(redises.contains(new HostPort("10.0.0.2", 6379))); Assert.assertTrue(redises.contains(new HostPort("10.0.0.2", 6479))); }