@zowe/zos-files-for-zowe-sdk
Version:
Zowe SDK to interact with files and data sets on z/OS
612 lines • 35.2 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.Create = void 0;
const imperative_1 = require("@zowe/imperative");
const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk");
const ZosFiles_constants_1 = require("../../constants/ZosFiles.constants");
const ZosFiles_messages_1 = require("../../constants/ZosFiles.messages");
const Create_defaults_1 = require("./Create.defaults");
const invoke_1 = require("../invoke");
const list_1 = require("../list");
// Do not use import in anticipation of some internationalization work to be done later.
// const strings = (require("../../../../../packages/cli/zosfiles/src/-strings-/en").default as typeof i18nTypings);
/**
* Class to handle creation of data sets
*/
class Create {
/**
* Create a data set
* @param {AbstractSession} session - z/OSMF connection info
* @param {CreateDataSetTypeEnum} dataSetType - the type of data set we are going to create
* @param {string} dataSetName - the name of the data set to create
* @param {Partial<ICreateDataSetOptions>} [options={}] - overrides the default options provided by dataSetType
* @returns {Promise<IZosFilesResponse>}
*/
static dataSet(session, dataSetType, dataSetName, options) {
return __awaiter(this, void 0, void 0, function* () {
let validCmdType = true;
// Removes undefined properties
let tempOptions = !(options === null || options === undefined) ? JSON.parse(JSON.stringify(options)) : {};
// Required
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetType, ZosFiles_messages_1.ZosFilesMessages.missingDatasetType.message);
// Required
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message);
switch (dataSetType) {
case 3 /* CreateDataSetTypeEnum.DATA_SET_PARTITIONED */:
tempOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.DATA_SET.PARTITIONED), tempOptions);
break;
case 4 /* CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL */:
tempOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.DATA_SET.SEQUENTIAL), tempOptions);
break;
case 0 /* CreateDataSetTypeEnum.DATA_SET_BINARY */:
tempOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.DATA_SET.BINARY), tempOptions);
break;
case 1 /* CreateDataSetTypeEnum.DATA_SET_C */:
tempOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.DATA_SET.C), tempOptions);
break;
case 2 /* CreateDataSetTypeEnum.DATA_SET_CLASSIC */:
tempOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.DATA_SET.CLASSIC), tempOptions);
break;
case 5 /* CreateDataSetTypeEnum.DATA_SET_BLANK */:
tempOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.DATA_SET.BLANK), tempOptions);
break;
default:
validCmdType = false;
break;
}
if (!validCmdType) {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.unsupportedDatasetType.message });
}
else {
// Handle the size option
if (!(tempOptions.size === null || tempOptions.size === undefined)) {
const tAlcunit = tempOptions.size.toString().match(/[a-zA-Z]+/g);
if (!(tAlcunit === null || tAlcunit === undefined)) {
tempOptions.alcunit = tAlcunit.join("").toUpperCase();
}
const tPrimary = tempOptions.size.toString().match(/[0-9]+/g);
if (!(tPrimary === null || tPrimary === undefined)) {
tempOptions.primary = +tPrimary.join("");
if (tempOptions.secondary === null || tempOptions.secondary === undefined) {
const TEN_PERCENT = 0.10;
tempOptions.secondary = Math.round(tempOptions.primary * TEN_PERCENT);
}
}
}
else {
if (tempOptions.secondary === null || tempOptions.secondary === undefined) {
if (dataSetType === 5 /* CreateDataSetTypeEnum.DATA_SET_BLANK */) {
// do nothing
}
else if (dataSetType !== 0 /* CreateDataSetTypeEnum.DATA_SET_BINARY */) {
tempOptions.secondary = 1;
}
else {
tempOptions.secondary = 10;
}
}
}
delete tempOptions.size;
let response = "";
// Handle the print attributes option
if (!(tempOptions.showAttributes === null || tempOptions.showAttributes === undefined)) {
if (tempOptions.showAttributes) {
delete tempOptions.showAttributes;
response = imperative_1.TextUtils.prettyJson(tempOptions);
}
else {
delete tempOptions.showAttributes;
}
}
const endpoint = imperative_1.EncodeUri.encUriPathForZos(session, ZosFiles_constants_1.ZosFilesConstants.RESOURCE + ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES + "/" + dataSetName);
const headers = [core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING];
if (options && options.responseTimeout != null) {
headers.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() });
}
Create.dataSetValidateOptions(tempOptions);
yield core_for_zowe_sdk_1.ZosmfRestClient.postExpectString(session, endpoint, headers, JSON.stringify(tempOptions));
return {
success: true,
commandResponse: response + ZosFiles_messages_1.ZosFilesMessages.dataSetCreatedSuccessfully.message
};
}
});
}
static dataSetLike(session, dataSetName, likeDataSetName, options) {
return __awaiter(this, void 0, void 0, function* () {
// Required
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message);
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(likeDataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetLikeName.message);
const endpoint = imperative_1.EncodeUri.encUriPathForZos(session, ZosFiles_constants_1.ZosFilesConstants.RESOURCE + ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES + "/" + dataSetName);
const headers = [core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING];
if (options && options.responseTimeout != null) {
headers.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() });
}
const tempOptions = JSON.parse(JSON.stringify(Object.assign({ like: likeDataSetName }, options || {})));
Create.dataSetValidateOptions(tempOptions);
/*
* This is a fix for issue https://github.com/zowe/vscode-extension-for-zowe/issues/2610.
*
* If no block size is passed, then retrieve the attributes of the "Like" dataset and
* set the block size, as the zosmf Rest API does not set the block size properly in
* some instances.
*
*/
if (tempOptions.blksize === null || tempOptions.blksize === undefined) {
let likeDataSetObj;
const likeDataSetList = yield list_1.List.dataSet(session, likeDataSetName, {
attributes: true, maxLength: 1,
start: likeDataSetName,
recall: "wait"
});
const dsnameIndex = likeDataSetList.apiResponse.returnedRows === 0 ? -1 :
likeDataSetList.apiResponse.items.findIndex((ds) => ds.dsname.toUpperCase() === likeDataSetName.toUpperCase());
if (dsnameIndex !== -1) {
likeDataSetObj = likeDataSetList.apiResponse.items[dsnameIndex];
tempOptions.blksize = parseInt(likeDataSetObj.blksz);
}
else {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.datasetAllocateLikeNotFound.message });
}
}
yield core_for_zowe_sdk_1.ZosmfRestClient.postExpectString(session, endpoint, headers, JSON.stringify(tempOptions));
return {
success: true,
commandResponse: ZosFiles_messages_1.ZosFilesMessages.dataSetCreatedSuccessfully.message
};
});
}
/**
* Validate supplied parameters
* @static
* @param options - additional options for the creation of the data set
*/
static dataSetValidateOptions(options) {
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options, ZosFiles_messages_1.ZosFilesMessages.missingFilesCreateOptions.message);
const tempOptions = options;
for (const option in tempOptions) {
if (Object.prototype.hasOwnProperty.call(tempOptions, option)) {
switch (option) {
case "alcunit":
// zOSMF defaults to TRK if missing so mimic it's behavior
if (tempOptions.alcunit === null || tempOptions.alcunit === undefined) {
tempOptions.alcunit = "TRK";
}
// Only CYL and TRK valid
switch (tempOptions.alcunit.toUpperCase()) {
case "CYL":
case "TRK":
break;
default:
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidAlcunitOption.message + tempOptions.alcunit });
}
break;
case "avgblk":
// no validation at this time
break;
case "blksize":
/*
* This is a fix for issue https://github.com/zowe/zowe-cli/issues/1439.
*
*/
if (tempOptions.blksize === null || tempOptions.blksize === undefined) {
tempOptions.blksize = tempOptions.lrecl;
}
if (tempOptions.blksize <= tempOptions.lrecl) {
tempOptions.blksize = tempOptions.lrecl;
if (tempOptions.recfm && tempOptions.recfm.toUpperCase().startsWith("V")) {
tempOptions.blksize += 4;
}
}
break;
case "lrecl":
// Required
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(tempOptions.lrecl, ZosFiles_messages_1.ZosFilesMessages.missingRecordLength.message);
break;
case "dirblk":
// Validate non-zero if dsorg starts with "PS"
if (tempOptions.dirblk !== 0 && tempOptions.dsorg.startsWith("PS")) {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidPSDsorgDirblkCombination.message });
}
// Validate non-zero if dsorg starts with "PO"
if (tempOptions.dirblk === 0 && tempOptions.dsorg.startsWith("PO")) {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidPODsorgDirblkCombination.message });
}
break;
case "dsntype": {
// Key to create a PDSE.
const type = tempOptions.dsntype.toUpperCase();
const availableTypes = ["BASIC", "EXTPREF", "EXTREQ", "HFS", "LARGE", "PDS", "LIBRARY", "PIPE"];
if (availableTypes.indexOf(type) === -1) {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidDsntypeOption.message + tempOptions.dsntype });
}
break;
}
case "dsorg":
// Check if dsorg is PS-L, if it is change it to "PS" and the dsntype to "LARGE".
// Since the create endpoint does not see "PS-L" as a valid creation option
if (tempOptions.dsorg === "PS-L") {
tempOptions.dsorg = "PS";
tempOptions.dsntype = "LARGE";
}
break;
case "primary":
// Required
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(tempOptions.primary, ZosFiles_messages_1.ZosFilesMessages.missingPrimary.message);
// Validate maximum allocation quantity
if (tempOptions.primary > ZosFiles_constants_1.ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.maximumAllocationQuantityExceeded.message + " for 'primary'." });
}
break;
case "secondary":
// zOSMF defaults to 0 if missing so mimic it's behavior
if (tempOptions.secondary === null || tempOptions.secondary === undefined) {
tempOptions.secondary = 0;
}
// Validate maximum allocation quantity
if (tempOptions.secondary > ZosFiles_constants_1.ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.maximumAllocationQuantityExceeded.message + " for 'secondary'." });
}
break;
case "recfm":
// no validation
break;
// SMS class values
case "mgntclass":
case "storclass":
case "dataclass":
// no validation
break;
case "unit":
case "volser":
case "responseTimeout":
case "like":
// no validation
break;
default:
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidFilesCreateOption.message + option });
}
}
}
}
// ____________________________________________________________________________
/**
* Create a VSAM cluster
* @param {AbstractSession} session - An established z/OSMF session
* @param {string} dataSetName - the name of the dataset for the created cluster
* @param {Partial<ICreateVsamOptions>} options - options for the creation of the cluster
* @example
* ```typescript
*
* sessCfg: ISession = yourFunctionToCreateSessCfgFromArgs(commandParameters.arguments);
* sessCfgWithCreds = await ConnectionPropsForSessCfg.addPropsOrPrompt<ISession>(
* sessCfg, commandParameters.arguments
* );
* session = new Session(sessCfgWithCreds);
*
* // The option keys are defined in ZosFilesCreateOptions,
* // ZosFilesCreateExtraOptions and VsamCreateOptions.
* //
* const createVsamOptions: Partial<ICreateVsamOptions> = {
* dsorg: "INDEXED",
* size: "640KB",
* secondary: 64
* showAttributes: true
* }));
*
* try {
* createResponse = await Create.vsam(
* session, "SOME.DATASET.NAME", createVsamOptions
* );
* }
* catch (impErr) {
* // handle any error
* }
*
* // use the results in createResponse.commandResponse
* ```
* @returns {Promise<IZosFilesResponse>}
*/
static vsam(session, dataSetName, options) {
return __awaiter(this, void 0, void 0, function* () {
// We require the dataset name
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message);
const idcamsOptions = this.vsamConvertToIdcamsOptions(options);
// format the attributes to show, and remove the option
let attribText = "";
if (!(idcamsOptions.showAttributes === null || idcamsOptions.showAttributes === undefined)) {
if (idcamsOptions.showAttributes) {
delete idcamsOptions.showAttributes;
attribText = ZosFiles_messages_1.ZosFilesMessages.attributeTitle.message + imperative_1.TextUtils.prettyJson(idcamsOptions);
}
else {
delete idcamsOptions.showAttributes;
}
}
let respTimeout;
if (options) {
respTimeout = options.responseTimeout;
}
try {
this.vsamValidateOptions(idcamsOptions);
// We invoke IDCAMS to create the VSAM cluster
const idcamsCmds = this.vsamFormIdcamsCreateCmd(dataSetName, idcamsOptions);
imperative_1.Logger.getAppLogger().debug("Invoking this IDCAMS command:\n" + idcamsCmds.join("\n"));
const idcamsResponse = yield invoke_1.Invoke.ams(session, idcamsCmds, { responseTimeout: respTimeout });
return {
success: true,
commandResponse: attribText + ZosFiles_messages_1.ZosFilesMessages.dataSetCreatedSuccessfully.message,
apiResponse: idcamsResponse
};
}
catch (error) {
const impErr = new imperative_1.ImperativeError({
msg: attribText + error.mDetails.msg,
causeErrors: error.mDetails.causeErrors,
additionalDetails: error.mDetails.additionalDetails
});
imperative_1.Logger.getAppLogger().error(impErr.toString());
throw impErr;
}
});
}
/**
* Create a uss file or folder
* @param {AbstractSession} session - z/OSMF connection info
* @param {string} ussPath - USS path to create file or directory
* @param {string} type - the request type "file" or "directory"
* @param {string} mode - the characters to describe permissions
* @returns {Promise<IZosFilesResponse>}
*/
static uss(session, ussPath, type, mode, options) {
return __awaiter(this, void 0, void 0, function* () {
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(type, ZosFiles_messages_1.ZosFilesMessages.missingRequestType.message);
imperative_1.ImperativeExpect.toNotBeEqual(type, "", ZosFiles_messages_1.ZosFilesMessages.missingRequestType.message);
const parameters = imperative_1.EncodeUri.encUriPathForUss(session, `${ZosFiles_constants_1.ZosFilesConstants.RESOURCE}${ZosFiles_constants_1.ZosFilesConstants.RES_USS_FILES}/${ussPath}`);
const headers = [imperative_1.Headers.APPLICATION_JSON, core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING];
if (options && options.responseTimeout != null) {
headers.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() });
}
let payload = { type };
if (mode) {
payload = Object.assign(Object.assign({}, payload), { mode });
}
const data = yield core_for_zowe_sdk_1.ZosmfRestClient.postExpectString(session, parameters, headers, payload);
return {
success: true,
commandResponse: ZosFiles_messages_1.ZosFilesMessages.ussCreatedSuccessfully.message,
apiResponse: data
};
});
}
static zfs(session, fileSystemName, options) {
return __awaiter(this, void 0, void 0, function* () {
// We require the file system name
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(fileSystemName, ZosFiles_messages_1.ZosFilesMessages.missingFileSystemName.message);
// Removes undefined properties
const tempOptions = !(options === null || options === undefined) ? JSON.parse(JSON.stringify(options)) : {};
let endpoint = imperative_1.EncodeUri.encUriPathForZos(session, ZosFiles_constants_1.ZosFilesConstants.RESOURCE + ZosFiles_constants_1.ZosFilesConstants.RES_ZFS_FILES + "/" + fileSystemName);
this.zfsValidateOptions(tempOptions);
tempOptions.JSONversion = 1;
const headers = [];
if (!(tempOptions.timeout === null || tempOptions.timeout === undefined)) {
endpoint += `?timeout=${encodeURIComponent(tempOptions.timeout)}`;
delete tempOptions.timeout;
}
if (options && options.responseTimeout != null) {
headers.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() });
delete tempOptions.responseTimeout;
}
const jsonContent = JSON.stringify(tempOptions);
headers.push(core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING, { "Content-Length": jsonContent.length });
const data = yield core_for_zowe_sdk_1.ZosmfRestClient.postExpectString(session, endpoint, headers, jsonContent);
return {
success: true,
commandResponse: ZosFiles_messages_1.ZosFilesMessages.zfsCreatedSuccessfully.message,
apiResponse: data
};
});
}
// ____________________________________________________________________________
/**
* Convert the options received from the CLI into options that we supply to IDCAMS.
* @param {ICreateVsamOptions} cliOptions - The set of options from our CLI
* @returns {ICreateVsamOptions} - Options to provide to IDCAMS.
*/
static vsamConvertToIdcamsOptions(cliOptions) {
// Removes undefined properties
let idcamsOptions = !(cliOptions === null || cliOptions === undefined) ? JSON.parse(JSON.stringify(cliOptions)) : {};
// convert the zowe size into IDCAMS allocationUnit and primarySpace
let matchArray;
if (idcamsOptions.size) {
idcamsOptions.size = idcamsOptions.size.toUpperCase();
matchArray = idcamsOptions.size.match(/[A-Z]+/g);
if (matchArray) {
// the text part of size is the allocation unit
idcamsOptions.alcunit = matchArray[0];
}
matchArray = idcamsOptions.size.match(/[0-9]+/g);
if (matchArray) {
// the numeric part of size is the primary space
idcamsOptions.primary = matchArray[0];
}
delete idcamsOptions.size;
}
// start with our default options, and override with any supplied options.
idcamsOptions = Object.assign(Object.assign({}, Create_defaults_1.CreateDefaults.VSAM), idcamsOptions);
// when secondary is not specified, use 10% of primary
if (idcamsOptions.secondary === null || idcamsOptions.secondary === undefined) {
const tenPercent = 0.10;
idcamsOptions.secondary = Math.round(idcamsOptions.primary * tenPercent);
}
return idcamsOptions;
}
// ____________________________________________________________________________
/**
* Form the IDCAMS command to create a VSAM cluster
* @param {string} dataSetName - the name of the dataset for the created cluster
* @param options - options for the creation of the cluster
* @returns {string} - The IDCAMS command to be invoked.
*/
static vsamFormIdcamsCreateCmd(dataSetName, options) {
return [
"DEFINE CLUSTER -\n" +
"(" +
"NAME('" + dataSetName.toUpperCase() + "') -\n" +
options.dsorg.toUpperCase() + " -\n" +
options.alcunit.toUpperCase() + "(" + options.primary + " " + options.secondary + ")" + " -\n" +
(options.retainTo ? "TO(" + options.retainTo + ") -\n" : "") +
(options.retainFor ? "FOR(" + options.retainFor + ") -\n" : "") +
(options.volumes ? "VOLUMES(" + options.volumes.toUpperCase() + ") -\n" : "") +
(options.storclass ? "STORAGECLASS(" + options.storclass + ") -\n" : "") +
(options.mgntclass ? "MANAGEMENTCLASS(" + options.mgntclass + ") -\n" : "") +
(options.dataclass ? "DATACLASS(" + options.dataclass + ") -\n" : "") +
")"
];
}
// ____________________________________________________________________________
/**
* Validate the options for the command to create a VSAM cluster
* @param options - options for the creation of the cluster
*/
static vsamValidateOptions(options) {
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options, ZosFiles_messages_1.ZosFilesMessages.missingFilesCreateOptions.message);
/* If our caller does not supply these options, we supply default values for them,
* so they should exist at this point.
*/
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.dsorg, ZosFiles_messages_1.ZosFilesMessages.missingVsamOption.message + "dsorg");
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.alcunit, ZosFiles_messages_1.ZosFilesMessages.missingVsamOption.message + "alcunit");
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.primary, ZosFiles_messages_1.ZosFilesMessages.missingVsamOption.message + "primary");
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.secondary, ZosFiles_messages_1.ZosFilesMessages.missingVsamOption.message + "secondary");
// validate specific options
for (const option in options) {
if (Object.prototype.hasOwnProperty.call(options, option)) {
switch (option) {
case "dsorg":
if (!ZosFiles_constants_1.ZosFilesConstants.VSAM_DSORG_CHOICES.includes(options.dsorg.toUpperCase())) {
throw new imperative_1.ImperativeError({
msg: ZosFiles_messages_1.ZosFilesMessages.invalidDsorgOption.message + options.dsorg
});
}
break;
case "alcunit":
if (!ZosFiles_constants_1.ZosFilesConstants.VSAM_ALCUNIT_CHOICES.includes(options.alcunit.toUpperCase())) {
throw new imperative_1.ImperativeError({
msg: ZosFiles_messages_1.ZosFilesMessages.invalidAlcunitOption.message + options.alcunit
});
}
break;
case "primary":
case "secondary":
// Validate maximum allocation quantity
if (options[option] > ZosFiles_constants_1.ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new imperative_1.ImperativeError({
msg: ZosFiles_messages_1.ZosFilesMessages.maximumAllocationQuantityExceeded.message + " " +
ZosFiles_messages_1.ZosFilesMessages.commonFor.message + " '" + option + "' " + ZosFiles_messages_1.ZosFilesMessages.commonWithValue.message +
" = " + options[option] + "."
});
}
break;
case "retainFor":
if (options[option] < ZosFiles_constants_1.ZosFilesConstants.MIN_RETAIN_DAYS ||
options[option] > ZosFiles_constants_1.ZosFilesConstants.MAX_RETAIN_DAYS) {
throw new imperative_1.ImperativeError({
msg: imperative_1.TextUtils.formatMessage(ZosFiles_messages_1.ZosFilesMessages.valueOutOfBounds.message, {
optionName: option,
value: options[option],
minValue: ZosFiles_constants_1.ZosFilesConstants.MIN_RETAIN_DAYS,
maxValue: ZosFiles_constants_1.ZosFilesConstants.MAX_RETAIN_DAYS
})
});
}
break;
case "retainTo":
case "volumes":
case "storclass":
case "mgntclass":
case "dataclass":
case "responseTimeout":
// no validation at this time
break;
default:
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidFilesCreateOption.message + option });
} // end switch
}
} // end for
}
// ____________________________________________________________________________
/**
* Validate the options for the command to create a z/OS file system
* @param options - options for the creation of the file system
*/
static zfsValidateOptions(options) {
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options, ZosFiles_messages_1.ZosFilesMessages.missingFilesCreateOptions.message);
/* If our caller does not supply these options, we supply default values for them,
* so they should exist at this point.
*/
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.perms, ZosFiles_messages_1.ZosFilesMessages.missingZfsOption.message + "perms");
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.cylsPri, ZosFiles_messages_1.ZosFilesMessages.missingZfsOption.message + "cyls-pri");
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.cylsSec, ZosFiles_messages_1.ZosFilesMessages.missingZfsOption.message + "cyls-sec");
imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options.timeout, ZosFiles_messages_1.ZosFilesMessages.missingZfsOption.message + "timeout");
// validate specific options
for (const option in options) {
if (Object.prototype.hasOwnProperty.call(options, option)) {
switch (option) {
case "perms": {
const maxPerm = 777;
if (options.perms < 0 || options.perms > maxPerm) {
throw new imperative_1.ImperativeError({
msg: ZosFiles_messages_1.ZosFilesMessages.invalidPermsOption.message + options.perms
});
}
break;
}
case "cylsPri":
case "cylsSec":
// Validate maximum allocation quantity
if (options[option] > ZosFiles_constants_1.ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new imperative_1.ImperativeError({
msg: ZosFiles_messages_1.ZosFilesMessages.maximumAllocationQuantityExceeded.message + " " +
ZosFiles_messages_1.ZosFilesMessages.commonFor.message + " '" + option + "' " + ZosFiles_messages_1.ZosFilesMessages.commonWithValue.message +
" = " + options[option] + "."
});
}
break;
case "owner":
case "group":
case "storclass":
case "mgntclass":
case "dataclass":
case "volumes":
case "timeout":
case "responseTimeout":
// no validation at this time
break;
default:
throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidFilesCreateOption.message + option });
} // end switch
}
} // end for
}
}
exports.Create = Create;
//# sourceMappingURL=Create.js.map