Search in sources :

Example 26 with HostAndPort

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

Example 27 with HostAndPort

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

Example 28 with HostAndPort

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

Example 29 with HostAndPort

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

Example 30 with HostAndPort

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

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