|
@@ -1,385 +1,385 @@
|
1
|
|
-package com.xxl.job.admin.service.impl;
|
2
|
|
-
|
3
|
|
-import com.xxl.job.admin.core.model.XxlJobGroup;
|
4
|
|
-import com.xxl.job.admin.core.model.XxlJobInfo;
|
5
|
|
-import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
|
6
|
|
-import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
7
|
|
-import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
8
|
|
-import com.xxl.job.admin.core.util.I18nUtil;
|
9
|
|
-import com.xxl.job.admin.dao.XxlJobGroupDao;
|
10
|
|
-import com.xxl.job.admin.dao.XxlJobInfoDao;
|
11
|
|
-import com.xxl.job.admin.dao.XxlJobLogDao;
|
12
|
|
-import com.xxl.job.admin.dao.XxlJobLogGlueDao;
|
13
|
|
-import com.xxl.job.admin.service.XxlJobService;
|
14
|
|
-import com.xxl.job.core.biz.model.ReturnT;
|
15
|
|
-import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
16
|
|
-import com.xxl.job.core.glue.GlueTypeEnum;
|
17
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
18
|
|
-import org.apache.commons.lang3.StringUtils;
|
19
|
|
-import org.apache.commons.lang3.time.DateUtils;
|
20
|
|
-import org.apache.commons.lang3.time.FastDateFormat;
|
21
|
|
-import org.quartz.CronExpression;
|
22
|
|
-import org.quartz.SchedulerException;
|
23
|
|
-import org.slf4j.Logger;
|
24
|
|
-import org.slf4j.LoggerFactory;
|
25
|
|
-import org.springframework.stereotype.Service;
|
26
|
|
-
|
27
|
|
-import javax.annotation.Resource;
|
28
|
|
-import java.text.MessageFormat;
|
29
|
|
-import java.util.*;
|
30
|
|
-
|
31
|
|
-/**
|
32
|
|
- * core job action for xxl-job
|
33
|
|
- * @author xuxueli 2016-5-28 15:30:33
|
34
|
|
- */
|
35
|
|
-@Service
|
36
|
|
-public class XxlJobServiceImpl implements XxlJobService {
|
37
|
|
- private static Logger logger = LoggerFactory.getLogger(XxlJobServiceImpl.class);
|
38
|
|
-
|
39
|
|
- @Resource
|
40
|
|
- private XxlJobGroupDao xxlJobGroupDao;
|
41
|
|
- @Resource
|
42
|
|
- private XxlJobInfoDao xxlJobInfoDao;
|
43
|
|
- @Resource
|
44
|
|
- public XxlJobLogDao xxlJobLogDao;
|
45
|
|
- @Resource
|
46
|
|
- private XxlJobLogGlueDao xxlJobLogGlueDao;
|
47
|
|
-
|
48
|
|
- @Override
|
49
|
|
- public Map<String, Object> pageList(int start, int length, int jobGroup, String jobDesc, String executorHandler, String filterTime) {
|
50
|
|
-
|
51
|
|
- // page list
|
52
|
|
- List<XxlJobInfo> list = xxlJobInfoDao.pageList(start, length, jobGroup, jobDesc, executorHandler);
|
53
|
|
- int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, jobDesc, executorHandler);
|
54
|
|
-
|
55
|
|
- // fill job info
|
56
|
|
- if (list!=null && list.size()>0) {
|
57
|
|
- for (XxlJobInfo jobInfo : list) {
|
58
|
|
- XxlJobDynamicScheduler.fillJobInfo(jobInfo);
|
59
|
|
- }
|
60
|
|
- }
|
61
|
|
-
|
62
|
|
- // package result
|
63
|
|
- Map<String, Object> maps = new HashMap<String, Object>();
|
64
|
|
- maps.put("recordsTotal", list_count); // 总记录数
|
65
|
|
- maps.put("recordsFiltered", list_count); // 过滤后的总记录数
|
66
|
|
- maps.put("data", list); // 分页列表
|
67
|
|
- return maps;
|
68
|
|
- }
|
69
|
|
-
|
70
|
|
- @Override
|
71
|
|
- public ReturnT<String> add(XxlJobInfo jobInfo) {
|
72
|
|
- // valid
|
73
|
|
- XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
|
74
|
|
- if (group == null) {
|
75
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")) );
|
76
|
|
- }
|
77
|
|
- if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
78
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") );
|
79
|
|
- }
|
80
|
|
- if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
81
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
|
82
|
|
- }
|
83
|
|
- if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
84
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
|
85
|
|
- }
|
86
|
|
- if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
87
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
|
88
|
|
- }
|
89
|
|
- if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
90
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
|
91
|
|
- }
|
92
|
|
- if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
|
93
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) );
|
94
|
|
- }
|
95
|
|
- if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
|
96
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+"JobHandler") );
|
97
|
|
- }
|
98
|
|
-
|
99
|
|
- // fix "\r" in shell
|
100
|
|
- if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) {
|
101
|
|
- jobInfo.setGlueSource(jobInfo.getGlueSource().replaceAll("\r", ""));
|
102
|
|
- }
|
103
|
|
-
|
104
|
|
- // ChildJobId valid
|
105
|
|
- if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
|
106
|
|
- String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
|
107
|
|
- for (String childJobIdItem: childJobIds) {
|
108
|
|
- if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
|
109
|
|
- XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
|
110
|
|
- if (childJobInfo==null) {
|
111
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE,
|
112
|
|
- MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
|
113
|
|
- }
|
114
|
|
- } else {
|
115
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE,
|
116
|
|
- MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
|
117
|
|
- }
|
118
|
|
- }
|
119
|
|
- jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
|
120
|
|
- }
|
121
|
|
-
|
122
|
|
- // add in db
|
123
|
|
- xxlJobInfoDao.save(jobInfo);
|
124
|
|
- if (jobInfo.getId() < 1) {
|
125
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
|
126
|
|
- }
|
127
|
|
-
|
128
|
|
- // add in quartz
|
129
|
|
- String qz_group = String.valueOf(jobInfo.getJobGroup());
|
130
|
|
- String qz_name = String.valueOf(jobInfo.getId());
|
131
|
|
- try {
|
132
|
|
- XxlJobDynamicScheduler.addJob(qz_name, qz_group, jobInfo.getJobCron());
|
133
|
|
- //XxlJobDynamicScheduler.pauseJob(qz_name, qz_group);
|
134
|
|
- return ReturnT.SUCCESS;
|
135
|
|
- } catch (SchedulerException e) {
|
136
|
|
- logger.error(e.getMessage(), e);
|
137
|
|
- try {
|
138
|
|
- xxlJobInfoDao.delete(jobInfo.getId());
|
139
|
|
- XxlJobDynamicScheduler.removeJob(qz_name, qz_group);
|
140
|
|
- } catch (SchedulerException e1) {
|
141
|
|
- logger.error(e.getMessage(), e1);
|
142
|
|
- }
|
143
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail"))+":" + e.getMessage());
|
144
|
|
- }
|
145
|
|
- }
|
146
|
|
-
|
147
|
|
- @Override
|
148
|
|
- public ReturnT<String> update(XxlJobInfo jobInfo) {
|
149
|
|
-
|
150
|
|
- // valid
|
151
|
|
- if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
152
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") );
|
153
|
|
- }
|
154
|
|
- if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
155
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
|
156
|
|
- }
|
157
|
|
- if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
158
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
|
159
|
|
- }
|
160
|
|
- if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
161
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
|
162
|
|
- }
|
163
|
|
- if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
164
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
|
165
|
|
- }
|
166
|
|
-
|
167
|
|
- // ChildJobId valid
|
168
|
|
- if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
|
169
|
|
- String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
|
170
|
|
- for (String childJobIdItem: childJobIds) {
|
171
|
|
- if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
|
172
|
|
- XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
|
173
|
|
- if (childJobInfo==null) {
|
174
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE,
|
175
|
|
- MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
|
176
|
|
- }
|
177
|
|
- // avoid cycle relate
|
178
|
|
- if (childJobInfo.getId() == jobInfo.getId()) {
|
179
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format(I18nUtil.getString("jobinfo_field_childJobId_limit"), childJobIdItem));
|
180
|
|
- }
|
181
|
|
- } else {
|
182
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE,
|
183
|
|
- MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
|
184
|
|
- }
|
185
|
|
- }
|
186
|
|
- jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
|
187
|
|
- }
|
188
|
|
-
|
189
|
|
- // stage job info
|
190
|
|
- XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
|
191
|
|
- if (exists_jobInfo == null) {
|
192
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
|
193
|
|
- }
|
194
|
|
- //String old_cron = exists_jobInfo.getJobCron();
|
195
|
|
-
|
196
|
|
- exists_jobInfo.setJobCron(jobInfo.getJobCron());
|
197
|
|
- exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
|
198
|
|
- exists_jobInfo.setAuthor(jobInfo.getAuthor());
|
199
|
|
- exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
|
200
|
|
- exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
|
201
|
|
- exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
|
202
|
|
- exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam());
|
203
|
|
- exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
|
204
|
|
- exists_jobInfo.setExecutorFailStrategy(jobInfo.getExecutorFailStrategy());
|
205
|
|
- exists_jobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout());
|
206
|
|
- exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
|
207
|
|
- exists_jobInfo.setChildJobId(jobInfo.getChildJobId());
|
208
|
|
- xxlJobInfoDao.update(exists_jobInfo);
|
209
|
|
-
|
210
|
|
- // fresh quartz
|
211
|
|
- String qz_group = String.valueOf(exists_jobInfo.getJobGroup());
|
212
|
|
- String qz_name = String.valueOf(exists_jobInfo.getId());
|
213
|
|
- try {
|
214
|
|
- boolean ret = XxlJobDynamicScheduler.rescheduleJob(qz_group, qz_name, exists_jobInfo.getJobCron());
|
215
|
|
- return ret?ReturnT.SUCCESS:ReturnT.FAIL;
|
216
|
|
- } catch (SchedulerException e) {
|
217
|
|
- logger.error(e.getMessage(), e);
|
218
|
|
- }
|
219
|
|
-
|
220
|
|
- return ReturnT.FAIL;
|
221
|
|
- }
|
222
|
|
-
|
223
|
|
- @Override
|
224
|
|
- public ReturnT<String> remove(int id) {
|
225
|
|
- XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
226
|
|
- String group = String.valueOf(xxlJobInfo.getJobGroup());
|
227
|
|
- String name = String.valueOf(xxlJobInfo.getId());
|
228
|
|
-
|
229
|
|
- try {
|
230
|
|
- XxlJobDynamicScheduler.removeJob(name, group);
|
231
|
|
- xxlJobInfoDao.delete(id);
|
232
|
|
- xxlJobLogDao.delete(id);
|
233
|
|
- xxlJobLogGlueDao.deleteByJobId(id);
|
234
|
|
- return ReturnT.SUCCESS;
|
235
|
|
- } catch (SchedulerException e) {
|
236
|
|
- logger.error(e.getMessage(), e);
|
237
|
|
- }
|
238
|
|
- return ReturnT.FAIL;
|
239
|
|
- }
|
240
|
|
-
|
241
|
|
- @Override
|
242
|
|
- public ReturnT<String> pause(int id) {
|
243
|
|
- XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
244
|
|
- String group = String.valueOf(xxlJobInfo.getJobGroup());
|
245
|
|
- String name = String.valueOf(xxlJobInfo.getId());
|
246
|
|
-
|
247
|
|
- try {
|
248
|
|
- boolean ret = XxlJobDynamicScheduler.pauseJob(name, group); // jobStatus do not store
|
249
|
|
- return ret?ReturnT.SUCCESS:ReturnT.FAIL;
|
250
|
|
- } catch (SchedulerException e) {
|
251
|
|
- logger.error(e.getMessage(), e);
|
252
|
|
- return ReturnT.FAIL;
|
253
|
|
- }
|
254
|
|
- }
|
255
|
|
-
|
256
|
|
- @Override
|
257
|
|
- public ReturnT<String> resume(int id) {
|
258
|
|
- XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
259
|
|
- String group = String.valueOf(xxlJobInfo.getJobGroup());
|
260
|
|
- String name = String.valueOf(xxlJobInfo.getId());
|
261
|
|
-
|
262
|
|
- try {
|
263
|
|
- boolean ret = XxlJobDynamicScheduler.resumeJob(name, group);
|
264
|
|
- return ret?ReturnT.SUCCESS:ReturnT.FAIL;
|
265
|
|
- } catch (SchedulerException e) {
|
266
|
|
- logger.error(e.getMessage(), e);
|
267
|
|
- return ReturnT.FAIL;
|
268
|
|
- }
|
269
|
|
- }
|
270
|
|
-
|
271
|
|
- @Override
|
272
|
|
- public ReturnT<String> triggerJob(int id) {
|
273
|
|
-
|
274
|
|
- JobTriggerPoolHelper.trigger(id);
|
275
|
|
- return ReturnT.SUCCESS;
|
276
|
|
-
|
277
|
|
- /*XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
278
|
|
- if (xxlJobInfo == null) {
|
279
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_unvalid")) );
|
280
|
|
- }
|
281
|
|
-
|
282
|
|
- String group = String.valueOf(xxlJobInfo.getJobGroup());
|
283
|
|
- String name = String.valueOf(xxlJobInfo.getId());
|
284
|
|
-
|
285
|
|
- try {
|
286
|
|
- XxlJobDynamicScheduler.triggerJob(name, group);
|
287
|
|
- return ReturnT.SUCCESS;
|
288
|
|
- } catch (SchedulerException e) {
|
289
|
|
- logger.error(e.getMessage(), e);
|
290
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());
|
291
|
|
- }*/
|
292
|
|
-
|
293
|
|
- }
|
294
|
|
-
|
295
|
|
- @Override
|
296
|
|
- public Map<String, Object> dashboardInfo() {
|
297
|
|
-
|
298
|
|
- int jobInfoCount = xxlJobInfoDao.findAllCount();
|
299
|
|
- int jobLogCount = xxlJobLogDao.triggerCountByHandleCode(-1);
|
300
|
|
- int jobLogSuccessCount = xxlJobLogDao.triggerCountByHandleCode(ReturnT.SUCCESS_CODE);
|
301
|
|
-
|
302
|
|
- // executor count
|
303
|
|
- Set<String> executerAddressSet = new HashSet<String>();
|
304
|
|
- List<XxlJobGroup> groupList = xxlJobGroupDao.findAll();
|
305
|
|
-
|
306
|
|
- if (CollectionUtils.isNotEmpty(groupList)) {
|
307
|
|
- for (XxlJobGroup group: groupList) {
|
308
|
|
- if (CollectionUtils.isNotEmpty(group.getRegistryList())) {
|
309
|
|
- executerAddressSet.addAll(group.getRegistryList());
|
310
|
|
- }
|
311
|
|
- }
|
312
|
|
- }
|
313
|
|
-
|
314
|
|
- int executorCount = executerAddressSet.size();
|
315
|
|
-
|
316
|
|
- Map<String, Object> dashboardMap = new HashMap<String, Object>();
|
317
|
|
- dashboardMap.put("jobInfoCount", jobInfoCount);
|
318
|
|
- dashboardMap.put("jobLogCount", jobLogCount);
|
319
|
|
- dashboardMap.put("jobLogSuccessCount", jobLogSuccessCount);
|
320
|
|
- dashboardMap.put("executorCount", executorCount);
|
321
|
|
- return dashboardMap;
|
322
|
|
- }
|
323
|
|
-
|
324
|
|
- private static final String TRIGGER_CHART_DATA_CACHE = "trigger_chart_data_cache";
|
325
|
|
- @Override
|
326
|
|
- public ReturnT<Map<String, Object>> chartInfo(Date startDate, Date endDate) {
|
327
|
|
- /*// get cache
|
328
|
|
- String cacheKey = TRIGGER_CHART_DATA_CACHE + "_" + startDate.getTime() + "_" + endDate.getTime();
|
329
|
|
- Map<String, Object> chartInfo = (Map<String, Object>) LocalCacheUtil.get(cacheKey);
|
330
|
|
- if (chartInfo != null) {
|
331
|
|
- return new ReturnT<Map<String, Object>>(chartInfo);
|
332
|
|
- }*/
|
333
|
|
-
|
334
|
|
- // process
|
335
|
|
- List<String> triggerDayList = new ArrayList<String>();
|
336
|
|
- List<Integer> triggerDayCountRunningList = new ArrayList<Integer>();
|
337
|
|
- List<Integer> triggerDayCountSucList = new ArrayList<Integer>();
|
338
|
|
- List<Integer> triggerDayCountFailList = new ArrayList<Integer>();
|
339
|
|
- int triggerCountRunningTotal = 0;
|
340
|
|
- int triggerCountSucTotal = 0;
|
341
|
|
- int triggerCountFailTotal = 0;
|
342
|
|
-
|
343
|
|
- List<Map<String, Object>> triggerCountMapAll = xxlJobLogDao.triggerCountByDay(startDate, endDate);
|
344
|
|
- if (CollectionUtils.isNotEmpty(triggerCountMapAll)) {
|
345
|
|
- for (Map<String, Object> item: triggerCountMapAll) {
|
346
|
|
- String day = String.valueOf(item.get("triggerDay"));
|
347
|
|
- int triggerDayCount = Integer.valueOf(String.valueOf(item.get("triggerDayCount")));
|
348
|
|
- int triggerDayCountRunning = Integer.valueOf(String.valueOf(item.get("triggerDayCountRunning")));
|
349
|
|
- int triggerDayCountSuc = Integer.valueOf(String.valueOf(item.get("triggerDayCountSuc")));
|
350
|
|
- int triggerDayCountFail = triggerDayCount - triggerDayCountRunning - triggerDayCountSuc;
|
351
|
|
-
|
352
|
|
- triggerDayList.add(day);
|
353
|
|
- triggerDayCountRunningList.add(triggerDayCountRunning);
|
354
|
|
- triggerDayCountSucList.add(triggerDayCountSuc);
|
355
|
|
- triggerDayCountFailList.add(triggerDayCountFail);
|
356
|
|
-
|
357
|
|
- triggerCountRunningTotal += triggerDayCountRunning;
|
358
|
|
- triggerCountSucTotal += triggerDayCountSuc;
|
359
|
|
- triggerCountFailTotal += triggerDayCountFail;
|
360
|
|
- }
|
361
|
|
- } else {
|
362
|
|
- for (int i = 4; i > -1; i--) {
|
363
|
|
- triggerDayList.add(FastDateFormat.getInstance("yyyy-MM-dd").format(DateUtils.addDays(new Date(), -i)));
|
364
|
|
- triggerDayCountSucList.add(0);
|
365
|
|
- triggerDayCountFailList.add(0);
|
366
|
|
- }
|
367
|
|
- }
|
368
|
|
-
|
369
|
|
- Map<String, Object> result = new HashMap<String, Object>();
|
370
|
|
- result.put("triggerDayList", triggerDayList);
|
371
|
|
- result.put("triggerDayCountRunningList", triggerDayCountRunningList);
|
372
|
|
- result.put("triggerDayCountSucList", triggerDayCountSucList);
|
373
|
|
- result.put("triggerDayCountFailList", triggerDayCountFailList);
|
374
|
|
-
|
375
|
|
- result.put("triggerCountRunningTotal", triggerCountRunningTotal);
|
376
|
|
- result.put("triggerCountSucTotal", triggerCountSucTotal);
|
377
|
|
- result.put("triggerCountFailTotal", triggerCountFailTotal);
|
378
|
|
-
|
379
|
|
- /*// set cache
|
380
|
|
- LocalCacheUtil.set(cacheKey, result, 60*1000); // cache 60s*/
|
381
|
|
-
|
382
|
|
- return new ReturnT<Map<String, Object>>(result);
|
383
|
|
- }
|
384
|
|
-
|
385
|
|
-}
|
|
1
|
+package com.xxl.job.admin.service.impl;
|
|
2
|
+
|
|
3
|
+import com.xxl.job.admin.core.model.XxlJobGroup;
|
|
4
|
+import com.xxl.job.admin.core.model.XxlJobInfo;
|
|
5
|
+import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
|
|
6
|
+import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
7
|
+import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
|
8
|
+import com.xxl.job.admin.core.util.I18nUtil;
|
|
9
|
+import com.xxl.job.admin.dao.XxlJobGroupDao;
|
|
10
|
+import com.xxl.job.admin.dao.XxlJobInfoDao;
|
|
11
|
+import com.xxl.job.admin.dao.XxlJobLogDao;
|
|
12
|
+import com.xxl.job.admin.dao.XxlJobLogGlueDao;
|
|
13
|
+import com.xxl.job.admin.service.XxlJobService;
|
|
14
|
+import com.xxl.job.core.biz.model.ReturnT;
|
|
15
|
+import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
|
16
|
+import com.xxl.job.core.glue.GlueTypeEnum;
|
|
17
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
18
|
+import org.apache.commons.lang3.StringUtils;
|
|
19
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
20
|
+import org.apache.commons.lang3.time.FastDateFormat;
|
|
21
|
+import org.quartz.CronExpression;
|
|
22
|
+import org.quartz.SchedulerException;
|
|
23
|
+import org.slf4j.Logger;
|
|
24
|
+import org.slf4j.LoggerFactory;
|
|
25
|
+import org.springframework.stereotype.Service;
|
|
26
|
+
|
|
27
|
+import javax.annotation.Resource;
|
|
28
|
+import java.text.MessageFormat;
|
|
29
|
+import java.util.*;
|
|
30
|
+
|
|
31
|
+/**
|
|
32
|
+ * core job action for xxl-job
|
|
33
|
+ * @author xuxueli 2016-5-28 15:30:33
|
|
34
|
+ */
|
|
35
|
+@Service
|
|
36
|
+public class XxlJobServiceImpl implements XxlJobService {
|
|
37
|
+ private static Logger logger = LoggerFactory.getLogger(XxlJobServiceImpl.class);
|
|
38
|
+
|
|
39
|
+ @Resource
|
|
40
|
+ private XxlJobGroupDao xxlJobGroupDao;
|
|
41
|
+ @Resource
|
|
42
|
+ private XxlJobInfoDao xxlJobInfoDao;
|
|
43
|
+ @Resource
|
|
44
|
+ public XxlJobLogDao xxlJobLogDao;
|
|
45
|
+ @Resource
|
|
46
|
+ private XxlJobLogGlueDao xxlJobLogGlueDao;
|
|
47
|
+
|
|
48
|
+ @Override
|
|
49
|
+ public Map<String, Object> pageList(int start, int length, int jobGroup, String jobDesc, String executorHandler, String filterTime) {
|
|
50
|
+
|
|
51
|
+ // page list
|
|
52
|
+ List<XxlJobInfo> list = xxlJobInfoDao.pageList(start, length, jobGroup, jobDesc, executorHandler);
|
|
53
|
+ int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, jobDesc, executorHandler);
|
|
54
|
+
|
|
55
|
+ // fill job info
|
|
56
|
+ if (list!=null && list.size()>0) {
|
|
57
|
+ for (XxlJobInfo jobInfo : list) {
|
|
58
|
+ XxlJobDynamicScheduler.fillJobInfo(jobInfo);
|
|
59
|
+ }
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ // package result
|
|
63
|
+ Map<String, Object> maps = new HashMap<String, Object>();
|
|
64
|
+ maps.put("recordsTotal", list_count); // 总记录数
|
|
65
|
+ maps.put("recordsFiltered", list_count); // 过滤后的总记录数
|
|
66
|
+ maps.put("data", list); // 分页列表
|
|
67
|
+ return maps;
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Override
|
|
71
|
+ public ReturnT<String> add(XxlJobInfo jobInfo) {
|
|
72
|
+ // valid
|
|
73
|
+ XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup());
|
|
74
|
+ if (group == null) {
|
|
75
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")) );
|
|
76
|
+ }
|
|
77
|
+ if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
|
78
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") );
|
|
79
|
+ }
|
|
80
|
+ if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
|
81
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
|
|
82
|
+ }
|
|
83
|
+ if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
|
84
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
|
|
85
|
+ }
|
|
86
|
+ if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
|
87
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
|
|
88
|
+ }
|
|
89
|
+ if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
|
90
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
|
|
91
|
+ }
|
|
92
|
+ if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
|
|
93
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) );
|
|
94
|
+ }
|
|
95
|
+ if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && StringUtils.isBlank(jobInfo.getExecutorHandler())) {
|
|
96
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+"JobHandler") );
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ // fix "\r" in shell
|
|
100
|
+ if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) {
|
|
101
|
+ jobInfo.setGlueSource(jobInfo.getGlueSource().replaceAll("\r", ""));
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ // ChildJobId valid
|
|
105
|
+ if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
|
|
106
|
+ String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
|
|
107
|
+ for (String childJobIdItem: childJobIds) {
|
|
108
|
+ if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
|
|
109
|
+ XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
|
|
110
|
+ if (childJobInfo==null) {
|
|
111
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE,
|
|
112
|
+ MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
|
|
113
|
+ }
|
|
114
|
+ } else {
|
|
115
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE,
|
|
116
|
+ MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
|
|
117
|
+ }
|
|
118
|
+ }
|
|
119
|
+ jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ // add in db
|
|
123
|
+ xxlJobInfoDao.save(jobInfo);
|
|
124
|
+ if (jobInfo.getId() < 1) {
|
|
125
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ // add in quartz
|
|
129
|
+ String qz_group = String.valueOf(jobInfo.getJobGroup());
|
|
130
|
+ String qz_name = String.valueOf(jobInfo.getId());
|
|
131
|
+ try {
|
|
132
|
+ XxlJobDynamicScheduler.addJob(qz_name, qz_group, jobInfo.getJobCron());
|
|
133
|
+ //XxlJobDynamicScheduler.pauseJob(qz_name, qz_group);
|
|
134
|
+ return ReturnT.SUCCESS;
|
|
135
|
+ } catch (SchedulerException e) {
|
|
136
|
+ logger.error(e.getMessage(), e);
|
|
137
|
+ try {
|
|
138
|
+ xxlJobInfoDao.delete(jobInfo.getId());
|
|
139
|
+ XxlJobDynamicScheduler.removeJob(qz_name, qz_group);
|
|
140
|
+ } catch (SchedulerException e1) {
|
|
141
|
+ logger.error(e.getMessage(), e1);
|
|
142
|
+ }
|
|
143
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail"))+":" + e.getMessage());
|
|
144
|
+ }
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ @Override
|
|
148
|
+ public ReturnT<String> update(XxlJobInfo jobInfo) {
|
|
149
|
+
|
|
150
|
+ // valid
|
|
151
|
+ if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
|
152
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") );
|
|
153
|
+ }
|
|
154
|
+ if (StringUtils.isBlank(jobInfo.getJobDesc())) {
|
|
155
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
|
|
156
|
+ }
|
|
157
|
+ if (StringUtils.isBlank(jobInfo.getAuthor())) {
|
|
158
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
|
|
159
|
+ }
|
|
160
|
+ if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
|
161
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
|
|
162
|
+ }
|
|
163
|
+ if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
|
164
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ // ChildJobId valid
|
|
168
|
+ if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
|
|
169
|
+ String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
|
|
170
|
+ for (String childJobIdItem: childJobIds) {
|
|
171
|
+ if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
|
|
172
|
+ XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
|
|
173
|
+ if (childJobInfo==null) {
|
|
174
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE,
|
|
175
|
+ MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
|
|
176
|
+ }
|
|
177
|
+ // avoid cycle relate
|
|
178
|
+ if (childJobInfo.getId() == jobInfo.getId()) {
|
|
179
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, MessageFormat.format(I18nUtil.getString("jobinfo_field_childJobId_limit"), childJobIdItem));
|
|
180
|
+ }
|
|
181
|
+ } else {
|
|
182
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE,
|
|
183
|
+ MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
|
|
184
|
+ }
|
|
185
|
+ }
|
|
186
|
+ jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ // stage job info
|
|
190
|
+ XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
|
|
191
|
+ if (exists_jobInfo == null) {
|
|
192
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
|
|
193
|
+ }
|
|
194
|
+ //String old_cron = exists_jobInfo.getJobCron();
|
|
195
|
+
|
|
196
|
+ exists_jobInfo.setJobCron(jobInfo.getJobCron());
|
|
197
|
+ exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
|
|
198
|
+ exists_jobInfo.setAuthor(jobInfo.getAuthor());
|
|
199
|
+ exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
|
|
200
|
+ exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
|
|
201
|
+ exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
|
|
202
|
+ exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam());
|
|
203
|
+ exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
|
|
204
|
+ exists_jobInfo.setExecutorFailStrategy(jobInfo.getExecutorFailStrategy());
|
|
205
|
+ exists_jobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout());
|
|
206
|
+ exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
|
|
207
|
+ exists_jobInfo.setChildJobId(jobInfo.getChildJobId());
|
|
208
|
+ xxlJobInfoDao.update(exists_jobInfo);
|
|
209
|
+
|
|
210
|
+ // fresh quartz
|
|
211
|
+ String qz_group = String.valueOf(exists_jobInfo.getJobGroup());
|
|
212
|
+ String qz_name = String.valueOf(exists_jobInfo.getId());
|
|
213
|
+ try {
|
|
214
|
+ boolean ret = XxlJobDynamicScheduler.rescheduleJob(qz_group, qz_name, exists_jobInfo.getJobCron());
|
|
215
|
+ return ret?ReturnT.SUCCESS:ReturnT.FAIL;
|
|
216
|
+ } catch (SchedulerException e) {
|
|
217
|
+ logger.error(e.getMessage(), e);
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ return ReturnT.FAIL;
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ @Override
|
|
224
|
+ public ReturnT<String> remove(int id) {
|
|
225
|
+ XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
|
226
|
+ String group = String.valueOf(xxlJobInfo.getJobGroup());
|
|
227
|
+ String name = String.valueOf(xxlJobInfo.getId());
|
|
228
|
+
|
|
229
|
+ try {
|
|
230
|
+ XxlJobDynamicScheduler.removeJob(name, group);
|
|
231
|
+ xxlJobInfoDao.delete(id);
|
|
232
|
+ xxlJobLogDao.delete(id);
|
|
233
|
+ xxlJobLogGlueDao.deleteByJobId(id);
|
|
234
|
+ return ReturnT.SUCCESS;
|
|
235
|
+ } catch (SchedulerException e) {
|
|
236
|
+ logger.error(e.getMessage(), e);
|
|
237
|
+ }
|
|
238
|
+ return ReturnT.FAIL;
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ @Override
|
|
242
|
+ public ReturnT<String> pause(int id) {
|
|
243
|
+ XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
|
244
|
+ String group = String.valueOf(xxlJobInfo.getJobGroup());
|
|
245
|
+ String name = String.valueOf(xxlJobInfo.getId());
|
|
246
|
+
|
|
247
|
+ try {
|
|
248
|
+ boolean ret = XxlJobDynamicScheduler.pauseJob(name, group); // jobStatus do not store
|
|
249
|
+ return ret?ReturnT.SUCCESS:ReturnT.FAIL;
|
|
250
|
+ } catch (SchedulerException e) {
|
|
251
|
+ logger.error(e.getMessage(), e);
|
|
252
|
+ return ReturnT.FAIL;
|
|
253
|
+ }
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ @Override
|
|
257
|
+ public ReturnT<String> resume(int id) {
|
|
258
|
+ XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
|
259
|
+ String group = String.valueOf(xxlJobInfo.getJobGroup());
|
|
260
|
+ String name = String.valueOf(xxlJobInfo.getId());
|
|
261
|
+
|
|
262
|
+ try {
|
|
263
|
+ boolean ret = XxlJobDynamicScheduler.resumeJob(name, group);
|
|
264
|
+ return ret?ReturnT.SUCCESS:ReturnT.FAIL;
|
|
265
|
+ } catch (SchedulerException e) {
|
|
266
|
+ logger.error(e.getMessage(), e);
|
|
267
|
+ return ReturnT.FAIL;
|
|
268
|
+ }
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ @Override
|
|
272
|
+ public ReturnT<String> triggerJob(int id) {
|
|
273
|
+
|
|
274
|
+ JobTriggerPoolHelper.trigger(id);
|
|
275
|
+ return ReturnT.SUCCESS;
|
|
276
|
+
|
|
277
|
+ /*XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
|
278
|
+ if (xxlJobInfo == null) {
|
|
279
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_unvalid")) );
|
|
280
|
+ }
|
|
281
|
+
|
|
282
|
+ String group = String.valueOf(xxlJobInfo.getJobGroup());
|
|
283
|
+ String name = String.valueOf(xxlJobInfo.getId());
|
|
284
|
+
|
|
285
|
+ try {
|
|
286
|
+ XxlJobDynamicScheduler.triggerJob(name, group);
|
|
287
|
+ return ReturnT.SUCCESS;
|
|
288
|
+ } catch (SchedulerException e) {
|
|
289
|
+ logger.error(e.getMessage(), e);
|
|
290
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());
|
|
291
|
+ }*/
|
|
292
|
+
|
|
293
|
+ }
|
|
294
|
+
|
|
295
|
+ @Override
|
|
296
|
+ public Map<String, Object> dashboardInfo() {
|
|
297
|
+
|
|
298
|
+ int jobInfoCount = xxlJobInfoDao.findAllCount();
|
|
299
|
+ int jobLogCount = xxlJobLogDao.triggerCountByHandleCode(-1);
|
|
300
|
+ int jobLogSuccessCount = xxlJobLogDao.triggerCountByHandleCode(ReturnT.SUCCESS_CODE);
|
|
301
|
+
|
|
302
|
+ // executor count
|
|
303
|
+ Set<String> executerAddressSet = new HashSet<String>();
|
|
304
|
+ List<XxlJobGroup> groupList = xxlJobGroupDao.findAll();
|
|
305
|
+
|
|
306
|
+ if (CollectionUtils.isNotEmpty(groupList)) {
|
|
307
|
+ for (XxlJobGroup group: groupList) {
|
|
308
|
+ if (CollectionUtils.isNotEmpty(group.getRegistryList())) {
|
|
309
|
+ executerAddressSet.addAll(group.getRegistryList());
|
|
310
|
+ }
|
|
311
|
+ }
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+ int executorCount = executerAddressSet.size();
|
|
315
|
+
|
|
316
|
+ Map<String, Object> dashboardMap = new HashMap<String, Object>();
|
|
317
|
+ dashboardMap.put("jobInfoCount", jobInfoCount);
|
|
318
|
+ dashboardMap.put("jobLogCount", jobLogCount);
|
|
319
|
+ dashboardMap.put("jobLogSuccessCount", jobLogSuccessCount);
|
|
320
|
+ dashboardMap.put("executorCount", executorCount);
|
|
321
|
+ return dashboardMap;
|
|
322
|
+ }
|
|
323
|
+
|
|
324
|
+ private static final String TRIGGER_CHART_DATA_CACHE = "trigger_chart_data_cache";
|
|
325
|
+ @Override
|
|
326
|
+ public ReturnT<Map<String, Object>> chartInfo(Date startDate, Date endDate) {
|
|
327
|
+ /*// get cache
|
|
328
|
+ String cacheKey = TRIGGER_CHART_DATA_CACHE + "_" + startDate.getTime() + "_" + endDate.getTime();
|
|
329
|
+ Map<String, Object> chartInfo = (Map<String, Object>) LocalCacheUtil.get(cacheKey);
|
|
330
|
+ if (chartInfo != null) {
|
|
331
|
+ return new ReturnT<Map<String, Object>>(chartInfo);
|
|
332
|
+ }*/
|
|
333
|
+
|
|
334
|
+ // process
|
|
335
|
+ List<String> triggerDayList = new ArrayList<String>();
|
|
336
|
+ List<Integer> triggerDayCountRunningList = new ArrayList<Integer>();
|
|
337
|
+ List<Integer> triggerDayCountSucList = new ArrayList<Integer>();
|
|
338
|
+ List<Integer> triggerDayCountFailList = new ArrayList<Integer>();
|
|
339
|
+ int triggerCountRunningTotal = 0;
|
|
340
|
+ int triggerCountSucTotal = 0;
|
|
341
|
+ int triggerCountFailTotal = 0;
|
|
342
|
+
|
|
343
|
+ List<Map<String, Object>> triggerCountMapAll = xxlJobLogDao.triggerCountByDay(startDate, endDate);
|
|
344
|
+ if (CollectionUtils.isNotEmpty(triggerCountMapAll)) {
|
|
345
|
+ for (Map<String, Object> item: triggerCountMapAll) {
|
|
346
|
+ String day = String.valueOf(item.get("triggerDay"));
|
|
347
|
+ int triggerDayCount = Integer.valueOf(String.valueOf(item.get("triggerDayCount")));
|
|
348
|
+ int triggerDayCountRunning = Integer.valueOf(String.valueOf(item.get("triggerDayCountRunning")));
|
|
349
|
+ int triggerDayCountSuc = Integer.valueOf(String.valueOf(item.get("triggerDayCountSuc")));
|
|
350
|
+ int triggerDayCountFail = triggerDayCount - triggerDayCountRunning - triggerDayCountSuc;
|
|
351
|
+
|
|
352
|
+ triggerDayList.add(day);
|
|
353
|
+ triggerDayCountRunningList.add(triggerDayCountRunning);
|
|
354
|
+ triggerDayCountSucList.add(triggerDayCountSuc);
|
|
355
|
+ triggerDayCountFailList.add(triggerDayCountFail);
|
|
356
|
+
|
|
357
|
+ triggerCountRunningTotal += triggerDayCountRunning;
|
|
358
|
+ triggerCountSucTotal += triggerDayCountSuc;
|
|
359
|
+ triggerCountFailTotal += triggerDayCountFail;
|
|
360
|
+ }
|
|
361
|
+ } else {
|
|
362
|
+ for (int i = 4; i > -1; i--) {
|
|
363
|
+ triggerDayList.add(FastDateFormat.getInstance("yyyy-MM-dd").format(DateUtils.addDays(new Date(), -i)));
|
|
364
|
+ triggerDayCountSucList.add(0);
|
|
365
|
+ triggerDayCountFailList.add(0);
|
|
366
|
+ }
|
|
367
|
+ }
|
|
368
|
+
|
|
369
|
+ Map<String, Object> result = new HashMap<String, Object>();
|
|
370
|
+ result.put("triggerDayList", triggerDayList);
|
|
371
|
+ result.put("triggerDayCountRunningList", triggerDayCountRunningList);
|
|
372
|
+ result.put("triggerDayCountSucList", triggerDayCountSucList);
|
|
373
|
+ result.put("triggerDayCountFailList", triggerDayCountFailList);
|
|
374
|
+
|
|
375
|
+ result.put("triggerCountRunningTotal", triggerCountRunningTotal);
|
|
376
|
+ result.put("triggerCountSucTotal", triggerCountSucTotal);
|
|
377
|
+ result.put("triggerCountFailTotal", triggerCountFailTotal);
|
|
378
|
+
|
|
379
|
+ /*// set cache
|
|
380
|
+ LocalCacheUtil.set(cacheKey, result, 60*1000); // cache 60s*/
|
|
381
|
+
|
|
382
|
+ return new ReturnT<Map<String, Object>>(result);
|
|
383
|
+ }
|
|
384
|
+
|
|
385
|
+}
|