Search in sources :

Example 41 with AppDesc

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

the class AppDeployCenterImpl method checkHorizontalNodes.

@Override
public DataFormatCheckResult checkHorizontalNodes(Long appAuditId, String masterSizeSlave) {
    if (appAuditId == null) {
        logger.error("appAuditId is null");
        return DataFormatCheckResult.fail("审核id不能为空!");
    }
    if (StringUtils.isBlank(masterSizeSlave)) {
        logger.error("masterSizeSlave 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));
    }
    //节点数组 master:memSize:slave
    String[] array = masterSizeSlave.split(ConstUtils.COLON);
    if (array == null || array.length == 0) {
        return DataFormatCheckResult.fail(String.format("添加节点%s格式错误", masterSizeSlave));
    }
    //检查格式
    String masterHost = null;
    String memSize = null;
    String slaveHost = null;
    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, 格式错误!", masterSizeSlave));
    }
    //检查主节点机器是否存在
    if (!checkHostExist(masterHost)) {
        return DataFormatCheckResult.fail(String.format("%s中的ip=%s不存在,请在机器管理中添加!", masterSizeSlave, masterHost));
    }
    //检查memSize格式
    if (StringUtils.isNotBlank(memSize) && !NumberUtils.isDigits(memSize)) {
        return DataFormatCheckResult.fail(String.format("%s中的中的memSize=%s不是整数!", masterSizeSlave, memSize));
    }
    //检查从节点格式
    if (StringUtils.isNotBlank(slaveHost) && !checkHostExist(slaveHost)) {
        return DataFormatCheckResult.fail(String.format("%s中的ip=%s不存在,请在机器管理中添加!", masterSizeSlave, slaveHost));
    }
    return DataFormatCheckResult.success("添加节点格式正确,可以开始部署了!");
}
Also used : AppAudit(com.sohu.cache.entity.AppAudit) AppDesc(com.sohu.cache.entity.AppDesc)

Example 42 with AppDesc

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

the class AppDeployCenterImpl method checkHorizontal.

@Override
public HorizontalResult checkHorizontal(long appId, long appAuditId, long sourceId, long targetId, int startSlot, int endSlot, int migrateType) {
    // 0.当前应用正在迁移
    boolean isInProcess = isInProcess(appId);
    if (isInProcess) {
        return HorizontalResult.fail(String.format("appId=%s正在迁移!", appId));
    }
    // 1.应用信息
    AppDesc appDesc = appService.getByAppId(appId);
    if (appDesc == null) {
        return HorizontalResult.fail("应用信息为空");
    }
    // 2.0 源实例ID不能等于目标实例ID
    if (sourceId == targetId) {
        return HorizontalResult.fail(String.format("源实例ID=%s不能等于目标实例ID=%s", sourceId, targetId));
    }
    // 2.1 源实例信息
    InstanceInfo sourceInstanceInfo = instanceDao.getInstanceInfoById(sourceId);
    if (sourceInstanceInfo == null) {
        return HorizontalResult.fail(String.format("源实例id=%s为空", sourceId));
    }
    // 2.2 对比源实例的appId是否正确
    long sourceAppId = sourceInstanceInfo.getAppId();
    if (sourceAppId != appId) {
        return HorizontalResult.fail(String.format("源实例id=%s不属于appId=%s", sourceId, appId));
    }
    // 2.3 源实例是否在线
    boolean sourceIsRun = redisCenter.isRun(sourceInstanceInfo.getIp(), sourceInstanceInfo.getPort());
    if (!sourceIsRun) {
        return HorizontalResult.fail(String.format("源实例%s必须运行中", sourceInstanceInfo.getHostPort()));
    }
    // 2.4必须是master节点
    boolean sourceIsMaster = redisCenter.isMaster(sourceInstanceInfo.getIp(), sourceInstanceInfo.getPort());
    if (!sourceIsMaster) {
        return HorizontalResult.fail(String.format("源实例%s必须是主节点", sourceInstanceInfo.getHostPort()));
    }
    // 3.1 目标实例信息
    InstanceInfo targetInstanceInfo = instanceDao.getInstanceInfoById(targetId);
    if (targetInstanceInfo == null) {
        return HorizontalResult.fail(String.format("目标实例id=%s为空", targetId));
    }
    // 3.2 对比目标实例的appId是否正确
    long targetAppId = targetInstanceInfo.getAppId();
    if (targetAppId != appId) {
        return HorizontalResult.fail(String.format("目标实例id=%s不属于appId=%s", targetId, appId));
    }
    // 3.3 目标实例是否在线
    boolean targetIsRun = redisCenter.isRun(targetInstanceInfo.getIp(), targetInstanceInfo.getPort());
    if (!targetIsRun) {
        return HorizontalResult.fail(String.format("目标实例%s必须运行中", targetInstanceInfo.getHostPort()));
    }
    // 3.4 必须是master节点
    boolean targetIsMaster = redisCenter.isMaster(targetInstanceInfo.getIp(), targetInstanceInfo.getPort());
    if (!targetIsMaster) {
        return HorizontalResult.fail(String.format("目标实例%s必须是主节点", targetInstanceInfo.getHostPort()));
    }
    // 4.startSlot和endSlot是否在源实例中
    // 4.1 判断数值
    int maxSlot = 16383;
    if (startSlot < 0 || startSlot > maxSlot) {
        return HorizontalResult.fail(String.format("startSlot=%s必须在0-%s", startSlot, maxSlot));
    }
    if (endSlot < 0 || endSlot > maxSlot) {
        return HorizontalResult.fail(String.format("endSlot=%s必须在0-%s", endSlot, maxSlot));
    }
    if (startSlot > endSlot) {
        return HorizontalResult.fail("startSlot不能大于endSlot");
    }
    // 4.2 判断startSlot和endSlot属于sourceId
    // 获取所有slot分布
    Map<String, InstanceSlotModel> clusterSlotsMap = redisCenter.getClusterSlotsMap(appId);
    if (MapUtils.isEmpty(clusterSlotsMap)) {
        return HorizontalResult.fail("无法获取slot分布!");
    }
    // 获取源实例负责的slot
    String sourceHostPort = sourceInstanceInfo.getHostPort();
    InstanceSlotModel instanceSlotModel = clusterSlotsMap.get(sourceHostPort);
    if (instanceSlotModel == null || CollectionUtils.isEmpty(instanceSlotModel.getSlotList())) {
        return HorizontalResult.fail("源实例上没有slot!");
    }
    List<Integer> slotList = instanceSlotModel.getSlotList();
    for (int i = startSlot; i <= endSlot; i++) {
        if (!slotList.contains(i)) {
            return HorizontalResult.fail(String.format("源实例没有包含尽startSlot=%s到endSlot=%s", startSlot, endSlot));
        }
    }
    //5.是否支持批量,版本要大于等于3.0.6
    String sourceRedisVersion = redisCenter.getRedisVersion(sourceInstanceInfo.getIp(), sourceInstanceInfo.getPort());
    if (StringUtils.isBlank(sourceRedisVersion)) {
        return HorizontalResult.fail(String.format("源实例%s版本为空", sourceInstanceInfo.getHostPort()));
    }
    String targetRedisVersion = redisCenter.getRedisVersion(targetInstanceInfo.getIp(), targetInstanceInfo.getPort());
    if (StringUtils.isBlank(targetRedisVersion)) {
        return HorizontalResult.fail(String.format("目标实例%s版本为空", targetInstanceInfo.getHostPort()));
    }
    RedisVersion sourceRedisVersionModel = getRedisVersion(sourceRedisVersion);
    //选择了批量,但是当前版本不支持pipeline
    if (migrateType == 1 && !sourceRedisVersionModel.isSupportPipelineMigrate()) {
        return HorizontalResult.fail(String.format("源实例%s版本为%s,不支持pipeline migrate!", sourceInstanceInfo.getHostPort(), sourceRedisVersion));
    }
    RedisVersion targetRedisVersionModel = getRedisVersion(targetRedisVersion);
    //选择了批量,但是当前版本不支持pipeline
    if (migrateType == 1 && !targetRedisVersionModel.isSupportPipelineMigrate()) {
        return HorizontalResult.fail(String.format("目标实例%s版本为%s,不支持pipeline migrate!", targetInstanceInfo.getHostPort(), targetRedisVersion));
    }
    return HorizontalResult.checkSuccess();
}
Also used : AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo) InstanceSlotModel(com.sohu.cache.entity.InstanceSlotModel)

Example 43 with AppDesc

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

the class AppClientConnInspector method alertAppClientConn.

/**
     * 应用连接数报警
     * @param appDetailVO
     * @param appClientConnThreshold
     * @param instanceCount
     */
private void alertAppClientConn(final AppDetailVO appDetailVO, final int appClientConnThreshold, final int instanceCount) {
    AppDesc appDesc = appDetailVO.getAppDesc();
    String content = String.format("应用(%s)-客户端连接数报警-预设阀值每个分片为%s-现已达到%s(分片个数:%s)-请及时关注", appDesc.getAppId(), appClientConnThreshold, appDetailVO.getConn(), instanceCount);
    String title = "CacheCloud系统-客户端连接数报警";
    logger.warn("app title {}", title);
    logger.warn("app content {}", content);
    emailComponent.sendMail(title, content, appDetailVO.getEmailList(), Arrays.asList(emailComponent.getAdminEmail().split(ConstUtils.COMMA)));
}
Also used : AppDesc(com.sohu.cache.entity.AppDesc)

Example 44 with AppDesc

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

the class AppMemInspector method alertAppMemUse.

/**
     * @param appDetailVO
     */
private void alertAppMemUse(final AppDetailVO appDetailVO) {
    AppDesc appDesc = appDetailVO.getAppDesc();
    String content = String.format("应用(%s)-内存使用率报警-预设百分之%s-现已达到百分之%s-请及时关注", appDesc.getAppId(), appDesc.getMemAlertValue(), appDetailVO.getMemUsePercent());
    String title = "CacheCloud系统-应用内存使用率报警";
    emailComponent.sendMail(title, content, appDetailVO.getEmailList(), Arrays.asList(emailComponent.getAdminEmail().split(ConstUtils.COMMA)));
// TODO 临时注释掉
// mobileAlertComponent.sendPhone(content,
// appDetailVO.getPhoneList());
}
Also used : AppDesc(com.sohu.cache.entity.AppDesc)

Example 45 with AppDesc

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

the class AppAuditDaoTest method testInsert.

@Test
public void testInsert() {
    int memSize = 4;
    AppDesc appDesc = appDao.getAppDescById(10132L);
    AppUser appUser = appUserDao.get(10016L);
    AppAudit appAudit = new AppAudit();
    appAudit.setAppId(appDesc.getAppId());
    appAudit.setUserId(appUser.getId());
    appAudit.setUserName(appUser.getName());
    appAudit.setModifyTime(new Date());
    appAudit.setParam1(String.valueOf(memSize));
    appAudit.setParam2(appDesc.getTypeDesc());
    appAudit.setInfo("应用申请:类型:" + appDesc.getTypeDesc() + ";初始申请空间:" + memSize + ";");
    appAudit.setStatus(AppStatusEnum.STATUS_INITIALIZE.getStatus());
    appAudit.setType(AppAuditType.APP_AUDIT.getValue());
    appAuditDao.insertAppAudit(appAudit);
}
Also used : AppAudit(com.sohu.cache.entity.AppAudit) AppUser(com.sohu.cache.entity.AppUser) AppDesc(com.sohu.cache.entity.AppDesc) Date(java.util.Date) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

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