Parcourir la source

调度中心参数配置逻辑重构

xuxueli il y a 8 ans
Parent
révision
0ddef14076

+ 2 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java Voir le fichier

@@ -120,7 +120,7 @@ public class JobLogController {
120 120
 	@ResponseBody
121 121
 	public ReturnT<LogResult> logDetailCat(String executorAddress, long triggerTime, int logId, int fromLineNum){
122 122
 		try {
123
-			ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, executorAddress, XxlJobDynamicScheduler.getAccessToken()).getObject();
123
+			ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(executorAddress);
124 124
 			ReturnT<LogResult> logResult = executorBiz.log(triggerTime, logId, fromLineNum);
125 125
 
126 126
 			// is end
@@ -154,7 +154,7 @@ public class JobLogController {
154 154
 		// request of kill
155 155
 		ReturnT<String> runResult = null;
156 156
 		try {
157
-			ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, log.getExecutorAddress(), XxlJobDynamicScheduler.getAccessToken()).getObject();
157
+			ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(log.getExecutorAddress());
158 158
 			runResult = executorBiz.kill(jobInfo.getId());
159 159
 		} catch (Exception e) {
160 160
 			logger.error(e.getMessage(), e);

+ 0 - 29
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/ExecutorRouter.java Voir le fichier

@@ -1,10 +1,7 @@
1 1
 package com.xxl.job.admin.core.route;
2 2
 
3
-import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
4
-import com.xxl.job.core.biz.ExecutorBiz;
5 3
 import com.xxl.job.core.biz.model.ReturnT;
6 4
 import com.xxl.job.core.biz.model.TriggerParam;
7
-import com.xxl.job.core.rpc.netcom.NetComClientProxy;
8 5
 import org.slf4j.Logger;
9 6
 import org.slf4j.LoggerFactory;
10 7
 
@@ -25,30 +22,4 @@ public abstract class ExecutorRouter {
25 22
      */
26 23
     public abstract ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList);
27 24
 
28
-    /**
29
-     * run executor
30
-     * @param triggerParam
31
-     * @param address
32
-     * @return  ReturnT.content: final address
33
-     */
34
-    public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address){
35
-        ReturnT<String> runResult = null;
36
-        try {
37
-            ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, address, XxlJobDynamicScheduler.getAccessToken()).getObject();
38
-            runResult = executorBiz.run(triggerParam);
39
-        } catch (Exception e) {
40
-            logger.error(e.getMessage(), e);
41
-            runResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
42
-        }
43
-
44
-        StringBuffer runResultSB = new StringBuffer("触发调度:");
45
-        runResultSB.append("<br>address:").append(address);
46
-        runResultSB.append("<br>code:").append(runResult.getCode());
47
-        runResultSB.append("<br>msg:").append(runResult.getMsg());
48
-
49
-        runResult.setMsg(runResultSB.toString());
50
-        runResult.setContent(address);
51
-        return runResult;
52
-    }
53
-
54 25
 }

+ 3 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteBusyover.java Voir le fichier

@@ -2,10 +2,10 @@ package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4 4
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
5
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5 6
 import com.xxl.job.core.biz.ExecutorBiz;
6 7
 import com.xxl.job.core.biz.model.ReturnT;
7 8
 import com.xxl.job.core.biz.model.TriggerParam;
8
-import com.xxl.job.core.rpc.netcom.NetComClientProxy;
9 9
 
10 10
 import java.util.ArrayList;
11 11
 
@@ -26,7 +26,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
26 26
             // beat
27 27
             ReturnT<String> idleBeatResult = null;
28 28
             try {
29
-                ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, address, XxlJobDynamicScheduler.getAccessToken()).getObject();
29
+                ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
30 30
                 idleBeatResult = executorBiz.idleBeat(triggerParam.getJobId());
31 31
             } catch (Exception e) {
32 32
                 logger.error(e.getMessage(), e);
@@ -41,7 +41,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
41 41
             // beat success
42 42
             if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
43 43
 
44
-                ReturnT<String> runResult = runExecutor(triggerParam, address);
44
+                ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
45 45
                 idleBeatResultSB.append("<br><br>").append(runResult.getMsg());
46 46
 
47 47
                 // result

+ 2 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteConsistentHash.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
4 5
 import com.xxl.job.core.biz.model.ReturnT;
5 6
 import com.xxl.job.core.biz.model.TriggerParam;
6 7
 
@@ -82,7 +83,7 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
82 83
         String address = route(triggerParam.getJobId(), addressList);
83 84
 
84 85
         // run executor
85
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
86
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
86 87
         runResult.setContent(address);
87 88
         return runResult;
88 89
     }

+ 3 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFailover.java Voir le fichier

@@ -2,10 +2,10 @@ package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4 4
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
5
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5 6
 import com.xxl.job.core.biz.ExecutorBiz;
6 7
 import com.xxl.job.core.biz.model.ReturnT;
7 8
 import com.xxl.job.core.biz.model.TriggerParam;
8
-import com.xxl.job.core.rpc.netcom.NetComClientProxy;
9 9
 
10 10
 import java.util.ArrayList;
11 11
 
@@ -26,7 +26,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
26 26
             // beat
27 27
             ReturnT<String> beatResult = null;
28 28
             try {
29
-                ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, address, XxlJobDynamicScheduler.getAccessToken()).getObject();
29
+                ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
30 30
                 beatResult = executorBiz.beat();
31 31
             } catch (Exception e) {
32 32
                 logger.error(e.getMessage(), e);
@@ -41,7 +41,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
41 41
             // beat success
42 42
             if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {
43 43
 
44
-                ReturnT<String> runResult = runExecutor(triggerParam, address);
44
+                ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
45 45
                 beatResultSB.append("<br><br>").append(runResult.getMsg());
46 46
 
47 47
                 // result

+ 2 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFirst.java Voir le fichier

@@ -1,7 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3
-import com.xxl.job.admin.core.model.XxlJobLog;
4 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5 5
 import com.xxl.job.core.biz.model.ReturnT;
6 6
 import com.xxl.job.core.biz.model.TriggerParam;
7 7
 
@@ -23,7 +23,7 @@ public class ExecutorRouteFirst extends ExecutorRouter {
23 23
         String address = route(triggerParam.getJobId(), addressList);
24 24
 
25 25
         // run executor
26
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
26
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
27 27
         runResult.setContent(address);
28 28
         return runResult;
29 29
     }

+ 2 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
4 5
 import com.xxl.job.core.biz.model.ReturnT;
5 6
 import com.xxl.job.core.biz.model.TriggerParam;
6 7
 
@@ -62,7 +63,7 @@ public class ExecutorRouteLFU extends ExecutorRouter {
62 63
         String address = route(triggerParam.getJobId(), addressList);
63 64
 
64 65
         // run executor
65
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
66
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
66 67
         runResult.setContent(address);
67 68
         return runResult;
68 69
     }

+ 2 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
4 5
 import com.xxl.job.core.biz.model.ReturnT;
5 6
 import com.xxl.job.core.biz.model.TriggerParam;
6 7
 
@@ -61,7 +62,7 @@ public class ExecutorRouteLRU extends ExecutorRouter {
61 62
         String address = route(triggerParam.getJobId(), addressList);
62 63
 
63 64
         // run executor
64
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
65
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
65 66
         runResult.setContent(address);
66 67
         return runResult;
67 68
     }

+ 2 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLast.java Voir le fichier

@@ -1,7 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3
-import com.xxl.job.admin.core.model.XxlJobLog;
4 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
5 5
 import com.xxl.job.core.biz.model.ReturnT;
6 6
 import com.xxl.job.core.biz.model.TriggerParam;
7 7
 
@@ -22,7 +22,7 @@ public class ExecutorRouteLast extends ExecutorRouter {
22 22
         String address = route(triggerParam.getJobId(), addressList);
23 23
 
24 24
         // run executor
25
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
25
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
26 26
         runResult.setContent(address);
27 27
         return runResult;
28 28
     }

+ 2 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRandom.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
4 5
 import com.xxl.job.core.biz.model.ReturnT;
5 6
 import com.xxl.job.core.biz.model.TriggerParam;
6 7
 
@@ -25,7 +26,7 @@ public class ExecutorRouteRandom extends ExecutorRouter {
25 26
         String address = route(triggerParam.getJobId(), addressList);
26 27
 
27 28
         // run executor
28
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
29
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
29 30
         runResult.setContent(address);
30 31
         return runResult;
31 32
     }

+ 2 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.xxl.job.admin.core.route.strategy;
2 2
 
3 3
 import com.xxl.job.admin.core.route.ExecutorRouter;
4
+import com.xxl.job.admin.core.trigger.XxlJobTrigger;
4 5
 import com.xxl.job.core.biz.model.ReturnT;
5 6
 import com.xxl.job.core.biz.model.TriggerParam;
6 7
 
@@ -41,7 +42,7 @@ public class ExecutorRouteRound extends ExecutorRouter {
41 42
         String address = route(triggerParam.getJobId(), addressList);
42 43
 
43 44
         // run executor
44
-        ReturnT<String> runResult = runExecutor(triggerParam, address);
45
+        ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
45 46
         runResult.setContent(address);
46 47
         return runResult;
47 48
     }

+ 155 - 78
xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java Voir le fichier

@@ -9,29 +9,33 @@ import com.xxl.job.admin.dao.XxlJobInfoDao;
9 9
 import com.xxl.job.admin.dao.XxlJobLogDao;
10 10
 import com.xxl.job.admin.dao.XxlJobRegistryDao;
11 11
 import com.xxl.job.core.biz.AdminBiz;
12
+import com.xxl.job.core.biz.ExecutorBiz;
13
+import com.xxl.job.core.rpc.netcom.NetComClientProxy;
12 14
 import com.xxl.job.core.rpc.netcom.NetComServerFactory;
13 15
 import org.quartz.*;
14 16
 import org.quartz.Trigger.TriggerState;
15
-import org.quartz.impl.matchers.GroupMatcher;
16 17
 import org.quartz.impl.triggers.CronTriggerImpl;
17 18
 import org.slf4j.Logger;
18 19
 import org.slf4j.LoggerFactory;
19 20
 import org.springframework.beans.BeansException;
20
-import org.springframework.beans.factory.InitializingBean;
21 21
 import org.springframework.context.ApplicationContext;
22 22
 import org.springframework.context.ApplicationContextAware;
23 23
 import org.springframework.util.Assert;
24 24
 
25
-import java.util.*;
25
+import java.util.Date;
26
+import java.util.HashSet;
27
+import java.util.concurrent.ConcurrentHashMap;
26 28
 
27 29
 /**
28 30
  * base quartz scheduler util
29 31
  * @author xuxueli 2015-12-19 16:13:53
30 32
  */
31
-public final class XxlJobDynamicScheduler implements ApplicationContextAware, InitializingBean {
33
+public final class XxlJobDynamicScheduler implements ApplicationContextAware {
32 34
     private static final Logger logger = LoggerFactory.getLogger(XxlJobDynamicScheduler.class);
33
-    
34
-    // Scheduler
35
+
36
+    // ---------------------- param ----------------------
37
+
38
+    // scheduler
35 39
     private static Scheduler scheduler;
36 40
     public void setScheduler(Scheduler scheduler) {
37 41
 		XxlJobDynamicScheduler.scheduler = scheduler;
@@ -42,25 +46,41 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
42 46
     public void setAccessToken(String accessToken) {
43 47
         this.accessToken = accessToken;
44 48
     }
45
-    public static String getAccessToken() {
46
-        return accessToken;
47
-    }
48 49
 
49
-    // init
50
+    // dao
51
+    public static XxlJobLogDao xxlJobLogDao;
52
+    public static XxlJobInfoDao xxlJobInfoDao;
53
+    public static XxlJobRegistryDao xxlJobRegistryDao;
54
+    public static XxlJobGroupDao xxlJobGroupDao;
55
+    public static AdminBiz adminBiz;
56
+
57
+    // ---------------------- applicationContext ----------------------
58
+    @Override
59
+	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
60
+		XxlJobDynamicScheduler.xxlJobLogDao = applicationContext.getBean(XxlJobLogDao.class);
61
+		XxlJobDynamicScheduler.xxlJobInfoDao = applicationContext.getBean(XxlJobInfoDao.class);
62
+        XxlJobDynamicScheduler.xxlJobRegistryDao = applicationContext.getBean(XxlJobRegistryDao.class);
63
+        XxlJobDynamicScheduler.xxlJobGroupDao = applicationContext.getBean(XxlJobGroupDao.class);
64
+        XxlJobDynamicScheduler.adminBiz = applicationContext.getBean(AdminBiz.class);
65
+	}
66
+
67
+    // ---------------------- init + destroy ----------------------
50 68
     public void init() throws Exception {
51
-		// admin registry monitor run
69
+        // admin registry monitor run
52 70
         JobRegistryMonitorHelper.getInstance().start();
53 71
 
54 72
         // admin monitor run
55 73
         JobFailMonitorHelper.getInstance().start();
56 74
 
57
-        // rpc-service, base on spring-mvc
75
+        // admin-server(spring-mvc)
58 76
         NetComServerFactory.putService(AdminBiz.class, XxlJobDynamicScheduler.adminBiz);
59 77
         NetComServerFactory.setAccessToken(accessToken);
60 78
 
79
+        // valid
80
+        Assert.notNull(scheduler, "quartz scheduler is null");
81
+        logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler);
61 82
     }
62
-    
63
-    // destroy
83
+
64 84
     public void destroy(){
65 85
         // admin registry stop
66 86
         JobRegistryMonitorHelper.getInstance().toStop();
@@ -68,64 +88,35 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
68 88
         // admin monitor stop
69 89
         JobFailMonitorHelper.getInstance().toStop();
70 90
     }
71
-    
72
-    // xxlJobLogDao、xxlJobInfoDao
73
-    public static XxlJobLogDao xxlJobLogDao;
74
-    public static XxlJobInfoDao xxlJobInfoDao;
75
-    public static XxlJobRegistryDao xxlJobRegistryDao;
76
-    public static XxlJobGroupDao xxlJobGroupDao;
77
-    public static AdminBiz adminBiz;
78 91
 
79
-    @Override
80
-	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
81
-		XxlJobDynamicScheduler.xxlJobLogDao = applicationContext.getBean(XxlJobLogDao.class);
82
-		XxlJobDynamicScheduler.xxlJobInfoDao = applicationContext.getBean(XxlJobInfoDao.class);
83
-        XxlJobDynamicScheduler.xxlJobRegistryDao = applicationContext.getBean(XxlJobRegistryDao.class);
84
-        XxlJobDynamicScheduler.xxlJobGroupDao = applicationContext.getBean(XxlJobGroupDao.class);
85
-        XxlJobDynamicScheduler.adminBiz = applicationContext.getBean(AdminBiz.class);
86
-	}
87
-    
88
-	@Override
89
-    public void afterPropertiesSet() throws Exception {
90
-        Assert.notNull(scheduler, "quartz scheduler is null");
91
-        logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler);
92
-       
92
+    // ---------------------- executor-client ----------------------
93
+    private static ConcurrentHashMap<String, ExecutorBiz> executorBizRepository = new ConcurrentHashMap<String, ExecutorBiz>();
94
+    public static ExecutorBiz getExecutorBiz(String address) throws Exception {
95
+        // valid
96
+        if (address==null || address.trim().length()==0) {
97
+            return null;
98
+        }
99
+
100
+        // load-cache
101
+        address = address.trim();
102
+        ExecutorBiz executorBiz = executorBizRepository.get(address);
103
+        if (executorBiz != null) {
104
+            return executorBiz;
105
+        }
106
+
107
+        // set-cache
108
+        executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, address, accessToken).getObject();
109
+        executorBizRepository.put(address, executorBiz);
110
+        return executorBiz;
93 111
     }
94
-	
95
-	// getJobKeys
96
-	@Deprecated
97
-	public static List<Map<String, Object>> getJobList(){
98
-		List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
99
-		
100
-		try {
101
-			if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) {
102
-				return null;
103
-			}
104
-			String groupName = scheduler.getJobGroupNames().get(0);
105
-			Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
106
-			if (jobKeys!=null && jobKeys.size()>0) {
107
-				for (JobKey jobKey : jobKeys) {
108
-			        TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
109
-			        Trigger trigger = scheduler.getTrigger(triggerKey);
110
-			        JobDetail jobDetail = scheduler.getJobDetail(jobKey);
111
-			        TriggerState triggerState = scheduler.getTriggerState(triggerKey);
112
-			        Map<String, Object> jobMap = new HashMap<String, Object>();
113
-			        jobMap.put("TriggerKey", triggerKey);
114
-			        jobMap.put("Trigger", trigger);
115
-			        jobMap.put("JobDetail", jobDetail);
116
-			        jobMap.put("TriggerState", triggerState);
117
-			        jobList.add(jobMap);
118
-				}
119
-			}
120
-			
121
-		} catch (SchedulerException e) {
122
-			e.printStackTrace();
123
-			return null;
124
-		}
125
-		return jobList;
126
-	}
127
-	
128
-	// fill job info
112
+
113
+    // ---------------------- schedule util ----------------------
114
+
115
+    /**
116
+     * fill job info
117
+     *
118
+     * @param jobInfo
119
+     */
129 120
 	public static void fillJobInfo(XxlJobInfo jobInfo) {
130 121
 		// TriggerKey : name + group
131 122
         String group = String.valueOf(jobInfo.getJobGroup());
@@ -156,14 +147,28 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
156 147
 		}
157 148
 	}
158 149
 	
159
-	// check if exists
150
+    /**
151
+     * check if exists
152
+     *
153
+     * @param jobName
154
+     * @param jobGroup
155
+     * @return
156
+     * @throws SchedulerException
157
+     */
160 158
 	public static boolean checkExists(String jobName, String jobGroup) throws SchedulerException{
161 159
 		TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
162 160
 		return scheduler.checkExists(triggerKey);
163 161
 	}
164 162
 
165
-	// addJob 新增
166
-	@SuppressWarnings("unchecked")
163
+    /**
164
+     * addJob
165
+     *
166
+     * @param jobName
167
+     * @param jobGroup
168
+     * @param cronExpression
169
+     * @return
170
+     * @throws SchedulerException
171
+     */
167 172
 	public static boolean addJob(String jobName, String jobGroup, String cronExpression) throws SchedulerException {
168 173
     	// TriggerKey : name + group
169 174
         TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
@@ -196,7 +201,15 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
196 201
         return true;
197 202
     }
198 203
     
199
-    // reschedule
204
+    /**
205
+     * rescheduleJob
206
+     *
207
+     * @param jobGroup
208
+     * @param jobName
209
+     * @param cronExpression
210
+     * @return
211
+     * @throws SchedulerException
212
+     */
200 213
 	public static boolean rescheduleJob(String jobGroup, String jobName, String cronExpression) throws SchedulerException {
201 214
     	
202 215
     	// TriggerKey valid if_exists
@@ -245,7 +258,14 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
245 258
         return true;
246 259
     }
247 260
     
248
-    // unscheduleJob
261
+    /**
262
+     * unscheduleJob
263
+     *
264
+     * @param jobName
265
+     * @param jobGroup
266
+     * @return
267
+     * @throws SchedulerException
268
+     */
249 269
     public static boolean removeJob(String jobName, String jobGroup) throws SchedulerException {
250 270
     	// TriggerKey : name + group
251 271
         TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
@@ -257,7 +277,14 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
257 277
         return true;
258 278
     }
259 279
 
260
-    // Pause
280
+    /**
281
+     * pause
282
+     *
283
+     * @param jobName
284
+     * @param jobGroup
285
+     * @return
286
+     * @throws SchedulerException
287
+     */
261 288
     public static boolean pauseJob(String jobName, String jobGroup) throws SchedulerException {
262 289
     	// TriggerKey : name + group
263 290
     	TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
@@ -273,7 +300,14 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
273 300
         return result;
274 301
     }
275 302
     
276
-    // resume
303
+    /**
304
+     * resume
305
+     *
306
+     * @param jobName
307
+     * @param jobGroup
308
+     * @return
309
+     * @throws SchedulerException
310
+     */
277 311
     public static boolean resumeJob(String jobName, String jobGroup) throws SchedulerException {
278 312
     	// TriggerKey : name + group
279 313
     	TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
@@ -289,7 +323,14 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
289 323
         return result;
290 324
     }
291 325
     
292
-    // run
326
+    /**
327
+     * run
328
+     *
329
+     * @param jobName
330
+     * @param jobGroup
331
+     * @return
332
+     * @throws SchedulerException
333
+     */
293 334
     public static boolean triggerJob(String jobName, String jobGroup) throws SchedulerException {
294 335
     	// TriggerKey : name + group
295 336
     	JobKey jobKey = new JobKey(jobName, jobGroup);
@@ -305,5 +346,41 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
305 346
         return result;
306 347
     }
307 348
 
349
+    /**
350
+     * finaAllJobList
351
+     *
352
+     * @return
353
+     *//*
354
+    @Deprecated
355
+    public static List<Map<String, Object>> finaAllJobList(){
356
+        List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
357
+
358
+        try {
359
+            if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) {
360
+                return null;
361
+            }
362
+            String groupName = scheduler.getJobGroupNames().get(0);
363
+            Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
364
+            if (jobKeys!=null && jobKeys.size()>0) {
365
+                for (JobKey jobKey : jobKeys) {
366
+                    TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
367
+                    Trigger trigger = scheduler.getTrigger(triggerKey);
368
+                    JobDetail jobDetail = scheduler.getJobDetail(jobKey);
369
+                    TriggerState triggerState = scheduler.getTriggerState(triggerKey);
370
+                    Map<String, Object> jobMap = new HashMap<String, Object>();
371
+                    jobMap.put("TriggerKey", triggerKey);
372
+                    jobMap.put("Trigger", trigger);
373
+                    jobMap.put("JobDetail", jobDetail);
374
+                    jobMap.put("TriggerState", triggerState);
375
+                    jobList.add(jobMap);
376
+                }
377
+            }
378
+
379
+        } catch (SchedulerException e) {
380
+            e.printStackTrace();
381
+            return null;
382
+        }
383
+        return jobList;
384
+    }*/
308 385
 
309 386
 }

+ 29 - 3
xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java Voir le fichier

@@ -5,9 +5,9 @@ import com.xxl.job.admin.core.model.XxlJobGroup;
5 5
 import com.xxl.job.admin.core.model.XxlJobInfo;
6 6
 import com.xxl.job.admin.core.model.XxlJobLog;
7 7
 import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
8
-import com.xxl.job.admin.core.route.ExecutorRouter;
9 8
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
10 9
 import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
10
+import com.xxl.job.core.biz.ExecutorBiz;
11 11
 import com.xxl.job.core.biz.model.ReturnT;
12 12
 import com.xxl.job.core.biz.model.TriggerParam;
13 13
 import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
@@ -90,12 +90,12 @@ public class XxlJobTrigger {
90 90
                     triggerParam.setBroadcastTotal(addressList.size()); // update02
91 91
 
92 92
                     // 4.2、trigger-run (route run / trigger remote executor)
93
-                    triggerResult = ExecutorRouter.runExecutor(triggerParam, address);     // update03
93
+                    triggerResult = runExecutor(triggerParam, address);     // update03
94 94
                     triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>触发调度<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
95 95
 
96 96
                     // 4.3、trigger (fail retry)
97 97
                     if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_RETRY) {
98
-                        triggerResult = ExecutorRouter.runExecutor(triggerParam, address);  // update04
98
+                        triggerResult = runExecutor(triggerParam, address);  // update04
99 99
                         triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>失败重试<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
100 100
                     }
101 101
                 }
@@ -179,4 +179,30 @@ public class XxlJobTrigger {
179 179
         logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
180 180
     }
181 181
 
182
+    /**
183
+     * run executor
184
+     * @param triggerParam
185
+     * @param address
186
+     * @return  ReturnT.content: final address
187
+     */
188
+    public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address){
189
+        ReturnT<String> runResult = null;
190
+        try {
191
+            ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
192
+            runResult = executorBiz.run(triggerParam);
193
+        } catch (Exception e) {
194
+            logger.error(e.getMessage(), e);
195
+            runResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
196
+        }
197
+
198
+        StringBuffer runResultSB = new StringBuffer("触发调度:");
199
+        runResultSB.append("<br>address:").append(address);
200
+        runResultSB.append("<br>code:").append(runResult.getCode());
201
+        runResultSB.append("<br>msg:").append(runResult.getMsg());
202
+
203
+        runResult.setMsg(runResultSB.toString());
204
+        runResult.setContent(address);
205
+        return runResult;
206
+    }
207
+
182 208
 }

+ 7 - 7
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java Voir le fichier

@@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
26 26
 public class XxlJobExecutor implements ApplicationContextAware {
27 27
     private static final Logger logger = LoggerFactory.getLogger(XxlJobExecutor.class);
28 28
 
29
-    // ---------------------------------- param ------------------------------------
29
+    // ---------------------- param ----------------------
30 30
     private String ip;
31 31
     private int port = 9999;
32 32
     private String appName;
@@ -54,7 +54,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
54 54
     }
55 55
 
56 56
 
57
-    // ---------------------------------- applicationContext ------------------------------------
57
+    // ---------------------- applicationContext ----------------------
58 58
     private static ApplicationContext applicationContext;
59 59
     @Override
60 60
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -65,7 +65,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
65 65
     }
66 66
 
67 67
 
68
-    // ---------------------------------- start + stop ------------------------------------
68
+    // ---------------------- start + stop ----------------------
69 69
     public void start() throws Exception {
70 70
         // init admin-client
71 71
         initAdminBizList(adminAddresses, accessToken);
@@ -95,7 +95,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
95 95
     }
96 96
 
97 97
 
98
-    // ---------------------------------- admin-client ------------------------------------
98
+    // ---------------------- admin-client ----------------------
99 99
     private static List<AdminBiz> adminBizList;
100 100
     private static void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
101 101
         if (adminAddresses!=null && adminAddresses.trim().length()>0) {
@@ -116,7 +116,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
116 116
     }
117 117
 
118 118
 
119
-    // ---------------------------------- executor-server ------------------------------------
119
+    // ---------------------- executor-server(jetty) ----------------------
120 120
     private NetComServerFactory serverFactory = new NetComServerFactory();
121 121
     private void initExecutorServer(int port, String ip, String appName, String accessToken) throws Exception {
122 122
         NetComServerFactory.putService(ExecutorBiz.class, new ExecutorBizImpl());   // rpc-service, base on jetty
@@ -128,7 +128,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
128 128
     }
129 129
 
130 130
 
131
-    // ---------------------------------- job handler repository ------------------------------------
131
+    // ---------------------- job handler repository ----------------------
132 132
     private static ConcurrentHashMap<String, IJobHandler> jobHandlerRepository = new ConcurrentHashMap<String, IJobHandler>();
133 133
     public static IJobHandler registJobHandler(String name, IJobHandler jobHandler){
134 134
         logger.info("xxl-job register jobhandler success, name:{}, jobHandler:{}", name, jobHandler);
@@ -156,7 +156,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
156 156
     }
157 157
 
158 158
 
159
-    // ---------------------------------- job thread repository ------------------------------------
159
+    // ---------------------- job thread repository ----------------------
160 160
     private static ConcurrentHashMap<Integer, JobThread> JobThreadRepository = new ConcurrentHashMap<Integer, JobThread>();
161 161
     public static JobThread registJobThread(int jobId, IJobHandler handler, String removeOldReason){
162 162
         JobThread newJobThread = new JobThread(jobId, handler);