-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDispatcherShell.js
982 lines (865 loc) · 24 KB
/
DispatcherShell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
var repl = require('repl');
var readline = require('readline');
var http = require('http');
var fork = require('child_process').fork;
var fs = require('fs');
var Dispatcher = require('../core/Dispatcher.js');
var Pubsub = require('../core/Pubsub.js');
var randKey = require('../helpers.js').randKey;
/*****************************************************************************
QUEUE OBJECT
******************************************************************************/
/**
* An object that should be manually resolved to indicate
* that it has reached the front of the queue
*/
function QueueObject(){
var self = this;
this.front = new Promise(function(resolve){
self.resolve = resolve;
});
}
/**
* Used in conjunction with QueueObject to mimic a 'queue'
*/
function Queue(){
var self = this;
this.queue = [];
this.push = function(queueObject){
self.queue.push(queueObject);
self.queue[0].resolve();
}
this.pop = function(){
self.queue.splice(0, 1);
if(self.queue[0]){
self.queue[0].resolve();
}
}
}
/*****************************************************************************
SHELL OBJECT
******************************************************************************/
function DispatcherShell(){
var self = this;
this.queue = new Queue();
this.dispatcher = new Dispatcher({});
this.pubsub = new Pubsub();
this.FSPort = 3000;
this.FSURL = 'localhost';
this.FSPath = '/fs';
this.dir = '/';
console.log('>>> Shell <<<\n', 'Type \'cmds\' for all commands\n');
function ready(obj){
return new Promise(function(resolve){
obj.on('ready', resolve);
});
}
Promise.all([ready(self.pubsub), ready(self.dispatcher)]).then(function(){
var shell = repl.start({
prompt: '> ',
eval: self.eval,
writer: self.writer
});
shell.context = self;
});
}
DispatcherShell.prototype.parse = function(input){
var parsedInput = input.trim().split(/\s+/) || '';
return { cmd: parsedInput[0], args: parsedInput.splice(1, parsedInput.length-1) };
}
/**
* Evaluates expressions given from the command line
* Commands execute sequentially, "blocking" until the command reaches the front
* of the queue
*/
DispatcherShell.prototype.eval = function(input, context, filename, callback){
var parse = context.parse(input);
if(DispatcherShell.COMMANDS[parse.cmd]){
var queueObj = new QueueObject();
context.queue.push(queueObj);
queueObj.front.then(function(){
var eval = DispatcherShell.COMMANDS[parse.cmd].apply(context, parse.args);
if(eval instanceof Promise){
eval.then(function(data){
callback(null, data);
context.queue.pop();
});
}
else{
callback(null, eval);
context.queue.pop();
}
});
}
else{
callback(null, 'Unrecognized command: ' + parse.cmd);
}
}
DispatcherShell.prototype.writer = function(output){
try{
var pretty = JSON.stringify(JSON.parse(output), null, 2);
return '\x1b[36m' + pretty + '\x1b[0m';
}
catch(e){
if(typeof output === 'string'){
return '\x1b[36m' + output + '\x1b[0m';
}
else{
return '';
}
}
}
/**
* 'Standard' errors thrown by the shell
*/
DispatcherShell.ERRORS = {
/**
* Incorrect arguments
* @param {string[]} expectedArgs: brief description of the expected arguments to pass in
*/
ARGS: function(expectedArgs){
function inBrackets(args){
return args.map(function(argName){
return '<'+argName+'>'
});
}
var errString = 'Error: Incorrect number of arguments. Expecting ' + expectedArgs.length;
errString += '\nUsage: ' +arguments.callee.caller.name+ ' ' +inBrackets(expectedArgs).join(' ');
return errString;
},
EDNE: 'Error: It looks like this code engine does not exist',
IDNE: 'Error: It looks like this code instance does not exist',
EXISTS: function(path){
return 'Error: ' + path + ' already exists';
},
PDNE: function(dir){
return 'ERROR: The path ' + dir + ' does not exist';
},
CONFIG: 'Error: Problem processing config file',
FILE: 'Error: Problem reading file',
NAF: 'Error: Not a file',
NAD: 'Error: Not a directory',
FS: 'Error: Could not connect to the filesystem at ' + this.fsurl + ':' + this.port,
IDNE: 'Error: It looks like this code instance does not exist',
TIMEOUT: 'Error: Timeout occured'
}
/*****************************************************************************
FUNCTIONS RELATED TO CODE INSTANCES
AND ENGINES
******************************************************************************/
DispatcherShell.prototype.programMeta = function(instanceId){
var self = this;
if(!self.dispatcher.programs[instanceId]){
return DispatcherShell.ERRORS['IDNE'];
}
return 'NOT IMPLEMENTED';
}
/**
* Run code on an engine using the dispatcher
*/
DispatcherShell.prototype.run = function(engine, codeSource){
var self = this;
var code;
if(!this.dispatcher.engines[engine]){
return DispatcherShell.ERRORS['EDNE'];
}
try{
code = fs.readFileSync(codeSource, 'utf-8');
return new Promise(function(resolve){
self.dispatcher.runCode(engine, codeSource, code).then(function(data){
resolve(JSON.stringify(data));
})
.catch(function(err){
resolve(DispatcherShell.ERRORS['TIMEOUT']);
});
});
}
catch(e){
return 'Could not read file';
}
}
/**
* Pause a running instance on an engine using the dispatcher
*/
DispatcherShell.prototype.pause = function(engine, codeName, instanceId){
var self = this;
if(!this.dispatcher.engines[engine]){
return DispatcherShell.ERRORS['EDNE'];
}
return new Promise(function(resolve){
self.dispatcher.pauseCode(engine, codeName, instanceId).then(function(data){
resolve(JSON.stringify(data));
})
.catch(function(err){
resolve(DispatcherShell.ERRORS['TIMEOUT']);
});
});
}
/**
* Migrate an instance from one engine to another engine using the dispatcher
*/
DispatcherShell.prototype.migrateCode = function(from, to, codeName, instanceId){
var self = this;
if(!this.dispatcher.engines[from] || !this.dispatcher.engines[to]){
return DispatcherShell.ERRORS['EDNE'];
}
return new Promise(function(resolve){
self.dispatcher.moveCode(from, to, codeName, instanceId).then(function(data){
resolve(JSON.stringify(data));
})
.catch(function(err){
resolve(DispatcherShell.ERRORS['TIMEOUT']);
});
});
}
/**
* Kill an instance of code
*/
DispatcherShell.prototype.kill = function(codeName, instanceId){
var self = this;
return new Promise(function(resolve){
self.dispatcher.killCode(codeName, instanceId).then(function(data){
resolve(JSON.stringify(data));
})
.catch(function(err){
resolve(DispatcherShell.ERRORS['TIMEOUT']);
});
});
}
/**
* Communicates with code instance directly to pause/resume/snapshot/etc
* -- Not used now that dispatcher API works
*/
DispatcherShell.prototype.sendCodeCommand = function(codeName, instanceId, ctrl){
var self = this;
var pubChannel = codeName + '/' + instanceId + '/cmd';
var subChannel = this.pubsub.id + '/reply';
this.pubsub.publish(pubChannel, { ctrl: ctrl, request_id: Math.random(), reply_to: subChannel });
return new Promise(function(resolve){
var timeout = setTimeout(function(){
resolve(DispatcherShell.ERRORS['TIMEOUT']);
}, 10000);
self.pubsub.subscribe(subChannel, function(data){
clearTimeout(timeout);
self.pubsub.unsubscribe(subChannel);
resolve(JSON.stringify(data));
});
});
}
/**
* Get the particular resource usage of an engine
*/
DispatcherShell.prototype.getResourceUsage = function(engineId){
if(!this.dispatcher.engines[engineId]){
return DispatcherShell.ERRORS['EDNE'];
}
var stats = this.dispatcher.engines[engineId].stats;
return JSON.stringify(stats[stats.length-1]);
}
/**
* Get all currently running programs on the network
*/
DispatcherShell.prototype.getPrograms = function(){
var self = this;
console.log('[DispatcherShell] Please wait while I collect programs...\n');
return new Promise(function(resolve){
var instances = [];
self.pubsub.publish('program-monitor/bcast', { ctrl: 'report' });
self.pubsub.subscribe('program-monitor', function(data){
instances.push(data);
});
setTimeout(function(){
self.pubsub.unsubscribe('program-monitor');
var instanceResources = {};
if(instances.length === 0){
resolve(JSON.stringify(instanceResources));
}
instances.forEach(function(instance){
var name = instance.code_name;
var id = instance.instance_id;
self.pubsub.subscribe(name + '/' + id + '/resource', function(data){
instanceResources[id] = { resource: data, meta: instance };
});
setTimeout(function(){
instances.forEach(function(instance){
self.pubsub.unsubscribe(instance.code_name +'/'+instance.instance_id+'/resource');
});
resolve(JSON.stringify(instanceResources));
}, 2000);
});
}, 2000);
});
}
/**
* Get all current devices on the network
*/
DispatcherShell.prototype.getDevices = function(){
var self = this;
console.log('[DispatcherShell] Please wait while I collect devices...\n');
return new Promise(function(resolve){
var devices = [];
self.pubsub.publish('engine-registry/bcast', { ctrl: 'report' });
self.pubsub.subscribe('engine-registry', function(data){
devices.push(data);
});
setTimeout(function(){
self.pubsub.unsubscribe('engine-registry');
var deviceRes = {};
devices.forEach(function(device){
self.pubsub.subscribe(device.id + '/resource', function(data){
deviceRes[device.id] = data;
self.pubsub.unsubscribe(device.id + '/resource');
});
});
setTimeout(function(){
resolve(JSON.stringify(deviceRes));
}, 2000);
}, 2000);
});
}
/**
* Get the resource usage of a specific program
*/
DispatcherShell.prototype.getProgramResourceUsage = function(codeName, instanceId){
var self = this;
return new Promise(function(resolve){
var channel = codeName + '/' + instanceId + '/resource';
var timeout = setTimeout(function(){
self.pubsub.unsubscribe(channel);
resolve(DispatcherShell.ERRORS['TIMEOUT']);
}, 5000);
self.pubsub.subscribe(channel, function(data){
self.pubsub.unsubscribe(channel);
clearTimeout(timeout);
resolve(JSON.stringify(data));
});
});
}
DispatcherShell.prototype.killEngine = function(engineId){
}
DispatcherShell.prototype.pauseCode = function(codeName, instanceId){
return this.sendCodeCommand(codeName, instanceId, 'pause');
}
DispatcherShell.prototype.resumeCode = function(){
return this.sendCodeCommand(codeName, instanceId, 'resume');
}
DispatcherShell.prototype.snapshotCode = function(codeName, instanceId){
return this.sendCodeCommand(codeName, instanceId, 'snapshot');
}
DispatcherShell.prototype.killCode = function(codeName, instanceId){
return this.sendCodeCommand(codeName, instanceId, 'kill');
}
DispatcherShell.prototype.listInstances = function(){
return this.dispatcher.printPrograms();
}
DispatcherShell.prototype.listEngines = function(){
return this.dispatcher.printEngines();
}
/*****************************************************************************
FILESYSTEM FUNCTIONS
*****************************************************************************/
DispatcherShell.prototype.pwd = function(){
return this.dir;
}
DispatcherShell.prototype.make = function(path, content){
var self = this;
var type = (content) ? 'file' : 'directory';
var parent = path.split('/');
var name = parent.pop();
return new Promise(function(resolve, reject){
if(name === ''){
reject('No ' + type + ' name provided');
return;
}
self._exists(path).then(function(_id){
if(_id && (type === 'directory')){
reject(DispatcherShell.ERRORS['EXISTS'](path));
return;
}
self._goto(parent.join('/')).then(function(res){
var path = res.path;
self._post(path, type, name, content, _id).then(function(){
resolve(type + ' successfully created');
})
.catch(function(err){
reject(err);
});
})
.catch(function(err){
reject(err);
});
});
});
}
DispatcherShell.prototype.makeDirectory = function(path){
var self = this;
return new Promise(function(resolve){
self.make(path).then(function(res){
resolve(res);
})
.catch(function(err){
resolve(err);
});
});
}
DispatcherShell.prototype.makeFile = function(path, contentPath){
var self = this;
return new Promise(function(resolve){
try{
var file = fs.readFileSync(contentPath, 'utf-8');
}
catch(e){
resolve(DispatcherShell.ERRORS['FILE']);
return;
}
self.make(path, file).then(function(res){
resolve(res);
})
.catch(function(err){
resolve(err);
});
});
}
DispatcherShell.prototype.delete = function(path){
var self = this;
return new Promise(function(resolve){
self._goto(path).then(function(newPath){
var _id = newPath.data._id;
var absPath = newPath.path + '?ids=' + _id;
self.http(absPath, 'DELETE').then(function(){
resolve(newPath.data.type + ' succesfully deleted');
})
.catch(function(err){
resolve(err);
});
})
.catch(function(err){
resolve(err);
});
});
}
DispatcherShell.prototype.cat = function(path){
var self = this;
return new Promise(function(resolve){
self._goto(path).then(function(newPath){
if(newPath.data.type !== 'file'){
resolve(DispatcherShell.ERRORS['NAF']);
return;
}
resolve(newPath.data.content);
})
.catch(function(err){
resolve(err);
});
})
.catch(function(err){
resolve(err);
})
}
DispatcherShell.prototype.listFiles = function(){
var self = this;
return new Promise(function(resolve){
self._get(self.dir).then(function(data){
var files = JSON.parse(data).children;
resolve(Object.keys(files).join('\n'));
})
.catch(function(err){
resolve(DispatcherShell.ERRORS['FS']);
});
});
}
DispatcherShell.prototype.changeDirectory = function(path){
var self = this;
return new Promise(function(resolve){
self._goto(path).then(function(newPath){
if(newPath.data.type && newPath.data.type !== 'directory'){
resolve(DispatcherShell.ERRORS['NAD']);
return;
}
self.dir = newPath.path;
resolve();
})
.catch(function(err){
resolve(err)
});
});
}
DispatcherShell.prototype._exists = function(path){
var self = this;
return new Promise(function(resolve){
self._goto(path).then(function(res){
resolve(res.data._id);
})
.catch(function(err){
resolve(undefined);
});
});
}
DispatcherShell.prototype._goto = function(path){
var self = this;
var currTokens = self.dir.split('/');
var cdTokens = path.split('/');
currTokens.shift();
return new Promise(function(resolve, reject){
cdTokens.forEach(function(token, index){
switch(token){
case '':
if(index === 0){
currTokens = [];
}
break;
case '..':
currTokens.pop();
break;
case '.':
break;
default:
currTokens.push(token);
}
});
var newPath = (currTokens[0] === '') ? currTokens.join('/') : '/' + currTokens.join('/');
self._get(newPath).then(function(res){
var res = JSON.parse(res);
if(res['error']){
reject(DispatcherShell.ERRORS['PDNE'](newPath));
}
else{
resolve({ path: newPath, data: res });
}
})
.catch(function(err){
reject(DispatcherShell.ERRORS['FS']);
});
});
}
DispatcherShell.prototype.http = function(absPath, method, requestBody){
var self = this;
var options = {
method: method,
host: self.FSURL,
port: self.FSPort,
path: self.FSPath + absPath,
headers: {
'Content-Type': 'application/json'
}
}
return new Promise(function(resolve, reject){
var req = http.request(options, function(res){
var body = '';
res.on('data', function(c){
body += c;
});
res.on('end', function(){
resolve(body);
});
res.on('error', function(){
reject(err);
});
}).on('error', function(){
reject(DispatcherShell.ERRORS['FS']);
});
if(requestBody){
req.write(JSON.stringify(requestBody));
}
req.end();
});
}
DispatcherShell.prototype._post = function(absPath, type, name, content, _id){
var self = this;
var requestBody = {
type: type,
name: name
}
if(content){
requestBody.content = content;
}
if(_id){
requestBody._id = _id;
}
return self.http(absPath, 'POST', requestBody);
}
DispatcherShell.prototype._get = function(absPath){
var self = this;
return self.http(absPath, 'GET');
}
/*****************************************************************************
SCHEDULING FUNCTIONS
*****************************************************************************/
/**
* Send a 'run application' request to the scheduler
* @param {string} schedulerId - the id of the scheduler to send the request to
* @param {json} appConfig - the application data described in json format
*/
DispatcherShell.prototype.runApplication = function(schedulerId, appConfig){
var self = this;
var config;
var sendChannel = schedulerId + '/cmd';
var requestId = randKey();
var listenChannel = requestId;
return new Promise(function(resolve){
try{
config = JSON.parse(fs.readFileSync(appConfig, 'utf-8'));
var app = {
ctrl: 'run_application',
kwargs: config,
request_id: requestId,
reply_to: requestId
}
}
catch(e){
resolve(DispatcherShell.ERRORS['CONFIG']);
}
self._listenTimeout(5000, listenChannel)
.then(function(res){
resolve(JSON.stringify(res));
})
.catch(function(err){
resolve(err);
});
self.pubsub.publish(sendChannel, app);
});
}
/**
* Generic function to control an application
* @param {string} schedulerId - the id of the scheduler to send the request to
* @param {string} appToken - the token associated with the application to control
* @param {string} - one of pause_application/kill_application/resume_application
*/
DispatcherShell.prototype.ctrlApplication = function(schedulerId, appToken, cmd){
var self = this;
var sendChannel = schedulerId + '/cmd';
var requestId = randKey();
var listenChannel = requestId;
var req = {
ctrl: cmd,
kwargs: { token: appToken },
request_id: requestId,
reply_to: requestId
}
return new Promise(function(resolve){
self._listenTimeout(5000, listenChannel)
.then(function(res){
resolve(JSON.stringify(res));
})
.catch(function(err){
resolve(err);
});
self.pubsub.publish(sendChannel, req);
});
}
DispatcherShell.prototype.pauseApplication = function(schedulerId, appToken){
return this.ctrlApplication(schedulerId, appToken, 'pause_application');
}
DispatcherShell.prototype.resumeApplication = function(schedulerId, appToken){
return this.ctrlApplication(schedulerId, appToken, 'resume_application');
}
DispatcherShell.prototype.killApplication = function(schedulerId, appToken){
return this.ctrlApplication(schedulerId, appToken, 'kill_application');
}
DispatcherShell.prototype._listenAccumulate = function(ms, channel){
var self = this;
var messages = [];
return new Promise(function(resolve){
self.pubsub.subscribe(channel, function(msg){
messages.push(msg);
});
setTimeout(function(){
resolve(messages);
}, ms);
});
}
DispatcherShell.prototype._listenTimeout = function(ms, channel){
var self = this;
return new Promise(function(resolve, reject){
var timer = setTimeout(function(){
reject(DispatcherShell.ERRORS['TIMEOUT']);
}, ms);
self.pubsub.subscribe(channel, function(msg){
clearTimeout(timer);
resolve(msg);
});
});
}
/*****************************************************************************
MISC FUNCTIONS
******************************************************************************/
/**
* Execute a script file. The commands must be in the syntax of this shell
*/
DispatcherShell.prototype.executeScript = function(scriptFile){
var self = this;
var lineReader;
var commands = [];
return new Promise(function(resolve){
var stream = fs.createReadStream(scriptFile);
stream.on('error', function(err){
resolve('Problem reading the script file');
});
lineReader = readline.createInterface({
input: stream
});
lineReader.on('line', function (line) {
commands.push(line);
});
lineReader.on('close', function(){
var promises = [];
commands.forEach(function(cmd, line){
// parse commands into tokens
var tokens = cmd.split(' ');
var action = tokens[0];
var args = tokens.slice(1);
if(action in DispatcherShell.COMMANDS){
var res = DispatcherShell.COMMANDS[action].apply(self, args);
promises.push(res);
}
else{
resolve('Error with script: Unrecognized command found on line ' + (line+1));
}
});
Promise.all(promises).then(function(res){
resolve(res.join('\n'));
});
});
});
}
/**
* All available commands on the shell
*/
DispatcherShell.COMMANDS = {
run_app: function(arg1, arg2){
if(arguments.length < 2){
return DispatcherShell.ERRORS['ARGS'](['scheduler id', 'application JSON']);
}
return this.runApplication(arg1, arg2);
},
kill_app: function(arg1, arg2){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['scheduler id', 'application token']);
}
return this.killApplication(arg1, arg2);
},
pause_app: function(arg1, arg2){
if(arguments.length < 2){
return DispatcherShell.ERRORS['ARGS'](['scheduler id', 'application token']);
}
return this.pauseApplication(arg1, arg2);
},
resume_app: function(arg1, arg2){
if(arguments.length < 2){
return DispatcherShell.ERRORS['ARGS'](['scheduler id', 'application token']);
}
return this.resumeApplication(arg1, arg2);
},
rm: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['global path']);
}
return this.delete(arg1);
},
mkdir: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['directory']);
}
return this.makeDirectory(arg1);
},
touch: function(arg1, arg2){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['global file path', 'local content path']);
}
return this.makeFile(arg1, arg2);
},
cat: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['global file path']);
}
return this.cat(arg1);
},
pwd: function(){
return this.pwd();
},
ls: function(){
return this.listFiles();
},
cd: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['path']);
}
return this.changeDirectory(arg1);
},
devices: function(){
return this.getDevices();
},
programs: function(){
return this.getPrograms();
},
user_meta: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['instance id']);
}
return this.programMeta(arg1);
},
presource: function(arg1, arg2){
if(arguments.length < 2){
return DispatcherShell.ERRORS['ARGS'](['code name', 'instance id']);
}
return this.getProgramResourceUsage(arg1, arg2);
},
resource: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['engine id']);
}
return this.getResourceUsage(arg1);
},
script: function(arg1){
if(arguments.length < 1){
return DispatcherShell.ERRORS['ARGS'](['path to script']);
}
return this.executeScript(arg1);
},
run: function(arg1, arg2){
if(arguments.length < 2){
return DispatcherShell.ERRORS['ARGS'](['engine id', 'path of code to execute']);
}
return this.run(arg1, arg2);
},
pause: function(arg1, arg2, arg3){
if(arguments.length < 3){
return DispatcherShell.ERRORS['ARGS'](['engine id', 'code name', 'instance id']);
}
return this.pause(arg1, arg2, arg3);
},
kill: function(arg1, arg2){
if(arguments.length < 3){
return DispatcherShell.ERRORS['ARGS'](['code name', 'instance id']);
}
return this.kill(arg1, arg2);
},
snapshot: function(arg1, arg2){
if(arguments.length < 2){
return DispatcherShell.ERRORS['ARGS'](['code name', 'instance id']);
}
return this.sendCodeCommand(arg1, arg2, 'snapshot');
},
migrate: function(arg1, arg2, arg3, arg4){
if(arguments.length < 4){
return DispatcherShell.ERRORS['ARGS'](['from', 'to', 'code name', 'instance id']);
}
return this.migrateCode(arg1, arg2, arg3, arg4);
},
instances: function(){
return this.listInstances();
},
engines: function(){
return this.listEngines();
},
exit: function(){
process.exit();
},
cmds: function(){
return Object.keys(DispatcherShell.COMMANDS).join('\n');
},
clear: function(){
process.stdout.write('\033c');
}
}
module.exports = DispatcherShell;