Search in sources :

Example 1 with InstanceConfig

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

the class RedisConfigTemplateServiceImpl method handleSentinelConfig.

@Override
public List<String> handleSentinelConfig(String masterName, String host, int port, int sentinelPort) {
    List<InstanceConfig> instanceConfigList = instanceConfigDao.getByType(ConstUtils.CACHE_REDIS_SENTINEL);
    if (CollectionUtils.isEmpty(instanceConfigList)) {
        return Collections.emptyList();
    }
    List<String> configs = new ArrayList<String>();
    for (InstanceConfig instanceConfig : instanceConfigList) {
        if (!instanceConfig.isEffective()) {
            continue;
        }
        String configKey = instanceConfig.getConfigKey();
        String configValue = instanceConfig.getConfigValue();
        if (StringUtils.isBlank(configValue)) {
            configValue = SPECIAL_EMPTY_STR;
        }
        if (RedisSentinelConfigEnum.PORT.getKey().equals(configKey)) {
            configValue = String.format(configValue, sentinelPort);
        } else if (RedisSentinelConfigEnum.MONITOR.getKey().equals(configKey)) {
            configValue = String.format(configValue, masterName, host, port);
        } else if (RedisSentinelConfigEnum.DOWN_AFTER_MILLISECONDS.getKey().equals(configKey) || RedisSentinelConfigEnum.FAILOVER_TIMEOUT.getKey().equals(configKey) || RedisSentinelConfigEnum.PARALLEL_SYNCS.getKey().equals(configKey)) {
            configValue = String.format(configValue, masterName);
        } else if (RedisConfigEnum.DIR.getKey().equals(configKey)) {
            configValue = MachineProtocol.DATA_DIR;
        }
        configs.add(combineConfigKeyValue(configKey, configValue));
    }
    return configs;
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) ArrayList(java.util.ArrayList)

Example 2 with InstanceConfig

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

the class RedisConfigTemplateController method remove.

/**
     * 删除配置
     */
@RequestMapping(value = "/remove")
public ModelAndView remove(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    String idParam = request.getParameter("id");
    long id = NumberUtils.toLong(idParam);
    if (id <= 0) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "id=" + idParam);
        return new ModelAndView("");
    }
    logger.warn("user {} want to delete id={}'s config", appUser.getName(), id);
    SuccessEnum successEnum;
    InstanceConfig instanceConfig = redisConfigTemplateService.getById(id);
    try {
        redisConfigTemplateService.remove(id);
        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 delete id={}'s config, result is {}", appUser.getName(), id, successEnum.value());
    //发送邮件通知
    appEmailUtil.sendRedisConfigTemplateChangeEmail(appUser, instanceConfig, successEnum, RedisConfigTemplateChangeEnum.DELETE);
    model.addAttribute("status", successEnum.value());
    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)

Example 3 with InstanceConfig

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

the class RedisConfigTemplateController method getInstanceConfig.

/**
     * 使用最简单的request生成InstanceConfig对象
     * 
     * @return
     */
private InstanceConfig getInstanceConfig(HttpServletRequest request) {
    String configKey = request.getParameter("configKey");
    String configValue = request.getParameter("configValue");
    String info = request.getParameter("info");
    String type = request.getParameter("type");
    InstanceConfig instanceConfig = new InstanceConfig();
    instanceConfig.setConfigKey(configKey);
    instanceConfig.setConfigValue(configValue);
    instanceConfig.setInfo(info);
    instanceConfig.setType(NumberUtils.toInt(type));
    instanceConfig.setStatus(1);
    return instanceConfig;
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig)

Example 4 with InstanceConfig

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

Example 5 with InstanceConfig

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

the class RedisConfigTemplateController method update.

/**
     * 修改配置
     */
@RequestMapping(value = "/update")
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    String id = request.getParameter("id");
    String configKey = request.getParameter("configKey");
    String configValue = request.getParameter("configValue");
    String info = request.getParameter("info");
    int status = NumberUtils.toInt(request.getParameter("status"), -1);
    if (StringUtils.isBlank(id) || !NumberUtils.isDigits(id) || StringUtils.isBlank(configKey) || status > 1 || status < 0) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "id=" + id + ",configKey=" + configKey + ",configValue=" + configValue + ",status=" + status);
        return new ModelAndView("");
    }
    //开始修改
    logger.warn("user {} want to change id={}'s configKey={}, configValue={}, info={}, status={}", appUser.getName(), id, configKey, configValue, info, status);
    SuccessEnum successEnum;
    InstanceConfig instanceConfig = redisConfigTemplateService.getById(NumberUtils.toLong(id));
    try {
        instanceConfig.setConfigValue(configValue);
        instanceConfig.setInfo(info);
        instanceConfig.setStatus(status);
        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 change id={}'s configKey={}, configValue={}, info={}, status={}, result is {}", appUser.getName(), id, configKey, configValue, info, status, successEnum.value());
    //发送邮件通知
    appEmailUtil.sendRedisConfigTemplateChangeEmail(appUser, instanceConfig, successEnum, RedisConfigTemplateChangeEnum.UPDATE);
    model.addAttribute("status", successEnum.value());
    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

InstanceConfig (com.sohu.cache.entity.InstanceConfig)10 AppUser (com.sohu.cache.entity.AppUser)3 SuccessEnum (com.sohu.cache.web.enums.SuccessEnum)3 BaseTest (com.sohu.test.BaseTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 Date (java.util.Date)1 Random (java.util.Random)1