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);
}
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;
}
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());
}
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());
}
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);
}
Aggregations