Search in sources :

Example 1 with SystemConfig

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

the class ConfigManageController method getDifConfigMap.

private Map<String, String> getDifConfigMap(List<SystemConfig> oldConfigList, Map<String, String> configMap) {
    Map<String, String> systemDifConfigMap = new HashMap<String, String>();
    for (SystemConfig systemConfig : oldConfigList) {
        String key = systemConfig.getConfigKey();
        String oldValue = systemConfig.getConfigValue();
        String newValue = configMap.get(key);
        if (newValue != null && !oldValue.equals(newValue)) {
            systemDifConfigMap.put(systemConfig.getInfo(), String.format("old value: %s, new value: %s", oldValue, newValue));
        }
    }
    return systemDifConfigMap;
}
Also used : SystemConfig(com.sohu.cache.entity.SystemConfig) HashMap(java.util.HashMap)

Example 2 with SystemConfig

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

the class ConfigServiceImpl method getConfigMap.

/**
     * 获取所有配置的key-value
     * 
     * @return
     */
private Map<String, String> getConfigMap() {
    Map<String, String> configMap = new LinkedHashMap<String, String>();
    List<SystemConfig> systemConfigList = getConfigList(1);
    for (SystemConfig systemConfig : systemConfigList) {
        configMap.put(systemConfig.getConfigKey(), systemConfig.getConfigValue());
    }
    return configMap;
}
Also used : SystemConfig(com.sohu.cache.entity.SystemConfig) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with SystemConfig

use of com.sohu.cache.entity.SystemConfig 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)

Aggregations

SystemConfig (com.sohu.cache.entity.SystemConfig)3 HashMap (java.util.HashMap)2 AppUser (com.sohu.cache.entity.AppUser)1 SuccessEnum (com.sohu.cache.web.enums.SuccessEnum)1 LinkedHashMap (java.util.LinkedHashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1