Search in sources :

Example 16 with AppDesc

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

the class AppDeployCenterImpl method offLineApp.

@Override
public boolean offLineApp(Long appId) {
    Assert.isTrue(appId != null && appId > 0L);
    AppDesc appDesc = appService.getByAppId(appId);
    if (appDesc == null) {
        logger.error("appId={} not exist");
        return false;
    }
    List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
    int type = appDesc.getType();
    if (instanceInfos != null) {
        for (InstanceInfo instanceInfo : instanceInfos) {
            final String ip = instanceInfo.getIp();
            final int port = instanceInfo.getPort();
            if (TypeUtil.isRedisType(type)) {
                //取消收集
                redisCenter.unDeployRedisCollection(appId, ip, port);
                redisCenter.unDeployRedisSlowLogCollection(appId, ip, port);
                boolean isShutdown = redisCenter.shutdown(ip, port);
                if (!isShutdown) {
                    logger.error("{}:{} redis not shutdown!", ip, port);
                    return false;
                }
            }
            //更新实例下线
            instanceInfo.setStatus(InstanceStatusEnum.OFFLINE_STATUS.getStatus());
            instanceDao.update(instanceInfo);
        }
    }
    //更新应用信息
    appDesc.setStatus(AppStatusEnum.STATUS_OFFLINE.getStatus());
    appService.update(appDesc);
    return true;
}
Also used : AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 17 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 18 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 19 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 20 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)

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