Search in sources :

Example 1 with SystemConfig

use of com.vip.saturn.job.console.mybatis.entity.SystemConfig in project Saturn by vipshop.

the class SystemConfigController method genSystemConfigInfo.

private Map<String, List<SystemConfigVo>> genSystemConfigInfo(Map<String, List<JobConfigMeta>> jobConfigGroups, List<SystemConfig> systemConfigs) {
    Map<String, SystemConfig> systemConfigMap = convertList2Map(systemConfigs);
    Map<String, List<SystemConfigVo>> jobConfigDisplayInfoMap = Maps.newHashMap();
    for (Map.Entry<String, List<JobConfigMeta>> group : jobConfigGroups.entrySet()) {
        List<JobConfigMeta> jobConfigMetas = group.getValue();
        List<SystemConfigVo> jobConfigVos = Lists.newArrayListWithCapacity(jobConfigMetas.size());
        for (JobConfigMeta configMeta : jobConfigMetas) {
            SystemConfig systemConfig = systemConfigMap.get(configMeta.getName());
            String value = systemConfig != null ? systemConfig.getValue() : null;
            jobConfigVos.add(new SystemConfigVo(configMeta.getName(), value, configMeta.getDesc_zh()));
        }
        jobConfigDisplayInfoMap.put(group.getKey(), jobConfigVos);
    }
    return jobConfigDisplayInfoMap;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JobConfigMeta(com.vip.saturn.job.console.domain.JobConfigMeta) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SystemConfigVo(com.vip.saturn.job.console.domain.SystemConfigVo)

Example 2 with SystemConfig

use of com.vip.saturn.job.console.mybatis.entity.SystemConfig in project Saturn by vipshop.

the class SystemConfigController method createOrUpdateConfig.

/**
 * 创建或者更新配置项。
 *
 * @param key 配置key
 * @param value 配置值
 */
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping
public SuccessResponseEntity createOrUpdateConfig(@AuditParam(value = "key") @RequestParam String key, @AuditParam(value = "value") @RequestParam String value) throws SaturnJobConsoleException {
    assertIsPermitted(Permissions.systemConfig);
    SystemConfig systemConfig = new SystemConfig();
    systemConfig.setProperty(key);
    systemConfig.setValue(value);
    systemConfigService.insertOrUpdate(systemConfig);
    return new SuccessResponseEntity();
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with SystemConfig

use of com.vip.saturn.job.console.mybatis.entity.SystemConfig in project Saturn by vipshop.

the class ConsoleConfigController method genSystemConfigInfo.

/**
 * 根据Yaml定义,返回作业配置。
 *
 * @param jobConfigGroups 来自yaml定义的配置展现分类定义
 * @param systemConfigs 数据库的系统配置项
 * @return 配置分组与配置信息map
 */
private Map<String, List<SystemConfigVo>> genSystemConfigInfo(Map<String, List<JobConfigMeta>> jobConfigGroups, List<SystemConfig> systemConfigs) {
    Map<String, SystemConfig> systemConfigMap = convertList2Map(systemConfigs);
    Map<String, List<SystemConfigVo>> jobConfigDisplayInfoMap = Maps.newHashMap();
    Set<String> categorizedConfigKeySet = Sets.newHashSet();
    for (Map.Entry<String, List<JobConfigMeta>> group : jobConfigGroups.entrySet()) {
        List<JobConfigMeta> jobConfigMetas = group.getValue();
        List<SystemConfigVo> jobConfigVos = Lists.newArrayListWithCapacity(jobConfigMetas.size());
        for (JobConfigMeta configMeta : jobConfigMetas) {
            String configName = configMeta.getName();
            SystemConfig systemConfig = systemConfigMap.get(configName);
            String value = systemConfig != null ? systemConfig.getValue() : null;
            jobConfigVos.add(new SystemConfigVo(configName, value, configMeta.getDesc_zh()));
            categorizedConfigKeySet.add(configName);
        }
        jobConfigDisplayInfoMap.put(group.getKey(), jobConfigVos);
    }
    // 将所有没有在yaml定义的配置放到Others组别
    if (categorizedConfigKeySet.size() != systemConfigs.size()) {
        List<SystemConfigVo> unCategorizedJobConfigVos = getUncategorizedSystemConfigs(systemConfigs, categorizedConfigKeySet);
        jobConfigDisplayInfoMap.put("other_configs", unCategorizedJobConfigVos);
    }
    return jobConfigDisplayInfoMap;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JobConfigMeta(com.vip.saturn.job.console.domain.JobConfigMeta) SystemConfigVo(com.vip.saturn.job.console.domain.SystemConfigVo)

Example 4 with SystemConfig

use of com.vip.saturn.job.console.mybatis.entity.SystemConfig in project Saturn by vipshop.

the class ConsoleConfigController method updateConfig.

/**
 * 更新配置项。
 *
 * @param key 配置key
 * @param value 配置值
 */
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/update")
public SuccessResponseEntity updateConfig(@AuditParam(value = "key") @RequestParam String key, @AuditParam(value = "value") @RequestParam String value) throws SaturnJobConsoleException {
    assertIsPermitted(PermissionKeys.systemConfig);
    // 不能更新EXECUTOR_CONFIGS
    if (SystemConfigProperties.EXECUTOR_CONFIGS.equals(key)) {
        throw new SaturnJobConsoleException(String.format("配置项不能为%s", key));
    }
    SystemConfig systemConfig = new SystemConfig();
    systemConfig.setProperty(key);
    systemConfig.setValue(value);
    systemConfigService.updateConfig(systemConfig);
    return new SuccessResponseEntity();
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with SystemConfig

use of com.vip.saturn.job.console.mybatis.entity.SystemConfig in project Saturn by vipshop.

the class ConsoleConfigController method getUncategorizedSystemConfigs.

private List<SystemConfigVo> getUncategorizedSystemConfigs(List<SystemConfig> systemConfigList, Set<String> configKeySet) {
    List<SystemConfigVo> unCategorizedJobConfigVos = Lists.newArrayList();
    for (SystemConfig systemConfig : systemConfigList) {
        String property = systemConfig.getProperty();
        if (configKeySet.contains(property)) {
            continue;
        }
        unCategorizedJobConfigVos.add(new SystemConfigVo(property, systemConfig.getValue(), ""));
    }
    return unCategorizedJobConfigVos;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) SystemConfigVo(com.vip.saturn.job.console.domain.SystemConfigVo)

Aggregations

SystemConfig (com.vip.saturn.job.console.mybatis.entity.SystemConfig)15 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)7 Audit (com.vip.saturn.job.console.aop.annotation.Audit)4 SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)4 ApiResponses (io.swagger.annotations.ApiResponses)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 SystemConfigVo (com.vip.saturn.job.console.domain.SystemConfigVo)3 JobConfigMeta (com.vip.saturn.job.console.domain.JobConfigMeta)2 RequestResult (com.vip.saturn.job.console.domain.RequestResult)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1