Search in sources :

Example 1 with KeepercontainerTbl

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;
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) java.util(java.util) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting) Resource(javax.annotation.Resource) Autowired(org.springframework.beans.factory.annotation.Autowired) Maps(com.google.common.collect.Maps) AbstractSpringConfigContext(com.ctrip.xpipe.spring.AbstractSpringConfigContext) com.ctrip.xpipe.redis.console.service(com.ctrip.xpipe.redis.console.service) ExecutionException(java.util.concurrent.ExecutionException) BiPredicate(java.util.function.BiPredicate) Component(org.springframework.stereotype.Component) Future(java.util.concurrent.Future) RedisTblDao(com.ctrip.xpipe.redis.console.model.RedisTblDao) RedisProtocol(com.ctrip.xpipe.redis.core.protocal.RedisProtocol) KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with KeepercontainerTbl

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()));
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) DirtiesContext(org.springframework.test.annotation.DirtiesContext) ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) ClusterDao(com.ctrip.xpipe.redis.console.dao.ClusterDao) List(java.util.List) KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IOException(java.io.IOException) Assert(org.junit.Assert) KeeperContainerCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.KeeperContainerCreateInfo) XPipeConsoleConstant(com.ctrip.xpipe.redis.console.constant.XPipeConsoleConstant) Before(org.junit.Before) KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 3 with KeepercontainerTbl

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());
}
Also used : KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 4 with KeepercontainerTbl

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);
    }
}
Also used : KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl)

Example 5 with KeepercontainerTbl

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());
}
Also used : KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) Test(org.junit.Test)

Aggregations

KeepercontainerTbl (com.ctrip.xpipe.redis.console.model.KeepercontainerTbl)6 Test (org.junit.Test)4 KeeperContainerCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.KeeperContainerCreateInfo)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 XPipeConsoleConstant (com.ctrip.xpipe.redis.console.constant.XPipeConsoleConstant)1 ClusterDao (com.ctrip.xpipe.redis.console.dao.ClusterDao)1 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)1 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 RedisTblDao (com.ctrip.xpipe.redis.console.model.RedisTblDao)1 com.ctrip.xpipe.redis.console.service (com.ctrip.xpipe.redis.console.service)1 RedisProtocol (com.ctrip.xpipe.redis.core.protocal.RedisProtocol)1 AbstractSpringConfigContext (com.ctrip.xpipe.spring.AbstractSpringConfigContext)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 java.util (java.util)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1