use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp.CuratorTransactionOp in project Saturn by vipshop.
the class JobDimensionServiceImpl method updateJobSettings.
@Transactional
@Override
public String updateJobSettings(final JobSettings jobSettings, RegistryCenterConfiguration configInSession) {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
// Modify JobSettings.updateFields() sync, if the update fields changed.
jobSettings.setDefaultValues();
BooleanWrapper bw = new BooleanWrapper(false);
CuratorTransactionOp curatorTransactionOp = null;
try {
curatorTransactionOp = curatorFrameworkOp.inTransaction().replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobMode"), jobSettings.getJobMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "shardingTotalCount"), jobSettings.getShardingTotalCount(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "loadLevel"), jobSettings.getLoadLevel(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobDegree"), jobSettings.getJobDegree(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "enabledReport"), jobSettings.getEnabledReport(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeZone"), StringUtils.trim(jobSettings.getTimeZone()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "cron"), StringUtils.trim(jobSettings.getCron()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "pausePeriodDate"), jobSettings.getPausePeriodDate(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "pausePeriodTime"), jobSettings.getPausePeriodTime(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "shardingItemParameters"), jobSettings.getShardingItemParameters(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobParameter"), jobSettings.getJobParameter(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "processCountIntervalSeconds"), jobSettings.getProcessCountIntervalSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeout4AlarmSeconds"), jobSettings.getTimeout4AlarmSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeoutSeconds"), jobSettings.getTimeoutSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "dependencies"), jobSettings.getDependencies(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "groups"), jobSettings.getGroups(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "description"), jobSettings.getDescription(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "channelName"), StringUtils.trim(jobSettings.getChannelName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "queueName"), StringUtils.trim(jobSettings.getQueueName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "showNormalLog"), jobSettings.getShowNormalLog(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "preferList"), jobSettings.getPreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "useDispreferList"), jobSettings.getUseDispreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "failover"), jobSettings.getFailover(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "localMode"), jobSettings.getLocalMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "useSerial"), jobSettings.getUseSerial(), bw);
if (jobSettings.getEnabledReport() != null && !jobSettings.getEnabledReport()) {
// 当enabledReport关闭上报时,要清理execution节点
log.info("the switch of enabledReport set to false, now deleteJob the execution zk node");
String executionNodePath = JobNodePath.getExecutionNodePath(jobSettings.getJobName());
if (curatorFrameworkOp.checkExists(executionNodePath)) {
curatorFrameworkOp.deleteRecursive(executionNodePath);
}
}
} catch (Exception e) {
log.error("update settings to zk failed: {}", e.getMessage());
log.error(e.getMessage(), e);
return e.getMessage();
}
try {
CurrentJobConfig jobconfig = currentJobConfigService.findConfigByNamespaceAndJobName(configInSession.getNamespace(), jobSettings.getJobName());
// config not exists, save it to current config.
if (jobconfig == null) {
CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
current.setNamespace(configInSession.getNamespace());
current.setCreateTime(new Date());
current.setLastUpdateTime(new Date());
currentJobConfigService.create(current);
} else if (bw.isValue()) {
// config changed, update current config and save a copy to history config.
currentJobConfigService.updateConfigAndSave2History(jobconfig, jobSettings, null);
}
if (curatorTransactionOp != null) {
curatorTransactionOp.commit();
}
} catch (Exception e) {
log.error("update settings to db failed: {}", e.getMessage());
log.error(e.getMessage(), e);
return e.getMessage();
}
return null;
}
Aggregations