瀏覽代碼

任务调度模块,底层代码重构

xuxueli 7 年之前
父節點
當前提交
e43791d4a1

+ 2 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/ExecutorRouter.java 查看文件

5
 import org.slf4j.Logger;
5
 import org.slf4j.Logger;
6
 import org.slf4j.LoggerFactory;
6
 import org.slf4j.LoggerFactory;
7
 
7
 
8
-import java.util.ArrayList;
8
+import java.util.List;
9
 
9
 
10
 /**
10
 /**
11
  * Created by xuxueli on 17/3/10.
11
  * Created by xuxueli on 17/3/10.
19
      * @param addressList
19
      * @param addressList
20
      * @return  ReturnT.content=address
20
      * @return  ReturnT.content=address
21
      */
21
      */
22
-    public abstract ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList);
22
+    public abstract ReturnT<String> route(TriggerParam triggerParam, List<String> addressList);
23
 
23
 
24
 }
24
 }

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteBusyover.java 查看文件

2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
4
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
5
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
6
 import com.xxl.job.admin.core.util.I18nUtil;
5
 import com.xxl.job.admin.core.util.I18nUtil;
7
 import com.xxl.job.core.biz.ExecutorBiz;
6
 import com.xxl.job.core.biz.ExecutorBiz;
8
 import com.xxl.job.core.biz.model.ReturnT;
7
 import com.xxl.job.core.biz.model.ReturnT;
9
 import com.xxl.job.core.biz.model.TriggerParam;
8
 import com.xxl.job.core.biz.model.TriggerParam;
10
 
9
 
11
-import java.util.ArrayList;
10
+import java.util.List;
12
 
11
 
13
 /**
12
 /**
14
  * Created by xuxueli on 17/3/10.
13
  * Created by xuxueli on 17/3/10.
16
 public class ExecutorRouteBusyover extends ExecutorRouter {
15
 public class ExecutorRouteBusyover extends ExecutorRouter {
17
 
16
 
18
     @Override
17
     @Override
19
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
18
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
20
         StringBuffer idleBeatResultSB = new StringBuffer();
19
         StringBuffer idleBeatResultSB = new StringBuffer();
21
         for (String address : addressList) {
20
         for (String address : addressList) {
22
             // beat
21
             // beat

+ 3 - 4
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteConsistentHash.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
8
 import java.io.UnsupportedEncodingException;
7
 import java.io.UnsupportedEncodingException;
9
 import java.security.MessageDigest;
8
 import java.security.MessageDigest;
10
 import java.security.NoSuchAlgorithmException;
9
 import java.security.NoSuchAlgorithmException;
11
-import java.util.ArrayList;
10
+import java.util.List;
12
 import java.util.SortedMap;
11
 import java.util.SortedMap;
13
 import java.util.TreeMap;
12
 import java.util.TreeMap;
14
 
13
 
57
         return truncateHashCode;
56
         return truncateHashCode;
58
     }
57
     }
59
 
58
 
60
-    public String hashJob(int jobId, ArrayList<String> addressList) {
59
+    public String hashJob(int jobId, List<String> addressList) {
61
 
60
 
62
         // ------A1------A2-------A3------
61
         // ------A1------A2-------A3------
63
         // -----------J1------------------
62
         // -----------J1------------------
78
     }
77
     }
79
 
78
 
80
     @Override
79
     @Override
81
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
80
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
82
         String address = hashJob(triggerParam.getJobId(), addressList);
81
         String address = hashJob(triggerParam.getJobId(), addressList);
83
         return new ReturnT<String>(address);
82
         return new ReturnT<String>(address);
84
     }
83
     }

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFailover.java 查看文件

2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
4
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
5
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
6
 import com.xxl.job.admin.core.util.I18nUtil;
5
 import com.xxl.job.admin.core.util.I18nUtil;
7
 import com.xxl.job.core.biz.ExecutorBiz;
6
 import com.xxl.job.core.biz.ExecutorBiz;
8
 import com.xxl.job.core.biz.model.ReturnT;
7
 import com.xxl.job.core.biz.model.ReturnT;
9
 import com.xxl.job.core.biz.model.TriggerParam;
8
 import com.xxl.job.core.biz.model.TriggerParam;
10
 
9
 
11
-import java.util.ArrayList;
10
+import java.util.List;
12
 
11
 
13
 /**
12
 /**
14
  * Created by xuxueli on 17/3/10.
13
  * Created by xuxueli on 17/3/10.
16
 public class ExecutorRouteFailover extends ExecutorRouter {
15
 public class ExecutorRouteFailover extends ExecutorRouter {
17
 
16
 
18
     @Override
17
     @Override
19
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
18
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
20
 
19
 
21
         StringBuffer beatResultSB = new StringBuffer();
20
         StringBuffer beatResultSB = new StringBuffer();
22
         for (String address : addressList) {
21
         for (String address : addressList) {

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFirst.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
8
-import java.util.ArrayList;
7
+import java.util.List;
9
 
8
 
10
 /**
9
 /**
11
  * Created by xuxueli on 17/3/10.
10
  * Created by xuxueli on 17/3/10.
13
 public class ExecutorRouteFirst extends ExecutorRouter {
12
 public class ExecutorRouteFirst extends ExecutorRouter {
14
 
13
 
15
     @Override
14
     @Override
16
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList){
15
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList){
17
         return new ReturnT<String>(addressList.get(0));
16
         return new ReturnT<String>(addressList.get(0));
18
     }
17
     }
19
 
18
 

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
20
     private static ConcurrentHashMap<Integer, HashMap<String, Integer>> jobLfuMap = new ConcurrentHashMap<Integer, HashMap<String, Integer>>();
19
     private static ConcurrentHashMap<Integer, HashMap<String, Integer>> jobLfuMap = new ConcurrentHashMap<Integer, HashMap<String, Integer>>();
21
     private static long CACHE_VALID_TIME = 0;
20
     private static long CACHE_VALID_TIME = 0;
22
 
21
 
23
-    public String route(int jobId, ArrayList<String> addressList) {
22
+    public String route(int jobId, List<String> addressList) {
24
 
23
 
25
         // cache clear
24
         // cache clear
26
         if (System.currentTimeMillis() > CACHE_VALID_TIME) {
25
         if (System.currentTimeMillis() > CACHE_VALID_TIME) {
57
     }
56
     }
58
 
57
 
59
     @Override
58
     @Override
60
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
59
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
61
         String address = route(triggerParam.getJobId(), addressList);
60
         String address = route(triggerParam.getJobId(), addressList);
62
         return new ReturnT<String>(address);
61
         return new ReturnT<String>(address);
63
     }
62
     }

+ 3 - 4
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
8
-import java.util.ArrayList;
9
 import java.util.LinkedHashMap;
7
 import java.util.LinkedHashMap;
8
+import java.util.List;
10
 import java.util.concurrent.ConcurrentHashMap;
9
 import java.util.concurrent.ConcurrentHashMap;
11
 
10
 
12
 /**
11
 /**
21
     private static ConcurrentHashMap<Integer, LinkedHashMap<String, String>> jobLRUMap = new ConcurrentHashMap<Integer, LinkedHashMap<String, String>>();
20
     private static ConcurrentHashMap<Integer, LinkedHashMap<String, String>> jobLRUMap = new ConcurrentHashMap<Integer, LinkedHashMap<String, String>>();
22
     private static long CACHE_VALID_TIME = 0;
21
     private static long CACHE_VALID_TIME = 0;
23
 
22
 
24
-    public String route(int jobId, ArrayList<String> addressList) {
23
+    public String route(int jobId, List<String> addressList) {
25
 
24
 
26
         // cache clear
25
         // cache clear
27
         if (System.currentTimeMillis() > CACHE_VALID_TIME) {
26
         if (System.currentTimeMillis() > CACHE_VALID_TIME) {
55
     }
54
     }
56
 
55
 
57
     @Override
56
     @Override
58
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
57
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
59
         String address = route(triggerParam.getJobId(), addressList);
58
         String address = route(triggerParam.getJobId(), addressList);
60
         return new ReturnT<String>(address);
59
         return new ReturnT<String>(address);
61
     }
60
     }

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLast.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
8
-import java.util.ArrayList;
7
+import java.util.List;
9
 
8
 
10
 /**
9
 /**
11
  * Created by xuxueli on 17/3/10.
10
  * Created by xuxueli on 17/3/10.
13
 public class ExecutorRouteLast extends ExecutorRouter {
12
 public class ExecutorRouteLast extends ExecutorRouter {
14
 
13
 
15
     @Override
14
     @Override
16
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
15
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
17
         return new ReturnT<String>(addressList.get(addressList.size()-1));
16
         return new ReturnT<String>(addressList.get(addressList.size()-1));
18
     }
17
     }
19
 
18
 

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRandom.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
8
-import java.util.ArrayList;
7
+import java.util.List;
9
 import java.util.Random;
8
 import java.util.Random;
10
 
9
 
11
 /**
10
 /**
16
     private static Random localRandom = new Random();
15
     private static Random localRandom = new Random();
17
 
16
 
18
     @Override
17
     @Override
19
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
18
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
20
         String address = addressList.get(localRandom.nextInt(addressList.size()));
19
         String address = addressList.get(localRandom.nextInt(addressList.size()));
21
         return new ReturnT<String>(address);
20
         return new ReturnT<String>(address);
22
     }
21
     }

+ 2 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java 查看文件

1
 package com.xxl.job.admin.core.route.strategy;
1
 package com.xxl.job.admin.core.route.strategy;
2
 
2
 
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
-import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5
 import com.xxl.job.core.biz.model.ReturnT;
4
 import com.xxl.job.core.biz.model.ReturnT;
6
 import com.xxl.job.core.biz.model.TriggerParam;
5
 import com.xxl.job.core.biz.model.TriggerParam;
7
 
6
 
8
-import java.util.ArrayList;
7
+import java.util.List;
9
 import java.util.Random;
8
 import java.util.Random;
10
 import java.util.concurrent.ConcurrentHashMap;
9
 import java.util.concurrent.ConcurrentHashMap;
11
 
10
 
31
     }
30
     }
32
 
31
 
33
     @Override
32
     @Override
34
-    public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
33
+    public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
35
         String address = addressList.get(count(triggerParam.getJobId())%addressList.size());
34
         String address = addressList.get(count(triggerParam.getJobId())%addressList.size());
36
         return new ReturnT<String>(address);
35
         return new ReturnT<String>(address);
37
     }
36
     }

+ 85 - 134
xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java 查看文件

18
 
18
 
19
 import java.util.ArrayList;
19
 import java.util.ArrayList;
20
 import java.util.Date;
20
 import java.util.Date;
21
+import java.util.List;
21
 
22
 
22
 /**
23
 /**
23
  * xxl-job trigger
24
  * xxl-job trigger
36
      *
37
      *
37
      */
38
      */
38
     public static void trigger(int jobId, int failRetryCount, TriggerTypeEnum triggerType) {
39
     public static void trigger(int jobId, int failRetryCount, TriggerTypeEnum triggerType) {
39
-
40
         // load data
40
         // load data
41
         XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId);              // job info
41
         XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId);              // job info
42
         if (jobInfo == null) {
42
         if (jobInfo == null) {
43
             logger.warn(">>>>>>>>>>>> trigger fail, jobId invalid,jobId={}", jobId);
43
             logger.warn(">>>>>>>>>>>> trigger fail, jobId invalid,jobId={}", jobId);
44
             return;
44
             return;
45
         }
45
         }
46
-        int finalFailRetryCount = jobInfo.getExecutorFailRetryCount();
47
-        if (failRetryCount >= 0) {
48
-            finalFailRetryCount = failRetryCount;
46
+        int finalFailRetryCount = failRetryCount>=0?failRetryCount:jobInfo.getExecutorFailRetryCount();
47
+        XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup());  // group info
48
+
49
+        // process trigger
50
+        if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) && CollectionUtils.isNotEmpty(group.getRegistryList())) {
51
+            for (int i = 0; i < group.getRegistryList().size(); i++) {
52
+                processTrigger(group, jobInfo, finalFailRetryCount, triggerType, i);
53
+            }
54
+        } else {
55
+            processTrigger(group, jobInfo, finalFailRetryCount, triggerType, 0);
49
         }
56
         }
57
+    }
50
 
58
 
51
-        XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup());  // group info
59
+    private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index){
52
 
60
 
61
+        // param
53
         ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION);  // block strategy
62
         ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION);  // block strategy
54
         ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null);    // route strategy
63
         ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null);    // route strategy
55
-        ArrayList<String> addressList = (ArrayList<String>) group.getRegistryList();
56
-
57
-        // broadcast
58
-        if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum && CollectionUtils.isNotEmpty(addressList)) {
59
-            for (int i = 0; i < addressList.size(); i++) {
60
-                String address = addressList.get(i);
61
-
62
-                // 1、save log-id
63
-                XxlJobLog jobLog = new XxlJobLog();
64
-                jobLog.setJobGroup(jobInfo.getJobGroup());
65
-                jobLog.setJobId(jobInfo.getId());
66
-                XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog);
67
-                logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());
68
-
69
-                // 2、prepare trigger-info
70
-                //jobLog.setExecutorAddress(executorAddress);
71
-                jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
72
-                jobLog.setExecutorParam(jobInfo.getExecutorParam());
73
-                jobLog.setExecutorFailRetryCount(finalFailRetryCount);
74
-                jobLog.setTriggerTime(new Date());
75
-
76
-                ReturnT<String> triggerResult = new ReturnT<String>(null);
77
-                StringBuffer triggerMsgSb = new StringBuffer();
78
-                triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle());
79
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp());
80
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":")
81
-                        .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
82
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
83
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle()).append("("+i+"/"+addressList.size()+")"); // update01
84
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
85
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
86
-                triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount);
87
-
88
-
89
-                // 3.1、trigger-param
90
-                TriggerParam triggerParam = new TriggerParam();
91
-                triggerParam.setJobId(jobInfo.getId());
92
-                triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
93
-                triggerParam.setExecutorParams(jobInfo.getExecutorParam());
94
-                triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
95
-                triggerParam.setExecutorTimeout(jobInfo.getExecutorTimeout());
96
-                triggerParam.setLogId(jobLog.getId());
97
-                triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());
98
-                triggerParam.setGlueType(jobInfo.getGlueType());
99
-                triggerParam.setGlueSource(jobInfo.getGlueSource());
100
-                triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
101
-                triggerParam.setBroadcastIndex(i);
102
-                triggerParam.setBroadcastTotal(addressList.size()); // update02
103
-
104
-                // 3.2、trigger-run (route run / trigger remote executor)
105
-                triggerResult = runExecutor(triggerParam, address);     // update03
106
-                triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
107
-
108
-                // 4、save trigger-info
109
-                jobLog.setExecutorAddress(triggerResult.getContent());
110
-                jobLog.setTriggerCode(triggerResult.getCode());
111
-                jobLog.setTriggerMsg(triggerMsgSb.toString());
112
-                XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);
113
-
114
-                // 5、monitor trigger
115
-                JobFailMonitorHelper.monitor(jobLog.getId());
116
-                logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
117
-
118
-            }
119
 
64
 
120
-        } else {
121
-            // 1、save log-id
122
-            XxlJobLog jobLog = new XxlJobLog();
123
-            jobLog.setJobGroup(jobInfo.getJobGroup());
124
-            jobLog.setJobId(jobInfo.getId());
125
-            XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog);
126
-            logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());
127
-
128
-            // 2、prepare trigger-info
129
-            //jobLog.setExecutorAddress(executorAddress);
130
-            jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
131
-            jobLog.setExecutorParam(jobInfo.getExecutorParam());
132
-            jobLog.setExecutorFailRetryCount(finalFailRetryCount);
133
-            jobLog.setTriggerTime(new Date());
134
-
135
-            ReturnT<String> triggerResult = new ReturnT<String>(null);
136
-            StringBuffer triggerMsgSb = new StringBuffer();
137
-            triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle());
138
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp());
139
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":")
140
-                    .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
141
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
142
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle());
143
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
144
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
145
-            triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount);
146
-
147
-            // 3.0、trigger-valid
148
-            String address = null;
149
-            if (CollectionUtils.isEmpty(addressList)) {
150
-                triggerResult.setCode(ReturnT.FAIL_CODE);
151
-                triggerMsgSb.append("<br>----------------------<br>").append(I18nUtil.getString("jobconf_trigger_address_empty"));
65
+        // 1、save log-id
66
+        XxlJobLog jobLog = new XxlJobLog();
67
+        jobLog.setJobGroup(jobInfo.getJobGroup());
68
+        jobLog.setJobId(jobInfo.getId());
69
+        jobLog.setTriggerTime(new Date());
70
+        XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog);
71
+        logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());
72
+
73
+        // 2、init trigger-param
74
+        TriggerParam triggerParam = new TriggerParam();
75
+        triggerParam.setJobId(jobInfo.getId());
76
+        triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
77
+        triggerParam.setExecutorParams(jobInfo.getExecutorParam());
78
+        triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
79
+        triggerParam.setExecutorTimeout(jobInfo.getExecutorTimeout());
80
+        triggerParam.setLogId(jobLog.getId());
81
+        triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());
82
+        triggerParam.setGlueType(jobInfo.getGlueType());
83
+        triggerParam.setGlueSource(jobInfo.getGlueSource());
84
+        triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
85
+        triggerParam.setBroadcastIndex(index);
86
+        triggerParam.setBroadcastTotal(group.getRegistryList()!=null?group.getRegistryList().size():0);
87
+
88
+        // 3、init address
89
+        String address = null;
90
+        ReturnT<String> routeAddressResult = null;
91
+        if (CollectionUtils.isNotEmpty(group.getRegistryList())) {
92
+            if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) {
93
+                address = group.getRegistryList().get(index);
152
             } else {
94
             } else {
153
-                // 3.1、trigger-param
154
-                TriggerParam triggerParam = new TriggerParam();
155
-                triggerParam.setJobId(jobInfo.getId());
156
-                triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
157
-                triggerParam.setExecutorParams(jobInfo.getExecutorParam());
158
-                triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
159
-                triggerParam.setExecutorTimeout(jobInfo.getExecutorTimeout());
160
-                triggerParam.setLogId(jobLog.getId());
161
-                triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());
162
-                triggerParam.setGlueType(jobInfo.getGlueType());
163
-                triggerParam.setGlueSource(jobInfo.getGlueSource());
164
-                triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
165
-                triggerParam.setBroadcastIndex(0);
166
-                triggerParam.setBroadcastTotal(1);
167
-
168
-                // 3.2、trigger-run (route run / trigger remote executor)
169
-                //triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList);
170
-                ReturnT<String> routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, addressList);
95
+                routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, group.getRegistryList());
171
                 if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) {
96
                 if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) {
172
                     address = routeAddressResult.getContent();
97
                     address = routeAddressResult.getContent();
173
-                    triggerResult = runExecutor(triggerParam, address);
174
                 }
98
                 }
175
-                triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>")
176
-                        .append(routeAddressResult.getMsg()!=null?routeAddressResult.getMsg()+"<br><br>":"").append(triggerResult.getMsg()!=null?triggerResult.getMsg():"");
177
-
178
             }
99
             }
100
+        } else {
101
+            routeAddressResult = new ReturnT<String>(ReturnT.FAIL_CODE, "<br>----------------------<br>" + I18nUtil.getString("jobconf_trigger_address_empty"));
102
+        }
179
 
103
 
180
-            // 4、save trigger-info
181
-            jobLog.setExecutorAddress(address);
182
-            jobLog.setTriggerCode(triggerResult.getCode());
183
-            jobLog.setTriggerMsg(triggerMsgSb.toString());
184
-            XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);
185
-
186
-            // 5、monitor trigger
187
-            JobFailMonitorHelper.monitor(jobLog.getId());
188
-            logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
104
+        // 4、trigger remote executor
105
+        ReturnT<String> triggerResult = null;
106
+        if (address != null) {
107
+            triggerResult = runExecutor(triggerParam, address);
108
+        } else {
109
+            triggerResult = new ReturnT<String>(ReturnT.FAIL_CODE, null);
189
         }
110
         }
190
 
111
 
112
+        // 5、collection trigger info
113
+        StringBuffer triggerMsgSb = new StringBuffer();
114
+        triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle());
115
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp());
116
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":")
117
+                .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
118
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
119
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle());
120
+        if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null)) {
121
+            triggerMsgSb.append("("+index+"/"+(group.getRegistryList()!=null?group.getRegistryList().size():0)+")");
122
+        }
123
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
124
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
125
+        triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount);
126
+
127
+        triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>")
128
+                .append((routeAddressResult!=null&&routeAddressResult.getMsg()!=null)?routeAddressResult.getMsg()+"<br><br>":"").append(triggerResult.getMsg()!=null?triggerResult.getMsg():"");
129
+
130
+        // 6、save log trigger-info
131
+        jobLog.setExecutorAddress(address);
132
+        jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
133
+        jobLog.setExecutorParam(jobInfo.getExecutorParam());
134
+        jobLog.setExecutorFailRetryCount(finalFailRetryCount);
135
+        //jobLog.setTriggerTime();
136
+        jobLog.setTriggerCode(triggerResult.getCode());
137
+        jobLog.setTriggerMsg(triggerMsgSb.toString());
138
+        XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);
139
+
140
+        // 7、monitor trigger
141
+        JobFailMonitorHelper.monitor(jobLog.getId());
142
+        logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
191
     }
143
     }
192
 
144
 
193
     /**
145
     /**
194
      * run executor
146
      * run executor
195
      * @param triggerParam
147
      * @param triggerParam
196
      * @param address
148
      * @param address
197
-     * @return  ReturnT.content: final address
149
+     * @return
198
      */
150
      */
199
     public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address){
151
     public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address){
200
         ReturnT<String> runResult = null;
152
         ReturnT<String> runResult = null;
212
         runResultSB.append("<br>msg:").append(runResult.getMsg());
164
         runResultSB.append("<br>msg:").append(runResult.getMsg());
213
 
165
 
214
         runResult.setMsg(runResultSB.toString());
166
         runResult.setMsg(runResultSB.toString());
215
-        runResult.setContent(address);
216
         return runResult;
167
         return runResult;
217
     }
168
     }
218
 
169
 

+ 2 - 0
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml 查看文件

117
 		INSERT INTO XXL_JOB_QRTZ_TRIGGER_LOG (
117
 		INSERT INTO XXL_JOB_QRTZ_TRIGGER_LOG (
118
 			`job_group`,
118
 			`job_group`,
119
 			`job_id`,
119
 			`job_id`,
120
+			`trigger_time`,
120
 			`trigger_code`,
121
 			`trigger_code`,
121
 			`handle_code`
122
 			`handle_code`
122
 		) VALUES (
123
 		) VALUES (
123
 			#{jobGroup},
124
 			#{jobGroup},
124
 			#{jobId},
125
 			#{jobId},
126
+			#{triggerTime},
125
 			#{triggerCode},
127
 			#{triggerCode},
126
 			#{handleCode}
128
 			#{handleCode}
127
 		);
129
 		);