@zowe/cli
Version:
Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.
123 lines • 6.54 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 util_1 = require("util");
const rest_1 = require("../../../rest");
const SendTso_1 = require("./SendTso");
const TsoValidator_1 = require("./TsoValidator");
const TsoConstants_1 = require("./TsoConstants");
const TsoResponseService_1 = require("./TsoResponseService");
/**
* Start TSO address space and receive servlet key
* @export
* @class StartTso
*/
class StartTso {
/**
* Start TSO address space with provided parameters
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {IStartTsoParms} commandParms - object with required parameters, @see {IStartTsoParms}
* @returns {Promise<IZosmfTsoResponse>} z/OSMF response object, @see {IZosmfTsoResponse}
* @memberOf StartTso
*/
static startCommon(session, commandParms) {
TsoValidator_1.TsoValidator.validateSession(session);
TsoValidator_1.TsoValidator.validateStartParams(commandParms);
const startResources = this.getResourcesQuery(commandParms);
return rest_1.ZosmfRestClient.postExpectJSON(session, startResources, [rest_1.ZosmfHeaders.X_CSRF_ZOSMF_HEADER, imperative_1.Headers.APPLICATION_JSON]);
}
/**
* Start TSO address space with provided parameters.
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {string} accountNumber - this key of IStartTsoParms required, because it cannot be default.
* @param {IStartTsoParms} parms - optional object with required parameters, @see {IStartTsoParms}
* @returns {Promise<IStartStopResponses>} command response on resolve, @see {IStartStopResponses}
* @memberOf StartTso
*/
static start(session, accountNumber, parms) {
return __awaiter(this, void 0, void 0, function* () {
TsoValidator_1.TsoValidator.validateSession(session);
TsoValidator_1.TsoValidator.validateNotEmptyString(accountNumber, TsoConstants_1.noAccountNumber.message);
let customParms;
if (util_1.isNullOrUndefined(parms)) {
customParms = this.setDefaultAddressSpaceParams({}, accountNumber);
}
else {
customParms = this.setDefaultAddressSpaceParams(parms, accountNumber);
}
const zosmfResponse = yield this.startCommon(session, customParms);
let collectedResponses = null;
if (!util_1.isNullOrUndefined(zosmfResponse.servletKey)) {
collectedResponses = yield SendTso_1.SendTso.getAllResponses(session, zosmfResponse);
}
return TsoResponseService_1.TsoResponseService.populateStartAndStopCollectAll(zosmfResponse, collectedResponses);
});
}
/**
* Sets required parameters by default if not provided. If some parameters provided
* it uses received and the rest required parameters will be default
* @static
* @param {IStartTsoParms} parms - object with required parameters, @see {IStartTsoParms}
* @param {string} accountNumber - this key of IStartTsoParms required, because it cannot be default.
* @returns {IStartTsoParms} object with provided parameters if not the with default
* @memberOf StartTso
*/
static setDefaultAddressSpaceParams(parms, accountNumber) {
const proc = util_1.isNullOrUndefined(parms.logonProcedure) ? TsoConstants_1.TsoConstants.DEFAULT_PROC : parms.logonProcedure;
const chset = util_1.isNullOrUndefined(parms.characterSet) ? TsoConstants_1.TsoConstants.DEFAULT_CHSET : parms.characterSet;
const cpage = util_1.isNullOrUndefined(parms.codePage) ? TsoConstants_1.TsoConstants.DEFAULT_CPAGE : parms.codePage;
const rowNum = util_1.isNullOrUndefined(parms.rows) ? TsoConstants_1.TsoConstants.DEFAULT_ROWS : parms.rows;
const cols = util_1.isNullOrUndefined(parms.columns) ? TsoConstants_1.TsoConstants.DEFAULT_COLS : parms.columns;
const rSize = util_1.isNullOrUndefined(parms.regionSize) ? TsoConstants_1.TsoConstants.DEFAULT_RSIZE : parms.regionSize;
const parameters = {
logonProcedure: proc,
characterSet: chset,
codePage: cpage,
rows: rowNum,
columns: cols,
regionSize: rSize,
account: accountNumber
};
return parameters;
}
/**
* Builds a resources query from passed parameters which is needed for z/OSMF api URI.
* @param {IStartTsoParms} parms - object with required parameters, @see {IStartTsoParms}
* @returns {string} URI for z/OSMF REST call
* @memberOf StartTso
*/
static getResourcesQuery(parms) {
let query = `${TsoConstants_1.TsoConstants.RESOURCE + "/" + TsoConstants_1.TsoConstants.RES_START_TSO}?`;
query += `${TsoConstants_1.TsoConstants.PARM_ACCT}=${parms.account}&`;
query += `${TsoConstants_1.TsoConstants.PARM_PROC}=${parms.logonProcedure}&`;
query += `${TsoConstants_1.TsoConstants.PARM_CHSET}=${parms.characterSet}&`;
query += `${TsoConstants_1.TsoConstants.PARM_CPAGE}=${parms.codePage}&`;
query += `${TsoConstants_1.TsoConstants.PARM_ROWS}=${parms.rows}&`;
query += `${TsoConstants_1.TsoConstants.PARM_COLS}=${parms.columns}&`;
query += `${TsoConstants_1.TsoConstants.PARM_RSIZE}=${parms.regionSize}`;
return query;
}
}
exports.StartTso = StartTso;
//# sourceMappingURL=StartTso.js.map