use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class JedisSentinelPoolTest method waitForJedisSentinelPoolRecognizeNewMaster.
private void waitForJedisSentinelPoolRecognizeNewMaster(JedisSentinelPool pool, HostAndPort newMaster) throws InterruptedException {
while (true) {
HostAndPort currentHostMaster = pool.getCurrentHostMaster();
if (newMaster.equals(currentHostMaster))
break;
System.out.println("JedisSentinelPool's master is not yet changed, sleep...");
Thread.sleep(100);
}
}
use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class JedisSentinelPoolTest method forceFailover.
private void forceFailover(JedisSentinelPool pool) throws InterruptedException {
HostAndPort oldMaster = pool.getCurrentHostMaster();
// jedis connection should be master
Jedis beforeFailoverJedis = pool.getResource();
assertEquals("PONG", beforeFailoverJedis.ping());
waitForFailover(pool, oldMaster);
Jedis afterFailoverJedis = pool.getResource();
assertEquals("PONG", afterFailoverJedis.ping());
assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
assertEquals(2, afterFailoverJedis.getDB());
// returning both connections to the pool should not throw
beforeFailoverJedis.close();
afterFailoverJedis.close();
}
use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class JedisSentinelPoolTest method waitForFailover.
private void waitForFailover(JedisSentinelPool pool, HostAndPort oldMaster) throws InterruptedException {
HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster(MASTER_NAME, sentinelJedis1, sentinelJedis2);
waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster);
}
use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class ClusterNodeInformationParser method parse.
public ClusterNodeInformation parse(String nodeInfo, HostAndPort current) {
String[] nodeInfoPartArray = nodeInfo.split(" ");
HostAndPort node = getHostAndPortFromNodeLine(nodeInfoPartArray, current);
ClusterNodeInformation info = new ClusterNodeInformation(node);
if (nodeInfoPartArray.length >= SLOT_INFORMATIONS_START_INDEX) {
String[] slotInfoPartArray = extractSlotParts(nodeInfoPartArray);
fillSlotInformation(slotInfoPartArray, info);
}
return info;
}
use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class AppDeployCenterImpl method addHorizontalNodes.
@Override
public boolean addHorizontalNodes(Long appId, String masterHost, String slaveHost, int memory) {
AppDesc appDesc = appDao.getAppDescById(appId);
// 1. 寻找主从节点的可用端口
Integer masterPort = machineCenter.getAvailablePort(masterHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
if (masterPort == null) {
logger.error("master host={} getAvailablePort is null", masterHost);
return false;
}
Integer slavePort = 0;
boolean hasSlave = StringUtils.isNotBlank(slaveHost);
if (hasSlave) {
slavePort = machineCenter.getAvailablePort(slaveHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
if (slavePort == null) {
logger.error("slave host={} getAvailablePort is null", slaveHost);
return false;
}
}
// 2. 启动主从节点
boolean isMasterCreate = redisDeployCenter.createRunNode(appDesc, masterHost, masterPort, memory, true);
if (!isMasterCreate) {
logger.error("createRunNode master failed {}:{}", masterHost, masterPort);
return false;
}
if (hasSlave) {
// 运行节点
boolean isSlaveCreate = redisDeployCenter.createRunNode(appDesc, slaveHost, slavePort, memory, true);
if (!isSlaveCreate) {
logger.error("createRunNode slave failed {}:{}", slaveHost, slavePort);
return false;
}
}
// 3. 获取应用下有效节点
Set<HostAndPort> clusterHosts = getEffectiveInstanceList(appId);
// 4. 添加新节点: meet,复制,不做slot分配
RedisClusterReshard clusterReshard = new RedisClusterReshard(clusterHosts, redisCenter, instanceReshardProcessDao);
boolean joinCluster = clusterReshard.joinCluster(appId, masterHost, masterPort, slaveHost, slavePort);
if (joinCluster) {
// 5. 保存实例,开启统计功能
saveInstance(appId, masterHost, masterPort, memory);
redisCenter.deployRedisCollection(appId, masterHost, masterPort);
if (hasSlave) {
saveInstance(appId, slaveHost, slavePort, memory);
redisCenter.deployRedisCollection(appId, slaveHost, slavePort);
}
}
return joinCluster;
}
Aggregations