-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
148 lines (130 loc) · 4.68 KB
/
gulpfile.js
File metadata and controls
148 lines (130 loc) · 4.68 KB
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
// var gulp = require('gulp-help')(require('gulp'));
var gulp = require('gulp-help')(require('gulp'));
var gulpSequence = require('gulp-sequence');
var PluginError = require('plugin-error');
var cmd = require('node-cmd');
/**
* await Job Callback
* @callback awaitJobCallback
* @param {Error} err
*/
/**
* Polls jobId. Callback is made without error if Job completes with CC < MaxRC in the allotted time
* @param {string} jobId jobId to check the completion of
* @param {number} [maxRC=0] maximum allowable return code
* @param {awaitJobCallback} callback function to call after completion
* @param {number} tries max attempts to check the completion of the job
* @param {number} wait wait time in ms between each check
*/
function awaitJobCompletion(jobId, maxRC=0, callback, tries = 30, wait = 1000) {
if (tries > 0) {
sleep(wait);
cmd.get(
'bright jobs view job-status-by-jobid ' + jobId + ' --rff retcode --rft string',
function (err, data, stderr) {
retcode = data.trim();
//retcode should either be null of in the form CC nnnn where nnnn is the return code
if (retcode == "null") {
awaitJobCompletion(jobId, maxRC, callback, tries - 1, wait);
} else if (retcode.split(" ")[1] <= maxRC) {
callback(null);
} else {
callback(new Error(jobId + " had a return code of " + retcode + " exceeding maximum allowable return code of " + maxRC));
}
}
);
} else {
callback(new Error(jobId + " timed out."));
}
}
/**
* Sleep function.
* @param {number} ms Number of ms to sleep
*/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
gulp.task('bind-n-grant', 'Bind & Grant Job', function (callback) {
var command = 'bright jobs submit data-set "CUSTXXX.MARBLES.JCL(MARBIND)" --rff jobid --rft string';
// Submit job, await completion
cmd.get(command, function (err, data, stderr) {
if(err){
callback(err);
} else if (stderr){
callback(new Error("\nCommand:\n" + command + "\n" + stderr + "Stack Trace:"));
} else {
// Strip unwanted whitespace/newline
var jobId = data.trim();
// Await the jobs completion
awaitJobCompletion(jobId, 4, function(err){
if(err){
callback(err);
} else{
callback();
}
});
}
});
});
gulp.task('build-cobol', 'Build COBOL element', function (callback) {
var command = "bright endevor generate element MARBLEXX --type COBOL --override-signout --maxrc 0";
cmd.get(command, function (err, data, stderr) {
if(err){
callback(err);
} else if (stderr){
callback(new Error("\nCommand:\n" + command + "\n" + stderr + "Stack Trace:"));
} else {
callback();
}
});
});
gulp.task('build-lnk', 'Build LNK element', function (callback) {
var command = "bright endevor generate element MARBLEXX --type LNK --override-signout --maxrc 0";
cmd.get(command, function (err, data, stderr) {
if(err){
callback(err);
} else if (stderr){
callback(new Error("\nCommand:\n" + command + "\n" + stderr + "Stack Trace:"));
} else {
callback();
}
});
});
gulp.task('build', 'Build Program', gulpSequence('build-cobol','build-lnk'));
gulp.task('cics-refresh', 'Refresh(new-copy) MARBLEXX CICS Program', function (callback) {
var command = 'bright cics refresh program "MARBLEXX"';
cmd.get(command, function (err, data, stderr) {
if(err){
callback(err);
} else if (stderr){
callback(new Error("\nCommand:\n" + command + "\n" + stderr + "Stack Trace:"));
} else {
callback();
};
});
});
gulp.task('copy-dbrm', 'Copy DBRMLIB to test environment', function (callback) {
var command = 'bright file-master-plus copy data-set "PRODUCT.NDVR.MARBLES.MARBLES.D1.DBRMLIB" "BRIGHT.MARBLES.DBRMLIB" -m MARBLEXX';
cmd.get(command, function (err, data, stderr) {
if(err){
callback(err);
} else if (stderr){
callback(new Error("\nCommand:\n" + command + "\n" + stderr + "Stack Trace:"));
} else {
callback();
};
});
});
gulp.task('copy-load', 'Copy LOADLIB to test environment', function (callback) {
var command = 'bright file-master-plus copy data-set "PRODUCT.NDVR.MARBLES.MARBLES.D1.LOADLIB" "CICS.TRAIN.MARBLES.LOADLIB" -m MARBLEXX';
cmd.get(command, function (err, data, stderr) {
if(err){
callback(err);
} else if (stderr){
callback(new Error("\nCommand:\n" + command + "\n" + stderr + "Stack Trace:"));
} else {
callback();
};
});
});
gulp.task('deploy', 'Deploy Program', gulpSequence('copy-dbrm','copy-load','bind-n-grant','cics-refresh'));