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 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);
}
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class ZkDBDiffServiceImpl method diffByNamespace.
@Override
public List<JobDiffInfo> diffByNamespace(String namespace) throws SaturnJobConsoleException {
long startTime = System.currentTimeMillis();
List<JobDiffInfo> jobDiffInfos = Lists.newArrayList();
CuratorRepository.CuratorFrameworkOp zkClient;
try {
List<JobConfig4DB> dbJobConfigList = currentJobConfigService.findConfigsByNamespace(namespace);
if (dbJobConfigList == null || dbJobConfigList.isEmpty()) {
return jobDiffInfos;
}
zkClient = initCuratorClient(namespace);
if (zkClient == null) {
return jobDiffInfos;
}
Set<String> jobNamesInDb = getAllJobNames(dbJobConfigList);
for (JobConfig4DB dbJobConfig : dbJobConfigList) {
String jobName = dbJobConfig.getJobName();
log.info("start to diff job:{}@{}", jobName, namespace);
if (!checkJobIsExsitInZk(jobName, zkClient)) {
jobDiffInfos.add(new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.DB_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()));
continue;
}
JobConfig jobConfigFromZK = jobService.getJobConfigFromZK(namespace, jobName);
JobDiffInfo jobDiffInfo = diff(namespace, dbJobConfig, jobConfigFromZK, false);
if (jobDiffInfo != null) {
jobDiffInfos.add(jobDiffInfo);
}
}
List<JobDiffInfo> jobsInZkOnly = getJobNamesWhichInZKOnly(namespace, jobNamesInDb);
if (jobsInZkOnly != null && !jobsInZkOnly.isEmpty()) {
jobDiffInfos.addAll(jobsInZkOnly);
}
} catch (SaturnJobConsoleException e) {
log.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("exception throws during diff by namespace [{}]", namespace, e);
throw new SaturnJobConsoleException(e);
} finally {
log.info("Finish diff namespace:{} which cost {}ms", namespace, System.currentTimeMillis() - startTime);
}
return jobDiffInfos;
}
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);
}
Aggregations