use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class AppDeployCenterImpl method getEffectiveInstanceList.
/**
* 获取应用下有效节点
* @param appId
* @return
*/
private Set<HostAndPort> getEffectiveInstanceList(long appId) {
Set<HostAndPort> clusterHosts = new HashSet<HostAndPort>();
// 全部节点
List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
for (InstanceInfo instance : instanceInfos) {
if (instance.isOffline()) {
continue;
}
clusterHosts.add(new HostAndPort(instance.getIp(), instance.getPort()));
}
return clusterHosts;
}
use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.
the class MachineCenterImpl method getMachineInstanceInfo.
@Override
public List<InstanceInfo> getMachineInstanceInfo(String ip) {
List<InstanceInfo> resultList = instanceDao.getInstListByIp(ip);
if (resultList == null || resultList.isEmpty()) {
return resultList;
}
if (resultList != null && resultList.size() > 0) {
for (InstanceInfo instanceInfo : resultList) {
int type = instanceInfo.getType();
if (instanceInfo.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
continue;
}
if (TypeUtil.isRedisType(type)) {
if (TypeUtil.isRedisSentinel(type)) {
continue;
}
String host = instanceInfo.getIp();
int port = instanceInfo.getPort();
long appId = instanceInfo.getAppId();
AppDesc appDesc = appDao.getAppDescById(appId);
String password = appDesc.getPassword();
Boolean isMaster = redisCenter.isMaster(appId, host, port);
instanceInfo.setRoleDesc(isMaster);
if (isMaster != null && !isMaster) {
HostAndPort hap = redisCenter.getMaster(host, port, password);
if (hap != null) {
instanceInfo.setMasterHost(hap.getHost());
instanceInfo.setMasterPort(hap.getPort());
for (InstanceInfo innerInfo : resultList) {
if (innerInfo.getIp().equals(hap.getHost()) && innerInfo.getPort() == hap.getPort()) {
instanceInfo.setMasterInstanceId(innerInfo.getId());
break;
}
}
}
}
}
}
}
return resultList;
}
use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.
the class JedisSentinelPoolTest method initializeWithNotAvailableSentinelsShouldThrowException.
@Test(expected = JedisConnectionException.class)
public void initializeWithNotAvailableSentinelsShouldThrowException() {
Set<String> wrongSentinels = new HashSet<String>();
wrongSentinels.add(new HostAndPort("localhost", 65432).toString());
wrongSentinels.add(new HostAndPort("localhost", 65431).toString());
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, wrongSentinels);
pool.destroy();
}
use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.
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 cachecloud by sohutv.
the class HostAndPortUtil method parseHosts.
public static List<HostAndPort> parseHosts(String envHosts, List<HostAndPort> existingHostsAndPorts) {
if (null != envHosts && 0 < envHosts.length()) {
String[] hostDefs = envHosts.split(",");
if (null != hostDefs && 2 <= hostDefs.length) {
List<HostAndPort> envHostsAndPorts = new ArrayList<HostAndPort>(hostDefs.length);
for (String hostDef : hostDefs) {
String[] hostAndPort = hostDef.split(":");
if (null != hostAndPort && 2 == hostAndPort.length) {
String host = hostAndPort[0];
int port = Protocol.DEFAULT_PORT;
try {
port = Integer.parseInt(hostAndPort[1]);
} catch (final NumberFormatException nfe) {
}
envHostsAndPorts.add(new HostAndPort(host, port));
}
}
return envHostsAndPorts;
}
}
return existingHostsAndPorts;
}
Aggregations