提交 | 用户 | 时间
|
e7c126
|
1 |
package com.xxl.job.admin.service.impl; |
H |
2 |
|
|
3 |
import com.xxl.job.admin.core.cron.CronExpression; |
|
4 |
import com.xxl.job.admin.core.model.XxlJobGroup; |
|
5 |
import com.xxl.job.admin.core.model.XxlJobInfo; |
|
6 |
import com.xxl.job.admin.core.model.XxlJobLogReport; |
|
7 |
import com.xxl.job.admin.core.model.XxlJobUser; |
|
8 |
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum; |
|
9 |
import com.xxl.job.admin.core.scheduler.MisfireStrategyEnum; |
|
10 |
import com.xxl.job.admin.core.scheduler.ScheduleTypeEnum; |
|
11 |
import com.xxl.job.admin.core.thread.JobScheduleHelper; |
|
12 |
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; |
|
13 |
import com.xxl.job.admin.core.trigger.TriggerTypeEnum; |
|
14 |
import com.xxl.job.admin.core.util.I18nUtil; |
|
15 |
import com.xxl.job.admin.dao.*; |
|
16 |
import com.xxl.job.admin.service.XxlJobService; |
|
17 |
import com.xxl.job.core.biz.model.ReturnT; |
|
18 |
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; |
|
19 |
import com.xxl.job.core.glue.GlueTypeEnum; |
|
20 |
import com.xxl.job.core.util.DateUtil; |
|
21 |
import org.slf4j.Logger; |
|
22 |
import org.slf4j.LoggerFactory; |
|
23 |
import org.springframework.stereotype.Service; |
|
24 |
|
|
25 |
import javax.annotation.Resource; |
|
26 |
import java.text.MessageFormat; |
|
27 |
import java.util.*; |
|
28 |
|
|
29 |
/** |
|
30 |
* core job action for xxl-job |
|
31 |
* @author xuxueli 2016-5-28 15:30:33 |
|
32 |
*/ |
|
33 |
@Service |
|
34 |
public class XxlJobServiceImpl implements XxlJobService { |
|
35 |
private static Logger logger = LoggerFactory.getLogger(XxlJobServiceImpl.class); |
|
36 |
|
|
37 |
@Resource |
|
38 |
private XxlJobGroupDao xxlJobGroupDao; |
|
39 |
@Resource |
|
40 |
private XxlJobInfoDao xxlJobInfoDao; |
|
41 |
@Resource |
|
42 |
public XxlJobLogDao xxlJobLogDao; |
|
43 |
@Resource |
|
44 |
private XxlJobLogGlueDao xxlJobLogGlueDao; |
|
45 |
@Resource |
|
46 |
private XxlJobLogReportDao xxlJobLogReportDao; |
|
47 |
|
|
48 |
@Override |
|
49 |
public Map<String, Object> pageList(int start, int length, int jobGroup, int triggerStatus, String jobDesc, String executorHandler, String author) { |
|
50 |
|
|
51 |
// page list |
|
52 |
List<XxlJobInfo> list = xxlJobInfoDao.pageList(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author); |
|
53 |
int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author); |
|
54 |
|
|
55 |
// package result |
|
56 |
Map<String, Object> maps = new HashMap<String, Object>(); |
|
57 |
maps.put("recordsTotal", list_count); // 总记录数 |
|
58 |
maps.put("recordsFiltered", list_count); // 过滤后的总记录数 |
|
59 |
maps.put("data", list); // 分页列表 |
|
60 |
return maps; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public ReturnT<String> add(XxlJobInfo jobInfo) { |
|
65 |
|
|
66 |
// valid base |
|
67 |
XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup()); |
|
68 |
if (group == null) { |
|
69 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")) ); |
|
70 |
} |
|
71 |
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { |
|
72 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); |
|
73 |
} |
|
74 |
if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) { |
|
75 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); |
|
76 |
} |
|
77 |
|
|
78 |
// valid trigger |
|
79 |
ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(jobInfo.getScheduleType(), null); |
|
80 |
if (scheduleTypeEnum == null) { |
|
81 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
82 |
} |
|
83 |
if (scheduleTypeEnum == ScheduleTypeEnum.CRON) { |
|
84 |
if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) { |
|
85 |
return new ReturnT<String>(ReturnT.FAIL_CODE, "Cron"+I18nUtil.getString("system_unvalid")); |
|
86 |
} |
|
87 |
} else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE/* || scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) { |
|
88 |
if (jobInfo.getScheduleConf() == null) { |
|
89 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")) ); |
|
90 |
} |
|
91 |
try { |
|
92 |
int fixSecond = Integer.valueOf(jobInfo.getScheduleConf()); |
|
93 |
if (fixSecond < 1) { |
|
94 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
95 |
} |
|
96 |
} catch (Exception e) { |
|
97 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
// valid job |
|
102 |
if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) { |
|
103 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) ); |
|
104 |
} |
|
105 |
if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && (jobInfo.getExecutorHandler()==null || jobInfo.getExecutorHandler().trim().length()==0) ) { |
|
106 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+"JobHandler") ); |
|
107 |
} |
|
108 |
// 》fix "\r" in shell |
|
109 |
if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) { |
|
110 |
jobInfo.setGlueSource(jobInfo.getGlueSource().replaceAll("\r", "")); |
|
111 |
} |
|
112 |
|
|
113 |
// valid advanced |
|
114 |
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) { |
|
115 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); |
|
116 |
} |
|
117 |
if (MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), null) == null) { |
|
118 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) ); |
|
119 |
} |
|
120 |
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { |
|
121 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); |
|
122 |
} |
|
123 |
|
|
124 |
// 》ChildJobId valid |
|
125 |
if (jobInfo.getChildJobId()!=null && jobInfo.getChildJobId().trim().length()>0) { |
|
126 |
String[] childJobIds = jobInfo.getChildJobId().split(","); |
|
127 |
for (String childJobIdItem: childJobIds) { |
|
128 |
if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) { |
|
129 |
XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(childJobIdItem)); |
|
130 |
if (childJobInfo==null) { |
|
131 |
return new ReturnT<String>(ReturnT.FAIL_CODE, |
|
132 |
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem)); |
|
133 |
} |
|
134 |
} else { |
|
135 |
return new ReturnT<String>(ReturnT.FAIL_CODE, |
|
136 |
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem)); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
// join , avoid "xxx,," |
|
141 |
String temp = ""; |
|
142 |
for (String item:childJobIds) { |
|
143 |
temp += item + ","; |
|
144 |
} |
|
145 |
temp = temp.substring(0, temp.length()-1); |
|
146 |
|
|
147 |
jobInfo.setChildJobId(temp); |
|
148 |
} |
|
149 |
|
|
150 |
// add in db |
|
151 |
jobInfo.setAddTime(new Date()); |
|
152 |
jobInfo.setUpdateTime(new Date()); |
|
153 |
jobInfo.setGlueUpdatetime(new Date()); |
|
154 |
xxlJobInfoDao.save(jobInfo); |
|
155 |
if (jobInfo.getId() < 1) { |
|
156 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) ); |
|
157 |
} |
|
158 |
|
|
159 |
return new ReturnT<String>(String.valueOf(jobInfo.getId())); |
|
160 |
} |
|
161 |
|
|
162 |
private boolean isNumeric(String str){ |
|
163 |
try { |
|
164 |
int result = Integer.valueOf(str); |
|
165 |
return true; |
|
166 |
} catch (NumberFormatException e) { |
|
167 |
return false; |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
@Override |
|
172 |
public ReturnT<String> update(XxlJobInfo jobInfo) { |
|
173 |
|
|
174 |
// valid base |
|
175 |
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { |
|
176 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); |
|
177 |
} |
|
178 |
if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) { |
|
179 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); |
|
180 |
} |
|
181 |
|
|
182 |
// valid trigger |
|
183 |
ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(jobInfo.getScheduleType(), null); |
|
184 |
if (scheduleTypeEnum == null) { |
|
185 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
186 |
} |
|
187 |
if (scheduleTypeEnum == ScheduleTypeEnum.CRON) { |
|
188 |
if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) { |
|
189 |
return new ReturnT<String>(ReturnT.FAIL_CODE, "Cron"+I18nUtil.getString("system_unvalid") ); |
|
190 |
} |
|
191 |
} else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE /*|| scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) { |
|
192 |
if (jobInfo.getScheduleConf() == null) { |
|
193 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
194 |
} |
|
195 |
try { |
|
196 |
int fixSecond = Integer.valueOf(jobInfo.getScheduleConf()); |
|
197 |
if (fixSecond < 1) { |
|
198 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
199 |
} |
|
200 |
} catch (Exception e) { |
|
201 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
// valid advanced |
|
206 |
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) { |
|
207 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); |
|
208 |
} |
|
209 |
if (MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), null) == null) { |
|
210 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) ); |
|
211 |
} |
|
212 |
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { |
|
213 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); |
|
214 |
} |
|
215 |
|
|
216 |
// 》ChildJobId valid |
|
217 |
if (jobInfo.getChildJobId()!=null && jobInfo.getChildJobId().trim().length()>0) { |
|
218 |
String[] childJobIds = jobInfo.getChildJobId().split(","); |
|
219 |
for (String childJobIdItem: childJobIds) { |
|
220 |
if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) { |
|
221 |
XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(childJobIdItem)); |
|
222 |
if (childJobInfo==null) { |
|
223 |
return new ReturnT<String>(ReturnT.FAIL_CODE, |
|
224 |
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem)); |
|
225 |
} |
|
226 |
} else { |
|
227 |
return new ReturnT<String>(ReturnT.FAIL_CODE, |
|
228 |
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem)); |
|
229 |
} |
|
230 |
} |
|
231 |
|
|
232 |
// join , avoid "xxx,," |
|
233 |
String temp = ""; |
|
234 |
for (String item:childJobIds) { |
|
235 |
temp += item + ","; |
|
236 |
} |
|
237 |
temp = temp.substring(0, temp.length()-1); |
|
238 |
|
|
239 |
jobInfo.setChildJobId(temp); |
|
240 |
} |
|
241 |
|
|
242 |
// group valid |
|
243 |
XxlJobGroup jobGroup = xxlJobGroupDao.load(jobInfo.getJobGroup()); |
|
244 |
if (jobGroup == null) { |
|
245 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) ); |
|
246 |
} |
|
247 |
|
|
248 |
// stage job info |
|
249 |
XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId()); |
|
250 |
if (exists_jobInfo == null) { |
|
251 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) ); |
|
252 |
} |
|
253 |
|
|
254 |
// next trigger time (5s后生效,避开预读周期) |
|
255 |
long nextTriggerTime = exists_jobInfo.getTriggerNextTime(); |
|
256 |
boolean scheduleDataNotChanged = jobInfo.getScheduleType().equals(exists_jobInfo.getScheduleType()) && jobInfo.getScheduleConf().equals(exists_jobInfo.getScheduleConf()); |
|
257 |
if (exists_jobInfo.getTriggerStatus() == 1 && !scheduleDataNotChanged) { |
|
258 |
try { |
|
259 |
Date nextValidTime = JobScheduleHelper.generateNextValidTime(jobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); |
|
260 |
if (nextValidTime == null) { |
|
261 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
262 |
} |
|
263 |
nextTriggerTime = nextValidTime.getTime(); |
|
264 |
} catch (Exception e) { |
|
265 |
logger.error(e.getMessage(), e); |
|
266 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
270 |
exists_jobInfo.setJobGroup(jobInfo.getJobGroup()); |
|
271 |
exists_jobInfo.setJobDesc(jobInfo.getJobDesc()); |
|
272 |
exists_jobInfo.setAuthor(jobInfo.getAuthor()); |
|
273 |
exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail()); |
|
274 |
exists_jobInfo.setScheduleType(jobInfo.getScheduleType()); |
|
275 |
exists_jobInfo.setScheduleConf(jobInfo.getScheduleConf()); |
|
276 |
exists_jobInfo.setMisfireStrategy(jobInfo.getMisfireStrategy()); |
|
277 |
exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy()); |
|
278 |
exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler()); |
|
279 |
exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam()); |
|
280 |
exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy()); |
|
281 |
exists_jobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout()); |
|
282 |
exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount()); |
|
283 |
exists_jobInfo.setChildJobId(jobInfo.getChildJobId()); |
|
284 |
exists_jobInfo.setTriggerNextTime(nextTriggerTime); |
|
285 |
|
|
286 |
exists_jobInfo.setUpdateTime(new Date()); |
|
287 |
xxlJobInfoDao.update(exists_jobInfo); |
|
288 |
|
|
289 |
|
|
290 |
return ReturnT.SUCCESS; |
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public ReturnT<String> remove(int id) { |
|
295 |
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); |
|
296 |
if (xxlJobInfo == null) { |
|
297 |
return ReturnT.SUCCESS; |
|
298 |
} |
|
299 |
|
|
300 |
xxlJobInfoDao.delete(id); |
|
301 |
xxlJobLogDao.delete(id); |
|
302 |
xxlJobLogGlueDao.deleteByJobId(id); |
|
303 |
return ReturnT.SUCCESS; |
|
304 |
} |
|
305 |
|
|
306 |
@Override |
|
307 |
public ReturnT<String> start(int id) { |
|
308 |
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); |
|
309 |
|
|
310 |
// valid |
|
311 |
ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(xxlJobInfo.getScheduleType(), ScheduleTypeEnum.NONE); |
|
312 |
if (ScheduleTypeEnum.NONE == scheduleTypeEnum) { |
|
313 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type_none_limit_start")) ); |
|
314 |
} |
|
315 |
|
|
316 |
// next trigger time (5s后生效,避开预读周期) |
|
317 |
long nextTriggerTime = 0; |
|
318 |
try { |
|
319 |
Date nextValidTime = JobScheduleHelper.generateNextValidTime(xxlJobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); |
|
320 |
if (nextValidTime == null) { |
|
321 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
322 |
} |
|
323 |
nextTriggerTime = nextValidTime.getTime(); |
|
324 |
} catch (Exception e) { |
|
325 |
logger.error(e.getMessage(), e); |
|
326 |
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); |
|
327 |
} |
|
328 |
|
|
329 |
xxlJobInfo.setTriggerStatus(1); |
|
330 |
xxlJobInfo.setTriggerLastTime(0); |
|
331 |
xxlJobInfo.setTriggerNextTime(nextTriggerTime); |
|
332 |
|
|
333 |
xxlJobInfo.setUpdateTime(new Date()); |
|
334 |
xxlJobInfoDao.update(xxlJobInfo); |
|
335 |
return ReturnT.SUCCESS; |
|
336 |
} |
|
337 |
|
|
338 |
@Override |
|
339 |
public ReturnT<String> stop(int id) { |
|
340 |
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); |
|
341 |
|
|
342 |
xxlJobInfo.setTriggerStatus(0); |
|
343 |
xxlJobInfo.setTriggerLastTime(0); |
|
344 |
xxlJobInfo.setTriggerNextTime(0); |
|
345 |
|
|
346 |
xxlJobInfo.setUpdateTime(new Date()); |
|
347 |
xxlJobInfoDao.update(xxlJobInfo); |
|
348 |
return ReturnT.SUCCESS; |
|
349 |
} |
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
@Override |
|
354 |
public ReturnT<String> trigger(XxlJobUser loginUser, int jobId, String executorParam, String addressList) { |
|
355 |
// permission |
|
356 |
if (loginUser == null) { |
|
357 |
return new ReturnT<String>(ReturnT.FAIL.getCode(), I18nUtil.getString("system_permission_limit")); |
|
358 |
} |
|
359 |
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(jobId); |
|
360 |
if (xxlJobInfo == null) { |
|
361 |
return new ReturnT<String>(ReturnT.FAIL.getCode(), I18nUtil.getString("jobinfo_glue_jobid_unvalid")); |
|
362 |
} |
|
363 |
if (!hasPermission(loginUser, xxlJobInfo.getJobGroup())) { |
|
364 |
return new ReturnT<String>(ReturnT.FAIL.getCode(), I18nUtil.getString("system_permission_limit")); |
|
365 |
} |
|
366 |
|
|
367 |
// force cover job param |
|
368 |
if (executorParam == null) { |
|
369 |
executorParam = ""; |
|
370 |
} |
|
371 |
|
|
372 |
JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList); |
|
373 |
return ReturnT.SUCCESS; |
|
374 |
} |
|
375 |
|
|
376 |
private boolean hasPermission(XxlJobUser loginUser, int jobGroup){ |
|
377 |
if (loginUser.getRole() == 1) { |
|
378 |
return true; |
|
379 |
} |
|
380 |
List<String> groupIdStrs = new ArrayList<>(); |
|
381 |
if (loginUser.getPermission()!=null && loginUser.getPermission().trim().length()>0) { |
|
382 |
groupIdStrs = Arrays.asList(loginUser.getPermission().trim().split(",")); |
|
383 |
} |
|
384 |
return groupIdStrs.contains(String.valueOf(jobGroup)); |
|
385 |
} |
|
386 |
|
|
387 |
@Override |
|
388 |
public Map<String, Object> dashboardInfo() { |
|
389 |
|
|
390 |
int jobInfoCount = xxlJobInfoDao.findAllCount(); |
|
391 |
int jobLogCount = 0; |
|
392 |
int jobLogSuccessCount = 0; |
|
393 |
XxlJobLogReport xxlJobLogReport = xxlJobLogReportDao.queryLogReportTotal(); |
|
394 |
if (xxlJobLogReport != null) { |
|
395 |
jobLogCount = xxlJobLogReport.getRunningCount() + xxlJobLogReport.getSucCount() + xxlJobLogReport.getFailCount(); |
|
396 |
jobLogSuccessCount = xxlJobLogReport.getSucCount(); |
|
397 |
} |
|
398 |
|
|
399 |
// executor count |
|
400 |
Set<String> executorAddressSet = new HashSet<String>(); |
|
401 |
List<XxlJobGroup> groupList = xxlJobGroupDao.findAll(); |
|
402 |
|
|
403 |
if (groupList!=null && !groupList.isEmpty()) { |
|
404 |
for (XxlJobGroup group: groupList) { |
|
405 |
if (group.getRegistryList()!=null && !group.getRegistryList().isEmpty()) { |
|
406 |
executorAddressSet.addAll(group.getRegistryList()); |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
int executorCount = executorAddressSet.size(); |
|
412 |
|
|
413 |
Map<String, Object> dashboardMap = new HashMap<String, Object>(); |
|
414 |
dashboardMap.put("jobInfoCount", jobInfoCount); |
|
415 |
dashboardMap.put("jobLogCount", jobLogCount); |
|
416 |
dashboardMap.put("jobLogSuccessCount", jobLogSuccessCount); |
|
417 |
dashboardMap.put("executorCount", executorCount); |
|
418 |
return dashboardMap; |
|
419 |
} |
|
420 |
|
|
421 |
@Override |
|
422 |
public ReturnT<Map<String, Object>> chartInfo(Date startDate, Date endDate) { |
|
423 |
|
|
424 |
// process |
|
425 |
List<String> triggerDayList = new ArrayList<String>(); |
|
426 |
List<Integer> triggerDayCountRunningList = new ArrayList<Integer>(); |
|
427 |
List<Integer> triggerDayCountSucList = new ArrayList<Integer>(); |
|
428 |
List<Integer> triggerDayCountFailList = new ArrayList<Integer>(); |
|
429 |
int triggerCountRunningTotal = 0; |
|
430 |
int triggerCountSucTotal = 0; |
|
431 |
int triggerCountFailTotal = 0; |
|
432 |
|
|
433 |
List<XxlJobLogReport> logReportList = xxlJobLogReportDao.queryLogReport(startDate, endDate); |
|
434 |
|
|
435 |
if (logReportList!=null && logReportList.size()>0) { |
|
436 |
for (XxlJobLogReport item: logReportList) { |
|
437 |
String day = DateUtil.formatDate(item.getTriggerDay()); |
|
438 |
int triggerDayCountRunning = item.getRunningCount(); |
|
439 |
int triggerDayCountSuc = item.getSucCount(); |
|
440 |
int triggerDayCountFail = item.getFailCount(); |
|
441 |
|
|
442 |
triggerDayList.add(day); |
|
443 |
triggerDayCountRunningList.add(triggerDayCountRunning); |
|
444 |
triggerDayCountSucList.add(triggerDayCountSuc); |
|
445 |
triggerDayCountFailList.add(triggerDayCountFail); |
|
446 |
|
|
447 |
triggerCountRunningTotal += triggerDayCountRunning; |
|
448 |
triggerCountSucTotal += triggerDayCountSuc; |
|
449 |
triggerCountFailTotal += triggerDayCountFail; |
|
450 |
} |
|
451 |
} else { |
|
452 |
for (int i = -6; i <= 0; i++) { |
|
453 |
triggerDayList.add(DateUtil.formatDate(DateUtil.addDays(new Date(), i))); |
|
454 |
triggerDayCountRunningList.add(0); |
|
455 |
triggerDayCountSucList.add(0); |
|
456 |
triggerDayCountFailList.add(0); |
|
457 |
} |
|
458 |
} |
|
459 |
|
|
460 |
Map<String, Object> result = new HashMap<String, Object>(); |
|
461 |
result.put("triggerDayList", triggerDayList); |
|
462 |
result.put("triggerDayCountRunningList", triggerDayCountRunningList); |
|
463 |
result.put("triggerDayCountSucList", triggerDayCountSucList); |
|
464 |
result.put("triggerDayCountFailList", triggerDayCountFailList); |
|
465 |
|
|
466 |
result.put("triggerCountRunningTotal", triggerCountRunningTotal); |
|
467 |
result.put("triggerCountSucTotal", triggerCountSucTotal); |
|
468 |
result.put("triggerCountFailTotal", triggerCountFailTotal); |
|
469 |
|
|
470 |
return new ReturnT<Map<String, Object>>(result); |
|
471 |
} |
|
472 |
|
|
473 |
} |