-
Notifications
You must be signed in to change notification settings - Fork 85
/
Create.ts
705 lines (613 loc) · 30.3 KB
/
Create.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*
* 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.
*
*/
import { AbstractSession, Headers, IHeaderContent, ImperativeError, ImperativeExpect, Logger, TextUtils } from "@zowe/imperative";
import { isNullOrUndefined } from "util";
import { ZosmfHeaders, ZosmfRestClient } from "@zowe/core-for-zowe-sdk";
import { ZosFilesConstants } from "../../constants/ZosFiles.constants";
import { ZosFilesMessages } from "../../constants/ZosFiles.messages";
import { IZosFilesResponse } from "../../doc/IZosFilesResponse";
import { CreateDefaults } from "./Create.defaults";
import { CreateDataSetTypeEnum } from "./CreateDataSetType.enum";
import { ICreateDataSetOptions } from "./doc/ICreateDataSetOptions";
import { Invoke } from "../invoke";
import { ICreateVsamOptions } from "./doc/ICreateVsamOptions";
import { ICreateZfsOptions } from "./doc/ICreateZfsOptions";
import * as path from "path";
import { IZosFilesOptions } from "../../doc/IZosFilesOptions";
// 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
*/
export class Create {
/**
* Create a data set
* @param {AbstractSession} session - z/OSMF connection info
* @param {CreateDataSetTypeEnum} cmdType - 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={}] - additional options for the creation of the data set
* @returns {Promise<IZosFilesResponse>}
*/
public static async dataSet(session: AbstractSession,
cmdType: CreateDataSetTypeEnum,
dataSetName: string,
options?: Partial<ICreateDataSetOptions>): Promise<IZosFilesResponse> {
let validCmdType = true;
// Removes undefined properties
let tempOptions = !isNullOrUndefined(options) ? JSON.parse(JSON.stringify(options)) : {};
// Required
ImperativeExpect.toNotBeNullOrUndefined(cmdType, ZosFilesMessages.missingDatasetType.message);
// Required
ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFilesMessages.missingDatasetName.message);
switch (cmdType) {
case CreateDataSetTypeEnum.DATA_SET_PARTITIONED:
tempOptions = { ...CreateDefaults.DATA_SET.PARTITIONED, ...tempOptions };
break;
case CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL:
tempOptions = { ...CreateDefaults.DATA_SET.SEQUENTIAL, ...tempOptions };
break;
case CreateDataSetTypeEnum.DATA_SET_BINARY:
tempOptions = { ...CreateDefaults.DATA_SET.BINARY, ...tempOptions };
break;
case CreateDataSetTypeEnum.DATA_SET_C:
tempOptions = { ...CreateDefaults.DATA_SET.C, ...tempOptions };
break;
case CreateDataSetTypeEnum.DATA_SET_CLASSIC:
tempOptions = { ...CreateDefaults.DATA_SET.CLASSIC, ...tempOptions };
break;
case CreateDataSetTypeEnum.DATA_SET_BLANK:
tempOptions = { ...CreateDefaults.DATA_SET.BLANK, ...tempOptions };
break;
default:
validCmdType = false;
break;
}
if (!validCmdType) {
throw new ImperativeError({ msg: ZosFilesMessages.unsupportedDatasetType.message });
} else {
try {
// Handle the size option
if (!isNullOrUndefined(tempOptions.size)) {
const tAlcunit = tempOptions.size.toString().match(/[a-zA-Z]+/g);
if (!isNullOrUndefined(tAlcunit)) {
tempOptions.alcunit = tAlcunit.join("").toUpperCase();
}
const tPrimary = tempOptions.size.toString().match(/[0-9]+/g);
if (!isNullOrUndefined(tPrimary)) {
tempOptions.primary = +(tPrimary.join(""));
if (isNullOrUndefined(tempOptions.secondary)) {
const TEN_PERCENT = 0.10;
tempOptions.secondary = Math.round(tempOptions.primary * TEN_PERCENT);
}
}
} else {
if (isNullOrUndefined(tempOptions.secondary)) {
if (cmdType !== CreateDataSetTypeEnum.DATA_SET_BINARY) {
tempOptions.secondary = 1;
} else {
// tslint:disable-next-line:no-magic-numbers
tempOptions.secondary = 10;
}
}
}
delete tempOptions.size;
let response = "";
// Handle the print attributes option
if (!isNullOrUndefined(tempOptions.showAttributes)) {
if (tempOptions.showAttributes) {
delete tempOptions.showAttributes;
response = TextUtils.prettyJson(tempOptions);
} else {
delete tempOptions.showAttributes;
}
}
const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dataSetName;
const headers: IHeaderContent[] = [ZosmfHeaders.ACCEPT_ENCODING];
if (options && options.responseTimeout != null) {
headers.push({[ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString()});
}
Create.dataSetValidateOptions(tempOptions);
await ZosmfRestClient.postExpectString(session, endpoint, headers, JSON.stringify(tempOptions));
return {
success: true,
commandResponse: response + ZosFilesMessages.dataSetCreatedSuccessfully.message
};
} catch (error) {
throw error;
}
}
}
public static async dataSetLike(session: AbstractSession,
dataSetName: string,
likeDataSetName: string,
options?: Partial<ICreateDataSetOptions>): Promise<IZosFilesResponse> {
// Required
ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFilesMessages.missingDatasetName.message);
ImperativeExpect.toNotBeNullOrUndefined(likeDataSetName, ZosFilesMessages.missingDatasetLikeName.message);
// Removes undefined properties
const tempOptions = !isNullOrUndefined(options) ? JSON.parse(JSON.stringify({ like: likeDataSetName, ...(options || {}) })) : {};
Create.dataSetValidateOptions(tempOptions);
try {
const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dataSetName;
await ZosmfRestClient.postExpectString(session, endpoint, [ZosmfHeaders.ACCEPT_ENCODING], JSON.stringify(tempOptions));
return {
success: true,
commandResponse: ZosFilesMessages.dataSetCreatedSuccessfully.message
};
} catch (error) {
throw error;
}
}
/**
* Validate supplied parameters
* @static
* @param options - additional options for the creation of the data set
*/
public static dataSetValidateOptions(options: ICreateDataSetOptions) {
ImperativeExpect.toNotBeNullOrUndefined(options, ZosFilesMessages.missingFilesCreateOptions.message);
const tempOptions: any = options;
for (const option in tempOptions) {
if (tempOptions.hasOwnProperty(option)) {
switch (option) {
case "alcunit":
// zOSMF defaults to TRK if missing so mimic it's behavior
if (isNullOrUndefined(tempOptions.alcunit)) {
tempOptions.alcunit = "TRK";
}
// Only CYL and TRK valid
switch (tempOptions.alcunit.toUpperCase()) {
case "CYL":
case "TRK":
break;
default:
throw new ImperativeError({ msg: ZosFilesMessages.invalidAlcunitOption.message + tempOptions.alcunit });
}
break;
case "avgblk":
// no validation at this time
break;
case "blksize":
// zOSMF defaults to TRK if missing so mimic it's behavior
if (isNullOrUndefined(tempOptions.blksize)) {
tempOptions.blksize = tempOptions.lrecl;
}
break;
case "lrecl":
// Required
ImperativeExpect.toNotBeNullOrUndefined(tempOptions.lrecl, ZosFilesMessages.missingRecordLength.message);
break;
case "dirblk":
// Validate non-zero if dsorg is PS
if (tempOptions.dirblk !== 0 && tempOptions.dsorg === "PS") {
throw new ImperativeError({ msg: ZosFilesMessages.invalidPSDsorgDirblkCombination.message });
}
// Validate non-zero if 'dsorg' is PO
if (tempOptions.dirblk === 0 && tempOptions.dsorg === "PO") {
throw new ImperativeError({ msg: ZosFilesMessages.invalidPODsorgDirblkCombination.message });
}
break;
case "dsntype":
// Key to create a PDSE.
const type: string = tempOptions.dsntype.toUpperCase();
const availableTypes = ["BASIC", "EXTPREF", "EXTREQ", "HFS", "LARGE", "PDS", "LIBRARY", "PIPE"];
if (availableTypes.indexOf(type) === -1) {
throw new ImperativeError({ msg: ZosFilesMessages.invalidDsntypeOption.message + tempOptions.dsntype });
}
break;
case "dsorg":
// Only PO and PS valid
switch (tempOptions.dsorg.toUpperCase()) {
case "PO":
case "PS":
break;
default:
throw new ImperativeError({ msg: ZosFilesMessages.invalidDsorgOption.message + tempOptions.dsorg });
}
break;
case "primary":
// Required
ImperativeExpect.toNotBeNullOrUndefined(tempOptions.primary, ZosFilesMessages.missingPrimary.message);
// Validate maximum allocation quantity
if (tempOptions.primary > ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new ImperativeError({ msg: ZosFilesMessages.maximumAllocationQuantityExceeded.message + " for 'primary'." });
}
break;
case "secondary":
// zOSMF defaults to 0 if missing so mimic it's behavior
if (isNullOrUndefined(tempOptions.secondary)) {
tempOptions.secondary = 0;
}
// Validate maximum allocation quantity
if (tempOptions.secondary > ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new ImperativeError({ msg: ZosFilesMessages.maximumAllocationQuantityExceeded.message + " for 'secondary'." });
}
break;
case "recfm":
// zOSMF defaults to F if missing so mimic it's behavior
if (isNullOrUndefined(tempOptions.recfm)) {
tempOptions.recfm = "F";
}
// F, V, or U are required; B, A, M, S, T or additional
// VBA works on mainframe but not via zOSMF
switch (tempOptions.recfm.toUpperCase()) {
case "F":
case "FB":
case "V":
case "VB":
case "U":
break;
default:
throw new ImperativeError({ msg: ZosFilesMessages.invalidRecfmOption.message + tempOptions.recfm });
}
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 ImperativeError({ msg: 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>}
*/
public static async vsam(
session: AbstractSession,
dataSetName: string,
options?: Partial<ICreateVsamOptions>)
: Promise<IZosFilesResponse> {
// We require the dataset name
ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFilesMessages.missingDatasetName.message);
const idcamsOptions: ICreateVsamOptions = this.vsamConvertToIdcamsOptions(options);
// format the attributes to show, and remove the option
let attribText = "";
if (!isNullOrUndefined(idcamsOptions.showAttributes)) {
if (idcamsOptions.showAttributes) {
delete idcamsOptions.showAttributes;
attribText = ZosFilesMessages.attributeTitle.message + TextUtils.prettyJson(idcamsOptions);
} else {
delete idcamsOptions.showAttributes;
}
}
let respTimeout: number;
if (options) {
respTimeout = options.responseTimeout
}
try {
this.vsamValidateOptions(idcamsOptions);
// We invoke IDCAMS to create the VSAM cluster
const idcamsCmds = this.vsamFormIdcamsCreateCmd(dataSetName, idcamsOptions);
Logger.getAppLogger().debug("Invoking this IDCAMS command:\n" + idcamsCmds.join("\n"));
const idcamsResponse: IZosFilesResponse = await Invoke.ams(session, idcamsCmds, {responseTimeout: respTimeout});
return {
success: true,
commandResponse: attribText + ZosFilesMessages.dataSetCreatedSuccessfully.message,
apiResponse: idcamsResponse
};
} catch (error) {
const impErr = new ImperativeError({
msg: attribText + error.mDetails.msg,
causeErrors: error.mDetails.causeErrors,
additionalDetails: error.mDetails.additionalDetails
});
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>}
*/
public static async uss(session: AbstractSession,
ussPath: string,
type: string,
mode?: string,
options?: IZosFilesOptions)
: Promise<IZosFilesResponse> {
ImperativeExpect.toNotBeNullOrUndefined(type, ZosFilesMessages.missingRequestType.message);
ImperativeExpect.toNotBeEqual(type, "", ZosFilesMessages.missingRequestType.message);
ussPath = path.posix.normalize(ussPath);
ussPath = ussPath.charAt(0) === "/" ? ussPath.substring(1) : ussPath;
ussPath = encodeURIComponent(ussPath);
const parameters: string = `${ZosFilesConstants.RESOURCE}${ZosFilesConstants.RES_USS_FILES}/${ussPath}`;
const headers: IHeaderContent[] = [Headers.APPLICATION_JSON, ZosmfHeaders.ACCEPT_ENCODING];
if (options && options.responseTimeout != null) {
headers.push({[ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString()});
}
let payload: object = { type };
if (mode) {
payload = { ...payload, ...{ mode } };
}
const data = await ZosmfRestClient.postExpectString(session, parameters, headers, payload);
return {
success: true,
commandResponse: ZosFilesMessages.ussCreatedSuccessfully.message,
apiResponse: data
};
}
public static async zfs(
session: AbstractSession,
fileSystemName: string,
options?: Partial<ICreateZfsOptions>)
: Promise<IZosFilesResponse> {
// We require the file system name
ImperativeExpect.toNotBeNullOrUndefined(fileSystemName, ZosFilesMessages.missingFileSystemName.message);
// Removes undefined properties
const tempOptions = !isNullOrUndefined(options) ? JSON.parse(JSON.stringify(options)) : {};
let endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_ZFS_FILES + "/" + fileSystemName;
this.zfsValidateOptions(tempOptions);
tempOptions.JSONversion = 1;
if (!isNullOrUndefined(tempOptions.timeout)) {
endpoint += `?timeout=${tempOptions.timeout}`;
delete tempOptions.timeout;
}
const jsonContent = JSON.stringify(tempOptions);
const headers = [{ "Content-Length": jsonContent.length }, ZosmfHeaders.ACCEPT_ENCODING];
const data = await ZosmfRestClient.postExpectString(session, endpoint, headers, jsonContent);
return {
success: true,
commandResponse: 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.
*/
private static vsamConvertToIdcamsOptions(cliOptions: ICreateVsamOptions): ICreateVsamOptions {
// Removes undefined properties
let idcamsOptions = isNullOrUndefined(cliOptions) ? {} : 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 = { ...CreateDefaults.VSAM, ...idcamsOptions };
// when secondary is not specified, use 10% of primary
if (isNullOrUndefined(idcamsOptions.secondary)) {
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.
*/
private static vsamFormIdcamsCreateCmd(
dataSetName: string,
options: ICreateVsamOptions)
: string[] {
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
*/
private static vsamValidateOptions(options: ICreateVsamOptions): void {
ImperativeExpect.toNotBeNullOrUndefined(options,
ZosFilesMessages.missingFilesCreateOptions.message
);
/* If our caller does not supply these options, we supply default values for them,
* so they should exist at this point.
*/
ImperativeExpect.toNotBeNullOrUndefined(options.dsorg,
ZosFilesMessages.missingVsamOption.message + "dsorg"
);
ImperativeExpect.toNotBeNullOrUndefined(options.alcunit,
ZosFilesMessages.missingVsamOption.message + "alcunit"
);
ImperativeExpect.toNotBeNullOrUndefined(options.primary,
ZosFilesMessages.missingVsamOption.message + "primary"
);
ImperativeExpect.toNotBeNullOrUndefined(options.secondary,
ZosFilesMessages.missingVsamOption.message + "secondary"
);
// validate specific options
for (const option in options) {
if (options.hasOwnProperty(option)) {
switch (option) {
case "dsorg":
if (!ZosFilesConstants.VSAM_DSORG_CHOICES.includes(options.dsorg.toUpperCase())) {
throw new ImperativeError({
msg: ZosFilesMessages.invalidDsorgOption.message + options.dsorg
});
}
break;
case "alcunit":
if (!ZosFilesConstants.VSAM_ALCUNIT_CHOICES.includes(options.alcunit.toUpperCase())) {
throw new ImperativeError({
msg: ZosFilesMessages.invalidAlcunitOption.message + options.alcunit
});
}
break;
case "primary":
case "secondary":
// Validate maximum allocation quantity
if (options[option] > ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new ImperativeError({
msg: ZosFilesMessages.maximumAllocationQuantityExceeded.message + " " +
ZosFilesMessages.commonFor.message + " '" + option + "' " + ZosFilesMessages.commonWithValue.message +
" = " + options[option] + "."
});
}
break;
case "retainFor":
if (options[option] < ZosFilesConstants.MIN_RETAIN_DAYS ||
options[option] > ZosFilesConstants.MAX_RETAIN_DAYS) {
throw new ImperativeError({
msg: TextUtils.formatMessage(ZosFilesMessages.valueOutOfBounds.message, {
optionName: option,
value: options[option],
minValue: ZosFilesConstants.MIN_RETAIN_DAYS,
maxValue: 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 ImperativeError({ msg: 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
*/
private static zfsValidateOptions(options: ICreateZfsOptions): void {
ImperativeExpect.toNotBeNullOrUndefined(options,
ZosFilesMessages.missingFilesCreateOptions.message
);
/* If our caller does not supply these options, we supply default values for them,
* so they should exist at this point.
*/
ImperativeExpect.toNotBeNullOrUndefined(options.perms,
ZosFilesMessages.missingZfsOption.message + "perms"
);
ImperativeExpect.toNotBeNullOrUndefined(options.cylsPri,
ZosFilesMessages.missingZfsOption.message + "cyls-pri"
);
ImperativeExpect.toNotBeNullOrUndefined(options.cylsSec,
ZosFilesMessages.missingZfsOption.message + "cyls-sec"
);
ImperativeExpect.toNotBeNullOrUndefined(options.timeout,
ZosFilesMessages.missingZfsOption.message + "timeout"
);
// validate specific options
for (const option in options) {
if (options.hasOwnProperty(option)) {
switch (option) {
case "perms":
const maxPerm = 777;
if ((options.perms < 0) || (options.perms > maxPerm)) {
throw new ImperativeError({
msg: ZosFilesMessages.invalidPermsOption.message + options.perms
});
}
break;
case "cylsPri":
case "cylsSec":
// Validate maximum allocation quantity
if (options[option] > ZosFilesConstants.MAX_ALLOC_QUANTITY) {
throw new ImperativeError({
msg: ZosFilesMessages.maximumAllocationQuantityExceeded.message + " " +
ZosFilesMessages.commonFor.message + " '" + option + "' " + 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 ImperativeError({ msg: ZosFilesMessages.invalidFilesCreateOption.message + option });
} // end switch
}
} // end for
}
}