@zowe/zos-jobs-for-zowe-sdk
Version:
Zowe SDK to interact with jobs on z/OS
108 lines • 5.25 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 });
exports.CancelJobs = 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 deletion of job information
* @export
* @class CancelJobs
*/
class CancelJobs {
/**
* Cancel and purge a job
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {string} jobname - job name to be translated into parms object
* @param {string} jobid - job id to be translated into parms object
* @returns {Promise<undefined|IJobFeedback>} - promise of undefined, or IJobFeedback object returned by API if modifyVersion is 2.0
* @memberof CancelJobs
*/
static cancelJob(session, jobname, jobid, version) {
return __awaiter(this, void 0, void 0, function* () {
this.log.trace("cancelJob called with jobname %s jobid %s", jobname, jobid);
return CancelJobs.cancelJobCommon(session, { jobname, jobid, version });
});
}
/**
* Cancel and purge a job
* Alternative version of the cancel API accepting an IJob object returned from other APIs such as GetJobs and SubmitJobs
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {IJob} job - the job that you want to cancel
* @param {string} version - version of cancel request
* @returns {Promise<undefined|IJobFeedback>} - promise of undefined, or IJobFeedback object returned by API if modifyVersion is 2.0
* @memberof CancelJobs
*/
static cancelJobForJob(session, job, version) {
return __awaiter(this, void 0, void 0, function* () {
this.log.trace("cancelJobForJob called with job %s", JSON.stringify(job));
return CancelJobs.cancelJobCommon(session, { jobname: job.jobname, jobid: job.jobid, version });
});
}
/**
* Cancel and purge a job
* Full version of the API with a parameter object
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {ICancelJobParms} parms - parm object (see ICancelJobParms interface for details)
* @returns {Promise<undefined|IJobFeedback>} - promise of undefined, or IJobFeedback object returned by API if modifyVersion is 2.0
* @memberof CancelJobs
*/
static cancelJobCommon(session, parms) {
return __awaiter(this, void 0, void 0, function* () {
this.log.trace("cancelJobCommon called with parms %s", JSON.stringify(parms));
imperative_1.ImperativeExpect.keysToBeDefinedAndNonBlank(parms, ["jobname", "jobid"], "You must specify jobname and jobid for the job you want to cancel.");
if (parms.version !== "1.0") {
parms.version = JobsConstants_1.JobsConstants.DEFAULT_CANCEL_VERSION;
}
this.log.info("Canceling job %s(%s). Job modify version?: %s", parms.jobname, parms.jobid, parms.version);
const headers = [imperative_1.Headers.APPLICATION_JSON];
// build request
const request = {
request: JobsConstants_1.JobsConstants.REQUEST_CANCEL,
version: parms.version
};
const responseJson = yield core_for_zowe_sdk_1.ZosmfRestClient.putExpectJSON(session, imperative_1.EncodeUri.encUriPathForZos(session, JobsConstants_1.JobsConstants.RESOURCE + "/" + parms.jobname + "/" + parms.jobid), headers, request);
if (parms.version === "2.0") {
//"2.0" indicates an synchronous request
const responseFeedback = responseJson;
// Turns out status is a number, but we cannot introduce breaking changes.
responseFeedback.status = responseFeedback.status.toString();
return responseFeedback;
}
else {
return undefined;
}
});
}
/**
* Getter for Zowe logger
* @returns {Logger}
*/
static get log() {
return imperative_1.Logger.getAppLogger();
}
}
exports.CancelJobs = CancelJobs;
//# sourceMappingURL=CancelJobs.js.map