|
@@ -1,19 +1,6 @@
|
1
|
1
|
package com.xxl.job.admin.core.jobbean;
|
2
|
2
|
|
3
|
|
-import com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum;
|
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.XxlJobLog;
|
7
|
|
-import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
|
8
|
|
-import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
9
|
|
-import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
|
10
|
|
-import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
|
11
|
|
-import com.xxl.job.core.biz.model.ReturnT;
|
12
|
|
-import com.xxl.job.core.biz.model.TriggerParam;
|
13
|
|
-import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
14
|
|
-import com.xxl.job.core.enums.RegistryConfig;
|
15
|
|
-import org.apache.commons.collections.CollectionUtils;
|
16
|
|
-import org.apache.commons.lang.StringUtils;
|
|
3
|
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
|
17
|
4
|
import org.quartz.JobExecutionContext;
|
18
|
5
|
import org.quartz.JobExecutionException;
|
19
|
6
|
import org.quartz.JobKey;
|
|
@@ -21,10 +8,6 @@ import org.slf4j.Logger;
|
21
|
8
|
import org.slf4j.LoggerFactory;
|
22
|
9
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
23
|
10
|
|
24
|
|
-import java.util.ArrayList;
|
25
|
|
-import java.util.Arrays;
|
26
|
|
-import java.util.Date;
|
27
|
|
-
|
28
|
11
|
/**
|
29
|
12
|
* http job bean
|
30
|
13
|
* “@DisallowConcurrentExecution” diable concurrent, thread size can not be only one, better given more
|
|
@@ -38,96 +21,12 @@ public class RemoteHttpJobBean extends QuartzJobBean {
|
38
|
21
|
protected void executeInternal(JobExecutionContext context)
|
39
|
22
|
throws JobExecutionException {
|
40
|
23
|
|
41
|
|
- // load job
|
|
24
|
+ // load jobId
|
42
|
25
|
JobKey jobKey = context.getTrigger().getJobKey();
|
43
|
26
|
Integer jobId = Integer.valueOf(jobKey.getName());
|
44
|
|
- XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId);
|
45
|
|
-
|
46
|
|
- // log part-1
|
47
|
|
- XxlJobLog jobLog = new XxlJobLog();
|
48
|
|
- jobLog.setJobGroup(jobInfo.getJobGroup());
|
49
|
|
- jobLog.setJobId(jobInfo.getId());
|
50
|
|
- XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog);
|
51
|
|
- logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());
|
52
|
|
-
|
53
|
|
- // log part-2 param
|
54
|
|
- //jobLog.setExecutorAddress(executorAddress);
|
55
|
|
- jobLog.setGlueType(jobInfo.getGlueType());
|
56
|
|
- jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
|
57
|
|
- jobLog.setExecutorParam(jobInfo.getExecutorParam());
|
58
|
|
- jobLog.setTriggerTime(new Date());
|
59
|
|
-
|
60
|
|
- // trigger request
|
61
|
|
- TriggerParam triggerParam = new TriggerParam();
|
62
|
|
- triggerParam.setJobId(jobInfo.getId());
|
63
|
|
- triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
|
64
|
|
- triggerParam.setExecutorParams(jobInfo.getExecutorParam());
|
65
|
|
- triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
|
66
|
|
- triggerParam.setGlueType(jobInfo.getGlueType());
|
67
|
|
- triggerParam.setGlueSource(jobInfo.getGlueSource());
|
68
|
|
- triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
|
69
|
|
- triggerParam.setLogId(jobLog.getId());
|
70
|
|
- triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());
|
71
|
|
-
|
72
|
|
- // do trigger
|
73
|
|
- ReturnT<String> triggerResult = doTrigger(triggerParam, jobInfo, jobLog);
|
74
|
|
-
|
75
|
|
- // fail retry
|
76
|
|
- if (triggerResult.getCode()==ReturnT.FAIL_CODE &&
|
77
|
|
- ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), null) == ExecutorFailStrategyEnum.FAIL_RETRY) {
|
78
|
|
- ReturnT<String> retryTriggerResult = doTrigger(triggerParam, jobInfo, jobLog);
|
79
|
|
-
|
80
|
|
- triggerResult.setCode(retryTriggerResult.getCode());
|
81
|
|
- triggerResult.setMsg(triggerResult.getMsg() + "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>失败重试<<<<<<<<<<< </span><br><br>" +retryTriggerResult.getMsg());
|
82
|
|
- }
|
83
|
|
-
|
84
|
|
- // log part-2
|
85
|
|
- jobLog.setTriggerCode(triggerResult.getCode());
|
86
|
|
- jobLog.setTriggerMsg(triggerResult.getMsg());
|
87
|
|
- XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);
|
88
|
|
-
|
89
|
|
- // monitor triger
|
90
|
|
- JobFailMonitorHelper.monitor(jobLog.getId());
|
91
|
|
- logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
|
92
|
|
- }
|
93
|
|
-
|
94
|
|
- public ReturnT<String> doTrigger(TriggerParam triggerParam, XxlJobInfo jobInfo, XxlJobLog jobLog){
|
95
|
|
- StringBuffer triggerSb = new StringBuffer();
|
96
|
|
-
|
97
|
|
- // exerutor address list
|
98
|
|
- ArrayList<String> addressList = null;
|
99
|
|
- XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup());
|
100
|
|
- if (group.getAddressType() == 0) {
|
101
|
|
- triggerSb.append("注册方式:自动注册");
|
102
|
|
- addressList = (ArrayList<String>) JobRegistryMonitorHelper.discover(RegistryConfig.RegistType.EXECUTOR.name(), group.getAppName());
|
103
|
|
- } else {
|
104
|
|
- triggerSb.append("注册方式:手动录入");
|
105
|
|
- if (StringUtils.isNotBlank(group.getAddressList())) {
|
106
|
|
- addressList = new ArrayList<String>(Arrays.asList(group.getAddressList().split(",")));
|
107
|
|
- }
|
108
|
|
- }
|
109
|
|
- triggerSb.append("<br>阻塞处理策略:").append(ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION).getTitle());
|
110
|
|
- triggerSb.append("<br>失败处理策略:").append(ExecutorFailStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorFailStrategyEnum.FAIL_ALARM).getTitle());
|
111
|
|
- triggerSb.append("<br>地址列表:").append(addressList!=null?addressList.toString():"");
|
112
|
|
- if (CollectionUtils.isEmpty(addressList)) {
|
113
|
|
- triggerSb.append("<br>----------------------<br>").append("调度失败:").append("执行器地址为空");
|
114
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, triggerSb.toString());
|
115
|
|
- }
|
116
|
|
-
|
117
|
|
- // executor route strategy
|
118
|
|
- ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null);
|
119
|
|
- if (executorRouteStrategyEnum == null) {
|
120
|
|
- triggerSb.append("<br>----------------------<br>").append("调度失败:").append("执行器路由策略为空");
|
121
|
|
- return new ReturnT<String>(ReturnT.FAIL_CODE, triggerSb.toString());
|
122
|
|
- }
|
123
|
|
- triggerSb.append("<br>路由策略:").append(executorRouteStrategyEnum.name() + "-" + executorRouteStrategyEnum.getTitle());
|
124
|
|
-
|
125
|
|
-
|
126
|
|
- // route run / trigger remote executor
|
127
|
|
- ReturnT<String> routeRunResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList, jobLog);
|
128
|
|
- triggerSb.append("<br>----------------------<br>").append(routeRunResult.getMsg());
|
129
|
|
- return new ReturnT<String>(routeRunResult.getCode(), triggerSb.toString());
|
130
|
27
|
|
|
28
|
+ // trigger
|
|
29
|
+ XxlJobTrigger.trigger(jobId);
|
131
|
30
|
}
|
132
|
31
|
|
133
|
32
|
}
|