Search in sources :

Example 1 with KeeperBasicInfo

use of com.ctrip.xpipe.redis.console.service.KeeperBasicInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest2 method addKeepers1.

@Test
public void addKeepers1() throws Exception {
    String cluster = "cluster-test", shard = "shard-test", dc = "SHAJQ";
    when(redisService.findKeepersByDcClusterShard(dc, cluster, shard)).thenReturn(null);
    KeeperBasicInfo keeper1 = new KeeperBasicInfo();
    KeeperBasicInfo keeper2 = new KeeperBasicInfo();
    keeper1.setHost("127.0.0.1");
    keeper1.setPort(6379);
    keeper1.setKeeperContainerId(1);
    keeper2.setHost("127.0.0.1");
    keeper2.setPort(6380);
    keeper2.setKeeperContainerId(1);
    List<KeeperBasicInfo> keepers = Lists.newArrayList(keeper1, keeper2);
    when(keeperAdvancedService.findBestKeepers(eq(dc), eq(RedisProtocol.REDIS_PORT_DEFAULT), any(), eq(cluster))).thenReturn(keepers);
    when(redisService.insertKeepers(dc, cluster, shard, keepers)).thenReturn(2);
    Assert.assertEquals(2, metaUpdate.addKeepers(dc, cluster, new ShardTbl().setShardName(shard)));
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) KeeperBasicInfo(com.ctrip.xpipe.redis.console.service.KeeperBasicInfo) Test(org.junit.Test)

Example 2 with KeeperBasicInfo

use of com.ctrip.xpipe.redis.console.service.KeeperBasicInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest2 method addKeepers2.

@Test
public void addKeepers2() throws Exception {
    String cluster = "cluster-test", shard = "shard-test", dc = "SHAJQ";
    when(redisService.findKeepersByDcClusterShard(dc, cluster, shard)).thenReturn(null);
    KeeperBasicInfo keeper1 = new KeeperBasicInfo();
    keeper1.setHost("127.0.0.1");
    keeper1.setPort(6379);
    keeper1.setKeeperContainerId(1);
    keepers = Lists.newArrayList(keeper1);
    when(keeperAdvancedService.findBestKeepers(eq(dc), eq(RedisProtocol.REDIS_PORT_DEFAULT), any(), eq(cluster))).thenReturn(keepers);
    when(redisService.insertKeepers(anyString(), anyString(), anyString(), eq(keepers))).thenReturn(2 - keepers.size());
    Assert.assertEquals(1, metaUpdate.addKeepers(dc, cluster, new ShardTbl().setShardName(shard)));
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) KeeperBasicInfo(com.ctrip.xpipe.redis.console.service.KeeperBasicInfo) Test(org.junit.Test)

Example 3 with KeeperBasicInfo

use of com.ctrip.xpipe.redis.console.service.KeeperBasicInfo 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

KeeperBasicInfo (com.ctrip.xpipe.redis.console.service.KeeperBasicInfo)3 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)2 Test (org.junit.Test)2 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 LinkedList (java.util.LinkedList)1