use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class DefaultDiskLessCollector method versionMatches.
@VisibleForTesting
protected boolean versionMatches(HostPort hostPort) {
RedisConf redisConf = redisConfManager.findOrCreateConfig(hostPort.getHost(), hostPort.getPort());
String targetVersion = consoleConfig.getReplDisklessMinRedisVersion();
String version = redisConf.getRedisVersion();
logger.debug("[versionMatches]Redis {} version is {}", hostPort, version);
logger.debug("[versionMatches]Redis {} alert version is {}", hostPort, targetVersion);
return version != null && StringUtil.compareVersion(version, targetVersion) < 1;
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class ClusterServiceImpl method richClusterInfo.
@VisibleForTesting
protected List<ClusterListClusterModel> richClusterInfo(Map<String, ClusterListClusterModel> clusters) {
if (clusters.isEmpty()) {
return Collections.emptyList();
}
List<String> clusterNames = Lists.newArrayListWithExpectedSize(clusters.size());
clusterNames.addAll(clusters.keySet());
List<ClusterTbl> clusterTbls = clusterDao.findClustersWithName(clusterNames);
List<ClusterListClusterModel> result = Lists.newArrayListWithExpectedSize(clusterTbls.size());
for (ClusterTbl clusterTbl : clusterTbls) {
ClusterListClusterModel cluster = clusters.get(clusterTbl.getClusterName());
cluster.setActivedcId(clusterTbl.getActivedcId()).setClusterAdminEmails(clusterTbl.getClusterAdminEmails()).setClusterDescription(clusterTbl.getClusterDescription());
result.add(cluster);
}
return result;
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class SentinelUpdateController method convert2SentinelTbl.
@VisibleForTesting
protected SetinelTbl convert2SentinelTbl(SentinelModel sentinelModel) {
StringBuilder sb = new StringBuilder();
for (HostPort hostPort : sentinelModel.getSentinels()) {
sb.append(hostPort.getHost()).append(':').append(hostPort.getPort()).append(',');
}
String sentinels = sb.deleteCharAt(sb.length() - 1).toString();
SetinelTbl proto = new SetinelTbl();
proto.setSetinelAddress(sentinels);
proto.setDeleted(false);
proto.setSetinelDescription(sentinelModel.getDesc());
proto.setDcId(dcService.find(sentinelModel.getDcName()).getId());
return proto;
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class DefaultSentinelCollector method isKeeperOrDead.
@VisibleForTesting
protected boolean isKeeperOrDead(String host, int port) {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Object> role = new AtomicReference<>();
try {
RedisSession redisSession = sessionManager.findOrCreateSession(host, port);
redisSession.role(new RedisSession.RollCallback() {
@Override
public void role(String roleDesc) {
role.set(roleDesc);
latch.countDown();
}
@Override
public void fail(Throwable e) {
logger.error("[isKeeperOrDead][fail]" + host + ":" + port, e);
role.set(e);
latch.countDown();
}
});
} catch (Exception e) {
role.set(e);
logger.error("[isKeeperOrDead]" + host + ":" + port, e);
}
try {
latch.await(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.error("[isKeeperOrDead]latch await error: {}", e);
}
if (role.get() instanceof String && Server.SERVER_ROLE.KEEPER.sameRole((String) role.get())) {
return true;
}
if (role.get() instanceof RedisConnectionException) {
return true;
}
logger.info("[isKeeperOrDead] role: {}", role.get());
return false;
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class ClusterServiceImpl method balanceCluster.
// Add transaction for one cluster update, rollback if one 'DcClusterShard' update fails
@VisibleForTesting
@DalTransaction
protected void balanceCluster(Map<String, List<SetinelTbl>> dcToSentinels, final String cluster) {
for (String dcName : dcToSentinels.keySet()) {
List<DcClusterShardTbl> dcClusterShards = dcClusterShardService.findAllByDcCluster(dcName, cluster);
List<SetinelTbl> sentinels = dcToSentinels.get(dcName);
if (dcClusterShards == null || sentinels == null) {
throw new XpipeRuntimeException("DcClusterShard | Sentinels should not be null");
}
long randomlySelectedSentinelId = randomlyChoseSentinels(sentinels);
dcClusterShards.forEach(dcClusterShard -> {
dcClusterShard.setSetinelId(randomlySelectedSentinelId);
try {
dcClusterShardService.updateDcClusterShard(dcClusterShard);
} catch (DalException e) {
throw new XpipeRuntimeException(e.getMessage());
}
});
}
}
Aggregations