Skip to content

Commit 25c5123

Browse files
Merge pull request #29 from pcoop/branch1
Progress bar for Deploy/Undeploy
2 parents d2ad4fe + c2e6d0a commit 25c5123

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

__tests__/api/BundleDeploy/__snapshots__/BundleDeployer.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`BundleDeployer01 should complain if status can't be determined 1`] = `"
1616

1717
exports[`BundleDeployer01 should complain if status can't be determined 2`] = `"DFHDPLOY command completed, but status cannot be determined."`;
1818

19-
exports[`BundleDeployer01 should complain of SYSTSPRT not found 1`] = `"SYSTSPRT output from DFHDPLOY not found. Most recent status update: ''."`;
19+
exports[`BundleDeployer01 should complain of SYSTSPRT not found 1`] = `"SYSTSPRT output from DFHDPLOY not found. Most recent status update: 'Submitting DFHDPLOY JCL'."`;
2020

2121
exports[`BundleDeployer01 should complain with missing zOSMF profile for deploy 1`] = `"Expect Error: Required parameter 'hostname' must be defined"`;
2222

@@ -220,7 +220,7 @@ UNDEPLOY BUNDLE(12345678)
220220
"
221221
`;
222222

223-
exports[`BundleDeployer01 should handle failure during submitjobs processing 1`] = `"Failure occurred submitting DFHDPLOY JCL: 'Cannot read property 'hostname' of undefined'. Most recent status update: ''."`;
223+
exports[`BundleDeployer01 should handle failure during submitjobs processing 1`] = `"Failure occurred submitting DFHDPLOY JCL: 'Cannot read property 'hostname' of undefined'. Most recent status update: 'Submitting DFHDPLOY JCL'."`;
224224

225225
exports[`BundleDeployer01 should support long bundledir 1`] = `"DFHRL2037I"`;
226226

@@ -250,7 +250,7 @@ DEPLOY BUNDLE(12345678)
250250

251251
exports[`BundleDeployer01 should tolerate empty output from DFHDPLOY 1`] = `"undefined"`;
252252

253-
exports[`BundleDeployer01 should tolerate empty output from DFHDPLOY 2`] = `"DFHDPLOY did not generate any output. Most recent status update: ''."`;
253+
exports[`BundleDeployer01 should tolerate empty output from DFHDPLOY 2`] = `"DFHDPLOY did not generate any output. Most recent status update: 'Submitting DFHDPLOY JCL'."`;
254254

255255
exports[`BundleDeployer01 should undeploy successfully 1`] = `"DFHRL2037I"`;
256256

src/api/BundleDeploy/BundleDeployer.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
"use strict";
1313

14-
import { IHandlerParameters, Logger, ImperativeError, Session, ITaskWithStatus, TaskStage } from "@brightside/imperative";
14+
import { IHandlerParameters, Logger, ImperativeError, AbstractSession, ITaskWithStatus,
15+
TaskStage , TaskProgress} from "@brightside/imperative";
1516
import { ZosmfSession, SubmitJobs, List } from "@brightside/core";
1617
import { ParmValidator } from "./ParmValidator";
1718

@@ -24,6 +25,8 @@ import { ParmValidator } from "./ParmValidator";
2425
export class BundleDeployer {
2526

2627
private params: IHandlerParameters;
28+
private PROGRESS_BAR_INTERVAL = 1500; // milliseconds
29+
private PROGRESS_BAR_MAX = 67;
2730

2831
/**
2932
* Constructor for a BundleDeployer.
@@ -164,7 +167,7 @@ export class BundleDeployer {
164167
}
165168

166169

167-
private async createZosMFSession(): Promise<Session> {
170+
private async createZosMFSession(): Promise<any> {
168171
// Create a zosMF session
169172
const zosmfProfile = this.params.profiles.get("zosmf");
170173

@@ -174,7 +177,7 @@ export class BundleDeployer {
174177
return ZosmfSession.createBasicZosmfSession(zosmfProfile);
175178
}
176179

177-
private async checkHLQDatasets(session: Session) {
180+
private async checkHLQDatasets(session: any) {
178181
// Check that the CICS dataset value looks valid and can be viewed
179182
// Access errors will trigger an Exception
180183
const cicspds = this.params.arguments.cicshlq + ".SDFHLOAD";
@@ -203,9 +206,31 @@ export class BundleDeployer {
203206
}
204207
}
205208

206-
private async submitJCL(jcl: string, session: Session): Promise<string> {
209+
private updateProgressBar(status: ITaskWithStatus) {
210+
// Increment the progress by 1%. This will refresh what the user sees
211+
// on the console.
212+
status.percentComplete = status.percentComplete + 1;
213+
214+
// Continue iterating on progress updates until we've reached the max value,
215+
// or until the processing has completed.
216+
if (status.percentComplete < this.PROGRESS_BAR_MAX &&
217+
status.stageName === TaskStage.IN_PROGRESS) {
218+
setTimeout(this.updateProgressBar.bind(this), this.PROGRESS_BAR_INTERVAL, status);
219+
}
220+
}
221+
222+
private async submitJCL(jcl: string, session: any): Promise<string> {
207223
let spoolOutput: any;
208-
const status: ITaskWithStatus = { percentComplete: 0, statusMessage: "", stageName: TaskStage.NOT_STARTED };
224+
const status: ITaskWithStatus = { percentComplete: TaskProgress.TEN_PERCENT,
225+
statusMessage: "Submitting DFHDPLOY JCL",
226+
stageName: TaskStage.IN_PROGRESS };
227+
this.params.response.progress.startBar({task: status});
228+
229+
// Refresh the progress bar by 1% every second or so up to a max of 67%.
230+
// SubmitJobs will initialise it to 30% and set it to 70% when it
231+
// completes, we tweak it every so often until then for purely cosmetic purposes.
232+
setTimeout(this.updateProgressBar.bind(this), this.PROGRESS_BAR_INTERVAL, status);
233+
209234
try {
210235
spoolOutput = await SubmitJobs.submitJclString(session, jcl, {
211236
jclSource: "",
@@ -214,6 +239,7 @@ export class BundleDeployer {
214239
});
215240
}
216241
catch (error) {
242+
status.stageName = TaskStage.FAILED;
217243
throw new Error("Failure occurred submitting DFHDPLOY JCL: '" + error.message +
218244
"'. Most recent status update: '" + status.statusMessage + "'.");
219245
}
@@ -229,27 +255,38 @@ export class BundleDeployer {
229255
logger.debug(file.data);
230256

231257
if (file.data === undefined || file.data.length === 0) {
258+
status.stageName = TaskStage.FAILED;
232259
throw new Error("DFHDPLOY did not generate any output. Most recent status update: '" + status.statusMessage + "'.");
233260
}
234261

262+
// Finish the progress bar
263+
status.statusMessage = "Completed DFHDPLOY";
264+
this.params.response.progress.endBar();
265+
235266
// Did DFHDPLOY fail?
236267
if (file.data.indexOf("DFHRL2055I") > -1) {
268+
status.stageName = TaskStage.FAILED;
237269
throw new Error("DFHDPLOY stopped processing due to an error.");
238270
}
239271
if (file.data.indexOf("DFHRL2043I") > -1) {
272+
status.stageName = TaskStage.COMPLETE;
240273
return "DFHDPLOY completed with warnings.";
241274
}
242275
if (file.data.indexOf("DFHRL2012I") > -1) {
276+
status.stageName = TaskStage.COMPLETE;
243277
return "DFHDPLOY DEPLOY command successful.";
244278
}
245279
if (file.data.indexOf("DFHRL2037I") > -1) {
280+
status.stageName = TaskStage.COMPLETE;
246281
return "DFHDPLOY UNDEPLOY command successful.";
247282
}
248283

284+
status.stageName = TaskStage.FAILED;
249285
throw new Error("DFHDPLOY command completed, but status cannot be determined.");
250286
}
251287
}
252288

289+
status.stageName = TaskStage.FAILED;
253290
throw new Error("SYSTSPRT output from DFHDPLOY not found. Most recent status update: '" + status.statusMessage + "'.");
254291
}
255292
}

0 commit comments

Comments
 (0)