Search in sources :

Example 1 with RedisTbl

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

the class DcClusterShardDao method deleteDcClusterShardsBatch.

@DalTransaction
public void deleteDcClusterShardsBatch(List<DcClusterShardTbl> dcClusterShards) throws DalException {
    if (null == dcClusterShards || dcClusterShards.isEmpty()) {
        logger.warn("[deleteDcClusterShardsBatch] Empty list: {}", dcClusterShards);
        return;
    }
    List<RedisTbl> redises = new LinkedList<RedisTbl>();
    for (final DcClusterShardTbl dcClusterShard : dcClusterShards) {
        List<RedisTbl> relatedRedises = redisDao.findAllByDcClusterShard(dcClusterShard.getDcClusterShardId());
        if (null != relatedRedises && !relatedRedises.isEmpty()) {
            for (RedisTbl redis : relatedRedises) {
                redis.setRunId(generateDeletedName(redis.getRunId()));
            }
            redises.addAll(relatedRedises);
        }
    }
    redisDao.deleteRedisesBatch(redises);
    queryHandler.handleBatchDelete(new DalQuery<int[]>() {

        @Override
        public int[] doQuery() throws DalException {
            return dcClusterShardTblDao.deleteDcClusterShardsBatch(dcClusterShards.toArray(new DcClusterShardTbl[dcClusterShards.size()]), DcClusterShardTblEntity.UPDATESET_FULL);
        }
    }, true);
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) DalException(org.unidal.dal.jdbc.DalException) DcClusterShardTbl(com.ctrip.xpipe.redis.console.model.DcClusterShardTbl) LinkedList(java.util.LinkedList) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Example 2 with RedisTbl

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

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

the class RedisServiceImplTest method testSub.

@Test
public void testSub() {
    List<Pair<String, Integer>> first = Lists.newArrayList(Pair.from("127.0.0.1", 1111), Pair.from("127.0.0.1", 1112), Pair.from("127.0.0.1", 1113));
    List<RedisTbl> second = Lists.newArrayList(new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(1111), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(1112), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(9999));
    List<Pair<String, Integer>> sub = redisService.sub(first, second);
    Assert.assertEquals(1, sub.size());
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) Pair(com.ctrip.xpipe.tuple.Pair) Test(org.junit.Test)

Example 4 with RedisTbl

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

the class RedisServiceImplTest method testUpdateRedises.

@Test
public void testUpdateRedises() throws IOException, ResourceNotFoundException {
    List<RedisTbl> allByDcClusterShard = redisService.findAllByDcClusterShard(dcName, clusterName, shardName);
    checkAllInstances(allByDcClusterShard);
    boolean firstSlave = true;
    RedisTbl newMaster = null;
    for (RedisTbl redisTbl : allByDcClusterShard) {
        if (redisTbl.getRedisRole().equals(XPipeConsoleConstant.ROLE_REDIS)) {
            if (redisTbl.isMaster()) {
                redisTbl.setMaster(false);
            } else if (!redisTbl.isMaster() && firstSlave) {
                redisTbl.setMaster(true);
                newMaster = redisTbl;
                firstSlave = false;
            }
        }
    }
    checkAllInstances(allByDcClusterShard);
    ShardModel shardModel = new ShardModel(allByDcClusterShard);
    redisService.updateRedises(dcName, clusterName, shardName, shardModel);
    allByDcClusterShard = redisService.findAllByDcClusterShard(dcName, clusterName, shardName);
    checkAllInstances(allByDcClusterShard);
    Stream<RedisTbl> redisTblStream = allByDcClusterShard.stream().filter(instance -> instance.isMaster());
    RedisTbl currentMaster = redisTblStream.findFirst().get();
    Assert.assertEquals(newMaster.getId(), currentMaster.getId());
}
Also used : ShardModel(com.ctrip.xpipe.redis.console.model.ShardModel) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) Test(org.junit.Test)

Example 5 with RedisTbl

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

the class RedisMetaServiceImpl method updateKeeperStatus.

@Override
public void updateKeeperStatus(String dcId, String clusterId, String shardId, KeeperMeta newActiveKeeper) throws ResourceNotFoundException {
    List<RedisTbl> keepers = RedisDao.findWithRole(redisService.findAllByDcClusterShard(dcId, clusterId, shardId), XPipeConsoleConstant.ROLE_KEEPER);
    if (CollectionUtils.isEmpty(keepers)) {
        return;
    }
    for (RedisTbl keeper : keepers) {
        if (keeper.getKeepercontainerId() == newActiveKeeper.getKeeperContainerId()) {
            keeper.setKeeperActive(true);
        } else {
            keeper.setKeeperActive(false);
        }
    }
    redisService.updateBatchKeeperActive(keepers);
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl)

Aggregations

RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)15 Test (org.junit.Test)8 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)4 com.ctrip.xpipe.redis.console.service (com.ctrip.xpipe.redis.console.service)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 RetMessage (com.ctrip.xpipe.redis.console.controller.api.RetMessage)2 ClusterCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo)2 RedisCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo)2 ShardCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo)2 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)2 Pair (com.ctrip.xpipe.tuple.Pair)2 StringUtil (com.ctrip.xpipe.utils.StringUtil)2 Lists (com.google.common.collect.Lists)2 java.util.concurrent (java.util.concurrent)2 Collectors (java.util.stream.Collectors)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1