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();
}
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();
}
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;
}
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;
}
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);
}
}
Aggregations