Search in sources :

Example 6 with SuccessEnum

use of com.sohu.cache.web.enums.SuccessEnum in project cachecloud by sohutv.

the class ConfigManageController method update.

/**
     * 修改配置
     * 
     * @param request
     * @param response
     * @param model
     * @return
     */
@RequestMapping(value = "/update")
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    logger.warn("user {} want to change config!", appUser.getName());
    List<SystemConfig> oldConfigList = configService.getConfigList(1);
    SuccessEnum successEnum;
    Map<String, String> configMap = new HashMap<String, String>();
    try {
        Map<String, String[]> paramMap = request.getParameterMap();
        for (Entry<String, String[]> entry : paramMap.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue()[0];
            if (StringUtils.isNotBlank(key)) {
                configMap.put(key, value);
            }
        }
        if (MapUtils.isEmpty(configMap)) {
            logger.error("params {} may be empty!!", paramMap);
        }
        successEnum = configService.updateConfig(configMap);
        if (successEnum.equals(SuccessEnum.SUCCESS)) {
            configService.reloadSystemConfig();
        }
    } catch (Exception e) {
        successEnum = SuccessEnum.FAIL;
        logger.error(e.getMessage(), e);
    }
    Map<String, String> systemDifConfigMap = getDifConfigMap(oldConfigList, configMap);
    appEmailUtil.sendSystemConfigDifEmail(appUser, systemDifConfigMap, successEnum);
    logger.warn("user {} change config result is {}!", appUser.getName(), successEnum.value());
    return new ModelAndView("redirect:/manage/config/init?success=" + successEnum.value());
}
Also used : SystemConfig(com.sohu.cache.entity.SystemConfig) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with SuccessEnum

use of com.sohu.cache.web.enums.SuccessEnum in project cachecloud by sohutv.

the class InstanceAlertValueController method update.

/**
     * 修改配置
     */
@RequestMapping(value = "/update")
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    String configKey = request.getParameter("configKey");
    String alertValue = request.getParameter("alertValue");
    int compareType = NumberUtils.toInt(request.getParameter("compareType"));
    int valueType = NumberUtils.toInt(request.getParameter("valueType"));
    String info = request.getParameter("info");
    int status = NumberUtils.toInt(request.getParameter("status"), -1);
    if (StringUtils.isBlank(configKey) || status > 1 || status < 0) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + ",configKey=" + configKey + ",alertValue=" + alertValue + ",status=" + status);
        return new ModelAndView("");
    }
    //开始修改
    logger.warn("user {} want to change instance alert configKey={}, alertValue={}, info={}, status={}", appUser.getName(), configKey, alertValue, info, status);
    SuccessEnum successEnum;
    InstanceAlert instanceAlert = instanceAlertValueService.getByConfigKey(configKey);
    try {
        instanceAlert.setAlertValue(alertValue);
        instanceAlert.setValueType(valueType);
        instanceAlert.setInfo(info);
        instanceAlert.setStatus(status);
        instanceAlert.setCompareType(compareType);
        instanceAlertValueService.saveOrUpdate(instanceAlert);
        successEnum = SuccessEnum.SUCCESS;
    } catch (Exception e) {
        successEnum = SuccessEnum.FAIL;
        model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
        logger.error(e.getMessage(), e);
    }
    logger.warn("user {} want to change instance alert configKey={}, alertValue={}, info={}, status={}, result is {}", appUser.getName(), configKey, alertValue, info, status, successEnum.value());
    model.addAttribute("status", successEnum.value());
    return new ModelAndView("");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) InstanceAlert(com.sohu.cache.entity.InstanceAlert) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with SuccessEnum

use of com.sohu.cache.web.enums.SuccessEnum in project cachecloud by sohutv.

the class InstanceAlertValueController method add.

/**
     * 添加配置
     */
@RequestMapping(value = "/add")
public ModelAndView add(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    InstanceAlert instanceAlert = getInstanceAlert(request);
    if (StringUtils.isBlank(instanceAlert.getConfigKey())) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "configKey=" + instanceAlert.getConfigKey());
        return new ModelAndView("");
    }
    logger.warn("user {} want to add instance alert, configKey is {}, alertValue is {}, info is {}, orderId is {}", appUser.getName(), instanceAlert.getConfigKey(), instanceAlert.getAlertValue(), instanceAlert.getInfo(), instanceAlert.getOrderId());
    SuccessEnum successEnum;
    try {
        instanceAlertValueService.saveOrUpdate(instanceAlert);
        successEnum = SuccessEnum.SUCCESS;
    } catch (Exception e) {
        successEnum = SuccessEnum.FAIL;
        model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
        logger.error(e.getMessage(), e);
    }
    logger.warn("user {} want to add instance alert, configKey is {}, alertValue is {}, info is {}, orderId is {}, result is {}", appUser.getName(), instanceAlert.getConfigKey(), instanceAlert.getAlertValue(), instanceAlert.getInfo(), instanceAlert.getOrderId(), successEnum.info());
    model.addAttribute("status", successEnum.value());
    return new ModelAndView("");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) InstanceAlert(com.sohu.cache.entity.InstanceAlert) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with SuccessEnum

use of com.sohu.cache.web.enums.SuccessEnum in project cachecloud by sohutv.

the class AppManageController method doUpdateAppImportantLevel.

/**
     * 应用重要性级别
     */
@RequestMapping(value = "/updateAppImportantLevel")
public ModelAndView doUpdateAppImportantLevel(HttpServletRequest request, HttpServletResponse response, Model model) {
    long appId = NumberUtils.toLong(request.getParameter("appId"));
    int importantLevel = NumberUtils.toInt(request.getParameter("importantLevel"));
    SuccessEnum successEnum = SuccessEnum.FAIL;
    if (appId > 0 && importantLevel >= 0) {
        try {
            AppDesc appDesc = appService.getByAppId(appId);
            appDesc.setImportantLevel(importantLevel);
            appService.update(appDesc);
            successEnum = SuccessEnum.SUCCESS;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
    model.addAttribute("status", successEnum.value());
    return new ModelAndView("");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) ParseException(java.text.ParseException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with SuccessEnum

use of com.sohu.cache.web.enums.SuccessEnum in project cachecloud by sohutv.

the class RedisConfigTemplateController method add.

/**
     * 添加配置
     */
@RequestMapping(value = "/add")
public ModelAndView add(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    InstanceConfig instanceConfig = getInstanceConfig(request);
    if (StringUtils.isBlank(instanceConfig.getConfigKey())) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "configKey=" + instanceConfig.getConfigKey());
        return new ModelAndView("");
    }
    logger.warn("user {} want to add config, configKey is {}, configValue is {}, type is {}", appUser.getName(), instanceConfig.getConfigKey(), instanceConfig.getType());
    SuccessEnum successEnum;
    try {
        redisConfigTemplateService.saveOrUpdate(instanceConfig);
        successEnum = SuccessEnum.SUCCESS;
    } catch (Exception e) {
        successEnum = SuccessEnum.FAIL;
        model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
        logger.error(e.getMessage(), e);
    }
    logger.warn("user {} want to add config, configKey is {}, configValue is {}, type is {}, result is {}", appUser.getName(), instanceConfig.getConfigKey(), instanceConfig.getConfigValue(), instanceConfig.getType(), successEnum.value());
    model.addAttribute("status", successEnum.value());
    //发送邮件通知
    appEmailUtil.sendRedisConfigTemplateChangeEmail(appUser, instanceConfig, successEnum, RedisConfigTemplateChangeEnum.ADD);
    return new ModelAndView("");
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SuccessEnum (com.sohu.cache.web.enums.SuccessEnum)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ModelAndView (org.springframework.web.servlet.ModelAndView)9 AppUser (com.sohu.cache.entity.AppUser)8 InstanceConfig (com.sohu.cache.entity.InstanceConfig)3 InstanceAlert (com.sohu.cache.entity.InstanceAlert)2 ParseException (java.text.ParseException)2 AppAudit (com.sohu.cache.entity.AppAudit)1 SystemConfig (com.sohu.cache.entity.SystemConfig)1 HighchartPoint (com.sohu.cache.web.chart.model.HighchartPoint)1 HashMap (java.util.HashMap)1