UNPKG

@zowe/zos-tso-for-zowe-sdk

Version:
146 lines 7.9 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.IssueTso = void 0; const imperative_1 = require("@zowe/imperative"); const TsoConstants_1 = require("./TsoConstants"); const SendTso_1 = require("./SendTso"); const StartTso_1 = require("./StartTso"); const StopTso_1 = require("./StopTso"); const TsoValidator_1 = require("./TsoValidator"); const zosmf_for_zowe_sdk_1 = require("@zowe/zosmf-for-zowe-sdk"); const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk"); /** * Class to handle issue command to TSO * @class IssueTso */ class IssueTso { static issueTsoCmd(session, command, opts) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; let version; opts = opts || {}; opts.suppressStartupMessages = (_a = opts.suppressStartupMessages) !== null && _a !== void 0 ? _a : true; const versionCheck = yield zosmf_for_zowe_sdk_1.CheckStatus.isZosVersionAtLeast(session, zosmf_for_zowe_sdk_1.ZosmfConstants.VERSIONS.V2R4); // if useLegacyApi is true, it takes precedence over any of the inferences we // try to make based on the other options. const useNewApi = !opts.useLegacyApi && (opts.addressSpaceOptions == null || versionCheck && opts.suppressStartupMessages); if (useNewApi) { version = "v1"; try { const endpoint = `${TsoConstants_1.TsoConstants.RESOURCE}/${version}/${TsoConstants_1.TsoConstants.RES_START_TSO}`; const apiResponse = yield core_for_zowe_sdk_1.ZosmfRestClient.putExpectJSON(session, endpoint, [imperative_1.Headers.APPLICATION_JSON], { tsoCmd: command, cmdState: opts.isStateful ? "stateful" : "stateless", }); if (!apiResponse.cmdResponse || apiResponse.cmdResponse.length == 0) { throw new imperative_1.ImperativeError({ msg: "Did not receive output from the z/OSMF TSO API.", }); } const response = { success: true, startReady: apiResponse.cmdResponse[apiResponse.cmdResponse.length - 1].message.trim() === "READY", zosmfResponse: [apiResponse], commandResponse: apiResponse.cmdResponse .map((item) => item.message) .join("\n"), }; return response; } catch (e) { if (e.message == null || !e.message.includes("status 404")) { throw e; } } } // Deprecated API Behavior [former issueTsoCommand() behavior] TsoValidator_1.TsoValidator.validateSession(session); TsoValidator_1.TsoValidator.validateNotEmptyString((_b = opts.addressSpaceOptions) === null || _b === void 0 ? void 0 : _b.account, TsoConstants_1.noAccountNumber.message); TsoValidator_1.TsoValidator.validateNotEmptyString(command, TsoConstants_1.noCommandInput.message); const response = { success: false, startResponse: yield StartTso_1.StartTso.start(session, (_c = opts.addressSpaceOptions) === null || _c === void 0 ? void 0 : _c.account, opts.addressSpaceOptions || {}), startReady: false, zosmfResponse: null, commandResponse: null, stopResponse: null, }; if (!response.startResponse.success) { throw new imperative_1.ImperativeError({ msg: `TSO address space failed to start.`, additionalDetails: (_d = response.startResponse.failureResponse) === null || _d === void 0 ? void 0 : _d.message, }); } if ((_e = response.startResponse.messages) === null || _e === void 0 ? void 0 : _e.includes("IKJ56482I")) { throw new imperative_1.ImperativeError({ msg: `Invalid logon procedure.`, additionalDetails: response.startResponse.messages, }); } const sendResponse = yield SendTso_1.SendTso.sendDataToTSOCollect(session, response.startResponse.servletKey, command); response.success = sendResponse.success; response.zosmfResponse = sendResponse.zosmfResponse; response.commandResponse = sendResponse.commandResponse; response.stopResponse = yield StopTso_1.StopTso.stop(session, response.startResponse.servletKey); return response; }); } /** * @deprecated Use issueTsoCmd instead * API method to start a TSO address space, issue a command, collect responses until prompt is reached, and terminate the address space. * @param {AbstractSession} session - z/OSMF connection info * @param {string} accountNumber - accounting info for Jobs * @param {string} command - command text to issue to the TSO address space. * @param {IStartTsoParms} startParams - optional object with required parameters for starting TSO address space, @see {IStartTsoParms} * @returns {Promise<IIssueResponse>} IssueTso response object, @see {IIssueResponse} * @memberof IssueTso */ static issueTsoCommand(session, accountNumber, command, startParams) { return __awaiter(this, void 0, void 0, function* () { return yield IssueTso.issueTsoCmd(session, command, { suppressStartupMessages: false, addressSpaceOptions: Object.assign(Object.assign({}, startParams), { account: accountNumber }), }); }); } /** * @deprecated use issueTsoCmd instead * API method to start a TSO address space with provided parameters, issue a command, * collect responses until prompt is reached, and terminate the address space. * @param {AbstractSession} session - z/OSMF connection info * @param {IIssueTsoParms} commandParms - object with required parameters, @see {IIssueTsoParms} * @returns {Promise<IIssueResponse>} */ static issueTsoCommandCommon(session, commandParms) { return __awaiter(this, void 0, void 0, function* () { return yield IssueTso.issueTsoCmd(session, commandParms.command, { suppressStartupMessages: false, addressSpaceOptions: Object.assign(Object.assign({}, commandParms.startParams), { account: commandParms.accountNumber }), }); }); } } exports.IssueTso = IssueTso; //# sourceMappingURL=IssueTso.js.map