Search in sources :

Example 11 with SystemConfig

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

the class ExecutorConfigController method createOrUpdateConfig.

@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(PermissionKeys.systemConfig);
    String executorConfigsJsonInDB = systemConfigService.getValueDirectly(SystemConfigProperties.EXECUTOR_CONFIGS);
    JSONObject jsonObject = parseExecutorConfigJson(executorConfigsJsonInDB);
    if (jsonObject == null) {
        jsonObject = new JSONObject();
    }
    // I'm sure that key and value is not null, because @RequestParam required is true
    jsonObject.put(key.trim(), value.trim());
    String configStr = jsonObject.toJSONString();
    log.info("Start to update executor config data {}", configStr);
    // update zk
    List<ZkCluster> onlineZkClusterList = registryCenterService.getOnlineZkClusterList();
    for (ZkCluster zkCluster : onlineZkClusterList) {
        updateConfigInZk(configStr, zkCluster);
    }
    // update db
    SystemConfig systemConfig = new SystemConfig();
    systemConfig.setProperty(SystemConfigProperties.EXECUTOR_CONFIGS);
    systemConfig.setValue(configStr);
    systemConfigService.insertOrUpdate(systemConfig);
    log.info("Update executor config to db successfully");
    return new SuccessResponseEntity();
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JSONObject(com.alibaba.fastjson.JSONObject) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with SystemConfig

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

the class ConsoleConfigController method createConfig.

/**
 * 创建配置项。
 *
 * @param key 配置key
 * @param value 配置值
 */
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/create")
public SuccessResponseEntity createConfig(@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.createConfig(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 13 with SystemConfig

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

the class SystemConfigServiceImpl method insertOrUpdate.

@Override
public Integer insertOrUpdate(SystemConfig systemConfig) throws SaturnJobConsoleException {
    List<String> properties = new ArrayList<>();
    properties.add(systemConfig.getProperty());
    List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByPropertiesAndLastly(properties);
    if (systemConfigs != null && systemConfigs.size() > 0) {
        SystemConfig systemConfig1 = systemConfigs.get(0);
        if (systemConfig1 != null) {
            systemConfig1.setProperty(systemConfig.getProperty());
            systemConfig1.setValue(systemConfig.getValue());
            int result = systemConfig4SqlService.updateById(systemConfig1);
            updateCacheIfNeed(systemConfig, result);
            return result;
        }
    }
    int result = systemConfig4SqlService.insert(systemConfig);
    updateCacheIfNeed(systemConfig, result);
    return result;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig)

Example 14 with SystemConfig

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

the class SystemConfigServiceImpl method updateConfig.

@Override
public Integer updateConfig(SystemConfig systemConfig) throws SaturnJobConsoleException {
    List<String> properties = new ArrayList<>();
    properties.add(systemConfig.getProperty());
    List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByPropertiesAndLastly(properties);
    if (systemConfigs == null || systemConfigs.isEmpty()) {
        throw new SaturnJobConsoleException(String.format("systemConfig %s not existed, update fail", systemConfig.getProperty()));
    }
    SystemConfig config = systemConfigs.get(0);
    config.setProperty(systemConfig.getProperty());
    config.setValue(systemConfig.getValue());
    int result = systemConfig4SqlService.updateById(config);
    updateCacheIfNeed(systemConfig, result);
    return result;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 15 with SystemConfig

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

the class SystemConfigServiceImpl method loadAll.

private void loadAll() {
    try {
        log.info("begin to get system config from db");
        List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByLastly();
        synchronized (systemConfigCache) {
            systemConfigCache.clear();
            if (systemConfigs != null && !systemConfigs.isEmpty()) {
                for (SystemConfig systemConfig : systemConfigs) {
                    systemConfigCache.put(systemConfig.getProperty(), systemConfig.getValue());
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        log.info("end get system config from db");
        hasGotSystemConfigData.compareAndSet(false, true);
    }
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

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