|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.xxl.job.admin.service.impl;
|
2
|
2
|
|
|
3
|
+import com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum;
|
3
|
4
|
import com.xxl.job.admin.core.model.XxlJobGroup;
|
4
|
5
|
import com.xxl.job.admin.core.model.XxlJobInfo;
|
5
|
6
|
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
|
|
@@ -8,6 +9,7 @@ import com.xxl.job.admin.core.thread.JobRegistryHelper;
|
8
|
9
|
import com.xxl.job.admin.dao.*;
|
9
|
10
|
import com.xxl.job.admin.service.IXxlJobService;
|
10
|
11
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
12
|
+import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
11
|
13
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
12
|
14
|
import com.xxl.job.core.registry.RegistHelper;
|
13
|
15
|
import org.apache.commons.collections.CollectionUtils;
|
|
@@ -68,25 +70,31 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
68
|
70
|
// valid
|
69
|
71
|
XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
|
70
|
72
|
if (group == null) {
|
71
|
|
- return new ReturnT<String>(500, "请选择“执行器”");
|
|
73
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请选择“执行器”");
|
72
|
74
|
}
|
73
|
75
|
if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
74
|
|
- return new ReturnT<String>(500, "请输入格式正确的“Cron”");
|
|
76
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入格式正确的“Cron”");
|
75
|
77
|
}
|
76
|
78
|
if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
77
|
|
- return new ReturnT<String>(500, "请输入“任务描述”");
|
|
79
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入“任务描述”");
|
78
|
80
|
}
|
79
|
81
|
if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
80
|
|
- return new ReturnT<String>(500, "请输入“负责人”");
|
|
82
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入“负责人”");
|
81
|
83
|
}
|
82
|
84
|
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
83
|
|
- return new ReturnT<String>(500, "路由策略非法");
|
|
85
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "路由策略非法");
|
|
86
|
+ }
|
|
87
|
+ if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
|
88
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "阻塞处理策略非法");
|
|
89
|
+ }
|
|
90
|
+ if (ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), null) == null) {
|
|
91
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "失败处理策略非法");
|
84
|
92
|
}
|
85
|
93
|
if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
|
86
|
|
- return new ReturnT<String>(500, "运行模式非法非法");
|
|
94
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "运行模式非法非法");
|
87
|
95
|
}
|
88
|
96
|
if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
|
89
|
|
- return new ReturnT<String>(500, "请输入“JobHandler”");
|
|
97
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入“JobHandler”");
|
90
|
98
|
}
|
91
|
99
|
|
92
|
100
|
// fix "\r" in shell
|
|
@@ -100,11 +108,11 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
100
|
108
|
for (String childJobKeyItem: childJobKeys) {
|
101
|
109
|
String[] childJobKeyArr = childJobKeyItem.split("_");
|
102
|
110
|
if (childJobKeyArr.length!=2) {
|
103
|
|
- return new ReturnT<String>(500, MessageFormat.format("子任务Key({0})格式错误", childJobKeyItem));
|
|
111
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format("子任务Key({0})格式错误", childJobKeyItem));
|
104
|
112
|
}
|
105
|
113
|
XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobKeyArr[1]));
|
106
|
114
|
if (childJobInfo==null) {
|
107
|
|
- return new ReturnT<String>(500, MessageFormat.format("子任务Key({0})无效", childJobKeyItem));
|
|
115
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format("子任务Key({0})无效", childJobKeyItem));
|
108
|
116
|
}
|
109
|
117
|
}
|
110
|
118
|
}
|
|
@@ -112,7 +120,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
112
|
120
|
// add in db
|
113
|
121
|
xxlJobInfoDao.save(jobInfo);
|
114
|
122
|
if (jobInfo.getId() < 1) {
|
115
|
|
- return new ReturnT<String>(500, "新增任务失败");
|
|
123
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "新增任务失败");
|
116
|
124
|
}
|
117
|
125
|
|
118
|
126
|
// add in quartz
|
|
@@ -130,7 +138,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
130
|
138
|
} catch (SchedulerException e1) {
|
131
|
139
|
logger.error("", e1);
|
132
|
140
|
}
|
133
|
|
- return new ReturnT<String>(500, "新增任务失败:" + e.getMessage());
|
|
141
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "新增任务失败:" + e.getMessage());
|
134
|
142
|
}
|
135
|
143
|
}
|
136
|
144
|
|
|
@@ -139,16 +147,22 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
139
|
147
|
|
140
|
148
|
// valid
|
141
|
149
|
if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
142
|
|
- return new ReturnT<String>(500, "请输入格式正确的“Cron”");
|
|
150
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入格式正确的“Cron”");
|
143
|
151
|
}
|
144
|
152
|
if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
145
|
|
- return new ReturnT<String>(500, "请输入“任务描述”");
|
|
153
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入“任务描述”");
|
146
|
154
|
}
|
147
|
155
|
if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
148
|
|
- return new ReturnT<String>(500, "请输入“负责人”");
|
|
156
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "请输入“负责人”");
|
149
|
157
|
}
|
150
|
158
|
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
151
|
|
- return new ReturnT<String>(500, "路由策略非法");
|
|
159
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "路由策略非法");
|
|
160
|
+ }
|
|
161
|
+ if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
|
162
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "阻塞处理策略非法");
|
|
163
|
+ }
|
|
164
|
+ if (ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), null) == null) {
|
|
165
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "失败处理策略非法");
|
152
|
166
|
}
|
153
|
167
|
|
154
|
168
|
// childJobKey valid
|
|
@@ -157,11 +171,11 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
157
|
171
|
for (String childJobKeyItem: childJobKeys) {
|
158
|
172
|
String[] childJobKeyArr = childJobKeyItem.split("_");
|
159
|
173
|
if (childJobKeyArr.length!=2) {
|
160
|
|
- return new ReturnT<String>(500, MessageFormat.format("子任务Key({0})格式错误", childJobKeyItem));
|
|
174
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format("子任务Key({0})格式错误", childJobKeyItem));
|
161
|
175
|
}
|
162
|
176
|
XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobKeyArr[1]));
|
163
|
177
|
if (childJobInfo==null) {
|
164
|
|
- return new ReturnT<String>(500, MessageFormat.format("子任务Key({0})无效", childJobKeyItem));
|
|
178
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format("子任务Key({0})无效", childJobKeyItem));
|
165
|
179
|
}
|
166
|
180
|
}
|
167
|
181
|
}
|
|
@@ -170,7 +184,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
170
|
184
|
XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
|
171
|
185
|
String old_cron = exists_jobInfo.getJobCron();
|
172
|
186
|
if (exists_jobInfo == null) {
|
173
|
|
- return new ReturnT<String>(500, "参数异常");
|
|
187
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "参数异常");
|
174
|
188
|
}
|
175
|
189
|
|
176
|
190
|
exists_jobInfo.setJobCron(jobInfo.getJobCron());
|
|
@@ -180,6 +194,8 @@ public class XxlJobServiceImpl implements IXxlJobService {
|
180
|
194
|
exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
|
181
|
195
|
exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
|
182
|
196
|
exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam());
|
|
197
|
+ exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
|
|
198
|
+ exists_jobInfo.setExecutorFailStrategy(jobInfo.getExecutorFailStrategy());
|
183
|
199
|
exists_jobInfo.setChildJobKey(jobInfo.getChildJobKey());
|
184
|
200
|
xxlJobInfoDao.update(exists_jobInfo);
|
185
|
201
|
|