Search in sources :

Example 26 with InstanceInfo

use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.

the class InstanceManageController method doInitInstanceConfigChange.

/**
     * 处理实例配置修改
     * 
     * @param appAuditId 审批id
     */
@RequestMapping(value = "/initInstanceConfigChange")
public ModelAndView doInitInstanceConfigChange(HttpServletRequest request, HttpServletResponse response, Model model, Long appAuditId) {
    // 申请原因
    AppAudit appAudit = appService.getAppAuditById(appAuditId);
    model.addAttribute("appAudit", appAudit);
    // 用第一个参数存实例id
    Long instanceId = NumberUtils.toLong(appAudit.getParam1());
    Map<String, String> redisConfigList = redisCenter.getRedisConfigList(instanceId.intValue());
    model.addAttribute("redisConfigList", redisConfigList);
    // 实例
    InstanceInfo instanceInfo = instanceStatsCenter.getInstanceInfo(instanceId);
    model.addAttribute("instanceInfo", instanceInfo);
    model.addAttribute("appId", appAudit.getAppId());
    model.addAttribute("appAuditId", appAuditId);
    // 修改配置的键值对
    model.addAttribute("instanceConfigKey", appAudit.getParam2());
    model.addAttribute("instanceConfigValue", appAudit.getParam3());
    return new ModelAndView("manage/appAudit/initInstanceConfigChange");
}
Also used : AppAudit(com.sohu.cache.entity.AppAudit) ModelAndView(org.springframework.web.servlet.ModelAndView) InstanceInfo(com.sohu.cache.entity.InstanceInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with InstanceInfo

use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.

the class ObjectConvert method assembleInstance.

/**
     * 将实例列表转化为ip1:port1 ip2:port2
     *
     * @param instanceList
     * @return
     */
public static String assembleInstance(List<InstanceInfo> instanceList) {
    if (instanceList.isEmpty()) {
        return null;
    }
    StringBuilder instanceBuilder = new StringBuilder();
    for (int i = 0; i < instanceList.size(); i++) {
        InstanceInfo instanceInfo = instanceList.get(i);
        if (instanceInfo.isOffline()) {
            continue;
        }
        if (i > 0) {
            instanceBuilder.append(" ");
        }
        instanceBuilder.append(instanceInfo.getIp()).append(":").append(instanceInfo.getPort());
    }
    return StringUtils.trim(instanceBuilder.toString());
}
Also used : InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 28 with InstanceInfo

use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.

the class HostInspectHandler method getSplitMap.

@Override
protected Map<String, List<InstanceInfo>> getSplitMap() {
    List<InstanceInfo> list = getAllInstanceList();
    Map<String, List<InstanceInfo>> hostMap = new TreeMap<String, List<InstanceInfo>>();
    for (InstanceInfo instanceInfo : list) {
        String host = instanceInfo.getIp();
        if (hostMap.containsKey(host)) {
            hostMap.get(host).add(instanceInfo);
        } else {
            List<InstanceInfo> hostInstances = new ArrayList<InstanceInfo>();
            hostInstances.add(instanceInfo);
            hostMap.put(host, hostInstances);
        }
    }
    return hostMap;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 29 with InstanceInfo

use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.

the class RedisIsolationPersistenceInspector method inspect.

@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
    final String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
    List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
    outer: for (InstanceInfo info : list) {
        final int port = info.getPort();
        final int type = info.getType();
        int status = info.getStatus();
        //非正常节点
        if (status != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
            continue;
        }
        if (TypeUtil.isRedisDataType(type)) {
            Jedis jedis = new Jedis(host, port, REDIS_DEFAULT_TIME);
            try {
                Map<String, String> persistenceMap = parseMap(jedis);
                if (persistenceMap.isEmpty()) {
                    logger.error("{}:{} get persistenceMap failed", host, port);
                    continue;
                }
                if (!isAofEnabled(persistenceMap)) {
                    continue;
                }
                long aofCurrentSize = MapUtils.getLongValue(persistenceMap, "aof_current_size");
                long aofBaseSize = MapUtils.getLongValue(persistenceMap, "aof_base_size");
                //阀值大于60%
                long aofThresholdSize = (long) (aofBaseSize * 1.6);
                double percentage = getPercentage(aofCurrentSize, aofBaseSize);
                if (aofCurrentSize >= aofThresholdSize && //大于64Mb
                aofCurrentSize > (64 * 1024 * 1024)) {
                    //bgRewriteAof
                    boolean isInvoke = invokeBgRewriteAof(jedis);
                    if (!isInvoke) {
                        logger.error("{}:{} invokeBgRewriteAof failed", host, port);
                        continue;
                    } else {
                        logger.warn("{}:{} invokeBgRewriteAof started percentage={}", host, port, percentage);
                    }
                    while (true) {
                        try {
                            //before wait 1s
                            TimeUnit.SECONDS.sleep(1);
                            Map<String, String> loopMap = parseMap(jedis);
                            Integer aofRewriteInProgress = MapUtils.getInteger(loopMap, "aof_rewrite_in_progress", null);
                            if (aofRewriteInProgress == null) {
                                logger.error("loop watch:{}:{} return failed", host, port);
                                break;
                            } else if (aofRewriteInProgress <= 0) {
                                //bgrewriteaof Done
                                logger.warn("{}:{} bgrewriteaof Done lastSize:{}Mb,currentSize:{}Mb", host, port, getMb(aofCurrentSize), getMb(MapUtils.getLongValue(loopMap, "aof_current_size")));
                                break;
                            } else {
                                //wait 1s
                                TimeUnit.SECONDS.sleep(1);
                            }
                        } catch (Exception e) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                } else {
                    if (percentage > 50D) {
                        long currentSize = getMb(aofCurrentSize);
                        logger.info("checked {}:{} aof increase percentage:{}% currentSize:{}Mb", host, port, percentage, currentSize > 0 ? currentSize : "<1");
                    }
                }
            } finally {
                jedis.close();
            }
        }
    }
    return true;
}
Also used : Jedis(redis.clients.jedis.Jedis) List(java.util.List) InstanceInfo(com.sohu.cache.entity.InstanceInfo) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with InstanceInfo

use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.

the class RedisDeployCenterImpl method addSentinel.

@Override
public boolean addSentinel(long appId, String sentinelHost) {
    AppDesc appDesc = appDao.getAppDescById(appId);
    JedisSentinelPool jedisSentinelPool = redisCenter.getJedisSentinelPool(appDesc);
    if (jedisSentinelPool == null) {
        return false;
    }
    List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
    String masterName = null;
    for (Iterator<InstanceInfo> i = instanceInfos.iterator(); i.hasNext(); ) {
        InstanceInfo instanceInfo = i.next();
        if (instanceInfo.getType() != ConstUtils.CACHE_REDIS_SENTINEL) {
            i.remove();
            continue;
        }
        if (masterName == null && StringUtils.isNotBlank(instanceInfo.getCmd())) {
            masterName = instanceInfo.getCmd();
        }
    }
    Jedis jedis = null;
    String masterHost = null;
    Integer masterPort = null;
    try {
        jedis = jedisSentinelPool.getResource();
        masterHost = jedis.getClient().getHost();
        masterPort = jedis.getClient().getPort();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        jedis.close();
        jedisSentinelPool.destroy();
    }
    boolean isRun = runSentinel(sentinelHost, masterName, masterHost, masterPort, appId);
    if (!isRun) {
        return false;
    }
    return true;
}
Also used : Jedis(redis.clients.jedis.Jedis) AppDesc(com.sohu.cache.entity.AppDesc) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Aggregations

InstanceInfo (com.sohu.cache.entity.InstanceInfo)45 AppDesc (com.sohu.cache.entity.AppDesc)11 List (java.util.List)7 Jedis (redis.clients.jedis.Jedis)7 InstanceStats (com.sohu.cache.entity.InstanceStats)6 MachineInfo (com.sohu.cache.entity.MachineInfo)5 ArrayList (java.util.ArrayList)5 IdempotentConfirmer (com.sohu.cache.util.IdempotentConfirmer)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 InstanceCommandStats (com.sohu.cache.entity.InstanceCommandStats)2 InstanceSlotModel (com.sohu.cache.entity.InstanceSlotModel)2 AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)2 BaseTest (com.sohu.test.BaseTest)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 HostAndPort (redis.clients.jedis.HostAndPort)2