Kaynağa Gözat

记录调度日志

xueli.xue 9 yıl önce
ebeveyn
işleme
87ce15368e
25 değiştirilmiş dosya ile 822 ekleme ve 413 silme
  1. 3 0
      README.md
  2. 1 0
      xxl-job-admin/.gitignore
  3. 1 0
      xxl-job-admin/.settings/org.eclipse.core.resources.prefs
  4. 0 149
      xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java
  5. 166 0
      xxl-job-admin/src/main/java/com/xxl/job/controller/JobController.java
  6. 40 0
      xxl-job-admin/src/main/java/com/xxl/job/controller/JobLogController.java
  7. 48 24
      xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLog.java
  8. 95 0
      xxl-job-admin/src/main/java/com/xxl/job/core/model/mapper/XxlJobLogMapper.xml
  9. 14 2
      xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java
  10. 61 0
      xxl-job-admin/src/main/java/com/xxl/job/core/util/PropertiesUtil.java
  11. 22 0
      xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogDao.java
  12. 58 0
      xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogDaoImpl.java
  13. 0 11
      xxl-job-admin/src/main/java/com/xxl/job/service/ITriggerService.java
  14. 0 21
      xxl-job-admin/src/main/java/com/xxl/job/service/impl/TriggerServiceImpl.java
  15. 36 93
      xxl-job-admin/src/main/java/com/xxl/job/service/job/HttpJobBean.java
  16. 1 1
      xxl-job-admin/src/main/resources/applicationcontext-base.xml
  17. 1 1
      xxl-job-admin/src/main/resources/applicationcontext-database.xml
  18. 0 32
      xxl-job-admin/src/main/resources/applicationcontext-trigger-local.xml
  19. 1 0
      xxl-job-admin/src/main/resources/config.properties
  20. 67 0
      xxl-job-admin/src/test/java/com/xxl/job/dao/impl/XxlJobLogTest.java
  21. 60 37
      xxl-job-client/src/main/java/com/xxl/job/client/handler/HandlerRepository.java
  22. 0 11
      xxl-job-client/src/main/java/com/xxl/job/client/handler/IJobHandler.java
  23. 1 3
      xxl-job-client/src/main/java/com/xxl/job/client/netcom/http/XxlJobServlet.java
  24. 53 28
      xxl-job-client/src/main/java/com/xxl/job/client/util/HttpUtil.java
  25. 93 0
      xxl-job-client/src/main/java/com/xxl/job/client/util/JacksonUtil.java

+ 3 - 0
README.md Dosyayı Görüntüle

@@ -27,3 +27,6 @@ git.osc地址:http://git.oschina.net/xuxueli0323/xxl-job
27 27
 		
28 28
 	Tips:如果您追求一个简单调度服务,这里也提供了一个简洁分支[xxl-job-simple],它针对旧版调度框架做了细微完善;
29 29
 	
30
+# 其他说明
31
+	清楚僵尸任务:qrtz_cron_triggers、qrtz_triggers、qrtz_job_details顺序删除
32
+	

+ 1 - 0
xxl-job-admin/.gitignore Dosyayı Görüntüle

@@ -1 +1,2 @@
1 1
 /target/
2
+/.settings/

+ 1 - 0
xxl-job-admin/.settings/org.eclipse.core.resources.prefs Dosyayı Görüntüle

@@ -1,2 +1,3 @@
1 1
 eclipse.preferences.version=1
2 2
 encoding//src/main/java=UTF8
3
+encoding//src/test/java=UTF8

+ 0 - 149
xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java Dosyayı Görüntüle

@@ -1,27 +1,13 @@
1 1
 package com.xxl.job.controller;
2 2
 
3
-import java.io.UnsupportedEncodingException;
4
-import java.util.HashMap;
5 3
 import java.util.List;
6 4
 import java.util.Map;
7
-import java.util.Map.Entry;
8
-import java.util.Set;
9 5
 
10
-import javax.servlet.http.HttpServletRequest;
11
-
12
-import org.apache.commons.lang.StringUtils;
13
-import org.quartz.CronExpression;
14
-import org.quartz.Job;
15
-import org.quartz.SchedulerException;
16 6
 import org.springframework.stereotype.Controller;
17 7
 import org.springframework.ui.Model;
18 8
 import org.springframework.web.bind.annotation.RequestMapping;
19
-import org.springframework.web.bind.annotation.ResponseBody;
20 9
 
21
-import com.xxl.job.client.handler.HandlerRepository;
22
-import com.xxl.job.core.model.ReturnT;
23 10
 import com.xxl.job.core.util.DynamicSchedulerUtil;
24
-import com.xxl.job.service.job.HttpJobBean;
25 11
 
26 12
 /**
27 13
  * index controller
@@ -30,7 +16,6 @@ import com.xxl.job.service.job.HttpJobBean;
30 16
 @Controller
31 17
 public class IndexController {
32 18
 
33
-	
34 19
 	@RequestMapping("")
35 20
 	public String index(Model model) {
36 21
 		List<Map<String, Object>> jobList = DynamicSchedulerUtil.getJobList();
@@ -43,138 +28,4 @@ public class IndexController {
43 28
 		return "job/help";
44 29
 	}
45 30
 	
46
-	@RequestMapping("/job/add")
47
-	@ResponseBody
48
-	public ReturnT<String> add(HttpServletRequest request) {
49
-		String triggerKeyName = null;
50
-		String cronExpression = null;
51
-		Map<String, Object> jobData = new HashMap<String, Object>();
52
-		
53
-		try {
54
-			request.setCharacterEncoding("utf-8");
55
-		} catch (UnsupportedEncodingException e1) {
56
-			e1.printStackTrace();
57
-		}
58
-		@SuppressWarnings("unchecked")
59
-		Set<Map.Entry<String, String[]>> paramSet = request.getParameterMap().entrySet();
60
-		for (Entry<String, String[]> param : paramSet) {
61
-			if (param.getKey().equals("triggerKeyName")) {
62
-				triggerKeyName = param.getValue()[0];
63
-			} else if (param.getKey().equals("cronExpression")) {
64
-				cronExpression = param.getValue()[0];
65
-			} else {
66
-				jobData.put(param.getKey(), param.getValue().length>0?param.getValue()[0]:param.getValue());
67
-			}
68
-		}
69
-		
70
-		// triggerKeyName
71
-		if (StringUtils.isBlank(triggerKeyName)) {
72
-			return new ReturnT<String>(500, "请输入“任务key”");
73
-		}
74
-		
75
-		// cronExpression
76
-		if (StringUtils.isBlank(cronExpression)) {
77
-			return new ReturnT<String>(500, "请输入“任务corn”");
78
-		}
79
-		if (!CronExpression.isValidExpression(cronExpression)) {
80
-			return new ReturnT<String>(500, "“任务corn”不合法");
81
-		}
82
-		
83
-		// jobData
84
-		if (jobData.get(DynamicSchedulerUtil.job_desc)==null || jobData.get(DynamicSchedulerUtil.job_desc).toString().trim().length()==0) {
85
-			return new ReturnT<String>(500, "请输入“任务描述”");
86
-		}
87
-		if (jobData.get(DynamicSchedulerUtil.job_url)==null || jobData.get(DynamicSchedulerUtil.job_url).toString().trim().length()==0) {
88
-			return new ReturnT<String>(500, "请输入“任务URL”");
89
-		}
90
-		if (jobData.get(HandlerRepository.handleName)==null || jobData.get(HandlerRepository.handleName).toString().trim().length()==0) {
91
-			return new ReturnT<String>(500, "请输入“任务handler”");
92
-		}
93
-		
94
-		// jobClass
95
-		Class<? extends Job> jobClass = HttpJobBean.class;
96
-		
97
-		try {
98
-			boolean result = DynamicSchedulerUtil.addJob(triggerKeyName, cronExpression, jobClass, jobData);
99
-			if (!result) {
100
-				return new ReturnT<String>(500, "任务ID重复,请更换确认");
101
-			}
102
-			return ReturnT.SUCCESS;
103
-		} catch (SchedulerException e) {
104
-			e.printStackTrace();
105
-		}
106
-		return ReturnT.FAIL;
107
-	}
108
-	
109
-	@RequestMapping("/job/reschedule")
110
-	@ResponseBody
111
-	public ReturnT<String> reschedule(String triggerKeyName, String cronExpression) {
112
-		// triggerKeyName
113
-		if (StringUtils.isBlank(triggerKeyName)) {
114
-			return new ReturnT<String>(500, "请输入“任务key”");
115
-		}
116
-		// cronExpression
117
-		if (StringUtils.isBlank(cronExpression)) {
118
-			return new ReturnT<String>(500, "请输入“任务corn”");
119
-		}
120
-		if (!CronExpression.isValidExpression(cronExpression)) {
121
-			return new ReturnT<String>(500, "“任务corn”不合法");
122
-		}
123
-		try {
124
-			DynamicSchedulerUtil.rescheduleJob(triggerKeyName, cronExpression);
125
-			return ReturnT.SUCCESS;
126
-		} catch (SchedulerException e) {
127
-			e.printStackTrace();
128
-		}
129
-		return ReturnT.FAIL;
130
-	}
131
-	
132
-	@RequestMapping("/job/remove")
133
-	@ResponseBody
134
-	public ReturnT<String> remove(String triggerKeyName) {
135
-		try {
136
-			DynamicSchedulerUtil.removeJob(triggerKeyName);
137
-			return ReturnT.SUCCESS;
138
-		} catch (SchedulerException e) {
139
-			e.printStackTrace();
140
-			return ReturnT.FAIL;
141
-		}
142
-	}
143
-	
144
-	@RequestMapping("/job/pause")
145
-	@ResponseBody
146
-	public ReturnT<String> pause(String triggerKeyName) {
147
-		try {
148
-			DynamicSchedulerUtil.pauseJob(triggerKeyName);
149
-			return ReturnT.SUCCESS;
150
-		} catch (SchedulerException e) {
151
-			e.printStackTrace();
152
-			return ReturnT.FAIL;
153
-		}
154
-	}
155
-	
156
-	@RequestMapping("/job/resume")
157
-	@ResponseBody
158
-	public ReturnT<String> resume(String triggerKeyName) {
159
-		try {
160
-			DynamicSchedulerUtil.resumeJob(triggerKeyName);
161
-			return ReturnT.SUCCESS;
162
-		} catch (SchedulerException e) {
163
-			e.printStackTrace();
164
-			return ReturnT.FAIL;
165
-		}
166
-	}
167
-	
168
-	@RequestMapping("/job/trigger")
169
-	@ResponseBody
170
-	public ReturnT<String> triggerJob(String triggerKeyName) {
171
-		try {
172
-			DynamicSchedulerUtil.triggerJob(triggerKeyName);
173
-			return ReturnT.SUCCESS;
174
-		} catch (SchedulerException e) {
175
-			e.printStackTrace();
176
-			return ReturnT.FAIL;
177
-		}
178
-	}
179
-	
180 31
 }

+ 166 - 0
xxl-job-admin/src/main/java/com/xxl/job/controller/JobController.java Dosyayı Görüntüle

@@ -0,0 +1,166 @@
1
+package com.xxl.job.controller;
2
+
3
+import java.io.UnsupportedEncodingException;
4
+import java.util.HashMap;
5
+import java.util.Map;
6
+import java.util.Map.Entry;
7
+import java.util.Set;
8
+
9
+import javax.servlet.http.HttpServletRequest;
10
+
11
+import org.apache.commons.lang.StringUtils;
12
+import org.quartz.CronExpression;
13
+import org.quartz.Job;
14
+import org.quartz.SchedulerException;
15
+import org.springframework.stereotype.Controller;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.ResponseBody;
18
+
19
+import com.xxl.job.client.handler.HandlerRepository;
20
+import com.xxl.job.core.model.ReturnT;
21
+import com.xxl.job.core.util.DynamicSchedulerUtil;
22
+import com.xxl.job.service.job.HttpJobBean;
23
+
24
+/**
25
+ * index controller
26
+ * @author xuxueli 2015-12-19 16:13:16
27
+ */
28
+@Controller
29
+@RequestMapping("/job")
30
+public class JobController {
31
+	
32
+	@RequestMapping("/add")
33
+	@ResponseBody
34
+	public ReturnT<String> add(HttpServletRequest request) {
35
+		String triggerKeyName = null;
36
+		String cronExpression = null;
37
+		Map<String, Object> jobData = new HashMap<String, Object>();
38
+		
39
+		try {
40
+			request.setCharacterEncoding("utf-8");
41
+		} catch (UnsupportedEncodingException e1) {
42
+			e1.printStackTrace();
43
+		}
44
+		@SuppressWarnings("unchecked")
45
+		Set<Map.Entry<String, String[]>> paramSet = request.getParameterMap().entrySet();
46
+		for (Entry<String, String[]> param : paramSet) {
47
+			if (param.getKey().equals("triggerKeyName")) {
48
+				triggerKeyName = param.getValue()[0];
49
+			} else if (param.getKey().equals("cronExpression")) {
50
+				cronExpression = param.getValue()[0];
51
+			} else {
52
+				jobData.put(param.getKey(), param.getValue().length>0?param.getValue()[0]:param.getValue());
53
+			}
54
+		}
55
+		
56
+		// triggerKeyName
57
+		if (StringUtils.isBlank(triggerKeyName)) {
58
+			return new ReturnT<String>(500, "请输入“任务key”");
59
+		}
60
+		
61
+		// cronExpression
62
+		if (StringUtils.isBlank(cronExpression)) {
63
+			return new ReturnT<String>(500, "请输入“任务corn”");
64
+		}
65
+		if (!CronExpression.isValidExpression(cronExpression)) {
66
+			return new ReturnT<String>(500, "“任务corn”不合法");
67
+		}
68
+		
69
+		// jobData
70
+		if (jobData.get(HandlerRepository.job_desc)==null || jobData.get(HandlerRepository.job_desc).toString().trim().length()==0) {
71
+			return new ReturnT<String>(500, "请输入“任务描述”");
72
+		}
73
+		if (jobData.get(HandlerRepository.job_url)==null || jobData.get(HandlerRepository.job_url).toString().trim().length()==0) {
74
+			return new ReturnT<String>(500, "请输入“任务URL”");
75
+		}
76
+		if (jobData.get(HandlerRepository.handleName)==null || jobData.get(HandlerRepository.handleName).toString().trim().length()==0) {
77
+			return new ReturnT<String>(500, "请输入“任务handler”");
78
+		}
79
+		
80
+		// jobClass
81
+		Class<? extends Job> jobClass = HttpJobBean.class;
82
+		
83
+		try {
84
+			boolean result = DynamicSchedulerUtil.addJob(triggerKeyName, cronExpression, jobClass, jobData);
85
+			if (!result) {
86
+				return new ReturnT<String>(500, "任务ID重复,请更换确认");
87
+			}
88
+			return ReturnT.SUCCESS;
89
+		} catch (SchedulerException e) {
90
+			e.printStackTrace();
91
+		}
92
+		return ReturnT.FAIL;
93
+	}
94
+	
95
+	@RequestMapping("/reschedule")
96
+	@ResponseBody
97
+	public ReturnT<String> reschedule(String triggerKeyName, String cronExpression) {
98
+		// triggerKeyName
99
+		if (StringUtils.isBlank(triggerKeyName)) {
100
+			return new ReturnT<String>(500, "请输入“任务key”");
101
+		}
102
+		// cronExpression
103
+		if (StringUtils.isBlank(cronExpression)) {
104
+			return new ReturnT<String>(500, "请输入“任务corn”");
105
+		}
106
+		if (!CronExpression.isValidExpression(cronExpression)) {
107
+			return new ReturnT<String>(500, "“任务corn”不合法");
108
+		}
109
+		try {
110
+			DynamicSchedulerUtil.rescheduleJob(triggerKeyName, cronExpression);
111
+			return ReturnT.SUCCESS;
112
+		} catch (SchedulerException e) {
113
+			e.printStackTrace();
114
+		}
115
+		return ReturnT.FAIL;
116
+	}
117
+	
118
+	@RequestMapping("/remove")
119
+	@ResponseBody
120
+	public ReturnT<String> remove(String triggerKeyName) {
121
+		try {
122
+			DynamicSchedulerUtil.removeJob(triggerKeyName);
123
+			return ReturnT.SUCCESS;
124
+		} catch (SchedulerException e) {
125
+			e.printStackTrace();
126
+			return ReturnT.FAIL;
127
+		}
128
+	}
129
+	
130
+	@RequestMapping("/pause")
131
+	@ResponseBody
132
+	public ReturnT<String> pause(String triggerKeyName) {
133
+		try {
134
+			DynamicSchedulerUtil.pauseJob(triggerKeyName);
135
+			return ReturnT.SUCCESS;
136
+		} catch (SchedulerException e) {
137
+			e.printStackTrace();
138
+			return ReturnT.FAIL;
139
+		}
140
+	}
141
+	
142
+	@RequestMapping("/resume")
143
+	@ResponseBody
144
+	public ReturnT<String> resume(String triggerKeyName) {
145
+		try {
146
+			DynamicSchedulerUtil.resumeJob(triggerKeyName);
147
+			return ReturnT.SUCCESS;
148
+		} catch (SchedulerException e) {
149
+			e.printStackTrace();
150
+			return ReturnT.FAIL;
151
+		}
152
+	}
153
+	
154
+	@RequestMapping("/trigger")
155
+	@ResponseBody
156
+	public ReturnT<String> triggerJob(String triggerKeyName) {
157
+		try {
158
+			DynamicSchedulerUtil.triggerJob(triggerKeyName);
159
+			return ReturnT.SUCCESS;
160
+		} catch (SchedulerException e) {
161
+			e.printStackTrace();
162
+			return ReturnT.FAIL;
163
+		}
164
+	}
165
+	
166
+}

+ 40 - 0
xxl-job-admin/src/main/java/com/xxl/job/controller/JobLogController.java Dosyayı Görüntüle

@@ -0,0 +1,40 @@
1
+package com.xxl.job.controller;
2
+
3
+import java.util.Date;
4
+
5
+import javax.annotation.Resource;
6
+
7
+import org.springframework.stereotype.Controller;
8
+import org.springframework.web.bind.annotation.RequestMapping;
9
+import org.springframework.web.bind.annotation.ResponseBody;
10
+
11
+import com.xxl.job.core.model.ReturnT;
12
+import com.xxl.job.core.model.XxlJobLog;
13
+import com.xxl.job.dao.IXxlJobLogDao;
14
+
15
+/**
16
+ * index controller
17
+ * @author xuxueli 2015-12-19 16:13:16
18
+ */
19
+@Controller
20
+@RequestMapping("/joblog")
21
+public class JobLogController {
22
+
23
+	@Resource
24
+	public IXxlJobLogDao xxlJobLogDao;
25
+	
26
+	@RequestMapping("/save")
27
+	@ResponseBody
28
+	public ReturnT<String> triggerLog(int triggerLogId, String status, String msg) {
29
+		XxlJobLog log = xxlJobLogDao.load(triggerLogId);
30
+		if (log!=null) {
31
+			log.setHandleTime(new Date());
32
+			log.setHandleStatus(status);
33
+			log.setHandleMsg(msg);
34
+			xxlJobLogDao.updateHandleInfo(log);
35
+			return ReturnT.SUCCESS;
36
+		}
37
+		return ReturnT.FAIL;
38
+	}
39
+	
40
+}

+ 48 - 24
xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLog.java Dosyayı Görüntüle

@@ -8,28 +8,52 @@ import java.util.Date;
8 8
  */
9 9
 public class XxlJobLog {
10 10
 	
11
-	private String jobTriggerUuid;
12
-	private String jobHandleName;
11
+	private int id;
12
+	// job info
13
+	private String jobName;
14
+	private String jobCron;
15
+	private String jobClass;
16
+	private String jobData;
17
+	
13 18
 	// trigger info
14 19
 	private Date triggerTime;
15 20
 	private String triggerStatus;
16
-	private String triggerDetailLog;
21
+	private String triggerMsg;
22
+	
17 23
 	// handle info
18 24
 	private Date handleTime;
19 25
 	private String handleStatus;
20
-	private String handleDetailLog;
26
+	private String handleMsg;
21 27
 	
22
-	public String getJobTriggerUuid() {
23
-		return jobTriggerUuid;
28
+	public int getId() {
29
+		return id;
30
+	}
31
+	public void setId(int id) {
32
+		this.id = id;
33
+	}
34
+	public String getJobName() {
35
+		return jobName;
36
+	}
37
+	public void setJobName(String jobName) {
38
+		this.jobName = jobName;
39
+	}
40
+	public String getJobCron() {
41
+		return jobCron;
42
+	}
43
+	public void setJobCron(String jobCron) {
44
+		this.jobCron = jobCron;
45
+	}
46
+	public String getJobClass() {
47
+		return jobClass;
24 48
 	}
25
-	public void setJobTriggerUuid(String jobTriggerUuid) {
26
-		this.jobTriggerUuid = jobTriggerUuid;
49
+	public void setJobClass(String jobClass) {
50
+		this.jobClass = jobClass;
27 51
 	}
28
-	public String getJobHandleName() {
29
-		return jobHandleName;
52
+	public String getJobData() {
53
+		return jobData;
30 54
 	}
31
-	public void setJobHandleName(String jobHandleName) {
32
-		this.jobHandleName = jobHandleName;
55
+	public void setJobData(String jobData) {
56
+		this.jobData = jobData;
33 57
 	}
34 58
 	public Date getTriggerTime() {
35 59
 		return triggerTime;
@@ -43,11 +67,11 @@ public class XxlJobLog {
43 67
 	public void setTriggerStatus(String triggerStatus) {
44 68
 		this.triggerStatus = triggerStatus;
45 69
 	}
46
-	public String getTriggerDetailLog() {
47
-		return triggerDetailLog;
70
+	public String getTriggerMsg() {
71
+		return triggerMsg;
48 72
 	}
49
-	public void setTriggerDetailLog(String triggerDetailLog) {
50
-		this.triggerDetailLog = triggerDetailLog;
73
+	public void setTriggerMsg(String triggerMsg) {
74
+		this.triggerMsg = triggerMsg;
51 75
 	}
52 76
 	public Date getHandleTime() {
53 77
 		return handleTime;
@@ -61,19 +85,19 @@ public class XxlJobLog {
61 85
 	public void setHandleStatus(String handleStatus) {
62 86
 		this.handleStatus = handleStatus;
63 87
 	}
64
-	public String getHandleDetailLog() {
65
-		return handleDetailLog;
88
+	public String getHandleMsg() {
89
+		return handleMsg;
66 90
 	}
67
-	public void setHandleDetailLog(String handleDetailLog) {
68
-		this.handleDetailLog = handleDetailLog;
91
+	public void setHandleMsg(String handleMsg) {
92
+		this.handleMsg = handleMsg;
69 93
 	}
70 94
 	
71 95
 	@Override
72 96
 	public String toString() {
73
-		return "XxlJobLog [jobTriggerUuid=" + jobTriggerUuid + ", jobHandleName=" + jobHandleName
74
-				+ ", triggerTime=" + triggerTime + ", triggerStatus=" + triggerStatus + ", triggerDetailLog="
75
-				+ triggerDetailLog + ", handleTime=" + handleTime + ", handleStatus=" + handleStatus
76
-				+ ", handleDetailLog=" + handleDetailLog + "]";
97
+		return "XxlJobLog [id=" + id + ", jobName=" + jobName + ", jobCron=" + jobCron + ", jobClass=" + jobClass
98
+				+ ", jobData=" + jobData + ", triggerTime=" + triggerTime + ", triggerStatus=" + triggerStatus
99
+				+ ", triggerMsg=" + triggerMsg + ", handleTime=" + handleTime + ", handleStatus=" + handleStatus
100
+				+ ", handleMsg=" + handleMsg + "]";
77 101
 	}
78 102
 	
79 103
 }

+ 95 - 0
xxl-job-admin/src/main/java/com/xxl/job/core/model/mapper/XxlJobLogMapper.xml Dosyayı Görüntüle

@@ -0,0 +1,95 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3
+	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
+<mapper namespace="XxlJobLogMapper">
5
+	
6
+	<resultMap id="XxlJobLog" type="com.xxl.job.core.model.XxlJobLog" >
7
+		<result column="id" property="id" />
8
+	
9
+	    <result column="job_name" property="jobName" />
10
+	    <result column="job_cron" property="jobCron" />
11
+	    <result column="job_class" property="jobClass" />
12
+	    <result column="job_data" property="jobData" />
13
+	    
14
+	    <result column="trigger_time" property="triggerTime" />
15
+	    <result column="trigger_status" property="triggerStatus" />
16
+	    <result column="trigger_msg" property="triggerMsg" />
17
+	    
18
+	    <result column="handle_time" property="handleTime" />
19
+	    <result column="handle_status" property="handleStatus" />
20
+	    <result column="handle_msg" property="handleMsg" />
21
+	</resultMap>
22
+
23
+	<sql id="Base_Column_List">
24
+		t.id,
25
+		t.job_name,
26
+		t.job_cron,
27
+		t.job_class,
28
+		t.job_data,
29
+		t.trigger_time,
30
+		t.trigger_status,
31
+		t.trigger_msg,
32
+		t.handle_time,
33
+		t.handle_status,
34
+		t.handle_msg
35
+	</sql>
36
+	
37
+	<insert id="save" parameterType="com.xxl.job.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
38
+		INSERT INTO `qrtz_trigger_log` (
39
+			`job_name`, 
40
+			`job_cron`, 
41
+			`job_class`, 
42
+			`job_data`
43
+		) VALUES (
44
+			#{jobName}, 
45
+			#{jobCron}, 
46
+			#{jobClass}, 
47
+			#{jobData}
48
+		);
49
+		<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> 
50
+			SELECT LAST_INSERT_ID() 
51
+		</selectKey> 
52
+	</insert>
53
+	
54
+	<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobLog">
55
+		SELECT <include refid="Base_Column_List" />
56
+		FROM qrtz_trigger_log AS t
57
+		WHERE t.id = #{id}
58
+	</select>
59
+	
60
+	<update id="updateTriggerInfo">
61
+		UPDATE `qrtz_trigger_log` 
62
+		SET 
63
+			`trigger_time`= #{triggerTime}, 
64
+			`trigger_status`= #{triggerStatus}, 
65
+			`trigger_msg`= #{triggerMsg}
66
+		WHERE `id`= #{id}
67
+	</update>
68
+	
69
+	<update id="updateHandleInfo">
70
+		UPDATE `qrtz_trigger_log` 
71
+		SET 
72
+			`handle_time`= #{handleTime}, 
73
+			`handle_status`= #{handleStatus}, 
74
+			`handle_msg`= #{handleMsg} 
75
+		WHERE `id`= #{id}
76
+	</update>
77
+	
78
+	<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobLog">
79
+		SELECT <include refid="Base_Column_List" />
80
+		FROM qrtz_trigger_log AS t
81
+		<if test="jobName != null and jobName!=''">
82
+			WHERE t.job_name = #{jobName}
83
+		</if>
84
+		LIMIT #{offset}, #{pagesize}
85
+	</select>
86
+	
87
+	<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
88
+		SELECT count(1)
89
+		FROM qrtz_trigger_log AS t
90
+		<if test="jobName != null and jobName!=''">
91
+			WHERE t.job_name = #{jobName}
92
+		</if>
93
+	</select>
94
+	
95
+</mapper>

+ 14 - 2
xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java Dosyayı Görüntüle

@@ -7,6 +7,8 @@ import java.util.List;
7 7
 import java.util.Map;
8 8
 import java.util.Set;
9 9
 
10
+import javax.annotation.Resource;
11
+
10 12
 import org.quartz.CronScheduleBuilder;
11 13
 import org.quartz.CronTrigger;
12 14
 import org.quartz.Job;
@@ -26,6 +28,8 @@ import org.slf4j.LoggerFactory;
26 28
 import org.springframework.beans.factory.InitializingBean;
27 29
 import org.springframework.util.Assert;
28 30
 
31
+import com.xxl.job.dao.IXxlJobLogDao;
32
+
29 33
 /**
30 34
  * base quartz scheduler util
31 35
  * @author xuxueli 2015-12-19 16:13:53
@@ -33,6 +37,16 @@ import org.springframework.util.Assert;
33 37
 public final class DynamicSchedulerUtil implements InitializingBean {
34 38
     private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class);
35 39
     
40
+    // xxlJobLogDao
41
+    public static IXxlJobLogDao xxlJobLogDao;
42
+    @Resource
43
+    public void setXxlJobLogDao(IXxlJobLogDao xxlJobLogDao) {
44
+		DynamicSchedulerUtil.xxlJobLogDao = xxlJobLogDao;
45
+	}
46
+    public static IXxlJobLogDao getXxlJobLogDao() {
47
+		return xxlJobLogDao;
48
+	}
49
+    
36 50
     // Scheduler
37 51
     private static Scheduler scheduler;
38 52
     public static void setScheduler(Scheduler scheduler) {
@@ -77,8 +91,6 @@ public final class DynamicSchedulerUtil implements InitializingBean {
77 91
 		return jobList;
78 92
 	}
79 93
 
80
-	public static final String job_desc = "job_desc";
81
-	public static final String job_url = "job_url";
82 94
 	// addJob 新增
83 95
     public static boolean addJob(String triggerKeyName, String cronExpression, Class<? extends Job> jobClass, Map<String, Object> jobData) throws SchedulerException {
84 96
     	// TriggerKey : name + group

+ 61 - 0
xxl-job-admin/src/main/java/com/xxl/job/core/util/PropertiesUtil.java Dosyayı Görüntüle

@@ -0,0 +1,61 @@
1
+package com.xxl.job.core.util;
2
+
3
+import java.io.FileInputStream;
4
+import java.io.IOException;
5
+import java.io.InputStreamReader;
6
+import java.net.URL;
7
+import java.util.Properties;
8
+
9
+import org.slf4j.Logger;
10
+import org.slf4j.LoggerFactory;
11
+
12
+/**
13
+ * properties util
14
+ * @author xuxueli 2015-8-28 10:35:53
15
+ */
16
+public class PropertiesUtil {
17
+	private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
18
+	private static final String file_name = "config.properties";
19
+	
20
+	/**
21
+	 * load properties
22
+	 * @param propertyFileName
23
+	 * @param ifClassPath
24
+	 * @return
25
+	 */
26
+	public static Properties loadProperties(String propertyFileName) {
27
+		Properties prop = new Properties();
28
+		InputStreamReader  in = null;
29
+		try {
30
+			URL url = null;
31
+			ClassLoader loder = Thread.currentThread().getContextClassLoader();
32
+			url = loder.getResource(propertyFileName); 
33
+			in = new InputStreamReader(new FileInputStream(url.getPath()), "UTF-8");
34
+			prop.load(in);
35
+		} catch (IOException e) {
36
+			logger.error("load {} error!", propertyFileName);
37
+		} finally {
38
+			if (in != null) {
39
+				try {
40
+					in.close();
41
+				} catch (IOException e) {
42
+					logger.error("close {} error!", propertyFileName);
43
+				}
44
+			}
45
+		}
46
+		return prop;
47
+	}
48
+
49
+	public static String getString(String key) {
50
+		Properties prop = loadProperties(file_name);
51
+		if (prop!=null) {
52
+			return prop.getProperty(key);
53
+		}
54
+		return null;
55
+	}
56
+	
57
+	public static void main(String[] args) {
58
+		System.out.println(getString("triggerLogUrl"));
59
+	}
60
+
61
+}

+ 22 - 0
xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogDao.java Dosyayı Görüntüle

@@ -0,0 +1,22 @@
1
+package com.xxl.job.dao;
2
+
3
+
4
+import java.util.List;
5
+
6
+import com.xxl.job.core.model.XxlJobLog;
7
+
8
+public interface IXxlJobLogDao {
9
+	
10
+	public int save(XxlJobLog xxlJobLog);
11
+	
12
+	public XxlJobLog load(int id);
13
+	
14
+	public int updateTriggerInfo(XxlJobLog xxlJobLog);
15
+	
16
+	public int updateHandleInfo(XxlJobLog xxlJobLog);
17
+	
18
+	public List<XxlJobLog> pageList(int offset, int pagesize,String jobName);
19
+	
20
+	public int pageListCount(int offset, int pagesize,String jobName);
21
+	
22
+}

+ 58 - 0
xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogDaoImpl.java Dosyayı Görüntüle

@@ -0,0 +1,58 @@
1
+package com.xxl.job.dao.impl;
2
+
3
+import java.util.HashMap;
4
+import java.util.List;
5
+
6
+import javax.annotation.Resource;
7
+
8
+import org.mybatis.spring.SqlSessionTemplate;
9
+import org.springframework.stereotype.Repository;
10
+
11
+import com.xxl.job.core.model.XxlJobLog;
12
+import com.xxl.job.dao.IXxlJobLogDao;
13
+
14
+@Repository
15
+public class XxlJobLogDaoImpl implements IXxlJobLogDao {
16
+	
17
+	@Resource
18
+	public SqlSessionTemplate sqlSessionTemplate;
19
+
20
+	@Override
21
+	public int save(XxlJobLog xxlJobLog) {
22
+		return sqlSessionTemplate.insert("XxlJobLogMapper.save", xxlJobLog);
23
+	}
24
+
25
+	@Override
26
+	public XxlJobLog load(int id) {
27
+		return sqlSessionTemplate.selectOne("XxlJobLogMapper.load", id);
28
+	}
29
+
30
+	@Override
31
+	public int updateTriggerInfo(XxlJobLog xxlJobLog) {
32
+		return sqlSessionTemplate.update("XxlJobLogMapper.updateTriggerInfo", xxlJobLog);
33
+	}
34
+
35
+	@Override
36
+	public int updateHandleInfo(XxlJobLog xxlJobLog) {
37
+		return sqlSessionTemplate.update("XxlJobLogMapper.updateHandleInfo", xxlJobLog);
38
+	}
39
+
40
+	@Override
41
+	public List<XxlJobLog> pageList(int offset, int pagesize, String jobName) {
42
+		HashMap<String, Object> params = new HashMap<String, Object>();
43
+		params.put("offset", offset);
44
+		params.put("pagesize", pagesize);
45
+		params.put("jobName", jobName);
46
+		return sqlSessionTemplate.selectList("XxlJobLogMapper.pageList", params);
47
+	}
48
+
49
+	@Override
50
+	public int pageListCount(int offset, int pagesize, String jobName) {
51
+		HashMap<String, Object> params = new HashMap<String, Object>();
52
+		params.put("offset", offset);
53
+		params.put("pagesize", pagesize);
54
+		params.put("jobName", jobName);
55
+		return sqlSessionTemplate.selectOne("XxlJobLogMapper.pageListCount", params);
56
+	}
57
+	
58
+}

+ 0 - 11
xxl-job-admin/src/main/java/com/xxl/job/service/ITriggerService.java Dosyayı Görüntüle

@@ -1,11 +0,0 @@
1
-package com.xxl.job.service;
2
-
3
-/**
4
- * local trigger, only exists in local jvm
5
- * @author xuxueli 2015-12-17 17:29:23
6
- */
7
-public interface ITriggerService {
8
-	
9
-	public void beat();
10
-	
11
-}

+ 0 - 21
xxl-job-admin/src/main/java/com/xxl/job/service/impl/TriggerServiceImpl.java Dosyayı Görüntüle

@@ -1,21 +0,0 @@
1
-package com.xxl.job.service.impl;
2
-
3
-import org.slf4j.Logger;
4
-import org.slf4j.LoggerFactory;
5
-import org.springframework.stereotype.Service;
6
-
7
-import com.xxl.job.service.ITriggerService;
8
-
9
-/**
10
- * local trigger, only exists in local jvm
11
- * @author xuxueli 2015-12-17 17:31:24
12
- */
13
-@Service("triggerService")
14
-public class TriggerServiceImpl implements ITriggerService {
15
-	private static transient Logger logger = LoggerFactory.getLogger(TriggerServiceImpl.class);
16
-	
17
-	public void beat() {
18
-		logger.info(">>>>>>>>>>> xxl-job beat success.");
19
-	}
20
-	
21
-}

+ 36 - 93
xxl-job-admin/src/main/java/com/xxl/job/service/job/HttpJobBean.java Dosyayı Görüntüle

@@ -1,26 +1,11 @@
1 1
 package com.xxl.job.service.job;
2 2
 
3
-import java.io.IOException;
4
-import java.io.PrintWriter;
5
-import java.io.StringWriter;
6
-import java.util.ArrayList;
7 3
 import java.util.Date;
8 4
 import java.util.HashMap;
9
-import java.util.List;
10 5
 import java.util.Map;
11 6
 import java.util.Map.Entry;
12
-import java.util.UUID;
13 7
 
14
-import org.apache.http.HttpEntity;
15
-import org.apache.http.HttpResponse;
16
-import org.apache.http.NameValuePair;
17
-import org.apache.http.client.config.RequestConfig;
18
-import org.apache.http.client.entity.UrlEncodedFormEntity;
19
-import org.apache.http.client.methods.HttpPost;
20
-import org.apache.http.impl.client.CloseableHttpClient;
21
-import org.apache.http.impl.client.HttpClients;
22
-import org.apache.http.message.BasicNameValuePair;
23
-import org.apache.http.util.EntityUtils;
8
+import org.apache.commons.lang.StringUtils;
24 9
 import org.quartz.JobExecutionContext;
25 10
 import org.quartz.JobExecutionException;
26 11
 import org.slf4j.Logger;
@@ -28,9 +13,11 @@ import org.slf4j.LoggerFactory;
28 13
 import org.springframework.scheduling.quartz.QuartzJobBean;
29 14
 
30 15
 import com.xxl.job.client.handler.HandlerRepository;
31
-import com.xxl.job.client.handler.IJobHandler.JobTriggerStatus;
16
+import com.xxl.job.client.util.HttpUtil;
17
+import com.xxl.job.client.util.JacksonUtil;
32 18
 import com.xxl.job.core.model.XxlJobLog;
33 19
 import com.xxl.job.core.util.DynamicSchedulerUtil;
20
+import com.xxl.job.core.util.PropertiesUtil;
34 21
 
35 22
 /**
36 23
  * http job bean
@@ -43,11 +30,9 @@ public class HttpJobBean extends QuartzJobBean {
43 30
 	protected void executeInternal(JobExecutionContext context)
44 31
 			throws JobExecutionException {
45 32
 		
46
-		String triggerKey = context.getTrigger().getKey().getName();
47
-		String triggerGroup = context.getTrigger().getKey().getGroup();
48
-		Map<String, Object> jobDataMap = context.getMergedJobDataMap().getWrappedMap();
49
-		
33
+		String triggerKey = context.getTrigger().getJobKey().getName();
50 34
 		// jobDataMap 2 params
35
+		Map<String, Object> jobDataMap = context.getMergedJobDataMap().getWrappedMap();
51 36
 		Map<String, String> params = new HashMap<String, String>();
52 37
 		if (jobDataMap!=null && jobDataMap.size()>0) {
53 38
 			for (Entry<String, Object> item : jobDataMap.entrySet()) {
@@ -55,83 +40,41 @@ public class HttpJobBean extends QuartzJobBean {
55 40
 			}
56 41
 		}
57 42
 		
58
-		String job_url = params.get(DynamicSchedulerUtil.job_url);
59
-		triggerPost(job_url, params);
60
-		
61
-		logger.info(">>>>>>>>>>> xxl-job run :jobId:{}, group:{}, jobDataMap:{}", 
62
-				new Object[]{triggerKey, triggerGroup, jobDataMap});
63
-    }
64
-	
65
-	public static void triggerPost(String reqURL, Map<String, String> params){
66 43
 		// save log
67 44
 		XxlJobLog jobLog = new XxlJobLog();
68
-		jobLog.setJobTriggerUuid(UUID.randomUUID().toString());
69
-		jobLog.setJobHandleName(params.get(HandlerRepository.handleName));
70
-		jobLog.setTriggerTime(new Date());
71
-		logger.info(">>>>>>>>>>> xxl-job trigger start :jobLog:{}", jobLog);
45
+		jobLog.setJobName(triggerKey);
46
+		jobLog.setJobCron(null);
47
+		jobLog.setJobClass(HttpJobBean.class.getName());
48
+		jobLog.setJobData(JacksonUtil.writeValueAsString(params));
49
+		DynamicSchedulerUtil.xxlJobLogDao.save(jobLog);
50
+		logger.info(">>>>>>>>>>> xxl-job trigger start, jobLog:{}", jobLog);
72 51
 		
73
-		// post
74
-		String responseContent = null;
75
-		HttpPost httpPost = new HttpPost(reqURL);
76
-		CloseableHttpClient httpClient = HttpClients.createDefault();
77
-		try{
78
-			if (params != null && !params.isEmpty()) {
79
-				List<NameValuePair> formParams = new ArrayList<NameValuePair>();
80
-				for(Map.Entry<String,String> entry : params.entrySet()){
81
-					formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
82
-				}
83
-				httpPost.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8"));
84
-			}
85
-			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
86
-			httpPost.setConfig(requestConfig);
87
-			
88
-			HttpResponse response = httpClient.execute(httpPost);
89
-			HttpEntity entity = response.getEntity();
90
-			if (null != entity) {
91
-				responseContent = EntityUtils.toString(entity, "UTF-8");
92
-				EntityUtils.consume(entity);
93
-			}
94
-			logger.info(">>>>>>>>>>> xxl-job trigger ing :jobLog:{}, response:{}, responseContent:{}", jobLog, response, responseContent);
95
-		} catch (Exception e) {
96
-			e.printStackTrace();
97
-			
98
-			StringWriter out = new StringWriter();
99
-			e.printStackTrace(new PrintWriter(out));
100
-			responseContent = out.toString();
101
-		} finally{
102
-			httpPost.releaseConnection();
103
-			try {
104
-				httpClient.close();
105
-			} catch (IOException e) {
106
-				e.printStackTrace();
107
-			}
108
-			
109
-			// update trigger status
110
-			if (responseContent!=null && responseContent.equals(JobTriggerStatus.SUCCESS.name())) {
111
-				jobLog.setTriggerStatus(JobTriggerStatus.SUCCESS.name());
112
-			} else {
113
-				jobLog.setTriggerStatus(JobTriggerStatus.FAIL.name());
114
-			}
115
-			jobLog.setTriggerDetailLog(responseContent);
116
-			if (jobLog.getTriggerDetailLog()!=null && jobLog.getTriggerDetailLog().length()>1000) {
117
-				jobLog.setTriggerDetailLog(jobLog.getTriggerDetailLog().substring(0, 1000));
52
+		// trigger request
53
+		params.put(HandlerRepository.triggerLogId, String.valueOf(jobLog.getId()));
54
+		params.put(HandlerRepository.triggerLogUrl, PropertiesUtil.getString(HandlerRepository.triggerLogUrl));
55
+		String[] postResp = HttpUtil.post(params.get(HandlerRepository.job_url), params);
56
+		logger.info(">>>>>>>>>>> xxl-job trigger http response, jobLog.id:{}, jobLog:{}", jobLog.getId(), jobLog);
57
+		
58
+		// parse trigger response
59
+		String responseMsg = postResp[0];
60
+		String exceptionMsg = postResp[1];
61
+		
62
+		jobLog.setTriggerTime(new Date());
63
+		jobLog.setTriggerStatus(HttpUtil.FAIL);
64
+		jobLog.setTriggerMsg(exceptionMsg);
65
+		if (StringUtils.isNotBlank(responseMsg)) {
66
+			@SuppressWarnings("unchecked")
67
+			Map<String, String> responseMap = JacksonUtil.readValue(responseMsg, Map.class);
68
+			if (responseMap!=null && StringUtils.isNotBlank(responseMap.get(HttpUtil.status))) {
69
+				jobLog.setTriggerStatus(responseMap.get(HttpUtil.status));
70
+				jobLog.setTriggerMsg(responseMap.get(HttpUtil.msg));
118 71
 			}
119
-			
120
-			logger.info(">>>>>>>>>>> xxl-job trigger end :jobLog:{}", jobLog);
121 72
 		}
122 73
 		
123
-	}
124
-	
125
-	public static void main(String[] args) {
126
-		String url = "http://localhost:8080/xxl-job-client-demo/xxlJobServlet";
74
+		// update trigger info
75
+		DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog);
76
+		logger.info(">>>>>>>>>>> xxl-job trigger end, jobLog.id:{}, jobLog:{}", jobLog.getId(), jobLog);
127 77
 		
128
-		for (int i = 0; i < 3; i++) {
129
-			Map<String, String> params = new HashMap<String, String>();
130
-			params.put(HandlerRepository.handleName, "com.xxl.job.service.handler.DemoJobHandler");
131
-			params.put(HandlerRepository.triggerUuid, i+"");
132
-			params.put("key", i+"");
133
-			
134
-			triggerPost(url, params);
135
-		}
136
-	}
78
+    }
79
+	
137 80
 }

+ 1 - 1
xxl-job-admin/src/main/resources/applicationcontext-base.xml Dosyayı Görüntüle

@@ -10,7 +10,7 @@
10 10
            http://www.springframework.org/schema/util/spring-util.xsd">
11 11
 
12 12
 	<context:annotation-config />
13
-	<context:component-scan base-package="com.xxl.job.service" />
13
+	<context:component-scan base-package="com.xxl.job.service, com.xxl.job.dao" />
14 14
 
15 15
 	<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
16 16
 		<property name="templateLoaderPath" value="/WEB-INF/template/" />

+ 1 - 1
xxl-job-admin/src/main/resources/applicationcontext-database.xml Dosyayı Görüntüle

@@ -31,7 +31,7 @@
31 31
 	
32 32
 	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
33 33
 		<property name="dataSource" ref="dataSource" />
34
-		<property name="mapperLocations" value="classpath*:com/xxl/core/model/mapper/*.xml"/>
34
+		<property name="mapperLocations" value="classpath*:com/xxl/job/core/model/mapper/*.xml"/>
35 35
 	</bean>
36 36
     
37 37
     <!-- scope must be "prototype" when junit -->

+ 0 - 32
xxl-job-admin/src/main/resources/applicationcontext-trigger-local.xml Dosyayı Görüntüle

@@ -1,32 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<beans xmlns="http://www.springframework.org/schema/beans"
3
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4
-	xmlns:util="http://www.springframework.org/schema/util"
5
-	xsi:schemaLocation="http://www.springframework.org/schema/beans
6
-           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7
-           http://www.springframework.org/schema/context
8
-           http://www.springframework.org/schema/context/spring-context-3.0.xsd
9
-           http://www.springframework.org/schema/util 
10
-           http://www.springframework.org/schema/util/spring-util.xsd">
11
-
12
-	<bean id="beatJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
13
-		<property name="targetObject" ref="triggerService" />
14
-		<property name="targetMethod" value="beat" />
15
-		<property name="concurrent" value="false" />
16
-	</bean>
17
-	
18
-	<bean id="beatTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
19
-		<property name="jobDetail" ref="beatJobDetail" />
20
-		<property name="cronExpression" value="0/10 * * * * ? *" />
21
-	</bean>
22
-	
23
-	<!-- 进程-调度器 -->
24
-	<bean name="jvmQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
25
-		<property name="triggers">
26
-			<list>
27
-				<!-- <ref bean="beatTrigger" /> -->
28
-			</list>
29
-		</property>
30
-	</bean>
31
-
32
-</beans>

+ 1 - 0
xxl-job-admin/src/main/resources/config.properties Dosyayı Görüntüle

@@ -0,0 +1 @@
1
+triggerLogUrl=http://localhost:8080/xxl-job-admin/joblog/save

+ 67 - 0
xxl-job-admin/src/test/java/com/xxl/job/dao/impl/XxlJobLogTest.java Dosyayı Görüntüle

@@ -0,0 +1,67 @@
1
+package com.xxl.job.dao.impl;
2
+
3
+import java.util.Date;
4
+import java.util.List;
5
+
6
+import javax.annotation.Resource;
7
+
8
+import org.junit.Test;
9
+import org.junit.runner.RunWith;
10
+import org.springframework.test.context.ContextConfiguration;
11
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12
+
13
+import com.xxl.job.client.handler.IJobHandler;
14
+import com.xxl.job.client.util.HttpUtil;
15
+import com.xxl.job.core.model.XxlJobLog;
16
+import com.xxl.job.dao.IXxlJobLogDao;
17
+
18
+@RunWith(SpringJUnit4ClassRunner.class)
19
+@ContextConfiguration(locations = "classpath*:applicationcontext-*.xml")
20
+public class XxlJobLogTest {
21
+	
22
+	@Resource
23
+	private IXxlJobLogDao xxlJobLogDao;
24
+	
25
+	@Test
26
+	public void save_load(){
27
+		XxlJobLog xxlJobLog = new XxlJobLog();
28
+		xxlJobLog.setJobName("job_name");
29
+		xxlJobLog.setJobCron("jobCron");
30
+		xxlJobLog.setJobClass("jobClass");
31
+		xxlJobLog.setJobData("jobData");
32
+		int count = xxlJobLogDao.save(xxlJobLog);
33
+		System.out.println(count);
34
+		System.out.println(xxlJobLog.getId());
35
+		
36
+		XxlJobLog item = xxlJobLogDao.load(xxlJobLog.getId());
37
+		System.out.println(item);
38
+	}
39
+	
40
+	@Test
41
+	public void updateTriggerInfo(){
42
+		XxlJobLog xxlJobLog = xxlJobLogDao.load(29);
43
+		xxlJobLog.setTriggerTime(new Date());
44
+		xxlJobLog.setTriggerStatus(HttpUtil.SUCCESS);
45
+		xxlJobLog.setTriggerMsg("trigger msg");
46
+		xxlJobLogDao.updateTriggerInfo(xxlJobLog);
47
+	}
48
+	
49
+	@Test
50
+	public void updateHandleInfo(){
51
+		XxlJobLog xxlJobLog = xxlJobLogDao.load(29);
52
+		xxlJobLog.setHandleTime(new Date());
53
+		xxlJobLog.setHandleStatus(IJobHandler.JobHandleStatus.SUCCESS.name());
54
+		xxlJobLog.setHandleMsg("handle msg");
55
+		xxlJobLogDao.updateHandleInfo(xxlJobLog);
56
+	}
57
+	
58
+	@Test
59
+	public void pageList(){
60
+		List<XxlJobLog> list = xxlJobLogDao.pageList(0, 20, null);
61
+		int list_count = xxlJobLogDao.pageListCount(0, 20, null);
62
+		
63
+		System.out.println(list);
64
+		System.out.println(list_count);
65
+	}
66
+	
67
+}

+ 60 - 37
xxl-job-client/src/main/java/com/xxl/job/client/handler/HandlerRepository.java Dosyayı Görüntüle

@@ -2,6 +2,7 @@ package com.xxl.job.client.handler;
2 2
 
3 3
 import java.io.PrintWriter;
4 4
 import java.io.StringWriter;
5
+import java.util.HashMap;
5 6
 import java.util.Map;
6 7
 import java.util.concurrent.ConcurrentHashMap;
7 8
 import java.util.concurrent.LinkedBlockingQueue;
@@ -11,7 +12,8 @@ import org.slf4j.Logger;
11 12
 import org.slf4j.LoggerFactory;
12 13
 
13 14
 import com.xxl.job.client.handler.IJobHandler.JobHandleStatus;
14
-import com.xxl.job.client.handler.IJobHandler.JobTriggerStatus;
15
+import com.xxl.job.client.util.HttpUtil;
16
+import com.xxl.job.client.util.JacksonUtil;
15 17
 
16 18
 
17 19
 /**
@@ -21,8 +23,11 @@ import com.xxl.job.client.handler.IJobHandler.JobTriggerStatus;
21 23
 public class HandlerRepository {
22 24
 	private static Logger logger = LoggerFactory.getLogger(HandlerRepository.class);
23 25
 	
24
-	public static final String triggerUuid = "triggerUuid";
26
+	public static final String job_desc = "job_desc";
27
+	public static final String job_url = "job_url";
25 28
 	public static final String handleName = "handleName";
29
+	public static final String triggerLogId = "triggerLogId";
30
+	public static final String triggerLogUrl = "triggerLogUrl";
26 31
 
27 32
 	// handler class map
28 33
 	private static ConcurrentHashMap<String, IJobHandler> handlerClassMap = new ConcurrentHashMap<String, IJobHandler>();
@@ -57,23 +62,36 @@ public class HandlerRepository {
57 62
 		public void run() {
58 63
 			while (isValid) {
59 64
 				LinkedBlockingQueue<Map<String, String>> handlerDateQueue = handlerDataQueueMap.get(_handleName);
60
-				Map<String, String> handlerDate = handlerDateQueue.poll();
61
-				if (handlerDate!=null) {
62
-					JobHandleStatus jobHandleStatus = null;
63
-					String jobHandleDetail = null;
65
+				Map<String, String> handlerData = handlerDateQueue.poll();
66
+				if (handlerData!=null) {
67
+					// handle job
68
+					JobHandleStatus _status = JobHandleStatus.FAIL;
69
+					String _msg = null;
64 70
 					try {
65 71
 						IJobHandler handler = handlerClassMap.get(_handleName);
66
-						jobHandleStatus = handler.handle(handlerDate);
72
+						_status = handler.handle(handlerData);
67 73
 					} catch (Exception e) {
68 74
 						e.printStackTrace();
69
-						jobHandleStatus = JobHandleStatus.FAIL;
75
+						_status = JobHandleStatus.FAIL;
70 76
 						StringWriter out = new StringWriter();
71 77
 						e.printStackTrace(new PrintWriter(out));
72
-						jobHandleDetail = out.toString();
78
+						_msg = out.toString();
73 79
 					}
74
-					String _triggerUuid = handlerDate.get(triggerUuid);
75
-					logger.info("<<<<<<<<<<< xxl-job thread handle, _triggerUuid:{}, _handleName:{}, jobHandleStatus:{}, jobHandleDetail:{}, thread:{}", 
76
-							new Object[]{_triggerUuid, _handleName, jobHandleStatus, jobHandleDetail, this});
80
+
81
+					// callback handler info
82
+					String callback_response[] = null;
83
+					try {
84
+						String _triggerLogUrl = handlerData.get(HandlerRepository.triggerLogUrl);
85
+						HashMap<String, String> params = new HashMap<String, String>();
86
+						params.put(HandlerRepository.triggerLogId, handlerData.get(HandlerRepository.triggerLogId));
87
+						params.put(HttpUtil.status, _status.name());
88
+						params.put(HttpUtil.msg, _msg);
89
+						callback_response = HttpUtil.post(_triggerLogUrl, params);
90
+					} catch (Exception e) {
91
+						e.printStackTrace();
92
+					}
93
+					logger.info("<<<<<<<<<<< xxl-job thread handle, handlerData:{}, callback_status:{}, callback_msg:{}, callback_response:{}, thread:{}", 
94
+							new Object[]{handlerData, _status, _msg, callback_response, this});
77 95
 				} else {
78 96
 					try {
79 97
 						TimeUnit.SECONDS.sleep(3);
@@ -86,51 +104,56 @@ public class HandlerRepository {
86 104
 	}
87 105
 	
88 106
 	// handler push to queue
89
-	public static String pushHandleQueue(String triggerUuid, String handleName, Map<String, String> _param) {
90
-		JobTriggerStatus _triggerStatus = JobTriggerStatus.FAIL;
91
-		String _triggerDetailLog = null;
107
+	public static String pushHandleQueue(Map<String, String> _param) {
92 108
 		
109
+		// resuolt
110
+		String _status = HttpUtil.FAIL;
111
+		String _msg = "";
112
+		// push data to queue
113
+		String _handleName = _param.get(HandlerRepository.handleName);
114
+		int _triggerLogId = Integer.valueOf(_param.get(HandlerRepository.triggerLogId));
93 115
 		try {
94
-			if (handleName!=null && handleName.trim().length()>0) {
95
-				IJobHandler handler = handlerClassMap.get(handleName);
116
+			if (_handleName!=null && _handleName.trim().length()>0) {
117
+				IJobHandler handler = handlerClassMap.get(_handleName);
96 118
 				if (handler != null) {
97 119
 					// push data to handler queue
98
-					LinkedBlockingQueue<Map<String, String>> handlerDateQueue = handlerDataQueueMap.get(handleName);
120
+					LinkedBlockingQueue<Map<String, String>> handlerDateQueue = handlerDataQueueMap.get(_handleName);
99 121
 					if (handlerDateQueue == null) {
100 122
 						handlerDateQueue = new LinkedBlockingQueue<Map<String, String>>();
101
-						handlerDataQueueMap.put(handleName, handlerDateQueue);
102
-						logger.info(">>>>>>>>>>> xxl-job handler lazy fresh handlerDateQueue, handleName:{}, handler:{}, handlerDateQueue:{}", 
103
-								new Object[]{handleName, handler, handlerDateQueue});
123
+						handlerDataQueueMap.put(_handleName, handlerDateQueue);
124
+						logger.info(">>>>>>>>>>> xxl-job handler lazy fresh handlerDateQueue, _handleName:{}, handler:{}, handlerDateQueue:{}", 
125
+								new Object[]{_handleName, handler, handlerDateQueue});
104 126
 					}
105
-					handlerDateQueue.offer(_param);
106 127
 					// check handler thread
107
-					HandlerThread handlerThreadOld = handlerTreadMap.get(handleName);
128
+					HandlerThread handlerThreadOld = handlerTreadMap.get(_handleName);
108 129
 					if (!handlerThreadOld.isAlive()) {
109 130
 						handlerThreadOld.stopThread();
110
-						HandlerThread handlerThread = new HandlerThread(handleName);
131
+						HandlerThread handlerThread = new HandlerThread(_handleName);
111 132
 						handlerThread.start();
112
-						handlerTreadMap.put(handleName, handlerThread);
113
-						logger.info(">>>>>>>>>>> xxl-job handler lazy fresh thread, handleName:{}, handler:{}, handlerThread:{}", 
114
-								new Object[]{handleName, handler, handlerThread});
133
+						handlerTreadMap.put(_handleName, handlerThread);
134
+						logger.info(">>>>>>>>>>> xxl-job handler lazy fresh thread, _handleName:{}, handler:{}, handlerThread:{}", 
135
+								new Object[]{_handleName, handler, handlerThread});
115 136
 					}
116
-					_triggerStatus = JobTriggerStatus.SUCCESS;
137
+					// push to queue
138
+					handlerDateQueue.offer(_param);
139
+					_status = HttpUtil.SUCCESS;
117 140
 				}
118 141
 			}
119 142
 		} catch (Exception e) {
120 143
 			e.printStackTrace();
121
-			_triggerStatus = JobTriggerStatus.FAIL;
122 144
 			StringWriter out = new StringWriter();
123 145
 			e.printStackTrace(new PrintWriter(out));
124
-			_triggerDetailLog = out.toString();
146
+			_status = HttpUtil.FAIL;
147
+			_msg = out.toString();
125 148
 		}
126
-		logger.info(">>>>>>>>>>> xxl-job pushHandleQueue, triggerUuid:{}, handleName, _triggerStatus:{}, _triggerDetailLog", 
127
-				new Object[]{triggerUuid, handleName, _triggerStatus, _triggerDetailLog});
149
+		logger.info(">>>>>>>>>>> xxl-job pushHandleQueue, _handleName:{}, _triggerLogId:{}, _param:{}, _status:{}, _msg:{}", 
150
+				new Object[]{_handleName, _triggerLogId, _param, _status, _msg});
151
+		
152
+		HashMap<String, String> triggerData = new HashMap<String, String>();
153
+		triggerData.put(HttpUtil.status, _status);
154
+		triggerData.put(HttpUtil.msg, _msg);
155
+		return JacksonUtil.writeValueAsString(triggerData);
128 156
 		
129
-		String responseBody = _triggerStatus.name();
130
-		if (JobTriggerStatus.SUCCESS != _triggerStatus) {
131
-			responseBody += "#" + _triggerDetailLog;
132
-		}
133
-		return responseBody;
134 157
 		/**
135 158
 		 * trigger-log : 
136 159
 		 * 		trigger side : store trigger-info >> trigger request >> update trigger-response-status

+ 0 - 11
xxl-job-client/src/main/java/com/xxl/job/client/handler/IJobHandler.java Dosyayı Görüntüle

@@ -32,15 +32,4 @@ public abstract class IJobHandler extends HandlerRepository{
32 32
 		NOT_FOUND;
33 33
 	}
34 34
 	
35
-	public enum JobTriggerStatus{
36
-		/**
37
-		 * trigger success
38
-		 */
39
-		SUCCESS, 
40
-		/**
41
-		 * trigger fail
42
-		 */
43
-		FAIL;
44
-	}
45
-	
46 35
 }

+ 1 - 3
xxl-job-client/src/main/java/com/xxl/job/client/netcom/http/XxlJobServlet.java Dosyayı Görüntüle

@@ -43,10 +43,8 @@ public class XxlJobServlet extends HttpServlet {
43 43
 				}
44 44
 			}
45 45
 		}
46
-		String _triggerUuid = _param.get(HandlerRepository.triggerUuid);
47
-		String _handleName = _param.get(HandlerRepository.handleName);
48 46
 		
49
-		String resp = HandlerRepository.pushHandleQueue(_triggerUuid, _handleName, _param);
47
+		String resp = HandlerRepository.pushHandleQueue(_param);
50 48
 		response.getWriter().append(resp);
51 49
 		return;
52 50
 	}

+ 53 - 28
xxl-job-client/src/main/java/com/xxl/job/client/util/HttpUtil.java Dosyayı Görüntüle

@@ -1,59 +1,84 @@
1 1
 package com.xxl.job.client.util;
2 2
 
3 3
 import java.io.IOException;
4
+import java.io.PrintWriter;
5
+import java.io.StringWriter;
6
+import java.util.ArrayList;
7
+import java.util.List;
8
+import java.util.Map;
4 9
 
5 10
 import org.apache.http.HttpEntity;
6 11
 import org.apache.http.HttpResponse;
7
-import org.apache.http.client.ClientProtocolException;
12
+import org.apache.http.NameValuePair;
8 13
 import org.apache.http.client.config.RequestConfig;
9
-import org.apache.http.client.methods.HttpGet;
14
+import org.apache.http.client.entity.UrlEncodedFormEntity;
15
+import org.apache.http.client.methods.HttpPost;
10 16
 import org.apache.http.impl.client.CloseableHttpClient;
11 17
 import org.apache.http.impl.client.HttpClients;
18
+import org.apache.http.message.BasicNameValuePair;
12 19
 import org.apache.http.util.EntityUtils;
13 20
 
14 21
 /**
15
- * http util to send hex data
22
+ * http util to send data
16 23
  * @author xuxueli
17 24
  * @version  2015-11-28 15:30:59
18 25
  */
19 26
 public class HttpUtil {
20
-
21
-	public static String sendHex(String reqURL, String queryString) {
22
-
23
-		String responseContent = null;
24
-		if (queryString != null && !queryString.equals("")) {
25
-			reqURL = reqURL + "?data=" + queryString;
26
-		}
27
-
28
-		HttpGet httpGet = new HttpGet(reqURL);
27
+	
28
+	// response param
29
+	public static final String status = "status";
30
+	public static final String msg = "msg";
31
+	// response status enum
32
+	public static final String SUCCESS = "SUCCESS";
33
+	public static final String FAIL = "FAIL";
34
+	
35
+	/**
36
+	 * http post request
37
+	 * @param reqURL
38
+	 * @param params
39
+	 * @return	[0]=responseMsg, [1]=exceptionMsg
40
+	 */
41
+	public static String[] post(String reqURL, Map<String, String> params){
42
+		String responseMsg = null;
43
+		String exceptionMsg = null;
44
+		
45
+		// do post
46
+		HttpPost httpPost = new HttpPost(reqURL);
29 47
 		CloseableHttpClient httpClient = HttpClients.createDefault();
30
-		try {
31
-			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build();
32
-			httpGet.setConfig(requestConfig);
33
-			
34
-			HttpResponse response = httpClient.execute(httpGet);
48
+		try{
49
+			if (params != null && !params.isEmpty()) {
50
+				List<NameValuePair> formParams = new ArrayList<NameValuePair>();
51
+				for(Map.Entry<String,String> entry : params.entrySet()){
52
+					formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
53
+				}
54
+				httpPost.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8"));
55
+			}
56
+			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
57
+			httpPost.setConfig(requestConfig);
35 58
 			
59
+			HttpResponse response = httpClient.execute(httpPost);
36 60
 			HttpEntity entity = response.getEntity();
37 61
 			if (null != entity) {
38
-				responseContent = EntityUtils.toString(entity, "UTF-8");
62
+				responseMsg = EntityUtils.toString(entity, "UTF-8");
39 63
 				EntityUtils.consume(entity);
40
-				if (responseContent!=null) {
41
-					responseContent = responseContent.trim();
42
-				}
43 64
 			}
44
-		} catch (ClientProtocolException e) {
65
+		} catch (Exception e) {
45 66
 			e.printStackTrace();
46
-		} catch (IOException e) {
47
-			e.printStackTrace();
48
-		} finally {
49
-			httpGet.releaseConnection();
67
+			StringWriter out = new StringWriter();
68
+			e.printStackTrace(new PrintWriter(out));
69
+			exceptionMsg = out.toString();
70
+		} finally{
71
+			httpPost.releaseConnection();
50 72
 			try {
51 73
 				httpClient.close();
52 74
 			} catch (IOException e) {
53 75
 				e.printStackTrace();
54 76
 			}
55 77
 		}
56
-		return responseContent;
78
+		
79
+		String[] result = new String[2];
80
+		result[0] = responseMsg;
81
+		result[1] = exceptionMsg;
82
+		return result;
57 83
 	}
58
-
59 84
 }

+ 93 - 0
xxl-job-client/src/main/java/com/xxl/job/client/util/JacksonUtil.java Dosyayı Görüntüle

@@ -0,0 +1,93 @@
1
+package com.xxl.job.client.util;
2
+
3
+
4
+import java.io.IOException;
5
+import java.util.HashMap;
6
+import java.util.Map;
7
+
8
+import org.codehaus.jackson.JsonGenerationException;
9
+import org.codehaus.jackson.JsonParseException;
10
+import org.codehaus.jackson.map.JsonMappingException;
11
+import org.codehaus.jackson.map.ObjectMapper;
12
+import org.codehaus.jackson.type.TypeReference;
13
+
14
+/**
15
+ * Jackson util
16
+ * 
17
+ * 1、obj need private and set/get;
18
+ * 2、do not support inner class;
19
+ * 
20
+ * @author xuxueli 2015-9-25 18:02:56
21
+ */
22
+public class JacksonUtil {
23
+    private final static ObjectMapper objectMapper = new ObjectMapper();
24
+    public static ObjectMapper getInstance() {
25
+        return objectMapper;
26
+    }
27
+
28
+    /**
29
+     * bean、array、List、Map --> json
30
+     * 
31
+     * @param obj
32
+     * @return
33
+     * @throws Exception
34
+     */
35
+    public static String writeValueAsString(Object obj) {
36
+    	try {
37
+			return getInstance().writeValueAsString(obj);
38
+		} catch (JsonGenerationException e) {
39
+			e.printStackTrace();
40
+		} catch (JsonMappingException e) {
41
+			e.printStackTrace();
42
+		} catch (IOException e) {
43
+			e.printStackTrace();
44
+		}
45
+        return null;
46
+    }
47
+
48
+    /**
49
+     * string --> bean、Map、List(array)
50
+     * 
51
+     * @param jsonStr
52
+     * @param clazz
53
+     * @return
54
+     * @throws Exception
55
+     */
56
+    public static <T> T readValue(String jsonStr, Class<T> clazz) {
57
+    	try {
58
+			return getInstance().readValue(jsonStr, clazz);
59
+		} catch (JsonParseException e) {
60
+			e.printStackTrace();
61
+		} catch (JsonMappingException e) {
62
+			e.printStackTrace();
63
+		} catch (IOException e) {
64
+			e.printStackTrace();
65
+		}
66
+    	return null;
67
+    }
68
+    public static <T> T readValueRefer(String jsonStr, Class<T> clazz) {
69
+    	try {
70
+			return getInstance().readValue(jsonStr, new TypeReference<T>() { });
71
+		} catch (JsonParseException e) {
72
+			e.printStackTrace();
73
+		} catch (JsonMappingException e) {
74
+			e.printStackTrace();
75
+		} catch (IOException e) {
76
+			e.printStackTrace();
77
+		}
78
+    	return null;
79
+    }
80
+
81
+    public static void main(String[] args) {
82
+		try {
83
+			Map<String, String> map = new HashMap<String, String>();
84
+			map.put("aaa", "111");
85
+			map.put("bbb", "222");
86
+			String json = writeValueAsString(map);
87
+			System.out.println(json);
88
+			System.out.println(readValue(json, Map.class));
89
+		} catch (Exception e) {
90
+			e.printStackTrace();
91
+		}
92
+	}
93
+}