Search in sources :

Example 11 with AppDesc

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

the class AppDeployCenterImpl method checkAppDeployDetail.

@Override
public DataFormatCheckResult checkAppDeployDetail(Long appAuditId, String appDeployText) {
    if (appAuditId == null) {
        logger.error("appAuditId is null");
        return DataFormatCheckResult.fail("审核id不能为空!");
    }
    if (StringUtils.isBlank(appDeployText)) {
        logger.error("appDeployText is null");
        return DataFormatCheckResult.fail("部署节点列表不能为空!");
    }
    String[] nodeInfoList = appDeployText.split(ConstUtils.NEXT_LINE);
    if (nodeInfoList == null || nodeInfoList.length == 0) {
        logger.error("nodeInfoList is null");
        return DataFormatCheckResult.fail("部署节点列表不能为空!");
    }
    AppAudit appAudit = appAuditDao.getAppAudit(appAuditId);
    if (appAudit == null) {
        logger.error("appAudit:id={} is not exist", appAuditId);
        return DataFormatCheckResult.fail(String.format("审核id=%s不存在", appAuditId));
    }
    long appId = appAudit.getAppId();
    AppDesc appDesc = appService.getByAppId(appId);
    if (appDesc == null) {
        logger.error("appDesc:id={} is not exist");
        return DataFormatCheckResult.fail(String.format("appId=%s不存在", appId));
    }
    int type = appDesc.getType();
    //检查每一行
    for (String nodeInfo : nodeInfoList) {
        nodeInfo = StringUtils.trim(nodeInfo);
        if (StringUtils.isBlank(nodeInfo)) {
            return DataFormatCheckResult.fail(String.format("部署列表%s中存在空行", appDeployText));
        }
        String[] array = nodeInfo.split(ConstUtils.COLON);
        if (array == null || array.length == 0) {
            return DataFormatCheckResult.fail(String.format("部署列表%s中存在空行", appDeployText));
        }
        String masterHost = null;
        String memSize = null;
        String slaveHost = null;
        if (TypeUtil.isRedisCluster(type)) {
            if (array.length == 2) {
                masterHost = array[0];
                memSize = array[1];
            } else if (array.length == 3) {
                masterHost = array[0];
                memSize = array[1];
                slaveHost = array[2];
            } else {
                return DataFormatCheckResult.fail(String.format("部署列表中%s, 格式错误!", nodeInfo));
            }
        } else if (TypeUtil.isRedisSentinel(type)) {
            if (array.length == 3) {
                masterHost = array[0];
                memSize = array[1];
                slaveHost = array[2];
            } else if (array.length == 1) {
                masterHost = array[0];
            } else {
                return DataFormatCheckResult.fail(String.format("部署列表中%s, 格式错误!", nodeInfo));
            }
        } else if (TypeUtil.isRedisStandalone(type)) {
            if (array.length == 2) {
                masterHost = array[0];
                memSize = array[1];
            } else {
                return DataFormatCheckResult.fail(String.format("部署列表中%s, 格式错误!", nodeInfo));
            }
        }
        if (!checkHostExist(masterHost)) {
            return DataFormatCheckResult.fail(String.format("%s中的ip=%s不存在,请在机器管理中添加!", nodeInfo, masterHost));
        }
        if (StringUtils.isNotBlank(memSize) && !NumberUtils.isDigits(memSize)) {
            return DataFormatCheckResult.fail(String.format("%s中的中的memSize=%s不是整数!", nodeInfo, memSize));
        }
        if (StringUtils.isNotBlank(slaveHost) && !checkHostExist(slaveHost)) {
            return DataFormatCheckResult.fail(String.format("%s中的ip=%s不存在,请在机器管理中添加!", nodeInfo, slaveHost));
        }
    }
    //检查sentinel类型:数据节点一行,sentinel节点多行
    if (TypeUtil.isRedisSentinel(type)) {
        return checkSentinelAppDeploy(nodeInfoList);
    //检查单点类型:只能有一行数据节点
    } else if (TypeUtil.isRedisStandalone(type)) {
        return checkStandaloneAppDeploy(nodeInfoList);
    }
    return DataFormatCheckResult.success("应用部署格式正确,可以开始部署了!");
}
Also used : AppAudit(com.sohu.cache.entity.AppAudit) AppDesc(com.sohu.cache.entity.AppDesc)

Example 12 with AppDesc

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

the class AppDeployCenterImpl method verticalExpansion.

@Override
public boolean verticalExpansion(Long appId, Long appAuditId, final int memory) {
    Assert.isTrue(appId != null && appId > 0L);
    Assert.isTrue(appAuditId != null && appAuditId > 0L);
    Assert.isTrue(memory > 0);
    boolean isInProcess = isInProcess(appId);
    if (isInProcess) {
        return false;
    }
    AppDesc appDesc = appService.getByAppId(appId);
    Assert.isTrue(appDesc != null);
    int type = appDesc.getType();
    if (!TypeUtil.isRedisType(type)) {
        logger.error("appId={};type={} is not redis!", appDesc, type);
        return false;
    }
    List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
    if (instanceInfos == null || instanceInfos.isEmpty()) {
        logger.error("instanceInfos is null");
        return false;
    }
    for (InstanceInfo instanceInfo : instanceInfos) {
        int instanceType = instanceInfo.getType();
        if (TypeUtil.isRedisSentinel(instanceType)) {
            continue;
        }
        // 下线实例不做操作
        if (instanceInfo.isOffline()) {
            continue;
        }
        String host = instanceInfo.getIp();
        int port = instanceInfo.getPort();
        final long maxMemoryBytes = Long.valueOf(memory) * 1024 * 1024;
        boolean isConfig = redisDeployCenter.modifyInstanceConfig(host, port, "maxmemory", String.valueOf(maxMemoryBytes));
        if (!isConfig) {
            logger.error("{}:{} set maxMemory error", host, port);
            return false;
        }
        //更新instanceInfo配置
        instanceInfo.setMem(memory);
        instanceDao.update(instanceInfo);
    }
    // 改变审核状态
    appAuditDao.updateAppAudit(appAuditId, AppCheckEnum.APP_ALLOCATE_RESOURCE.value());
    return true;
}
Also used : AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 13 with AppDesc

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

the class ImportAppController method check.

@RequestMapping(value = "/check")
public ModelAndView check(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppDesc appDesc = genAppDesc(request);
    String appInstanceInfo = request.getParameter("appInstanceInfo");
    ImportAppResult importAppResult = importAppCenter.check(appDesc, appInstanceInfo);
    model.addAttribute("status", importAppResult.getStatus());
    model.addAttribute("message", importAppResult.getMessage());
    return new ModelAndView("");
}
Also used : ImportAppResult(com.sohu.cache.constant.ImportAppResult) ModelAndView(org.springframework.web.servlet.ModelAndView) AppDesc(com.sohu.cache.entity.AppDesc) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with AppDesc

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

the class MachineManageController method fillInstanceModel.

/**
     * 实例统计信息
     * @param appAudit
     * @param model
     */
protected void fillInstanceModel(List<InstanceInfo> instanceList, List<InstanceStats> appInstanceStats, Model model) {
    Map<String, MachineStats> machineStatsMap = new HashMap<String, MachineStats>();
    Map<String, Long> machineCanUseMem = new HashMap<String, Long>();
    Map<String, InstanceStats> instanceStatsMap = new HashMap<String, InstanceStats>();
    Map<Long, AppDesc> appInfoMap = new HashMap<Long, AppDesc>();
    for (InstanceStats instanceStats : appInstanceStats) {
        instanceStatsMap.put(instanceStats.getIp() + ":" + instanceStats.getPort(), instanceStats);
        appInfoMap.put(instanceStats.getAppId(), appService.getByAppId(instanceStats.getAppId()));
    }
    for (InstanceInfo instanceInfo : instanceList) {
        if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
            continue;
        }
        String ip = instanceInfo.getIp();
        if (machineStatsMap.containsKey(ip)) {
            continue;
        }
        List<MachineStats> machineStatsList = machineCenter.getMachineStats(ip);
        MachineStats machineStats = null;
        for (MachineStats stats : machineStatsList) {
            if (stats.getIp().equals(ip)) {
                machineStats = stats;
                machineStatsMap.put(ip, machineStats);
                break;
            }
        }
        MachineStats ms = machineCenter.getMachineMemoryDetail(ip);
        machineCanUseMem.put(ip, ms.getMachineMemInfo().getLockedMem());
    }
    model.addAttribute("appInfoMap", appInfoMap);
    model.addAttribute("machineCanUseMem", machineCanUseMem);
    model.addAttribute("machineStatsMap", machineStatsMap);
    model.addAttribute("instanceList", instanceList);
    model.addAttribute("instanceStatsMap", instanceStatsMap);
}
Also used : HashMap(java.util.HashMap) InstanceStats(com.sohu.cache.entity.InstanceStats) MachineStats(com.sohu.cache.entity.MachineStats) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 15 with AppDesc

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

the class AppDailyDataCenterImpl method generateAppDaily.

@Override
public AppDailyData generateAppDaily(long appId, Date startDate, Date endDate) {
    Assert.isTrue(appId > 0L);
    AppDetailVO appDetailVO = appStatsCenter.getAppDetail(appId);
    if (appDetailVO == null) {
        logger.error("appId={} not exist", appId);
        return null;
    }
    AppDesc appDesc = appDetailVO.getAppDesc();
    if (appDesc.isOffline()) {
        return null;
    }
    if (appDesc.isTest()) {
        return null;
    }
    AppDailyData appDailyData = new AppDailyData();
    appDailyData.setStartDate(startDate);
    appDailyData.setEndDate(endDate);
    // 应用详情
    appDailyData.setAppDetailVO(appDetailVO);
    // 慢查询
    int slowLogCount = getSlowLogCount(appId, startDate, endDate);
    appDailyData.setSlowLogCount(slowLogCount);
    // 客户端异常数
    int clientExceptionCount = getClientExceptionCount(appId, startDate, endDate);
    appDailyData.setClientExceptionCount(clientExceptionCount);
    // 客户端值分布
    Map<String, Long> valueSizeDistributeCountMap = getAppClientValueSizeDistributeCountMap(appId, startDate, endDate);
    appDailyData.setValueSizeDistributeCountMap(valueSizeDistributeCountMap);
    // 应用相关统计
    Map<String, Object> appMinuteStatMap = getAppMinuteStat(appId, startDate, endDate);
    appDailyData.setMaxMinuteClientCount(MapUtils.getIntValue(appMinuteStatMap, "maxClientCount"));
    appDailyData.setAvgMinuteClientCount(MapUtils.getIntValue(appMinuteStatMap, "avgClientCount"));
    appDailyData.setMaxMinuteCommandCount(MapUtils.getIntValue(appMinuteStatMap, "maxCommandCount"));
    appDailyData.setAvgMinuteCommandCount(MapUtils.getIntValue(appMinuteStatMap, "avgCommandCount"));
    appDailyData.setMaxMinuteHitRatio(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "maxHitRatio") * 100.0));
    appDailyData.setMinMinuteHitRatio(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "minHitRatio") * 100.0));
    appDailyData.setAvgHitRatio(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "avgHitRatio") * 100.0));
    appDailyData.setAvgUsedMemory(MapUtils.getLongValue(appMinuteStatMap, "avgUsedMemory") / 1024 / 1024);
    appDailyData.setMaxUsedMemory(MapUtils.getLongValue(appMinuteStatMap, "maxUsedMemory") / 1024 / 1024);
    appDailyData.setExpiredKeysCount(MapUtils.getIntValue(appMinuteStatMap, "expiredKeys"));
    appDailyData.setEvictedKeysCount(MapUtils.getIntValue(appMinuteStatMap, "evictedKeys"));
    appDailyData.setAvgMinuteNetOutputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "avgNetInputByte") / 1024.0 / 1024.0));
    appDailyData.setMaxMinuteNetOutputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "maxNetInputByte") / 1024.0 / 1024.0));
    appDailyData.setAvgMinuteNetInputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "avgNetOutputByte") / 1024.0 / 1024.0));
    appDailyData.setMaxMinuteNetInputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "maxNetOutputByte") / 1024.0 / 1024.0));
    appDailyData.setAvgObjectSize(MapUtils.getIntValue(appMinuteStatMap, "avgObjectSize"));
    appDailyData.setMaxObjectSize(MapUtils.getIntValue(appMinuteStatMap, "maxObjectSize"));
    return appDailyData;
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) AppDesc(com.sohu.cache.entity.AppDesc) AppDailyData(com.sohu.cache.entity.AppDailyData)

Aggregations

AppDesc (com.sohu.cache.entity.AppDesc)47 BaseTest (com.sohu.test.BaseTest)18 Test (org.junit.Test)18 ImportAppResult (com.sohu.cache.constant.ImportAppResult)15 InstanceInfo (com.sohu.cache.entity.InstanceInfo)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 Date (java.util.Date)5 Jedis (redis.clients.jedis.Jedis)5 AppAudit (com.sohu.cache.entity.AppAudit)4 InstanceStats (com.sohu.cache.entity.InstanceStats)3 IdempotentConfirmer (com.sohu.cache.util.IdempotentConfirmer)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 AppUser (com.sohu.cache.entity.AppUser)2 AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AppClientCostTimeTotalStat (com.sohu.cache.entity.AppClientCostTimeTotalStat)1 AppClientExceptionStat (com.sohu.cache.entity.AppClientExceptionStat)1