Quellcode durchsuchen

新增任务运行模式 "GLUE模式(PowerShell) ",支持PowerShell脚本任务;

xuxueli vor 6 Jahren
Ursprung
Commit
b30db36033

+ 2 - 1
doc/XXL-JOB官方文档.md Datei anzeigen

1241
 - 25、任务调度备注中标注任务触发类型,如Cron触发、父任务触发、API触发等等,方便排查调度日志;
1241
 - 25、任务调度备注中标注任务触发类型,如Cron触发、父任务触发、API触发等等,方便排查调度日志;
1242
 - 26、底层日志组件SimpleDateFormat线程安全问题修复;
1242
 - 26、底层日志组件SimpleDateFormat线程安全问题修复;
1243
 - 27、执行器通讯线程优化,corePoolSize从256降低至32;
1243
 - 27、执行器通讯线程优化,corePoolSize从256降低至32;
1244
-- 28、【迭代中】分片任务失败重试优化,仅重试当前失败的分片;
1244
+- 28、【迭代中】新增任务运行模式 "GLUE模式(PowerShell) ",支持PowerShell脚本任务;
1245
+- 29、【迭代中】分片任务失败重试优化,仅重试当前失败的分片;
1245
 
1246
 
1246
 
1247
 
1247
 ### TODO LIST
1248
 ### TODO LIST

+ 3 - 0
xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/jobcode.index.ftl Datei anzeigen

134
     <#elseif jobInfo.glueType == "GLUE_NODEJS" >
134
     <#elseif jobInfo.glueType == "GLUE_NODEJS" >
135
         <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js" />
135
         <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js" />
136
         <#assign glueTypeIdeMode = "text/javascript" />
136
         <#assign glueTypeIdeMode = "text/javascript" />
137
+    <#elseif jobInfo.glueType == "GLUE_POWERSHELL" >
138
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/powershell/powershell.js" />
139
+        <#assign glueTypeIdeMode = "powershell" />
137
     </#if>
140
     </#if>
138
 
141
 
139
 
142
 

+ 22 - 1
xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl Datei anzeigen

268
 
268
 
269
 console.log("Good bye!")
269
 console.log("Good bye!")
270
 process.exit(0)
270
 process.exit(0)
271
-</textarea>		
271
+</textarea>
272
+<textarea class="glueSource_powershell" style="display:none;" >
273
+Write-Host "xxl-job: hello powershell"
274
+
275
+if($args.Count -eq 3) {
276
+	$executorparam = $args[0]
277
+	$shard_index = $args[1]
278
+	$shard_total = $args[2]
279
+} Else {
280
+	$executorparam = ""
281
+	$shard_index = $args[0]
282
+	$shard_total = $args[1]
283
+}
284
+
285
+Write-Host "${I18n.jobinfo_script_location}: " $MyInvocation.MyCommand.Definition
286
+Write-Host "${I18n.jobinfo_field_executorparam}: " $executorparam
287
+Write-Host "${I18n.jobinfo_shard_index}: " $shard_index
288
+Write-Host "${I18n.jobinfo_shard_total}: " $shard_total
289
+
290
+Write-Host "Good bye!"
291
+exit 0
292
+</textarea>
272
 				</form>
293
 				</form>
273
          	</div>
294
          	</div>
274
 		</div>
295
 		</div>

+ 4 - 0
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js Datei anzeigen

374
             $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_php").val() );
374
             $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_php").val() );
375
         } else if ('GLUE_NODEJS'==glueType){
375
         } else if ('GLUE_NODEJS'==glueType){
376
 			$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_nodejs").val() );			
376
 			$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_nodejs").val() );			
377
+		} else if ('GLUE_POWERSHELL'==glueType){
378
+            $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_powershell").val() );
379
+        } else {
380
+            $("#addModal .form textarea[name='glueSource']").val("");
377
 		}
381
 		}
378
 	});
382
 	});
379
 
383
 

+ 398 - 0
xxl-job-admin/src/main/webapp/static/plugins/codemirror/mode/powershell/powershell.js Datei anzeigen

1
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+// Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+(function(mod) {
5
+  'use strict';
6
+  if (typeof exports == 'object' && typeof module == 'object') // CommonJS
7
+    mod(require('../../lib/codemirror'));
8
+  else if (typeof define == 'function' && define.amd) // AMD
9
+    define(['../../lib/codemirror'], mod);
10
+  else // Plain browser env
11
+    mod(window.CodeMirror);
12
+})(function(CodeMirror) {
13
+'use strict';
14
+
15
+CodeMirror.defineMode('powershell', function() {
16
+  function buildRegexp(patterns, options) {
17
+    options = options || {};
18
+    var prefix = options.prefix !== undefined ? options.prefix : '^';
19
+    var suffix = options.suffix !== undefined ? options.suffix : '\\b';
20
+
21
+    for (var i = 0; i < patterns.length; i++) {
22
+      if (patterns[i] instanceof RegExp) {
23
+        patterns[i] = patterns[i].source;
24
+      }
25
+      else {
26
+        patterns[i] = patterns[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
27
+      }
28
+    }
29
+
30
+    return new RegExp(prefix + '(' + patterns.join('|') + ')' + suffix, 'i');
31
+  }
32
+
33
+  var notCharacterOrDash = '(?=[^A-Za-z\\d\\-_]|$)';
34
+  var varNames = /[\w\-:]/
35
+  var keywords = buildRegexp([
36
+    /begin|break|catch|continue|data|default|do|dynamicparam/,
37
+    /else|elseif|end|exit|filter|finally|for|foreach|from|function|if|in/,
38
+    /param|process|return|switch|throw|trap|try|until|where|while/
39
+  ], { suffix: notCharacterOrDash });
40
+
41
+  var punctuation = /[\[\]{},;`\.]|@[({]/;
42
+  var wordOperators = buildRegexp([
43
+    'f',
44
+    /b?not/,
45
+    /[ic]?split/, 'join',
46
+    /is(not)?/, 'as',
47
+    /[ic]?(eq|ne|[gl][te])/,
48
+    /[ic]?(not)?(like|match|contains)/,
49
+    /[ic]?replace/,
50
+    /b?(and|or|xor)/
51
+  ], { prefix: '-' });
52
+  var symbolOperators = /[+\-*\/%]=|\+\+|--|\.\.|[+\-*&^%:=!|\/]|<(?!#)|(?!#)>/;
53
+  var operators = buildRegexp([wordOperators, symbolOperators], { suffix: '' });
54
+
55
+  var numbers = /^((0x[\da-f]+)|((\d+\.\d+|\d\.|\.\d+|\d+)(e[\+\-]?\d+)?))[ld]?([kmgtp]b)?/i;
56
+
57
+  var identifiers = /^[A-Za-z\_][A-Za-z\-\_\d]*\b/;
58
+
59
+  var symbolBuiltins = /[A-Z]:|%|\?/i;
60
+  var namedBuiltins = buildRegexp([
61
+    /Add-(Computer|Content|History|Member|PSSnapin|Type)/,
62
+    /Checkpoint-Computer/,
63
+    /Clear-(Content|EventLog|History|Host|Item(Property)?|Variable)/,
64
+    /Compare-Object/,
65
+    /Complete-Transaction/,
66
+    /Connect-PSSession/,
67
+    /ConvertFrom-(Csv|Json|SecureString|StringData)/,
68
+    /Convert-Path/,
69
+    /ConvertTo-(Csv|Html|Json|SecureString|Xml)/,
70
+    /Copy-Item(Property)?/,
71
+    /Debug-Process/,
72
+    /Disable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)/,
73
+    /Disconnect-PSSession/,
74
+    /Enable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)/,
75
+    /(Enter|Exit)-PSSession/,
76
+    /Export-(Alias|Clixml|Console|Counter|Csv|FormatData|ModuleMember|PSSession)/,
77
+    /ForEach-Object/,
78
+    /Format-(Custom|List|Table|Wide)/,
79
+    new RegExp('Get-(Acl|Alias|AuthenticodeSignature|ChildItem|Command|ComputerRestorePoint|Content|ControlPanelItem|Counter|Credential'
80
+      + '|Culture|Date|Event|EventLog|EventSubscriber|ExecutionPolicy|FormatData|Help|History|Host|HotFix|Item|ItemProperty|Job'
81
+      + '|Location|Member|Module|PfxCertificate|Process|PSBreakpoint|PSCallStack|PSDrive|PSProvider|PSSession|PSSessionConfiguration'
82
+      + '|PSSnapin|Random|Service|TraceSource|Transaction|TypeData|UICulture|Unique|Variable|Verb|WinEvent|WmiObject)'),
83
+    /Group-Object/,
84
+    /Import-(Alias|Clixml|Counter|Csv|LocalizedData|Module|PSSession)/,
85
+    /ImportSystemModules/,
86
+    /Invoke-(Command|Expression|History|Item|RestMethod|WebRequest|WmiMethod)/,
87
+    /Join-Path/,
88
+    /Limit-EventLog/,
89
+    /Measure-(Command|Object)/,
90
+    /Move-Item(Property)?/,
91
+    new RegExp('New-(Alias|Event|EventLog|Item(Property)?|Module|ModuleManifest|Object|PSDrive|PSSession|PSSessionConfigurationFile'
92
+      + '|PSSessionOption|PSTransportOption|Service|TimeSpan|Variable|WebServiceProxy|WinEvent)'),
93
+    /Out-(Default|File|GridView|Host|Null|Printer|String)/,
94
+    /Pause/,
95
+    /(Pop|Push)-Location/,
96
+    /Read-Host/,
97
+    /Receive-(Job|PSSession)/,
98
+    /Register-(EngineEvent|ObjectEvent|PSSessionConfiguration|WmiEvent)/,
99
+    /Remove-(Computer|Event|EventLog|Item(Property)?|Job|Module|PSBreakpoint|PSDrive|PSSession|PSSnapin|TypeData|Variable|WmiObject)/,
100
+    /Rename-(Computer|Item(Property)?)/,
101
+    /Reset-ComputerMachinePassword/,
102
+    /Resolve-Path/,
103
+    /Restart-(Computer|Service)/,
104
+    /Restore-Computer/,
105
+    /Resume-(Job|Service)/,
106
+    /Save-Help/,
107
+    /Select-(Object|String|Xml)/,
108
+    /Send-MailMessage/,
109
+    new RegExp('Set-(Acl|Alias|AuthenticodeSignature|Content|Date|ExecutionPolicy|Item(Property)?|Location|PSBreakpoint|PSDebug' +
110
+               '|PSSessionConfiguration|Service|StrictMode|TraceSource|Variable|WmiInstance)'),
111
+    /Show-(Command|ControlPanelItem|EventLog)/,
112
+    /Sort-Object/,
113
+    /Split-Path/,
114
+    /Start-(Job|Process|Service|Sleep|Transaction|Transcript)/,
115
+    /Stop-(Computer|Job|Process|Service|Transcript)/,
116
+    /Suspend-(Job|Service)/,
117
+    /TabExpansion2/,
118
+    /Tee-Object/,
119
+    /Test-(ComputerSecureChannel|Connection|ModuleManifest|Path|PSSessionConfigurationFile)/,
120
+    /Trace-Command/,
121
+    /Unblock-File/,
122
+    /Undo-Transaction/,
123
+    /Unregister-(Event|PSSessionConfiguration)/,
124
+    /Update-(FormatData|Help|List|TypeData)/,
125
+    /Use-Transaction/,
126
+    /Wait-(Event|Job|Process)/,
127
+    /Where-Object/,
128
+    /Write-(Debug|Error|EventLog|Host|Output|Progress|Verbose|Warning)/,
129
+    /cd|help|mkdir|more|oss|prompt/,
130
+    /ac|asnp|cat|cd|chdir|clc|clear|clhy|cli|clp|cls|clv|cnsn|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|dnsn|ebp/,
131
+    /echo|epal|epcsv|epsn|erase|etsn|exsn|fc|fl|foreach|ft|fw|gal|gbp|gc|gci|gcm|gcs|gdr|ghy|gi|gjb|gl|gm|gmo|gp|gps/,
132
+    /group|gsn|gsnp|gsv|gu|gv|gwmi|h|history|icm|iex|ihy|ii|ipal|ipcsv|ipmo|ipsn|irm|ise|iwmi|iwr|kill|lp|ls|man|md/,
133
+    /measure|mi|mount|move|mp|mv|nal|ndr|ni|nmo|npssc|nsn|nv|ogv|oh|popd|ps|pushd|pwd|r|rbp|rcjb|rcsn|rd|rdr|ren|ri/,
134
+    /rjb|rm|rmdir|rmo|rni|rnp|rp|rsn|rsnp|rujb|rv|rvpa|rwmi|sajb|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls/,
135
+    /sort|sp|spjb|spps|spsv|start|sujb|sv|swmi|tee|trcm|type|where|wjb|write/
136
+  ], { prefix: '', suffix: '' });
137
+  var variableBuiltins = buildRegexp([
138
+    /[$?^_]|Args|ConfirmPreference|ConsoleFileName|DebugPreference|Error|ErrorActionPreference|ErrorView|ExecutionContext/,
139
+    /FormatEnumerationLimit|Home|Host|Input|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount/,
140
+    /MaximumHistoryCount|MaximumVariableCount|MyInvocation|NestedPromptLevel|OutputEncoding|Pid|Profile|ProgressPreference/,
141
+    /PSBoundParameters|PSCommandPath|PSCulture|PSDefaultParameterValues|PSEmailServer|PSHome|PSScriptRoot|PSSessionApplicationName/,
142
+    /PSSessionConfigurationName|PSSessionOption|PSUICulture|PSVersionTable|Pwd|ShellId|StackTrace|VerbosePreference/,
143
+    /WarningPreference|WhatIfPreference/,
144
+
145
+    /Event|EventArgs|EventSubscriber|Sender/,
146
+    /Matches|Ofs|ForEach|LastExitCode|PSCmdlet|PSItem|PSSenderInfo|This/,
147
+    /true|false|null/
148
+  ], { prefix: '\\$', suffix: '' });
149
+
150
+  var builtins = buildRegexp([symbolBuiltins, namedBuiltins, variableBuiltins], { suffix: notCharacterOrDash });
151
+
152
+  var grammar = {
153
+    keyword: keywords,
154
+    number: numbers,
155
+    operator: operators,
156
+    builtin: builtins,
157
+    punctuation: punctuation,
158
+    identifier: identifiers
159
+  };
160
+
161
+  // tokenizers
162
+  function tokenBase(stream, state) {
163
+    // Handle Comments
164
+    //var ch = stream.peek();
165
+
166
+    var parent = state.returnStack[state.returnStack.length - 1];
167
+    if (parent && parent.shouldReturnFrom(state)) {
168
+      state.tokenize = parent.tokenize;
169
+      state.returnStack.pop();
170
+      return state.tokenize(stream, state);
171
+    }
172
+
173
+    if (stream.eatSpace()) {
174
+      return null;
175
+    }
176
+
177
+    if (stream.eat('(')) {
178
+      state.bracketNesting += 1;
179
+      return 'punctuation';
180
+    }
181
+
182
+    if (stream.eat(')')) {
183
+      state.bracketNesting -= 1;
184
+      return 'punctuation';
185
+    }
186
+
187
+    for (var key in grammar) {
188
+      if (stream.match(grammar[key])) {
189
+        return key;
190
+      }
191
+    }
192
+
193
+    var ch = stream.next();
194
+
195
+    // single-quote string
196
+    if (ch === "'") {
197
+      return tokenSingleQuoteString(stream, state);
198
+    }
199
+
200
+    if (ch === '$') {
201
+      return tokenVariable(stream, state);
202
+    }
203
+
204
+    // double-quote string
205
+    if (ch === '"') {
206
+      return tokenDoubleQuoteString(stream, state);
207
+    }
208
+
209
+    if (ch === '<' && stream.eat('#')) {
210
+      state.tokenize = tokenComment;
211
+      return tokenComment(stream, state);
212
+    }
213
+
214
+    if (ch === '#') {
215
+      stream.skipToEnd();
216
+      return 'comment';
217
+    }
218
+
219
+    if (ch === '@') {
220
+      var quoteMatch = stream.eat(/["']/);
221
+      if (quoteMatch && stream.eol()) {
222
+        state.tokenize = tokenMultiString;
223
+        state.startQuote = quoteMatch[0];
224
+        return tokenMultiString(stream, state);
225
+      } else if (stream.eol()) {
226
+        return 'error';
227
+      } else if (stream.peek().match(/[({]/)) {
228
+        return 'punctuation';
229
+      } else if (stream.peek().match(varNames)) {
230
+        // splatted variable
231
+        return tokenVariable(stream, state);
232
+      }
233
+    }
234
+    return 'error';
235
+  }
236
+
237
+  function tokenSingleQuoteString(stream, state) {
238
+    var ch;
239
+    while ((ch = stream.peek()) != null) {
240
+      stream.next();
241
+
242
+      if (ch === "'" && !stream.eat("'")) {
243
+        state.tokenize = tokenBase;
244
+        return 'string';
245
+      }
246
+    }
247
+
248
+    return 'error';
249
+  }
250
+
251
+  function tokenDoubleQuoteString(stream, state) {
252
+    var ch;
253
+    while ((ch = stream.peek()) != null) {
254
+      if (ch === '$') {
255
+        state.tokenize = tokenStringInterpolation;
256
+        return 'string';
257
+      }
258
+
259
+      stream.next();
260
+      if (ch === '`') {
261
+        stream.next();
262
+        continue;
263
+      }
264
+
265
+      if (ch === '"' && !stream.eat('"')) {
266
+        state.tokenize = tokenBase;
267
+        return 'string';
268
+      }
269
+    }
270
+
271
+    return 'error';
272
+  }
273
+
274
+  function tokenStringInterpolation(stream, state) {
275
+    return tokenInterpolation(stream, state, tokenDoubleQuoteString);
276
+  }
277
+
278
+  function tokenMultiStringReturn(stream, state) {
279
+    state.tokenize = tokenMultiString;
280
+    state.startQuote = '"'
281
+    return tokenMultiString(stream, state);
282
+  }
283
+
284
+  function tokenHereStringInterpolation(stream, state) {
285
+    return tokenInterpolation(stream, state, tokenMultiStringReturn);
286
+  }
287
+
288
+  function tokenInterpolation(stream, state, parentTokenize) {
289
+    if (stream.match('$(')) {
290
+      var savedBracketNesting = state.bracketNesting;
291
+      state.returnStack.push({
292
+        /*jshint loopfunc:true */
293
+        shouldReturnFrom: function(state) {
294
+          return state.bracketNesting === savedBracketNesting;
295
+        },
296
+        tokenize: parentTokenize
297
+      });
298
+      state.tokenize = tokenBase;
299
+      state.bracketNesting += 1;
300
+      return 'punctuation';
301
+    } else {
302
+      stream.next();
303
+      state.returnStack.push({
304
+        shouldReturnFrom: function() { return true; },
305
+        tokenize: parentTokenize
306
+      });
307
+      state.tokenize = tokenVariable;
308
+      return state.tokenize(stream, state);
309
+    }
310
+  }
311
+
312
+  function tokenComment(stream, state) {
313
+    var maybeEnd = false, ch;
314
+    while ((ch = stream.next()) != null) {
315
+      if (maybeEnd && ch == '>') {
316
+          state.tokenize = tokenBase;
317
+          break;
318
+      }
319
+      maybeEnd = (ch === '#');
320
+    }
321
+    return 'comment';
322
+  }
323
+
324
+  function tokenVariable(stream, state) {
325
+    var ch = stream.peek();
326
+    if (stream.eat('{')) {
327
+      state.tokenize = tokenVariableWithBraces;
328
+      return tokenVariableWithBraces(stream, state);
329
+    } else if (ch != undefined && ch.match(varNames)) {
330
+      stream.eatWhile(varNames);
331
+      state.tokenize = tokenBase;
332
+      return 'variable-2';
333
+    } else {
334
+      state.tokenize = tokenBase;
335
+      return 'error';
336
+    }
337
+  }
338
+
339
+  function tokenVariableWithBraces(stream, state) {
340
+    var ch;
341
+    while ((ch = stream.next()) != null) {
342
+      if (ch === '}') {
343
+        state.tokenize = tokenBase;
344
+        break;
345
+      }
346
+    }
347
+    return 'variable-2';
348
+  }
349
+
350
+  function tokenMultiString(stream, state) {
351
+    var quote = state.startQuote;
352
+    if (stream.sol() && stream.match(new RegExp(quote + '@'))) {
353
+      state.tokenize = tokenBase;
354
+    }
355
+    else if (quote === '"') {
356
+      while (!stream.eol()) {
357
+        var ch = stream.peek();
358
+        if (ch === '$') {
359
+          state.tokenize = tokenHereStringInterpolation;
360
+          return 'string';
361
+        }
362
+
363
+        stream.next();
364
+        if (ch === '`') {
365
+          stream.next();
366
+        }
367
+      }
368
+    }
369
+    else {
370
+      stream.skipToEnd();
371
+    }
372
+
373
+    return 'string';
374
+  }
375
+
376
+  var external = {
377
+    startState: function() {
378
+      return {
379
+        returnStack: [],
380
+        bracketNesting: 0,
381
+        tokenize: tokenBase
382
+      };
383
+    },
384
+
385
+    token: function(stream, state) {
386
+      return state.tokenize(stream, state);
387
+    },
388
+
389
+    blockCommentStart: '<#',
390
+    blockCommentEnd: '#>',
391
+    lineComment: '#',
392
+    fold: 'brace'
393
+  };
394
+  return external;
395
+});
396
+
397
+CodeMirror.defineMIME('application/x-powershell', 'powershell');
398
+});

+ 2 - 1
xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueTypeEnum.java Datei anzeigen

10
     GLUE_SHELL("GLUE(Shell)", true, "bash", ".sh"),
10
     GLUE_SHELL("GLUE(Shell)", true, "bash", ".sh"),
11
     GLUE_PYTHON("GLUE(Python)", true, "python", ".py"),
11
     GLUE_PYTHON("GLUE(Python)", true, "python", ".py"),
12
     GLUE_PHP("GLUE(PHP)", true, "php", ".php"),
12
     GLUE_PHP("GLUE(PHP)", true, "php", ".php"),
13
-    GLUE_NODEJS("GLUE(Nodejs)", true, "node", ".js");
13
+    GLUE_NODEJS("GLUE(Nodejs)", true, "node", ".js"),
14
+    GLUE_POWERSHELL("GLUE(PowerShell)", true, "powershell ", ".ps1");
14
 
15
 
15
     private String desc;
16
     private String desc;
16
     private boolean isScript;
17
     private boolean isScript;