Procházet zdrojové kódy

V1.3版本,阶段A:GLUE模式开关

xueli.xue před 9 roky
rodič
revize
5c1bba3364

+ 15 - 4
doc/db/tables_xxl_job.sql Zobrazit soubor

@@ -1,7 +1,3 @@
1
-# DROP TABLE IF EXISTS XXL_JOB_QRTZ_FIRED_TRIGGERS;
2
-# DROP TABLE IF EXISTS XXL_JOB_QRTZ_PAUSED_TRIGGER_GRPS;
3
-# DROP TABLE IF EXISTS XXL_JOB_QRTZ_SCHEDULER_STATE;
4
-# DROP TABLE IF EXISTS XXL_JOB_QRTZ_LOCKS;
5 1
 
6 2
 CREATE TABLE XXL_JOB_QRTZ_JOB_DETAILS
7 3
   (
@@ -160,6 +156,9 @@ CREATE TABLE `xxl_job_qrtz_trigger_info` (
160 156
   `author` varchar(64) DEFAULT NULL COMMENT '作者',
161 157
   `alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮件',
162 158
   `alarm_threshold` int(11) DEFAULT NULL COMMENT '报警阀值(连续失败次数)',
159
+  `glue_switch` int(11) DEFAULT '0' COMMENT 'GLUE模式开关:0-否,1-是',
160
+  `glue_source` text COMMENT 'GLUE源代码',
161
+  `glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE备注',
163 162
   PRIMARY KEY (`id`)
164 163
 );
165 164
 
@@ -180,5 +179,17 @@ CREATE TABLE `xxl_job_qrtz_trigger_log` (
180 179
   PRIMARY KEY (`id`)
181 180
 );
182 181
 
182
+CREATE TABLE `xxl_job_qrtz_trigger_logglue` (
183
+  `id` int(11) NOT NULL AUTO_INCREMENT,
184
+  `job_group` varchar(255) NOT NULL,
185
+  `job_name` varchar(255) NOT NULL,
186
+  `glue_source` text,
187
+  `glue_remark` varchar(128) NOT NULL,
188
+  `add_time` timestamp NULL DEFAULT NULL,
189
+  `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
190
+  PRIMARY KEY (`id`)
191
+) ;
192
+
193
+
183 194
 commit;
184 195
 

+ 8 - 4
xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java Zobrazit soubor

@@ -70,7 +70,7 @@ public class JobInfoController {
70 70
 	@ResponseBody
71 71
 	public ReturnT<String> add(String jobGroup, String jobName, String jobCron, String jobDesc,
72 72
 			String handler_address, String handler_name, String handler_params, 
73
-			String author, String alarmEmail, int alarmThreshold) {
73
+			String author, String alarmEmail, int alarmThreshold, int glueSwitch) {
74 74
 		
75 75
 		// valid
76 76
 		if (JobGroupEnum.match(jobGroup) == null) {
@@ -88,7 +88,7 @@ public class JobInfoController {
88 88
 		if (StringUtils.isBlank(handler_address)) {
89 89
 			return new ReturnT<String>(500, "请输入“机器地址”");
90 90
 		}
91
-		if (StringUtils.isBlank(handler_name)) {
91
+		if (glueSwitch==0 && StringUtils.isBlank(handler_name)) {
92 92
 			return new ReturnT<String>(500, "请输入“执行器”");
93 93
 		}
94 94
 		if (StringUtils.isBlank(author)) {
@@ -127,6 +127,9 @@ public class JobInfoController {
127 127
 		jobInfo.setAuthor(author);
128 128
 		jobInfo.setAlarmEmail(alarmEmail);
129 129
 		jobInfo.setAlarmThreshold(alarmThreshold);
130
+		jobInfo.setGlueSwitch(glueSwitch);
131
+		jobInfo.setGlueSource(null);
132
+		jobInfo.setGlueRemark(null);
130 133
 		xxlJobInfoDao.save(jobInfo);
131 134
 		
132 135
 		try {
@@ -148,7 +151,7 @@ public class JobInfoController {
148 151
 	@ResponseBody
149 152
 	public ReturnT<String> reschedule(String jobGroup, String jobName, String jobCron, String jobDesc,
150 153
 			String handler_address, String handler_name, String handler_params, 
151
-			String author, String alarmEmail, int alarmThreshold) {
154
+			String author, String alarmEmail, int alarmThreshold, int glueSwitch) {
152 155
 		
153 156
 		// valid
154 157
 		if (JobGroupEnum.match(jobGroup) == null) {
@@ -166,7 +169,7 @@ public class JobInfoController {
166 169
 		if (StringUtils.isBlank(handler_address)) {
167 170
 			return new ReturnT<String>(500, "请输入“机器地址”");
168 171
 		}
169
-		if (StringUtils.isBlank(handler_name)) {
172
+		if (glueSwitch==0 && StringUtils.isBlank(handler_name)) {
170 173
 			return new ReturnT<String>(500, "请输入“执行器”");
171 174
 		}
172 175
 		if (StringUtils.isBlank(author)) {
@@ -192,6 +195,7 @@ public class JobInfoController {
192 195
 		jobInfo.setAuthor(author);
193 196
 		jobInfo.setAlarmEmail(alarmEmail);
194 197
 		jobInfo.setAlarmThreshold(alarmThreshold);
198
+		jobInfo.setGlueSwitch(glueSwitch);
195 199
 		
196 200
 		try {
197 201
 			// fresh quartz

+ 31 - 2
xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobInfo.java Zobrazit soubor

@@ -24,6 +24,10 @@ public class XxlJobInfo {
24 24
 	private String alarmEmail;	// 报警邮件
25 25
 	private int alarmThreshold;	// 报警阀值
26 26
 	
27
+	private int glueSwitch;		// GLUE模式开关:0-否,1-是
28
+	private String glueSource;	// GLUE源代码
29
+	private String glueRemark;	// GLUE备注
30
+	
27 31
 	// copy from quartz
28 32
 	private String jobStatus;	// 任务状态 【base on quartz】
29 33
 
@@ -131,12 +135,37 @@ public class XxlJobInfo {
131 135
 		this.jobStatus = jobStatus;
132 136
 	}
133 137
 
138
+	public int getGlueSwitch() {
139
+		return glueSwitch;
140
+	}
141
+
142
+	public void setGlueSwitch(int glueSwitch) {
143
+		this.glueSwitch = glueSwitch;
144
+	}
145
+
146
+	public String getGlueSource() {
147
+		return glueSource;
148
+	}
149
+
150
+	public void setGlueSource(String glueSource) {
151
+		this.glueSource = glueSource;
152
+	}
153
+
154
+	public String getGlueRemark() {
155
+		return glueRemark;
156
+	}
157
+
158
+	public void setGlueRemark(String glueRemark) {
159
+		this.glueRemark = glueRemark;
160
+	}
161
+
134 162
 	@Override
135 163
 	public String toString() {
136 164
 		return "XxlJobInfo [id=" + id + ", jobGroup=" + jobGroup + ", jobName=" + jobName + ", jobCron=" + jobCron
137 165
 				+ ", jobDesc=" + jobDesc + ", jobClass=" + jobClass + ", jobData=" + jobData + ", addTime=" + addTime
138 166
 				+ ", updateTime=" + updateTime + ", author=" + author + ", alarmEmail=" + alarmEmail
139
-				+ ", alarmThreshold=" + alarmThreshold + ", jobStatus=" + jobStatus + "]";
167
+				+ ", alarmThreshold=" + alarmThreshold + ", glueSwitch=" + glueSwitch + ", glueSource=" + glueSource
168
+				+ ", glueRemark=" + glueRemark + ", jobStatus=" + jobStatus + "]";
140 169
 	}
141
-
170
+	
142 171
 }

+ 20 - 4
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml Zobrazit soubor

@@ -19,6 +19,10 @@
19 19
 	    <result column="author" property="author" />
20 20
 	    <result column="alarm_email" property="alarmEmail" />
21 21
 	    <result column="alarm_threshold" property="alarmThreshold" />
22
+	    
23
+	    <result column="glue_switch" property="glueSwitch" />
24
+	    <result column="glue_source" property="glueSource" />
25
+	    <result column="glue_remark" property="glueRemark" />
22 26
 	</resultMap>
23 27
 
24 28
 	<sql id="Base_Column_List">
@@ -33,7 +37,10 @@
33 37
 		t.update_time,
34 38
 		t.author,
35 39
 		t.alarm_email,
36
-		t.alarm_threshold
40
+		t.alarm_threshold,
41
+		t.glue_switch,
42
+		t.glue_source,
43
+		t.glue_remark
37 44
 	</sql>
38 45
 	
39 46
 	<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
@@ -76,7 +83,10 @@
76 83
 			update_time,
77 84
 			author,
78 85
 			alarm_email,
79
-			alarm_threshold
86
+			alarm_threshold,
87
+			glue_switch,
88
+			glue_source,
89
+			glue_remark
80 90
 		) VALUES (
81 91
 			#{jobGroup}, 
82 92
 			#{jobName}, 
@@ -88,7 +98,10 @@
88 98
 			NOW(),
89 99
 			#{author},
90 100
 			#{alarmEmail},
91
-			#{alarmThreshold}
101
+			#{alarmThreshold},
102
+			#{glueSwitch},
103
+			#{glueSource},
104
+			#{glueRemark}
92 105
 		);
93 106
 		<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> 
94 107
 			SELECT LAST_INSERT_ID() 
@@ -111,7 +124,10 @@
111 124
 			update_time = NOW(),
112 125
 			author = #{author},
113 126
 			alarm_email = #{alarmEmail},
114
-			alarm_threshold = #{alarmThreshold}
127
+			alarm_threshold = #{alarmThreshold},
128
+			glue_switch = #{glueSwitch},
129
+			glue_source = #{glueSource},
130
+			glue_remark = #{glueRemark}
115 131
 		WHERE job_group = #{jobGroup}
116 132
 			AND job_name = #{jobName}
117 133
 	</update>

+ 15 - 2
xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl Zobrazit soubor

@@ -78,6 +78,7 @@
78 78
 					                  	<th name="author" >负责人</th>
79 79
 					                  	<th name="alarmEmail" >报警邮件</th>
80 80
 					                  	<th name="alarmThreshold" >报警阀值</th>
81
+					                  	<th name="glueSwitch" >GLUE模式</th>
81 82
 					                  	<th name="jobStatus" >状态</th>
82 83
 					                  	<th>操作</th>
83 84
 					                </tr>
@@ -142,10 +143,16 @@
142 143
 						<div class="col-sm-4"><input type="text" class="form-control" name="alarmThreshold" placeholder="请输入“报警阈值”" maxlength="200" ></div>
143 144
 					</div>
144 145
 					<div class="form-group">
145
-						<div class="col-sm-offset-3 col-sm-9">
146
+						<div class="col-sm-offset-3 col-sm-6">
146 147
 							<button type="submit" class="btn btn-primary"  >保存</button>
147 148
 							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
148 149
 						</div>
150
+						<div class="col-sm-3">
151
+							<div class="checkbox">
152
+		                        <label><input type="checkbox" class="ifGLUE" >开启GLUE模式<font color="black">*</font></label>
153
+		                        <input type="hidden" name="glueSwitch" value="0" >
154
+	                    	</div>
155
+						</div>
149 156
 					</div>
150 157
 				</form>
151 158
          	</div>
@@ -194,10 +201,16 @@
194 201
 						<div class="col-sm-4"><input type="text" class="form-control" name="alarmThreshold" placeholder="请输入“报警阈值”" maxlength="200" ></div>
195 202
 					</div>
196 203
 					<div class="form-group">
197
-						<div class="col-sm-offset-3 col-sm-9">
204
+						<div class="col-sm-offset-3 col-sm-6">
198 205
 							<button type="submit" class="btn btn-primary"  >保存</button>
199 206
 							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
200 207
 						</div>
208
+						<div class="col-sm-3">
209
+							<div class="checkbox">
210
+		                        <label><input type="checkbox" class="ifGLUE" >开启GLUE模式<font color="black">*</font></label>
211
+		                        <input type="hidden" name="glueSwitch" value="0" >
212
+	                    	</div>
213
+						</div>
201 214
 					</div>
202 215
 				</form>
203 216
          	</div>

+ 2 - 1
xxl-job-admin/src/main/webapp/static/js/jobcode.index.1.js Zobrazit soubor

@@ -8,10 +8,11 @@ $(function() {
8 8
 	});
9 9
 	codeEditor.setValue( $("#demoCode").val() );
10 10
 	
11
+	// editor height
11 12
 	var height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight);
12 13
 	$(".CodeMirror").attr('style', 'height:'+ height +'px');
13 14
 	
14
-	
15
+	// code source save
15 16
 	$("#save").click(function() {
16 17
 		var codeSource = codeEditor.getValue();
17 18
 		var codeRemark = $("#codeRemark").val();

+ 52 - 5
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js Zobrazit soubor

@@ -61,6 +61,7 @@ $(function() {
61 61
 	                { "data": 'author', "visible" : true},
62 62
 	                { "data": 'alarmEmail', "visible" : false},
63 63
 	                { "data": 'alarmThreshold', "visible" : false},
64
+	                { "data": 'glueSwitch', "visible" : false},
64 65
 	                { 
65 66
 	                	"data": 'jobStatus', 
66 67
 	                	"visible" : true,
@@ -87,8 +88,13 @@ $(function() {
87 88
 								}
88 89
 	                			// log url
89 90
 	                			var logUrl = base_url +'/joblog?jobGroup='+ row.jobGroup +'&jobName='+ row.jobName;
91
+	                			
90 92
 	                			// log url
91
-	                			var codeUrl = base_url +'/jobcode?id='+ row.id;
93
+	                			var codeHtml = "";
94
+	                			if(row.glueSwitch != 0){
95
+	                				var codeUrl = base_url +'/jobcode?id='+ row.id;
96
+	                				codeHtml = '<button class="btn btn-warning btn-xs" type="button" onclick="javascript:window.open(\'' + codeUrl + '\')" >GLUE</button>  '
97
+	                			}
92 98
 	                			
93 99
 	                			// job data
94 100
 	                			var jobDataMap = eval('(' + row.jobData + ')');
@@ -100,18 +106,19 @@ $(function() {
100 106
 	                							' jobDesc="'+ row.jobDesc +'" '+
101 107
 	                							' jobClass="'+ row.jobClass +'" '+
102 108
 	                							' jobData="'+ row.jobData +'" '+
103
-	                							' author="'+ row.author +'" '+
104
-	                							' alarmEmail="'+ row.alarmEmail +'" '+
105
-	                							' alarmThreshold="'+ row.alarmThreshold +'" '+
106 109
 	                							' handler_params="'+jobDataMap.handler_params +'" '+
107 110
 	                							' handler_address="'+ jobDataMap.handler_address +'" '+
108 111
 	                							' handler_name="'+ jobDataMap.handler_name +'" '+
112
+	                							' author="'+ row.author +'" '+
113
+	                							' alarmEmail="'+ row.alarmEmail +'" '+
114
+	                							' alarmThreshold="'+ row.alarmThreshold +'" '+
115
+	                							' glueSwitch="'+ row.glueSwitch +'" '+
109 116
 	                							'>'+
110 117
 										'<button class="btn btn-primary btn-xs job_operate" type="job_trigger" type="button">执行</button>  '+
111 118
 										pause_resume +
112 119
 										'<button class="btn btn-primary btn-xs" type="job_del" type="button" onclick="javascript:window.open(\'' + logUrl + '\')" >日志</button><br>  '+
113 120
 										'<button class="btn btn-warning btn-xs update" type="button">编辑</button>  '+
114
-										'<button class="btn btn-warning btn-xs" type="button" onclick="javascript:window.open(\'' + codeUrl + '\')" >GLUE</button>  '+
121
+										codeHtml +
115 122
 								  		'<button class="btn btn-danger btn-xs job_operate" type="job_del" type="button">删除</button>  '+
116 123
 									'</p>';
117 124
 									
@@ -318,6 +325,34 @@ $(function() {
318 325
 		$(".remote_panel").show();	// remote
319 326
 	});
320 327
 	
328
+	// GLUE模式开启
329
+	$("#addModal .form .ifGLUE").click(function(){
330
+		var ifGLUE = $(this).is(':checked');
331
+		var $handler_name = $("#addModal .form input[name='handler_name']");
332
+		var $glueSwitch = $("#addModal .form input[name='glueSwitch']");
333
+		if (ifGLUE) {
334
+			$handler_name.val("");
335
+			$handler_name.attr("readonly","readonly");
336
+			$glueSwitch.val(1);
337
+		} else {
338
+			$handler_name.removeAttr("readonly");
339
+			$glueSwitch.val(0);
340
+		}
341
+	});
342
+	$("#updateModal .form .ifGLUE").click(function(){
343
+		var ifGLUE = $(this).is(':checked');
344
+		var $handler_name = $("#updateModal .form input[name='handler_name']");
345
+		var $glueSwitch = $("#updateModal .form input[name='glueSwitch']");
346
+		if (ifGLUE) {
347
+			$handler_name.val("");
348
+			$handler_name.attr("readonly","readonly");
349
+			$glueSwitch.val(1);
350
+		} else {
351
+			$handler_name.removeAttr("readonly");
352
+			$glueSwitch.val(0);
353
+		}
354
+	});
355
+	
321 356
 	// 更新
322 357
 	$("#job_list").on('click', '.update',function() {
323 358
 		$("#updateModal .form input[name='jobGroup']").val($(this).parent('p').attr("jobGroup"));
@@ -330,6 +365,18 @@ $(function() {
330 365
 		$("#updateModal .form input[name='author']").val($(this).parent('p').attr("author"));
331 366
 		$("#updateModal .form input[name='alarmEmail']").val($(this).parent('p').attr("alarmEmail"));
332 367
 		$("#updateModal .form input[name='alarmThreshold']").val($(this).parent('p').attr("alarmThreshold"));
368
+		$("#updateModal .form input[name='glueSwitch']").val($(this).parent('p').attr("glueSwitch"));
369
+		
370
+		// GLUE check
371
+		var $glueSwitch = $("#updateModal .form input[name='glueSwitch']");
372
+		var $handler_name = $("#updateModal .form input[name='handler_name']");
373
+		if ($glueSwitch.val() != 0) {
374
+			$handler_name.attr("readonly","readonly");
375
+			$("#updateModal .form .ifGLUE").attr("checked", true);
376
+		} else {
377
+			$handler_name.removeAttr("readonly");
378
+			$("#updateModal .form .ifGLUE").attr("checked", false);
379
+		}
333 380
 		
334 381
 		$('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
335 382
 	});