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 saveJobConfigToDb.
private void saveJobConfigToDb(String namespace, JobConfig jobConfig, String createdBy) throws SaturnJobConsoleException {
String jobName = jobConfig.getJobName();
JobConfig4DB oldJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (oldJobConfig != null) {
log.warn("when create a new job, a jobConfig with the same name from db exists, will delete it first. namespace:{} and jobName:{}", namespace, jobName);
try {
currentJobConfigService.deleteByPrimaryKey(oldJobConfig.getId());
} catch (Exception e) {
log.error("exception is thrown during delete job config in db", e);
throw new SaturnJobConsoleException("创建作业时,数据库存在已经存在该作业的相关配置!并且清理该配置的时候失败", e);
}
}
JobConfig4DB currentJobConfig = new JobConfig4DB();
SaturnBeanUtils.copyProperties(jobConfig, currentJobConfig);
Date now = new Date();
currentJobConfig.setCreateTime(now);
currentJobConfig.setLastUpdateTime(now);
currentJobConfig.setCreateBy(createdBy);
currentJobConfig.setLastUpdateBy(createdBy);
currentJobConfig.setNamespace(namespace);
try {
currentJobConfigService.create(currentJobConfig);
} catch (Exception e) {
log.error("exception is thrown during creating job config in db", e);
throw new SaturnJobConsoleException(e);
}
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method updateJobConfig.
@Transactional
@Override
public void updateJobConfig(String namespace, UpdateJobConfigVo updateJobConfigVo, String updatedBy) throws SaturnJobConsoleException {
JobConfig jobConfig = updateJobConfigVo.toJobConfig();
JobConfig4DB jobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobConfig.getJobName());
if (jobConfig4DB == null) {
throw new SaturnJobConsoleException(String.format("该作业(%s)不存在", jobConfig.getJobName()));
}
jobConfig.setDefaultValues();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
BooleanWrapper bw = new BooleanWrapper(false);
CuratorRepository.CuratorFrameworkOp.CuratorTransactionOp curatorTransactionOp = null;
try {
curatorTransactionOp = curatorFrameworkOp.inTransaction().replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_JOB_MODE), jobConfig.getJobMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_SHARDING_TOTAL_COUNT), jobConfig.getShardingTotalCount(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_LOAD_LEVEL), jobConfig.getLoadLevel(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_JOB_DEGREE), jobConfig.getJobDegree(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_ENABLED_REPORT), jobConfig.getEnabledReport(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_TIME_ZONE), StringUtils.trim(jobConfig.getTimeZone()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_CRON), StringUtils.trim(jobConfig.getCron()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_PAUSE_PERIOD_DATE), jobConfig.getPausePeriodDate(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_PAUSE_PERIOD_TIME), jobConfig.getPausePeriodTime(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_SHARDING_ITEM_PARAMETERS), jobConfig.getShardingItemParameters(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_JOB_PARAMETER), jobConfig.getJobParameter(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_PROCESS_COUNT_INTERVAL_SECONDS), jobConfig.getProcessCountIntervalSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_TIMEOUT_4_ALARM_SECONDS), jobConfig.getTimeout4AlarmSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_TIMEOUT_SECONDS), jobConfig.getTimeoutSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_DEPENDENCIES), jobConfig.getDependencies(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_GROUPS), jobConfig.getGroups(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_DESCRIPTION), jobConfig.getDescription(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_CHANNEL_NAME), StringUtils.trim(jobConfig.getChannelName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_QUEUE_NAME), StringUtils.trim(jobConfig.getQueueName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_SHOW_NORMAL_LOG), jobConfig.getShowNormalLog(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_PREFER_LIST), jobConfig.getPreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_USE_DISPREFER_LIST), jobConfig.getUseDispreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_FAILOVER), jobConfig.getFailover(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_LOCAL_MODE), jobConfig.getLocalMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobConfig.getJobName(), CONFIG_ITEM_USE_SERIAL), jobConfig.getUseSerial(), bw);
// 当enabledReport关闭上报时,要清理execution节点
if (jobConfig.getEnabledReport() != null && !jobConfig.getEnabledReport()) {
log.info("the switch of enabledReport set to false, now deleteJob the execution zk node");
String executionNodePath = JobNodePath.getExecutionNodePath(jobConfig.getJobName());
if (curatorFrameworkOp.checkExists(executionNodePath)) {
curatorFrameworkOp.deleteRecursive(executionNodePath);
}
}
} catch (Exception e) {
log.error("update settings to zk failed: {}", e);
throw new SaturnJobConsoleException(e);
}
try {
// config changed, update current config and save a copy to history config.
if (bw.isValue()) {
JobConfig4DB newJobConfig4DB = new JobConfig4DB();
SaturnBeanUtils.copyProperties(jobConfig4DB, newJobConfig4DB);
SaturnBeanUtils.copyPropertiesIgnoreNull(jobConfig, newJobConfig4DB);
currentJobConfigService.updateNewAndSaveOld2History(newJobConfig4DB, jobConfig4DB, updatedBy);
}
if (curatorTransactionOp != null) {
curatorTransactionOp.commit();
}
} catch (Exception e) {
log.error("update settings to db failed: {}", e);
throw new SaturnJobConsoleException(e);
}
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method getDependedJobs.
@Override
public List<DependencyJob> getDependedJobs(String namespace, String jobName) throws SaturnJobConsoleException {
JobConfig4DB currentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (currentJobConfig == null) {
throw new SaturnJobConsoleException("不能获取依赖该作业(" + jobName + ")的所有作业,因为该作业不存在");
}
List<DependencyJob> dependencyJobs = new ArrayList<>();
List<JobConfig> unSystemJobs = getUnSystemJobs(namespace);
if (unSystemJobs == null) {
return dependencyJobs;
}
for (JobConfig jobConfig : unSystemJobs) {
if (jobConfig.getJobName().equals(jobName)) {
continue;
}
String dependencies = jobConfig.getDependencies();
if (StringUtils.isNotBlank(dependencies)) {
String[] split = dependencies.split(",");
for (String tmp : split) {
if (jobName.equals(tmp.trim())) {
DependencyJob dependencyJob = new DependencyJob();
dependencyJob.setJobName(jobConfig.getJobName());
dependencyJob.setEnabled(jobConfig.getEnabled());
dependencyJobs.add(dependencyJob);
}
}
}
}
return dependencyJobs;
}
use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.
the class JobServiceImpl method getDependingJobs.
@Override
public List<DependencyJob> getDependingJobs(String namespace, String jobName) throws SaturnJobConsoleException {
JobConfig4DB currentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (currentJobConfig == null) {
throw new SaturnJobConsoleException("不能获取该作业(" + jobName + ")依赖的所有作业,因为该作业不存在");
}
List<DependencyJob> dependencyJobs = new ArrayList<>();
List<JobConfig> unSystemJobs = getUnSystemJobs(namespace);
if (unSystemJobs != null) {
String dependencies = currentJobConfig.getDependencies();
List<String> dependencyList = new ArrayList<>();
if (StringUtils.isNotBlank(dependencies)) {
String[] split = dependencies.split(",");
for (String tmp : split) {
if (StringUtils.isNotBlank(tmp)) {
dependencyList.add(tmp.trim());
}
}
}
if (!dependencyList.isEmpty()) {
for (JobConfig jobConfig : unSystemJobs) {
if (jobConfig.getJobName().equals(jobName)) {
continue;
}
if (dependencyList.contains(jobConfig.getJobName())) {
DependencyJob dependencyJob = new DependencyJob();
dependencyJob.setJobName(jobConfig.getJobName());
dependencyJob.setEnabled(jobConfig.getEnabled());
dependencyJobs.add(dependencyJob);
}
}
}
}
return dependencyJobs;
}
Aggregations