use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobOperationServiceImpl method saveCronToDb.
private void saveCronToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newCustomContextStr, String newCron) throws SaturnJobConsoleException, SaturnJobConsoleHttpException {
String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (oldCurrentJobConfig == null) {
String errorMsg = "在DB找不到该作业的配置, namespace:" + namespace + " jobname:" + jobName;
log.error(errorMsg);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMsg);
}
CurrentJobConfig newCurrentJobConfig = mapper.map(oldCurrentJobConfig, CurrentJobConfig.class);
if (newCustomContextStr != null) {
newCurrentJobConfig.setCustomContext(newCustomContextStr);
}
if (newCron != null) {
newCurrentJobConfig.setCron(newCron);
}
try {
currentJobConfigService.updateConfigAndSave2History(newCurrentJobConfig, oldCurrentJobConfig, null);
} catch (Exception e) {
log.error("exception is thrown during change job state in db", e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobOperationServiceImpl method saveJobConfigToDb.
private void saveJobConfigToDb(JobConfig jobConfig, CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
String jobName = jobConfig.getJobName();
String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
CurrentJobConfig 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 SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "创建作业时,数据库存在已经存在该作业的相关配置!并且清理该配置的时候失败", e);
}
}
CurrentJobConfig currentJobConfig = new CurrentJobConfig();
mapper.map(jobConfig, currentJobConfig);
currentJobConfig.setCreateTime(new Date());
currentJobConfig.setLastUpdateTime(new Date());
currentJobConfig.setNamespace(namespace);
try {
currentJobConfigService.create(currentJobConfig);
} catch (Exception e) {
log.error("exception is thrown during creating job config in db", e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobOperationServiceImpl method setJobEnabledState.
@Transactional
@Override
public void setJobEnabledState(String jobName, boolean state) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (oldCurrentJobConfig != null) {
oldCurrentJobConfig.setEnabled(state);
oldCurrentJobConfig.setLastUpdateTime(new Date());
try {
currentJobConfigService.updateByPrimaryKey(oldCurrentJobConfig);
} catch (Exception e) {
log.error("exception is thrown during change job state in db", e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
} else {
log.warn("job:{} not existed in db", jobName);
}
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, "enabled"), state);
}
Aggregations