Skip to content

Commit 9301210

Browse files
Merge pull request #90 from pcoop/branch1
More for #82
2 parents 3e79aad + 8f3c85d commit 9301210

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

src/api/BundleDeploy/BundleDeployer.ts

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class BundleDeployer {
3131
private parmsValidated: boolean = false;
3232
private hlqsValidated: boolean = false;
3333
private jobId: string;
34+
private progressBar: ITaskWithStatus;
3435

3536
/**
3637
* Constructor for a BundleDeployer.
@@ -249,66 +250,66 @@ export class BundleDeployer {
249250
this.hlqsValidated = true;
250251
}
251252

252-
private updateProgressBar(status: ITaskWithStatus, action: string) {
253+
private updateProgressBar(action: string) {
253254
// Increment the progress by 1%. This will refresh what the user sees
254255
// on the console.
255-
status.percentComplete = status.percentComplete + 1;
256+
this.progressBar.percentComplete += 1;
256257

257258
// Have a look at the status message for the progress bar, has it been updated with
258259
// the jobid yet? If so, parse it out and refresh the message.
259260
if (this.jobId === "UNKNOWN") {
260-
const statusWords = status.statusMessage.split(" ");
261+
const statusWords = this.progressBar.statusMessage.split(" ");
261262
if (statusWords.length >= 2) {
262263
if (statusWords[2] !== undefined && statusWords[2].indexOf("JOB") === 0) {
263264
this.jobId = statusWords[2];
264-
status.statusMessage += " (Processing DFHDPLOY " + action + " action)";
265+
this.progressBar.statusMessage += " (Processing DFHDPLOY " + action + " action)";
265266

266-
this.params.response.progress.endBar();
267+
this.endProgressBar();
267268
// log the jobid for posterity
268269
if (this.params.arguments.verbose) {
269-
this.params.response.console.log(status.statusMessage + "\n");
270+
this.params.response.console.log(this.progressBar.statusMessage + "\n");
270271
}
271272
if (this.params.arguments.silent === undefined) {
272273
const logger = Logger.getAppLogger();
273-
logger.debug(status.statusMessage);
274+
logger.debug(this.progressBar.statusMessage);
274275
}
275-
this.params.response.progress.startBar({task: status});
276+
this.startProgressBar();
276277
}
277278
}
278279
}
279280

280281
// Continue iterating on progress updates until we've reached the max value,
281282
// or until the processing has completed.
282-
if (status.percentComplete < this.PROGRESS_BAR_MAX &&
283-
status.stageName === TaskStage.IN_PROGRESS) {
284-
setTimeout(this.updateProgressBar.bind(this), this.PROGRESS_BAR_INTERVAL, status, action);
283+
if (this.progressBar.percentComplete < this.PROGRESS_BAR_MAX &&
284+
this.progressBar.stageName === TaskStage.IN_PROGRESS) {
285+
setTimeout(this.updateProgressBar.bind(this), this.PROGRESS_BAR_INTERVAL, action);
285286
}
286287
}
287288

288289
private async submitJCL(jcl: string, action: string, session: any): Promise<string> {
289290
let spoolOutput: any;
290-
const status: ITaskWithStatus = { percentComplete: TaskProgress.TEN_PERCENT,
291-
statusMessage: "Submitting DFHDPLOY JCL for the " + action + " action",
292-
stageName: TaskStage.IN_PROGRESS };
293-
this.params.response.progress.startBar({task: status});
291+
this.progressBar = { percentComplete: TaskProgress.TEN_PERCENT,
292+
statusMessage: "Submitting DFHDPLOY JCL for the " + action + " action",
293+
stageName: TaskStage.IN_PROGRESS };
294+
this.startProgressBar();
294295
this.jobId = "UNKNOWN";
295296

296297
// Refresh the progress bar by 1% every second or so up to a max of 67%.
297298
// SubmitJobs will initialise it to 30% and set it to 70% when it
298299
// completes, we tweak it every so often until then for purely cosmetic purposes.
299-
setTimeout(this.updateProgressBar.bind(this), this.PROGRESS_BAR_INTERVAL, status, action);
300+
setTimeout(this.updateProgressBar.bind(this), this.PROGRESS_BAR_INTERVAL, action);
300301

301302
try {
302303
spoolOutput = await SubmitJobs.submitJclString(session, jcl, {
303304
jclSource: "",
304-
task: status,
305+
task: this.progressBar,
305306
viewAllSpoolContent: true
306307
});
307308
}
308309
catch (error) {
309-
status.stageName = TaskStage.FAILED;
310+
this.progressBar.stageName = TaskStage.FAILED;
310311
throw new Error("Failure occurred submitting DFHDPLOY JCL for JOBID " + this.jobId + ": '" + error.message +
311-
"'. Most recent status update: '" + status.statusMessage + "'.");
312+
"'. Most recent status update: '" + this.progressBar.statusMessage + "'.");
312313
}
313314

314315
// Find the output
@@ -317,9 +318,9 @@ export class BundleDeployer {
317318
if (file.ddName === "SYSTSPRT" && file.stepName === "DFHDPLOY") {
318319

319320
if (file.data === undefined || file.data.length === 0) {
320-
status.stageName = TaskStage.FAILED;
321+
this.progressBar.stageName = TaskStage.FAILED;
321322
throw new Error("DFHDPLOY did not generate any output for JOBID " + this.jobId +
322-
". Most recent status update: '" + status.statusMessage + "'.");
323+
". Most recent status update: '" + this.progressBar.statusMessage + "'.");
323324
}
324325

325326
// log the full output for serviceability to the log
@@ -329,40 +330,40 @@ export class BundleDeployer {
329330
}
330331

331332
// Finish the progress bar
332-
status.statusMessage = "Completed DFHDPLOY";
333-
this.params.response.progress.endBar();
333+
this.progressBar.statusMessage = "Completed DFHDPLOY";
334+
this.endProgressBar();
334335

335336
// Did DFHDPLOY fail?
336337
if (file.data.indexOf("DFHRL2055I") > -1) {
337-
status.stageName = TaskStage.FAILED;
338+
this.progressBar.stageName = TaskStage.FAILED;
338339
// log the error output to the console
339340
this.params.response.console.log(file.data);
340341
throw new Error("DFHDPLOY stopped processing for JOBID " + this.jobId + " due to an error.");
341342
}
342343
if (file.data.indexOf("DFHRL2043I") > -1) {
343-
status.stageName = TaskStage.COMPLETE;
344+
this.progressBar.stageName = TaskStage.COMPLETE;
344345
// log the error output to the console
345346
this.params.response.console.log(file.data);
346347
return "DFHDPLOY completed with warnings.";
347348
}
348349
if (file.data.indexOf("DFHRL2012I") > -1) {
349-
status.stageName = TaskStage.COMPLETE;
350+
this.progressBar.stageName = TaskStage.COMPLETE;
350351
// only log the output to the console if verbose output is enabled
351352
if (this.params.arguments.verbose) {
352353
this.params.response.console.log(file.data);
353354
}
354355
return "Bundle deployment successful.";
355356
}
356357
if (file.data.indexOf("DFHRL2037I") > -1) {
357-
status.stageName = TaskStage.COMPLETE;
358+
this.progressBar.stageName = TaskStage.COMPLETE;
358359
// only log the output to the console if verbose output is enabled
359360
if (this.params.arguments.verbose) {
360361
this.params.response.console.log(file.data);
361362
}
362363
return "Bundle undeployment successful.";
363364
}
364365

365-
status.stageName = TaskStage.FAILED;
366+
this.progressBar.stageName = TaskStage.FAILED;
366367
// log the error output to the console
367368
this.params.response.console.log(file.data);
368369
throw new Error("DFHDPLOY command completed for JOBID " + this.jobId + ", but status cannot be determined.");
@@ -372,15 +373,27 @@ export class BundleDeployer {
372373
// If we haven't found SYSTSPRT then echo JESMSGLG instead
373374
for (const file of spoolOutput) {
374375
if (file.ddName === "JESMSGLG") {
375-
status.stageName = TaskStage.FAILED;
376+
this.progressBar.stageName = TaskStage.FAILED;
376377
// log the error output to the console
377378
this.params.response.console.log(file.data);
378379
throw new Error("DFHDPLOY command completed in error for JOBID " + this.jobId + " without generating SYSTSPRT output.");
379380
}
380381
}
381382

382-
status.stageName = TaskStage.FAILED;
383+
this.progressBar.stageName = TaskStage.FAILED;
383384
throw new Error("SYSTSPRT and JESMSGLG output from DFHDPLOY not found for JOBID " + this.jobId +
384-
". Most recent status update: '" + status.statusMessage + "'.");
385+
". Most recent status update: '" + this.progressBar.statusMessage + "'.");
386+
}
387+
388+
private startProgressBar() {
389+
if (this.params.arguments.verbose !== true) {
390+
this.params.response.progress.startBar({task: this.progressBar});
391+
}
392+
}
393+
394+
private endProgressBar() {
395+
if (this.params.arguments.verbose !== true) {
396+
this.params.response.progress.endBar();
397+
}
385398
}
386399
}

src/cli/shared/BundleParent.handler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export abstract class BundleParentHandler implements ICommandHandler {
5454
// either throw an Exception or return a success message.
5555
msg = await this.performAction(params);
5656

57+
// Add a newline char if its needed
58+
if (msg.slice(-1) !== "\n") {
59+
msg += "\n";
60+
}
61+
5762
// Issue the success message
5863
params.response.console.log(Buffer.from(msg));
5964
if (params.arguments.silent === undefined) {

0 commit comments

Comments
 (0)