Search in sources :

Example 31 with HostAndPort

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;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 32 with HostAndPort

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;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort)

Example 33 with HostAndPort

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;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) InstanceInfo(com.sohu.cache.entity.InstanceInfo) HashSet(java.util.HashSet)

Example 34 with HostAndPort

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());
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Example 35 with HostAndPort

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));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)95 Test (org.junit.Test)42 JedisCluster (redis.clients.jedis.JedisCluster)33 HashSet (java.util.HashSet)31 Jedis (redis.clients.jedis.Jedis)24 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)10 Before (org.junit.Before)9 ArrayList (java.util.ArrayList)7 JedisPool (redis.clients.jedis.JedisPool)7 ClusterNodeInformation (redis.clients.util.ClusterNodeInformation)6 AppDesc (com.sohu.cache.entity.AppDesc)5 InstanceInfo (com.sohu.cache.entity.InstanceInfo)5 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)5 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JedisPubSub (redis.clients.jedis.JedisPubSub)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JSONObject (com.alibaba.fastjson.JSONObject)2