use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.
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 AppServiceImpl method getAppInstanceInfo.
@Override
public List<InstanceInfo> getAppInstanceInfo(Long appId) {
AppDesc appDesc = appDao.getAppDescById(appId);
String password = appDesc.getPassword();
List<InstanceInfo> resultList = instanceDao.getInstListByAppId(appId);
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();
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 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 cachecloud by sohutv.
the class JedisClusterNodeInformationParserTest method testParseNormalState.
@Test
public void testParseNormalState() {
String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd 192.168.0.3:7380 master - 0 1400598804016 2 connected 5461-10922";
HostAndPort current = new HostAndPort("localhost", 7379);
ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
assertNotEquals(clusterNodeInfo.getNode(), current);
assertEquals(clusterNodeInfo.getNode(), new HostAndPort("192.168.0.3", 7380));
for (int slot = 5461; slot <= 10922; slot++) {
assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
}
assertTrue(clusterNodeInfo.getSlotsBeingImported().isEmpty());
assertTrue(clusterNodeInfo.getSlotsBeingMigrated().isEmpty());
}
use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.
the class JedisClusterNodeInformationParserTest method testParseSlotBeingMigrated.
@Test
public void testParseSlotBeingMigrated() {
String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]";
HostAndPort current = new HostAndPort("localhost", 7379);
ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
assertEquals(clusterNodeInfo.getNode(), current);
for (int slot = 0; slot <= 5459; slot++) {
assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
}
assertEquals(1, clusterNodeInfo.getSlotsBeingMigrated().size());
assertTrue(clusterNodeInfo.getSlotsBeingMigrated().contains(5460));
assertEquals(1, clusterNodeInfo.getSlotsBeingImported().size());
assertTrue(clusterNodeInfo.getSlotsBeingImported().contains(5461));
}
Aggregations