|
|
@ -2,6 +2,7 @@ package com.xxl.job.admin.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobGroup;
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobGroup;
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobInfo;
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobInfo;
|
|
|
|
|
|
|
|
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
|
|
|
|
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
|
|
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
|
|
import com.xxl.job.admin.dao.IXxlJobGroupDao;
|
|
|
|
import com.xxl.job.admin.dao.IXxlJobGroupDao;
|
|
|
|
import com.xxl.job.admin.dao.IXxlJobInfoDao;
|
|
|
|
import com.xxl.job.admin.dao.IXxlJobInfoDao;
|
|
|
@ -64,33 +65,34 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ReturnT<String> add(int jobGroup, String jobCron, String jobDesc, String author, String alarmEmail,
|
|
|
|
public ReturnT<String> add(XxlJobInfo jobInfo) {
|
|
|
|
String executorHandler, String executorParam,
|
|
|
|
|
|
|
|
int glueSwitch, String glueSource, String glueRemark, String childJobKey) {
|
|
|
|
|
|
|
|
// valid
|
|
|
|
// valid
|
|
|
|
XxlJobGroup group = xxlJobGroupDao.load(jobGroup);
|
|
|
|
XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
|
|
|
|
if (group == null) {
|
|
|
|
if (group == null) {
|
|
|
|
return new ReturnT<String>(500, "请选择“执行器”");
|
|
|
|
return new ReturnT<String>(500, "请选择“执行器”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!CronExpression.isValidExpression(jobCron)) {
|
|
|
|
if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
|
|
|
return new ReturnT<String>(500, "请输入格式正确的“Cron”");
|
|
|
|
return new ReturnT<String>(500, "请输入格式正确的“Cron”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(jobDesc)) {
|
|
|
|
if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“任务描述”");
|
|
|
|
return new ReturnT<String>(500, "请输入“任务描述”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(author)) {
|
|
|
|
if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“负责人”");
|
|
|
|
return new ReturnT<String>(500, "请输入“负责人”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(alarmEmail)) {
|
|
|
|
if (StringUtils.isBlank(jobInfo.getAlarmEmail())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“报警邮件”");
|
|
|
|
return new ReturnT<String>(500, "请输入“报警邮件”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (glueSwitch==0 && StringUtils.isBlank(executorHandler)) {
|
|
|
|
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
|
|
|
|
|
|
|
return new ReturnT<String>(500, "路由策略非法");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jobInfo.getGlueSwitch()==0 && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“JobHandler”");
|
|
|
|
return new ReturnT<String>(500, "请输入“JobHandler”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// childJobKey valid
|
|
|
|
// childJobKey valid
|
|
|
|
if (StringUtils.isNotBlank(childJobKey)) {
|
|
|
|
if (StringUtils.isNotBlank(jobInfo.getChildJobKey())) {
|
|
|
|
String[] childJobKeys = childJobKey.split(",");
|
|
|
|
String[] childJobKeys = jobInfo.getChildJobKey().split(",");
|
|
|
|
for (String childJobKeyItem: childJobKeys) {
|
|
|
|
for (String childJobKeyItem: childJobKeys) {
|
|
|
|
String[] childJobKeyArr = childJobKeyItem.split("_");
|
|
|
|
String[] childJobKeyArr = childJobKeyItem.split("_");
|
|
|
|
if (childJobKeyArr.length!=2) {
|
|
|
|
if (childJobKeyArr.length!=2) {
|
|
|
@ -105,8 +107,9 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
|
|
|
|
|
|
|
|
// generate jobName
|
|
|
|
// generate jobName
|
|
|
|
String jobName = FastDateFormat.getInstance("yyyyMMddHHmmssSSSS").format(new Date());
|
|
|
|
String jobName = FastDateFormat.getInstance("yyyyMMddHHmmssSSSS").format(new Date());
|
|
|
|
|
|
|
|
jobInfo.setJobName(jobName);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (XxlJobDynamicScheduler.checkExists(jobName, String.valueOf(jobGroup))) {
|
|
|
|
if (XxlJobDynamicScheduler.checkExists(jobName, String.valueOf(jobInfo.getJobGroup()))) {
|
|
|
|
return new ReturnT<String>(500, "系统繁忙,请稍后重试");
|
|
|
|
return new ReturnT<String>(500, "系统繁忙,请稍后重试");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SchedulerException e1) {
|
|
|
|
} catch (SchedulerException e1) {
|
|
|
@ -115,7 +118,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Backup to the database
|
|
|
|
// Backup to the database
|
|
|
|
XxlJobInfo jobInfo = new XxlJobInfo();
|
|
|
|
/*XxlJobInfo jobInfo = new XxlJobInfo();
|
|
|
|
jobInfo.setJobGroup(jobGroup);
|
|
|
|
jobInfo.setJobGroup(jobGroup);
|
|
|
|
jobInfo.setJobName(jobName);
|
|
|
|
jobInfo.setJobName(jobName);
|
|
|
|
jobInfo.setJobCron(jobCron);
|
|
|
|
jobInfo.setJobCron(jobCron);
|
|
|
@ -127,11 +130,11 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
jobInfo.setGlueSwitch(glueSwitch);
|
|
|
|
jobInfo.setGlueSwitch(glueSwitch);
|
|
|
|
jobInfo.setGlueSource(glueSource);
|
|
|
|
jobInfo.setGlueSource(glueSource);
|
|
|
|
jobInfo.setGlueRemark(glueRemark);
|
|
|
|
jobInfo.setGlueRemark(glueRemark);
|
|
|
|
jobInfo.setChildJobKey(childJobKey);
|
|
|
|
jobInfo.setChildJobKey(childJobKey);*/
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// add job 2 quartz
|
|
|
|
// add job 2 quartz
|
|
|
|
boolean result = XxlJobDynamicScheduler.addJob(String.valueOf(jobGroup), jobName, jobCron);
|
|
|
|
boolean result = XxlJobDynamicScheduler.addJob(String.valueOf(jobInfo.getJobGroup()), jobName, jobInfo.getJobCron());
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
xxlJobInfoDao.save(jobInfo);
|
|
|
|
xxlJobInfoDao.save(jobInfo);
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
@ -145,36 +148,31 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ReturnT<String> reschedule(int jobGroup, String jobName, String jobCron, String jobDesc, String author, String alarmEmail,
|
|
|
|
public ReturnT<String> reschedule(XxlJobInfo jobInfo) {
|
|
|
|
String executorHandler, String executorParam, int glueSwitch, String childJobKey) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// valid
|
|
|
|
// valid
|
|
|
|
XxlJobGroup group = xxlJobGroupDao.load(jobGroup);
|
|
|
|
if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
|
|
|
if (group == null) {
|
|
|
|
|
|
|
|
return new ReturnT<String>(500, "请选择“执行器”");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(jobName)) {
|
|
|
|
|
|
|
|
return new ReturnT<String>(500, "请输入“任务名”");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CronExpression.isValidExpression(jobCron)) {
|
|
|
|
|
|
|
|
return new ReturnT<String>(500, "请输入格式正确的“Cron”");
|
|
|
|
return new ReturnT<String>(500, "请输入格式正确的“Cron”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(jobDesc)) {
|
|
|
|
if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“任务描述”");
|
|
|
|
return new ReturnT<String>(500, "请输入“任务描述”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(author)) {
|
|
|
|
if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“负责人”");
|
|
|
|
return new ReturnT<String>(500, "请输入“负责人”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(alarmEmail)) {
|
|
|
|
if (StringUtils.isBlank(jobInfo.getAlarmEmail())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“报警邮件”");
|
|
|
|
return new ReturnT<String>(500, "请输入“报警邮件”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (glueSwitch==0 && StringUtils.isBlank(executorHandler)) {
|
|
|
|
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
|
|
|
|
|
|
|
return new ReturnT<String>(500, "路由策略非法");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jobInfo.getGlueSwitch()==0 && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
|
|
|
|
return new ReturnT<String>(500, "请输入“JobHandler”");
|
|
|
|
return new ReturnT<String>(500, "请输入“JobHandler”");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// childJobKey valid
|
|
|
|
// childJobKey valid
|
|
|
|
if (StringUtils.isNotBlank(childJobKey)) {
|
|
|
|
if (StringUtils.isNotBlank(jobInfo.getChildJobKey())) {
|
|
|
|
String[] childJobKeys = childJobKey.split(",");
|
|
|
|
String[] childJobKeys = jobInfo.getChildJobKey().split(",");
|
|
|
|
for (String childJobKeyItem: childJobKeys) {
|
|
|
|
for (String childJobKeyItem: childJobKeys) {
|
|
|
|
String[] childJobKeyArr = childJobKeyItem.split("_");
|
|
|
|
String[] childJobKeyArr = childJobKeyItem.split("_");
|
|
|
|
if (childJobKeyArr.length!=2) {
|
|
|
|
if (childJobKeyArr.length!=2) {
|
|
|
@ -188,21 +186,26 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// stage job info
|
|
|
|
// stage job info
|
|
|
|
XxlJobInfo jobInfo = xxlJobInfoDao.load(jobGroup, jobName);
|
|
|
|
XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
|
|
|
|
jobInfo.setJobCron(jobCron);
|
|
|
|
if (exists_jobInfo == null) {
|
|
|
|
jobInfo.setJobDesc(jobDesc);
|
|
|
|
return new ReturnT<String>(500, "参数异常");
|
|
|
|
jobInfo.setAuthor(author);
|
|
|
|
}
|
|
|
|
jobInfo.setAlarmEmail(alarmEmail);
|
|
|
|
|
|
|
|
jobInfo.setExecutorHandler(executorHandler);
|
|
|
|
exists_jobInfo.setJobCron(jobInfo.getJobCron());
|
|
|
|
jobInfo.setExecutorParam(executorParam);
|
|
|
|
exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
|
|
|
|
jobInfo.setGlueSwitch(glueSwitch);
|
|
|
|
exists_jobInfo.setAuthor(jobInfo.getAuthor());
|
|
|
|
jobInfo.setChildJobKey(childJobKey);
|
|
|
|
exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
|
|
|
|
|
|
|
|
exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
|
|
|
|
|
|
|
|
exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
|
|
|
|
|
|
|
|
exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam());
|
|
|
|
|
|
|
|
exists_jobInfo.setGlueSwitch(jobInfo.getGlueSwitch());
|
|
|
|
|
|
|
|
exists_jobInfo.setChildJobKey(jobInfo.getChildJobKey());
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// fresh quartz
|
|
|
|
// fresh quartz
|
|
|
|
boolean ret = XxlJobDynamicScheduler.rescheduleJob(String.valueOf(jobGroup), jobName, jobCron);
|
|
|
|
boolean ret = XxlJobDynamicScheduler.rescheduleJob(String.valueOf(exists_jobInfo.getJobGroup()), exists_jobInfo.getJobName(), exists_jobInfo.getJobCron());
|
|
|
|
if (ret) {
|
|
|
|
if (ret) {
|
|
|
|
xxlJobInfoDao.update(jobInfo);
|
|
|
|
xxlJobInfoDao.update(exists_jobInfo);
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return new ReturnT<String>(500, "更新任务失败");
|
|
|
|
return new ReturnT<String>(500, "更新任务失败");
|
|
|
@ -215,11 +218,13 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ReturnT<String> remove(int jobGroup, String jobName) {
|
|
|
|
public ReturnT<String> remove(int jobGroup, String jobName) {
|
|
|
|
|
|
|
|
XxlJobInfo xxlJobInfo = xxlJobInfoDao.load(jobGroup, jobName);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
XxlJobDynamicScheduler.removeJob(jobName, String.valueOf(jobGroup));
|
|
|
|
XxlJobDynamicScheduler.removeJob(jobName, String.valueOf(jobGroup));
|
|
|
|
xxlJobInfoDao.delete(jobGroup, jobName);
|
|
|
|
xxlJobInfoDao.delete(jobGroup, jobName);
|
|
|
|
xxlJobLogDao.delete(jobGroup, jobName);
|
|
|
|
xxlJobLogDao.delete(jobGroup, jobName);
|
|
|
|
xxlJobLogGlueDao.delete(jobGroup, jobName);
|
|
|
|
xxlJobLogGlueDao.deleteByJobId(xxlJobInfo.getId());
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
} catch (SchedulerException e) {
|
|
|
|
} catch (SchedulerException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|