@zowe/cli
Version:
Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.
142 lines • 7.02 kB
JavaScript
;
/*
* 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 JobsConstants_1 = require("./JobsConstants");
const rest_1 = require("../../../rest");
const GetJobs_1 = require("./GetJobs");
/**
* Class to handle downloading of job information
* @export
* @class DownloadJobs
*/
class DownloadJobs {
/**
* Download spool content to a the default download directory
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param jobFile - spool file to download
* @returns {Promise<string>} - content downloaded
* @memberof DownloadJobs
*/
static downloadSpoolContent(session, jobFile) {
return __awaiter(this, void 0, void 0, function* () {
this.log.trace("Entered downloadSpoolContent for job file %s", JSON.stringify(jobFile));
return DownloadJobs.downloadSpoolContentCommon(session, { jobFile });
});
}
/**
* Download all job output (spool content) for a job to a the local directory
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {IDownloadAllSpoolContentParms} parms - parameter object (see IDownloadAllSpoolContentParms for details)
* @returns {Promise<void>} - a promise which will resolve when the download is complete
* @memberof DownloadJobs
*/
static downloadAllSpoolContentCommon(session, parms) {
return __awaiter(this, void 0, void 0, function* () {
this.log.trace("Entering downloadAllSpoolContentCommon with parms %s", JSON.stringify(parms));
imperative_1.ImperativeExpect.keysToBeDefined(parms, ["jobid", "jobname"], "You must specify job ID and job name on your" +
" 'parms' object to the downloadAllSpoolContent API.");
this.log.debug("Downloading all spool content for job %s(%s)", parms.jobname, parms.jobid);
const jobFiles = yield GetJobs_1.GetJobs.getSpoolFiles(session, parms.jobname, parms.jobid);
for (const file of jobFiles) {
yield DownloadJobs.downloadSpoolContentCommon(session, {
jobFile: file,
outDir: parms.outDir,
omitJobidDirectory: parms.omitJobidDirectory
});
}
});
}
/**
* Download spool content to specified directory
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {IDownloadSpoolContentParms} parms - parm object (see IDownloadSpoolContentParms interface for details)
* @returns {Promise<void>} - promise that resolves when the file is downloaded
* @memberof DownloadJobs
*/
static downloadSpoolContentCommon(session, parms) {
return __awaiter(this, void 0, void 0, function* () {
this.log.trace("Entering downloadSpoolContentCommon with parms %s", JSON.stringify(parms));
imperative_1.ImperativeExpect.keysToBeDefined(parms, ["jobFile"], "You must specify a job file on your 'parms' parameter" +
" object to the downloadSpoolContentCommon API.");
if (parms.outDir == null) {
parms.outDir = DownloadJobs.DEFAULT_JOBS_OUTPUT_DIR;
}
const file = DownloadJobs.getSpoolDownloadFile(parms.jobFile, parms.omitJobidDirectory, parms.outDir);
this.log.debug("Downloading spool file %s for job %s(%s) to file %s", parms.jobFile.ddname, parms.jobFile.jobname, parms.jobFile.jobid, file);
imperative_1.IO.createDirsSyncFromFilePath(file);
imperative_1.IO.createFileSync(file);
const parameters = "/" + parms.jobFile.jobname + "/" + parms.jobFile.jobid +
JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + "/" + parms.jobFile.id + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT;
const writeStream = imperative_1.IO.createWriteStream(file);
yield rest_1.ZosmfRestClient.getStreamed(session, JobsConstants_1.JobsConstants.RESOURCE + parameters, undefined, writeStream, true);
});
}
/**
* Get the file where a specified spool file (IJobFile) would be downloaded to
* @static
* @param {IJobFile} jobFile - the spool file that would be downloaded
* @param {boolean} omitJobidDirectory - if true, the job ID of the jobFile will not be included in the file path
* @param {string} outDir - parent output directory you would like to download to
* @returns {string} the file path that the spool file would be downloaded to
* @memberof DownloadJobs
*/
static getSpoolDownloadFile(jobFile, omitJobidDirectory, outDir = DownloadJobs.DEFAULT_JOBS_OUTPUT_DIR) {
this.log.trace("getSpoolDownloadFile called with jobFile %s, omitJobIDDirectory: %s, outDir: %s", JSON.stringify(jobFile), omitJobidDirectory + "", outDir);
let directory = outDir;
if (omitJobidDirectory == null || omitJobidDirectory === false) {
directory += imperative_1.IO.FILE_DELIM + jobFile.jobid;
}
if (jobFile.procstep != null) {
directory += imperative_1.IO.FILE_DELIM + jobFile.procstep;
}
if (jobFile.stepname != null) {
directory += imperative_1.IO.FILE_DELIM + jobFile.stepname;
}
return directory + imperative_1.IO.FILE_DELIM + jobFile.ddname + DownloadJobs.DEFAULT_JOBS_OUTPUT_FILE_EXT;
}
/**
* Getter for brightside logger
* @returns {Logger}
*/
static get log() {
return imperative_1.Logger.getAppLogger();
}
}
exports.DownloadJobs = DownloadJobs;
/**
* Default directory where output will be placed
* @static
* @type {string}
* @memberof DownloadJobs
*/
DownloadJobs.DEFAULT_JOBS_OUTPUT_DIR = "./output";
/**
* Default extension of downloaded folders
* @static
* @type {string}
* @memberof DownloadJobs
*/
DownloadJobs.DEFAULT_JOBS_OUTPUT_FILE_EXT = ".txt";
//# sourceMappingURL=DownloadJobs.js.map