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.

371 lines 19.7 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 JobsConstants_1 = require("./JobsConstants"); const rest_1 = require("../../../rest"); /** * Class to handle obtaining of z/OS batch job information * @export * @class GetJobs */ class GetJobs { /** * Get jobs (defaults to the user ID of the session as owner) * @static * @param {AbstractSession} session - z/OSMF connection info * @returns {Promise<IJob[]>} - promise that resolves to an array of IJob objects (matching jobs) * @memberof GetJobs */ static getJobs(session) { imperative_1.Logger.getAppLogger().trace("GetJobs.getJobs()"); return GetJobs.getJobsCommon(session); } /** * Get jobs that match a job name preixl * Defaults to jobs owned by the user ID in the session. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} prefix - job name prefix for which to list jobs. Supports wildcard e.g. JOBNM* * returns jobs with names starting with "JOBNM" * @returns {Promise<IJob[]>} - promise that resolves to an array of IJob objects (matching jobs) * @memberof GetJobs */ static getJobsByPrefix(session, prefix) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJobsByPrefix()"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(prefix, "prefix"); return GetJobs.getJobsCommon(session, { prefix }); }); } /** * Get jobs that are owned by a certain user or pattern of users * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} owner - owner for which to get jobs. Supports wildcard e.g. IBMU* returns jobs owned by * all users whose ID beings with "IBMU" * @returns {Promise<IJob[]>} - promise that resolves to an array of IJob objects (matching jobs) * @memberof GetJobs */ static getJobsByOwner(session, owner) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJobsByOwner()"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(owner, "owner"); return GetJobs.getJobsCommon(session, { owner }); }); } /** * Get a list of jobs that match an owner and prefix * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} owner - owner for which to get jobs. Supports wildcard e.g. IBMU* returns jobs owned by * all users whose ID beings with "IBMU" * @param {string} prefix - prefix for which to get jobs. Supports wildcard e.g. JOBNM* * returns jobs with names starting with "JOBNM" * @returns {Promise<IJob[]>} - promise that resolves to an array of IJob objects (matching jobs) * @memberof GetJobs */ static getJobsByOwnerAndPrefix(session, owner, prefix) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJobsByOwnerAndPrefix()"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(owner, "owner"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(prefix, "prefix"); return GetJobs.getJobsCommon(session, { owner, prefix }); }); } /** * Get a single job object from an input job id * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} jobid - the job ID for the job for which you want to get status * @returns {Promise<IJob>} - promise that resolves to an IJob object from an input jobid * @memberof GetJobs */ static getJob(session, jobid) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJob()"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(jobid, "jobid"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(session, "Required session must be defined"); const jobs = yield GetJobs.getJobsCommon(session, { jobid, owner: "*" }); const errorMessagePrefix = "Obtaining job info for a single job id " + jobid + " on " + session.ISession.hostname + ":" + session.ISession.port + " failed: "; // fail if no jobs if (jobs.length === 0) { throw new imperative_1.ImperativeError({ msg: errorMessagePrefix + "Job not found" }); } // fail if unexpected number of jobs (job id should be unique) if (jobs.length > 1) { throw new imperative_1.ImperativeError({ msg: errorMessagePrefix + "Expected 1 job returned but received " + jobs.length }); } // return the single job return jobs[0]; }); } /** * Get jobs filtered by owner and prefix. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {IGetJobsParms} parms - parm object (see IGetJobsParms interface for details) * @returns {Promise<IJob[]>} - promise that resolves to an array of IJob objects (matching jobs) * @memberof GetJobs */ static getJobsCommon(session, parms) { return __awaiter(this, void 0, void 0, function* () { // TODO(Kelosky): after **REMOVED** is fixed we can remove this message imperative_1.Logger.getAppLogger().trace("GetJobs.getJobsCommon()"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(session, "Required session must be defined"); let query = JobsConstants_1.JobsConstants.QUERY_ID; if (parms) { if (parms.owner) { if (parms.owner !== session.ISession.user) { query += (JobsConstants_1.JobsConstants.QUERY_OWNER + parms.owner); } } if (parms.prefix) { if (parms.prefix !== JobsConstants_1.JobsConstants.DEFAULT_PREFIX) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += JobsConstants_1.JobsConstants.QUERY_PREFIX + parms.prefix; } } if (parms.maxJobs) { if (parms.maxJobs !== JobsConstants_1.JobsConstants.DEFAULT_MAX_JOBS) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += (JobsConstants_1.JobsConstants.QUERY_MAX_JOBS + parms.maxJobs); } } if (parms.jobid) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += (JobsConstants_1.JobsConstants.QUERY_JOBID + parms.jobid); } } let resource = JobsConstants_1.JobsConstants.RESOURCE; resource += (query === JobsConstants_1.JobsConstants.QUERY_ID) ? "" : query; imperative_1.Logger.getAppLogger().info("GetJobs.getJobsCommon() resource: " + resource); return rest_1.ZosmfRestClient.getExpectJSON(session, resource); }); } /** * Get the status and other details (e.g. owner, return code) for a job * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} jobname - the job name for the job for which you want to get status * @param {string} jobid - the job ID for the job for which you want to get status * @returns {Promise<IJob>} - promise that resolves to an IJob object representing the job * @memberof GetJobs */ static getStatus(session, jobname, jobid) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getStatus()"); return GetJobs.getStatusCommon(session, { jobname, jobid }); }); } /** * Get the status and other details (e.g. owner, return code) for a job * Alternate version of the API that accepts an IJob object returned by * other APIs such as SubmitJobs. Even though the parameter and return * value are of the same type, the IJob object returned will have the * current status of the job. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {IJob} job - job object * @returns {Promise<IJob>} - promise that resolves to an IJob object representing the job * @memberof GetJobs */ static getStatusForJob(session, job) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getStatusForJob()"); return GetJobs.getStatusCommon(session, { jobname: job.jobname, jobid: job.jobid }); }); } /** * Get the status and other details (e.g. owner, return code) for a job * @static * @param {AbstractSession} session - z/OSMF connection info * @param {ICommonJobParms} parms - parm object (see ICommonJobParms interface for details) * @returns {Promise<IJob>} - promise that resolves to an IJob object representing the job * @memberof GetJobs */ static getStatusCommon(session, parms) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getStatusCommon()"); imperative_1.ImperativeExpect.keysToBeDefinedAndNonBlank(parms, ["jobname", "jobid"]); const parameters = "/" + parms.jobname + "/" + parms.jobid; // + Jobs.QUERY_ID + Jobs.STEP_DATA; imperative_1.Logger.getAppLogger().info("GetJobs.getStatusCommon() parameters: " + parameters); return rest_1.ZosmfRestClient.getExpectJSON(session, JobsConstants_1.JobsConstants.RESOURCE + parameters); }); } /** * Get a list of all spool files for a job. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} jobname - the job name for the job for which you want to get a list of spool files * @param {string} jobid - the job ID for the job for which you want to get a list of spool files * @returns {Promise<IJobFile[]>} - promise that resolves to an array of IJobFile objects * @memberof GetJobs */ static getSpoolFiles(session, jobname, jobid) { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolFiles()"); return GetJobs.getSpoolFilesCommon(session, { jobname, jobid }); } /** * Get a list of all job spool files for a job * Alternate version of the API that accepts an IJob object returned by * other APIs such as SubmitJobs. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {IJob} job - the job for which you would like to get a list of job spool files * @returns {Promise<IJobFile[]>} - promise that resolves to an array of IJobFile objects * @memberof GetJobs */ static getSpoolFilesForJob(session, job) { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolFilesForJob()"); return GetJobs.getSpoolFilesCommon(session, { jobname: job.jobname, jobid: job.jobid }); } /** * Get a list of all job spool files for a job. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {ICommonJobParms} parms - parm object (see for details) * @returns {Promise<IJobFile[]>} - promise that resolves to an array of IJobFile objectsl * @memberof GetJobs */ static getSpoolFilesCommon(session, parms) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolFilesCommon()"); imperative_1.ImperativeExpect.keysToBeDefinedAndNonBlank(parms, ["jobname", "jobid"]); const parameters = "/" + parms.jobname + "/" + parms.jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES; imperative_1.Logger.getAppLogger().info("GetJobs.getSpoolFilesCommon() parameters: " + parameters); return rest_1.ZosmfRestClient.getExpectJSON(session, JobsConstants_1.JobsConstants.RESOURCE + parameters); }); } /** * Get JCL from a job. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} jobname - the job name for the job for which you want to retrieve JCL * @param {string} jobid - the job ID for the job for which you want to retrieve JCL * @returns {Promise<IJob>} - job document on resolve * @memberof GetJobs */ static getJcl(session, jobname, jobid) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJcl()"); return GetJobs.getJclCommon(session, { jobname, jobid }); }); } /** * Get JCL from a job. * Alternate version of the API that accepts an IJob object returned by * other APIs such as SubmitJobs. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {IJob} job - the job for which you would like to retrieve JCL * @returns {Promise<string>} - promise that resolves to JCL content * @memberof GetJobs */ static getJclForJob(session, job) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJclForJob()"); return GetJobs.getJclCommon(session, { jobname: job.jobname, jobid: job.jobid }); }); } /** * Get the JCL that was used to submit a job. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {ICommonJobParms} parms - parm object (see ICommonJobParms interface for details) * @returns {Promise<string>} - promise that resolves to the JCL content * @memberof GetJobs */ static getJclCommon(session, parms) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJclCommon()"); imperative_1.ImperativeExpect.keysToBeDefinedAndNonBlank(parms, ["jobname", "jobid"]); const parameters = "/" + parms.jobname + "/" + parms.jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + JobsConstants_1.JobsConstants.RESOURCE_JCL_CONTENT + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT; imperative_1.Logger.getAppLogger().info("GetJobs.getJclCommon() parameters: " + parameters); return rest_1.ZosmfRestClient.getExpectString(session, JobsConstants_1.JobsConstants.RESOURCE + parameters); }); } /** * Get spool content from a job (keeping naming convention patter with this duplication function). * @static * @param {AbstractSession} session - z/OSMF connection info * @param jobFile - the spool file for which you want to retrieve the content * @returns {Promise<string>} - promise that resolves to the spool content * @memberof GetJobs */ static getSpoolContent(session, jobFile) { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolContent()"); return GetJobs.getSpoolContentCommon(session, jobFile); } /** * Get spool content from a job using the job name, job ID, and spool ID number from z/OSMF * @static * @param {AbstractSession} session - z/OSMF connection info * @param jobname - the job name for the job containing the spool content * @param jobid - the job id for the job containing the spool content * @param spoolId - id number assigned by zosmf that identifies the particular job spool file (DD) * @returns {Promise<string>} - promise that resolves to the spool content * @memberof GetJobs */ static getSpoolContentById(session, jobname, jobid, spoolId) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolContentById()"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(jobname, "Required parameter jobname must be defined"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(jobid, "Required parameter jobid must be defined"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(spoolId, "Required parameter spoolId must be defined"); const parameters = "/" + jobname + "/" + jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + "/" + spoolId + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT; imperative_1.Logger.getAppLogger().info("GetJobs.getSpoolContentById() parameters: " + parameters); return rest_1.ZosmfRestClient.getExpectString(session, JobsConstants_1.JobsConstants.RESOURCE + parameters, [imperative_1.Headers.TEXT_PLAIN_UTF8]); }); } /** * Get spool content from a job. * @static * @param {AbstractSession} session - z/OSMF connection info * @param jobFile - the spool file for which you want to retrieve the content * @returns {Promise<string>} - promise that resolves to the spool content * @memberof GetJobs */ static getSpoolContentCommon(session, jobFile) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolContentCommon()"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(jobFile, "Required job file object must be defined"); const parameters = "/" + jobFile.jobname + "/" + jobFile.jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + "/" + jobFile.id + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT; imperative_1.Logger.getAppLogger().info("GetJobs.getSpoolContentCommon() parameters: " + parameters); return rest_1.ZosmfRestClient.getExpectString(session, JobsConstants_1.JobsConstants.RESOURCE + parameters, [imperative_1.Headers.TEXT_PLAIN_UTF8]); }); } } exports.GetJobs = GetJobs; //# sourceMappingURL=GetJobs.js.map