UNPKG

@zowe/cli

Version:

Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.

165 lines 8.45 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const imperative_1 = require("@zowe/imperative"); const SubmitJobs_1 = require("../../../src/api/SubmitJobs"); const util_1 = require("util"); const fs = require("fs"); const Get_1 = require("../../../../zosfiles/src/api/methods/get/Get"); const ZosmfBaseHandler_1 = require("../../../../zosmf/src/ZosmfBaseHandler"); const getstdin = require("get-stdin"); /** * "zos-jobs submit data-set" command handler. Submits a job (JCL) contained within a z/OS data set (PS or PDS member). * @export * @class SubmitJobHandler * @implements {ICommandHandler} */ class SharedSubmitHandler extends ZosmfBaseHandler_1.ZosmfBaseHandler { /** * Command handler process - invoked by the command processor to handle the "zos-jobs submit data-set" * @param {IHandlerParameters} params - Command handler parameters * @returns {Promise<void>} - Fulfilled when the command completes successfully OR rejected with imperative error * @memberof SubmitDataSetHandler */ processCmd(params) { return __awaiter(this, void 0, void 0, function* () { const status = { statusMessage: "Submitting job", percentComplete: imperative_1.TaskProgress.TEN_PERCENT, stageName: imperative_1.TaskStage.IN_PROGRESS }; // Save the needed parameters for convenience const parms = { jclSource: undefined, viewAllSpoolContent: this.mArguments.viewAllSpoolContent, directory: this.mArguments.directory, extension: this.mArguments.extension, volume: this.mArguments.volume, waitForActive: this.mArguments.waitForActive, waitForOutput: this.mArguments.waitForOutput, task: status }; const options = {}; params.response.progress.startBar({ task: status }); // Determine the positional parameter specified and invoke the correct API // TODO: More will be added with additional commands let sourceType; if (this.mArguments.dataset) { sourceType = "dataset"; } else if (this.mArguments.localFile) { sourceType = "local-file"; } else if (params.definition.name === "stdin") { sourceType = "stdin"; } let response; // Response from Submit Job let apiObj; // API Object to set in the command JSON response let spoolFilesResponse; // Response from view all spool content option let source; // The actual JCL source (i.e. data-set name, file name, etc.) let directory = this.mArguments.directory; // Path where to download spool content // Process depending on the source type switch (sourceType) { // Submit the JCL from a data set case "dataset": // If the data set is not in catalog and volume option is provided if (parms.volume) { options.volume = parms.volume; // Get JCL from data set or member const getJcl = yield Get_1.Get.dataSet(this.mSession, this.mArguments.dataset, options); source = this.mArguments.dataset; apiObj = yield SubmitJobs_1.SubmitJobs.submitJclString(this.mSession, getJcl.toString(), parms); if (parms.viewAllSpoolContent) { spoolFilesResponse = apiObj; } break; } else { response = yield SubmitJobs_1.SubmitJobs.submitJob(this.mSession, this.mArguments.dataset); apiObj = yield SubmitJobs_1.SubmitJobs.checkSubmitOptions(this.mSession, parms, response); source = this.mArguments.dataset; if (parms.viewAllSpoolContent) { spoolFilesResponse = apiObj; } } break; // Submit the JCL from a local file case "local-file": parms.jclSource = this.mArguments.localFile; const JclString = fs.readFileSync(this.mArguments.localFile).toString(); apiObj = yield SubmitJobs_1.SubmitJobs.submitJclString(this.mSession, JclString, parms); source = this.mArguments.localFile; if (parms.viewAllSpoolContent) { spoolFilesResponse = apiObj; } break; // Submit the JCL piped in on stdin case "stdin": const Jcl = yield getstdin(); apiObj = yield SubmitJobs_1.SubmitJobs.submitJclString(this.mSession, Jcl, parms); source = "stdin"; if (parms.viewAllSpoolContent) { spoolFilesResponse = apiObj; } break; default: throw new imperative_1.ImperativeError({ msg: `Internal submit error: Unable to determine the JCL source. ` + `Please contact support.`, additionalDetails: JSON.stringify(params) }); } // Print the response to the command if (util_1.isNullOrUndefined(spoolFilesResponse)) { params.response.format.output({ fields: ["jobid", "retcode", "jobname", "status"], output: apiObj, format: "object" }); // Set the API object to the correct this.data.setObj(apiObj); // Print data from spool content } else { for (const spoolFile of spoolFilesResponse) { if (!util_1.isNullOrUndefined(spoolFile.procName) && spoolFile.procName.length > 0) { this.console.log("Spool file: %s (ID #%d, Step: %s, ProcStep: %s)", spoolFile.ddName, spoolFile.id, spoolFile.stepName, spoolFile.procName); } else { this.console.log("Spool file: %s (ID #%d, Step: %s)", spoolFile.ddName, spoolFile.id, spoolFile.stepName); } this.console.log(spoolFile.data); } // Set the API object to the correct this.data.setObj(spoolFilesResponse); } // Print path where spool content was downloaded if (!util_1.isNullOrUndefined(directory) && util_1.isNullOrUndefined(spoolFilesResponse)) { directory = directory.includes("./") ? directory : `./${directory}`; params.response.console.log(`Successfully downloaded output to ${directory}/${apiObj.jobid}`); } params.response.progress.endBar(); this.data.setMessage(`Submitted JCL contained in "${sourceType}": "${source}"`); }); } } exports.default = SharedSubmitHandler; //# sourceMappingURL=Submit.shared.handler.js.map