Search in sources :

Example 6 with RedisTbl

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

the class RedisDaoTest method testUpdateBatchMaster.

@Test
public void testUpdateBatchMaster() throws DalException {
    for (RedisTbl redisTbl : redises) {
        redisTbl.setMaster(!redisTbl.isMaster());
    }
    redisDao.updateBatchMaster(redises);
    for (RedisTbl redisTbl : redises) {
        RedisTbl byPK = redisDao.findByPK(redisTbl.getId());
        Assert.assertEquals(redisTbl.isMaster(), byPK.isMaster());
    }
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 7 with RedisTbl

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

the class MetaUpdateTest3 method createShard1.

@Test
public void createShard1() throws Exception {
    ShardCreateInfo shardCreateInfo = new ShardCreateInfo();
    shardCreateInfo.setShardMonitorName(shardName);
    shardCreateInfo.setShardName(shardName);
    metaUpdate.createShards(clusterName, Lists.newArrayList(new ShardCreateInfo()));
    List<RedisCreateInfo> createInfo = createInfo(Lists.newArrayList("192.168.0.1:6379", "192.168.0.1:6380"), Lists.newArrayList("192.168.0.2:6379", "192.168.0.2:6380"));
    metaUpdate.createShard(clusterName, shardName, createInfo);
    ShardTbl shardTbl = shardService.find(clusterName, shardName);
    List<RedisTbl> keepers = redisService.findKeepersByDcClusterShard(activeDC, clusterName, shardName);
    List<RedisTbl> redisTbls = redisService.findRedisesByDcClusterShard(activeDC, clusterName, shardName);
    logger.info("{}", shardTbl);
    logger.info("{}", keepers);
    logger.info("{}", redisTbls);
    Assert.assertTrue(listEquals(Lists.newArrayList("192.168.0.1:6379", "192.168.0.1:6380"), redisTbls.stream().map((redisTbl) -> {
        return redisTbl.getRedisIp() + ":" + redisTbl.getRedisPort();
    }).collect(Collectors.toList())));
    Assert.assertEquals(2, keepers.size());
}
Also used : ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) java.util.concurrent(java.util.concurrent) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) Collectors(java.util.stream.Collectors) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) com.ctrip.xpipe.redis.console.service(com.ctrip.xpipe.redis.console.service) List(java.util.List) Lists(com.google.common.collect.Lists) ClusterCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo) StringUtil(com.ctrip.xpipe.utils.StringUtil) Assert(org.junit.Assert) Before(org.junit.Before) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 8 with RedisTbl

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

the class MetaUpdateTest3 method createShard.

@Test
public void createShard() throws Exception {
    List<RedisCreateInfo> createInfo = createInfo(Lists.newArrayList("192.168.0.1:6379", "192.168.0.1:6380"), Lists.newArrayList("192.168.0.2:6379", "192.168.0.2:6380"));
    metaUpdate.createShard(clusterName, shardName, createInfo);
    ShardTbl shardTbl = shardService.find(clusterName, shardName);
    List<RedisTbl> keepers = redisService.findKeepersByDcClusterShard(activeDC, clusterName, shardName);
    List<RedisTbl> redisTbls = redisService.findRedisesByDcClusterShard(activeDC, clusterName, shardName);
    logger.info("{}", shardTbl);
    logger.info("{}", keepers);
    logger.info("{}", redisTbls);
    Assert.assertTrue(listEquals(Lists.newArrayList("192.168.0.1:6379", "192.168.0.1:6380"), redisTbls.stream().map((redisTbl) -> {
        return redisTbl.getRedisIp() + ":" + redisTbl.getRedisPort();
    }).collect(Collectors.toList())));
    Assert.assertEquals(2, keepers.size());
}
Also used : ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) java.util.concurrent(java.util.concurrent) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) Collectors(java.util.stream.Collectors) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) com.ctrip.xpipe.redis.console.service(com.ctrip.xpipe.redis.console.service) List(java.util.List) Lists(com.google.common.collect.Lists) ClusterCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo) StringUtil(com.ctrip.xpipe.utils.StringUtil) Assert(org.junit.Assert) Before(org.junit.Before) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 9 with RedisTbl

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

the class RedisDaoTest method testUpdateBatchKeeperActive.

@Test
public void testUpdateBatchKeeperActive() throws DalException {
    for (RedisTbl redisTbl : redises) {
        redisTbl.setKeeperActive(!redisTbl.isKeeperActive());
    }
    redisDao.updateBatchKeeperActive(redises);
    for (RedisTbl redisTbl : redises) {
        RedisTbl byPK = redisDao.findByPK(redisTbl.getId());
        Assert.assertEquals(redisTbl.isKeeperActive(), byPK.isKeeperActive());
    }
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 10 with RedisTbl

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

the class DefaultRedisMasterCollector method changeMasterRoleInDb.

private void changeMasterRoleInDb(RedisMasterSamplePlan plan, String newMasterIp, Integer newMasterPort) throws ResourceNotFoundException {
    logger.info("[changeMasterRoleInDb]{}, {}:{}", plan, newMasterIp, newMasterPort);
    List<RedisTbl> allByDcClusterShard = redisService.findAllByDcClusterShard(plan.getDcName(), plan.getClusterId(), plan.getShardId());
    boolean changed = false;
    for (RedisTbl redisTbl : allByDcClusterShard) {
        if (newMasterIp.equalsIgnoreCase(redisTbl.getRedisIp()) && newMasterPort.equals(redisTbl.getRedisPort())) {
            if (!redisTbl.isMaster()) {
                redisTbl.setMaster(true);
                changed = true;
            }
        } else if (redisTbl.isMaster()) {
            redisTbl.setMaster(false);
            changed = true;
        }
    }
    logger.info("[changeMasterRoleInDb]{}", changed);
    if (changed) {
        redisService.updateBatchMaster(allByDcClusterShard);
    }
}
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