Search in sources :

Example 11 with RedisTbl

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

the class DefaultRedisMasterCollectorTest method testDoCorrection.

@Test
public void testDoCorrection() throws Exception {
    when(redisService.findAllByDcClusterShard(any(), any(), any())).then(new Answer<List<RedisTbl>>() {

        @Override
        public List<RedisTbl> answer(InvocationOnMock invocation) throws Throwable {
            return Lists.newArrayList(new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(6379).setMaster(false), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(6380).setMaster(false));
        }
    });
    when(redisSessionManager.findOrCreateSession("127.0.0.1", 6380)).thenReturn(redisSession);
    when(redisSession.roleSync()).thenReturn("master");
    collector.doCorrection(plan);
    verify(redisService).updateBatchMaster(any());
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) Test(org.junit.Test)

Example 12 with RedisTbl

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

the class RedisServiceImplTest method checkAllInstances.

private void checkAllInstances(List<RedisTbl> allByDcClusterShard) {
    Assert.assertEquals(4, allByDcClusterShard.size());
    int masterCount = 0;
    for (RedisTbl redisTbl : allByDcClusterShard) {
        logger.debug("{}", redisTbl);
        if (redisTbl.isMaster()) {
            masterCount++;
        }
    }
    Assert.assertEquals(1, masterCount);
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl)

Example 13 with RedisTbl

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

the class RedisServiceImplTest method testInter.

@Test
public void testInter() {
    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<RedisTbl> inter = redisService.inter(first, second);
    Assert.assertEquals(2, inter.size());
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) Pair(com.ctrip.xpipe.tuple.Pair) Test(org.junit.Test)

Example 14 with RedisTbl

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

the class MigrationPublishState method updateRedisMaster.

private void updateRedisMaster() throws ResourceNotFoundException {
    List<RedisTbl> toUpdate = new LinkedList<>();
    MigrationCluster migrationCluster = getHolder();
    RedisService redisService = migrationCluster.getRedisService();
    String fromDc = migrationCluster.fromDc();
    String destDc = migrationCluster.destDc();
    String clusterName = migrationCluster.clusterName();
    List<RedisTbl> prevDcRedises = redisService.findAllRedisesByDcClusterName(fromDc, clusterName);
    for (RedisTbl redis : prevDcRedises) {
        if (redis.isMaster()) {
            redis.setMaster(false);
            toUpdate.add(redis);
        }
    }
    List<RedisTbl> newDcRedises = redisService.findAllRedisesByDcClusterName(destDc, clusterName);
    for (InetSocketAddress newMasterAddress : getNewMasters()) {
        for (RedisTbl redis : newDcRedises) {
            if (redis.getRedisIp().equals(newMasterAddress.getHostString()) && redis.getRedisPort() == newMasterAddress.getPort()) {
                redis.setMaster(true);
                toUpdate.add(redis);
            }
        }
    }
    logger.info("[UpdateMaster]{}", toUpdate);
    migrationCluster.getRedisService().updateBatchMaster(toUpdate);
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) InetSocketAddress(java.net.InetSocketAddress) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) RedisService(com.ctrip.xpipe.redis.console.service.RedisService) LinkedList(java.util.LinkedList)

Example 15 with RedisTbl

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

the class KeepercontainerDcController method findAvailableKeepers.

@RequestMapping(value = "/dcs/{dcName}/availablekeepers", method = RequestMethod.POST)
public List<RedisTbl> findAvailableKeepers(@PathVariable String dcName, @RequestBody(required = false) ShardModel shardModel) {
    logger.debug("[findAvailableKeepers]{}, {}", dcName, shardModel);
    int beginPort = findBeginPort(shardModel);
    String clusterName = getShardClusterName(shardModel);
    List<KeeperBasicInfo> bestKeepers = keeperAdvancedService.findBestKeepers(dcName, beginPort, (ip, port) -> {
        if (shardModel != null && existOnConsole(ip, port, shardModel.getKeepers())) {
            return false;
        }
        return true;
    }, clusterName);
    List<RedisTbl> result = new LinkedList<>();
    bestKeepers.forEach(keeperSelected -> result.add(new RedisTbl().setKeepercontainerId(keeperSelected.getKeeperContainerId()).setRedisIp(keeperSelected.getHost()).setRedisPort(keeperSelected.getPort())));
    return result;
}
Also used : RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) KeeperBasicInfo(com.ctrip.xpipe.redis.console.service.KeeperBasicInfo) LinkedList(java.util.LinkedList)

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