UNPKG

@zowe/zos-jobs-for-zowe-sdk

Version:
434 lines 23.1 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 }); exports.GetJobs = void 0; const imperative_1 = require("@zowe/imperative"); const JobsConstants_1 = require("./JobsConstants"); const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk"); /** * 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 list of jobs that match various parameters * @static * @param {AbstractSession} session - z/OSMF connection info * @param {string} * @returns {Promise<IJob[]>} - promise that resolves to an array of IJob objects (matching jobs) * @memberof GetJobs */ static getJobsByParameters(session, params) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("GetJobs.getJobsByParameters()"); return GetJobs.getJobsCommon(session, Object.assign({}, params)); }); } /** * 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 userMsg = "Cannot obtain job info for job id = " + jobid; const diagInfo = "Protocol: " + session.ISession.protocol + "\nHost: " + session.ISession.hostname + "\nPort: " + session.ISession.port + "\nBase Path: " + session.ISession.basePath + "\nAuth type: " + session.ISession.type + "\nAllow Unauth Cert: " + !session.ISession.rejectUnauthorized; // fail if no jobs if (jobs.length === 0) { throw new imperative_1.ImperativeError({ msg: userMsg, causeErrors: "Zero jobs were returned.", additionalDetails: diagInfo }); } // fail if unexpected number of jobs (job id should be unique) if (jobs.length > 1) { throw new imperative_1.ImperativeError({ msg: userMsg, causeErrors: jobs.length + " jobs were returned. Only expected 1.", additionalDetails: diagInfo }); } // return the single job return jobs[0]; }); } /** * Get jobs filtered by owner and prefix. * @static * @param {AbstractSession} session - z/OSMF connection info * @param {IGetJobsParms} params - 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, params) { 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 (params) { if (params.owner) { query += JobsConstants_1.JobsConstants.QUERY_OWNER + encodeURIComponent(params.owner); } if (params.prefix) { if (params.prefix !== JobsConstants_1.JobsConstants.DEFAULT_PREFIX) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += JobsConstants_1.JobsConstants.QUERY_PREFIX + encodeURIComponent(params.prefix); } } if (params.maxJobs) { if (params.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 + encodeURIComponent(params.maxJobs); } } if (params.jobid) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += JobsConstants_1.JobsConstants.QUERY_JOBID + encodeURIComponent(params.jobid); } if (params.execData) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += JobsConstants_1.JobsConstants.EXEC_DATA; } if (params.status) { if (imperative_1.RestClient.hasQueryString(query)) { query += JobsConstants_1.JobsConstants.COMBO_ID; } query += JobsConstants_1.JobsConstants.QUERY_STATUS + encodeURIComponent(params.status); } } let resource = JobsConstants_1.JobsConstants.RESOURCE; resource += query === JobsConstants_1.JobsConstants.QUERY_ID ? "" : query; imperative_1.Logger.getAppLogger().info("GetJobs.getJobsCommon() resource: " + resource); const jobs = yield core_for_zowe_sdk_1.ZosmfRestClient.getExpectJSON(session, resource); return GetJobs.filterResultsByStatuses(jobs, params); }); } /** * 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 = imperative_1.EncodeUri.encUriPathForZos(session, JobsConstants_1.JobsConstants.RESOURCE + "/" + parms.jobname + "/" + parms.jobid // + Jobs.QUERY_ID + Jobs.STEP_DATA; ); imperative_1.Logger.getAppLogger().info("GetJobs.getStatusCommon() parameters: " + parameters); return core_for_zowe_sdk_1.ZosmfRestClient.getExpectJSON(session, 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 = imperative_1.EncodeUri.encUriPathForZos(session, JobsConstants_1.JobsConstants.RESOURCE + "/" + parms.jobname + "/" + parms.jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES); imperative_1.Logger.getAppLogger().info("GetJobs.getSpoolFilesCommon() parameters: " + parameters); return core_for_zowe_sdk_1.ZosmfRestClient.getExpectJSON(session, 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 {IGetJclParms} parms - parm object (see IGetJclParms 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"]); let parameters = imperative_1.EncodeUri.encUriPathForZos(session, JobsConstants_1.JobsConstants.RESOURCE + "/" + parms.jobname + "/" + parms.jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + JobsConstants_1.JobsConstants.RESOURCE_JCL_CONTENT + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT); if (parms.binary) { parameters += "?mode=binary"; } else if (parms.record) { parameters += "?mode=record"; } else if (parms.encoding != null && String(parms.encoding).trim()) { parameters += "?fileEncoding=" + parms.encoding; } const headers = [imperative_1.Headers.TEXT_PLAIN_UTF8]; imperative_1.Logger.getAppLogger().info("GetJobs.getJclCommon() parameters: " + parameters); return core_for_zowe_sdk_1.ZosmfRestClient.getExpectString(session, parameters, headers); }); } /** * 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 * @param encoding - the code page to use for EBCDIC translation * @returns {Promise<string>} - promise that resolves to the spool content * @memberof GetJobs */ static getSpoolContent(session, jobFile, encoding) { imperative_1.Logger.getAppLogger().trace("GetJobs.getSpoolContent()"); return GetJobs.getSpoolContentCommon(session, jobFile, encoding); } /** * 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, encoding) { 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"); let parameters = imperative_1.EncodeUri.encUriPathForZos(session, JobsConstants_1.JobsConstants.RESOURCE + "/" + jobname + "/" + jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + "/" + spoolId + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT); if (encoding != null && String(encoding).trim() !== "") { parameters += "?fileEncoding=" + encoding; } imperative_1.Logger.getAppLogger().info("GetJobs.getSpoolContentById() parameters: " + parameters); return core_for_zowe_sdk_1.ZosmfRestClient.getExpectString(session, 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 * @param encoding - the code page to use for EBCDIC translation * @returns {Promise<string>} - promise that resolves to the spool content * @memberof GetJobs */ static getSpoolContentCommon(session, jobFile, encoding) { 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"); let parameters = imperative_1.EncodeUri.encUriPathForZos(session, JobsConstants_1.JobsConstants.RESOURCE + "/" + jobFile.jobname + "/" + jobFile.jobid + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_FILES + "/" + jobFile.id + JobsConstants_1.JobsConstants.RESOURCE_SPOOL_CONTENT); if (encoding && encoding.trim() != "") { parameters += "?fileEncoding=" + encoding; } imperative_1.Logger.getAppLogger().info("GetJobs.getSpoolContentCommon() parameters: " + parameters); return core_for_zowe_sdk_1.ZosmfRestClient.getExpectString(session, parameters, [imperative_1.Headers.TEXT_PLAIN_UTF8]); }); } static filterResultsByStatuses(jobs, params) { if ((params === null || params === void 0 ? void 0 : params.status) && params.status.toLowerCase() != "active" && params.status != "*") { const newJobs = jobs.filter(job => job.status.toLowerCase() === params.status.toLowerCase()); return newJobs; } return jobs; } } exports.GetJobs = GetJobs; //# sourceMappingURL=GetJobs.js.map