use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method getJobStatus.
@Override
public JobStatus getJobStatus(String namespace, String jobName) throws SaturnJobConsoleException {
JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (jobConfig == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能获取该作业(" + jobName + ")的状态,因为该作业不存在");
}
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
return getJobStatus(jobName, curatorFrameworkOp, jobConfig.getEnabled());
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method getUnSystemJobNames.
@Override
public List<String> getUnSystemJobNames(String namespace) throws SaturnJobConsoleException {
List<String> unSystemJobs = new ArrayList<>();
List<JobConfig4DB> jobConfig4DBList = currentJobConfigService.findConfigsByNamespace(namespace);
if (jobConfig4DBList != null) {
for (JobConfig4DB jobConfig4DB : jobConfig4DBList) {
if (!(StringUtils.isNotBlank(jobConfig4DB.getJobMode()) && jobConfig4DB.getJobMode().startsWith(JobMode.SYSTEM_PREFIX))) {
unSystemJobs.add(jobConfig4DB.getJobName());
}
}
}
return unSystemJobs;
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method updateJobConfig.
@Transactional(rollbackFor = Exception.class)
@Override
public void updateJobConfig(String namespace, JobConfig jobConfig, String updatedBy) throws SaturnJobConsoleException {
JobConfig4DB oldJobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobConfig.getJobName());
if (oldJobConfig4DB == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format("该作业(%s)不存在", jobConfig.getJobName()));
}
// 从数据库拿出老的数据,将需要更新的数据赋值(为空的字段视为不需要更新)
JobConfig4DB newJobConfig4DB = new JobConfig4DB();
SaturnBeanUtils.copyProperties(oldJobConfig4DB, newJobConfig4DB);
SaturnBeanUtils.copyPropertiesIgnoreNull(jobConfig, newJobConfig4DB);
// 与老的数据库中的该作业的配置对比,如果没有改变,则直接返回
if (oldJobConfig4DB.equals(newJobConfig4DB)) {
return;
}
// 设置作业配置字段默认值,并且强制纠正某些字段
correctConfigValueWhenUpdateJob(newJobConfig4DB);
// 校验作业配置
List<JobConfig> unSystemJobs = getUnSystemJobs(namespace);
Set<JobConfig> streamChangedJobs = new HashSet<>();
validateJobConfig(namespace, newJobConfig4DB, unSystemJobs, streamChangedJobs);
// 更新该作业到数据库
currentJobConfigService.updateNewAndSaveOld2History(newJobConfig4DB, oldJobConfig4DB, updatedBy);
// 更新关联作业的上下游
for (JobConfig streamChangedJob : streamChangedJobs) {
currentJobConfigService.updateStream(constructJobConfig4DB(namespace, streamChangedJob, null, updatedBy));
}
// 更新作业配置到zk,并联动更新关联作业的上下游
updateJobConfigToZk(newJobConfig4DB, streamChangedJobs, registryCenterService.getCuratorFrameworkOp(namespace));
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method disableJob.
@Transactional(rollbackFor = Exception.class)
@Override
public void disableJob(String namespace, String jobName, String updatedBy) throws SaturnJobConsoleException {
JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (jobConfig == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能禁用该作业(" + jobName + "),因为该作业不存在");
}
if (!jobConfig.getEnabled()) {
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "该作业(" + jobName + ")已经处于禁用状态");
}
jobConfig.setEnabled(Boolean.FALSE);
jobConfig.setLastUpdateTime(new Date());
jobConfig.setLastUpdateBy(updatedBy);
currentJobConfigService.updateByPrimaryKey(jobConfig);
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED), false);
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class UpdateJobConfigServiceImpl method batchUpdatePreferList.
@Override
public void batchUpdatePreferList(List<JobConfigInfo> jobConfigInfos) throws UpdateJobConfigException {
if (CollectionUtils.isEmpty(jobConfigInfos)) {
return;
}
List<JobConfig4DB> currentJobConfigs = new ArrayList<JobConfig4DB>();
JobConfig4DB currentJobConfig = null;
for (JobConfigInfo jobConfigInfo : jobConfigInfos) {
currentJobConfig = new JobConfig4DB();
currentJobConfig.setNamespace(jobConfigInfo.getNamespace());
currentJobConfig.setJobName(jobConfigInfo.getJobName());
currentJobConfig.setPreferList(jobConfigInfo.getPerferList());
currentJobConfigs.add(currentJobConfig);
}
try {
currentJobConfigService.batchUpdatePreferList(currentJobConfigs);
} catch (SaturnJobConsoleException e) {
throw new UpdateJobConfigException(e);
}
}
Aggregations