use of com.ctrip.xpipe.redis.console.model.KeepercontainerTbl in project x-pipe by ctripcorp.
the class DefaultKeeperAdvancedService method getIpAndPortsWithSameIpAsKC.
private Map<String, Set<Integer>> getIpAndPortsWithSameIpAsKC(List<KeepercontainerTbl> keeperCount) {
Map<String, Set<Integer>> map = Maps.newHashMap();
keeperCount.forEach(kc -> map.putIfAbsent(kc.getKeepercontainerIp(), new HashSet<Integer>()));
List<Future> futures = new ArrayList<>(map.size());
for (Map.Entry<String, Set<Integer>> entry : map.entrySet()) {
String ip = entry.getKey();
Set<Integer> existingPorts = entry.getValue();
Future future = executor.submit(new Runnable() {
@Override
public void run() {
List<RedisTbl> redisWithSameIP = redisService.findAllRedisWithSameIP(ip);
redisWithSameIP.forEach(redisTbl -> existingPorts.add(redisTbl.getRedisPort()));
}
});
futures.add(future);
}
for (Future future : futures) {
try {
future.get();
} catch (InterruptedException ignore) {
} catch (ExecutionException e) {
for (Future futureToCancel : futures) {
if (!futureToCancel.isDone() || !futureToCancel.isCancelled()) {
futureToCancel.cancel(true);
}
}
return getIpAndPortsWithSameIpAsKC(keeperCount);
}
}
return map;
}
use of com.ctrip.xpipe.redis.console.model.KeepercontainerTbl in project x-pipe by ctripcorp.
the class KeepercontainerServiceImplTest method testFindKeeperCountByClusterWithAllKeeperDeleted.
@Test
@DirtiesContext
public void testFindKeeperCountByClusterWithAllKeeperDeleted() {
String clusterName = "cluster4";
ClusterTbl clusterTbl = clusterDao.findClusterAndOrgByName(clusterName);
List<KeepercontainerTbl> keeperCount = keepercontainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName);
keeperCount.forEach(kc -> logger.info("{}", kc));
Assert.assertTrue(keeperCount.stream().allMatch(kc -> kc.getKeepercontainerOrgId() == clusterTbl.getClusterOrgId()));
}
use of com.ctrip.xpipe.redis.console.model.KeepercontainerTbl in project x-pipe by ctripcorp.
the class KeepercontainerServiceTest method testMetasService.
@Test
public void testMetasService() {
KeepercontainerTbl target_keepercontainer = new KeepercontainerTbl().setKeepercontainerId(1);
assertEquals(keepercontainerService.findAllByDcName("NTGXH").get(0).getKeepercontainerId(), target_keepercontainer.getKeepercontainerId());
}
use of com.ctrip.xpipe.redis.console.model.KeepercontainerTbl in project x-pipe by ctripcorp.
the class DefaultKeeperAdvancedService method fillInResult.
private void fillInResult(List<KeepercontainerTbl> keeperCount, List<KeeperBasicInfo> result, int beginPort, BiPredicate<String, Integer> keeperGood, int returnCount) {
Map<String, Set<Integer>> ipAndPorts = getIpAndPortsWithSameIpAsKC(keeperCount);
// find available port
for (int i = 0; i < returnCount; i++) {
KeepercontainerTbl keepercontainerTbl = keeperCount.get(i);
KeeperBasicInfo keeperSelected = new KeeperBasicInfo();
keeperSelected.setKeeperContainerId(keepercontainerTbl.getKeepercontainerId());
keeperSelected.setHost(keepercontainerTbl.getKeepercontainerIp());
int port = findAvailablePort(keepercontainerTbl, beginPort, keeperGood, result, ipAndPorts);
keeperSelected.setPort(port);
result.add(keeperSelected);
}
}
use of com.ctrip.xpipe.redis.console.model.KeepercontainerTbl in project x-pipe by ctripcorp.
the class KeepercontainerServiceImplTest method testFindAllActiveByDcName.
@Test
public void testFindAllActiveByDcName() {
String dcName = dcNames[0];
List<KeepercontainerTbl> allByDcName = keepercontainerService.findAllByDcName(dcName);
int size = allByDcName.size();
Assert.assertTrue(size > 0);
for (KeepercontainerTbl keepercontainerTbl : allByDcName) {
Assert.assertTrue(keepercontainerTbl.isKeepercontainerActive());
keepercontainerTbl.setKeepercontainerActive(false);
keepercontainerService.update(keepercontainerTbl);
}
List<KeepercontainerTbl> allActiveByDcName = keepercontainerService.findAllActiveByDcName(dcName);
Assert.assertEquals(0, allActiveByDcName.size());
allByDcName = keepercontainerService.findAllByDcName(dcName);
Assert.assertEquals(size, allByDcName.size());
}
Aggregations