Skip to content

Commit

Permalink
feat: update perUnitStorageThroughput
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed May 15, 2024
1 parent 74475e7 commit 9f1b1bb
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 8 deletions.
38 changes: 32 additions & 6 deletions packages/aws-cdk-lib/aws-fsx/lib/lustre-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,16 @@ export class LustreFileSystem extends FileSystemBase {
private validateProps(props: LustreFileSystemProps) {
const lustreConfiguration = props.lustreConfiguration;
const deploymentType = lustreConfiguration.deploymentType;
const perUnitStorageThroughput = lustreConfiguration.perUnitStorageThroughput;

// Make sure the import path is valid before validating the export path
this.validateImportPath(lustreConfiguration.importPath);
this.validateExportPath(lustreConfiguration.exportPath, lustreConfiguration.importPath);

this.validateImportedFileChunkSize(lustreConfiguration.importedFileChunkSizeMiB);
this.validateAutoImportPolicy(deploymentType, lustreConfiguration.importPath, lustreConfiguration.autoImportPolicy);
this.validatePerUnitStorageThroughput(deploymentType, lustreConfiguration.perUnitStorageThroughput, props.storageType);
this.validateStorageCapacity(deploymentType, props.storageCapacityGiB);
this.validatePerUnitStorageThroughput(deploymentType, perUnitStorageThroughput, props.storageType);
this.validateStorageCapacity(deploymentType, props.storageCapacityGiB, props.storageType, perUnitStorageThroughput);
this.validateStorageType(deploymentType, props.storageType);
}

Expand Down Expand Up @@ -403,14 +404,39 @@ export class LustreFileSystem extends FileSystemBase {
/**
* Validates the storage capacity is an acceptable value for the deployment type.
*/
private validateStorageCapacity(deploymentType: LustreDeploymentType, storageCapacity: number): void {
private validateStorageCapacity(
deploymentType: LustreDeploymentType,
storageCapacity: number,
storageType?: StorageType,
perUnitStorageThroughput?: number,
): void {
if (deploymentType === LustreDeploymentType.SCRATCH_1) {
if (![1200, 2400, 3600].includes(storageCapacity) && storageCapacity % 3600 !== 0) {
throw new Error('storageCapacity must be 1,200, 2,400, 3,600, or a multiple of 3,600');
throw new Error('storageCapacity must be 1,200, 2,400, 3,600, or a multiple of 3,600 for SCRATCH_1 deployment type');
}
} else {
}

if (
deploymentType === LustreDeploymentType.PERSISTENT_2
|| deploymentType === LustreDeploymentType.SCRATCH_2
) {
if (![1200, 2400].includes(storageCapacity) && storageCapacity % 2400 !== 0) {
throw new Error('storageCapacity must be 1,200, 2,400, or a multiple of 2,400');
throw new Error('storageCapacity must be 1,200, 2,400, or a multiple of 2,400 for SCRATCH_2 and PERSISTENT_2 deployment types');
}
}

if (deploymentType === LustreDeploymentType.PERSISTENT_1) {
if (storageType === StorageType.HDD) {
if (perUnitStorageThroughput === 12 && storageCapacity % 6000 !== 0) {
throw new Error('storageCapacity must be a multiple of 6,000 for PERSISTENT_1 HDD storage with 12 MB/s/TiB throughput');
}
if (perUnitStorageThroughput === 40 && storageCapacity % 1800 !== 0) {
throw new Error('storageCapacity must be a multiple of 1,800 for PERSISTENT_1 HDD storage with 40 MB/s/TiB throughput');
}
} else {
if (![1200, 2400].includes(storageCapacity) && storageCapacity % 2400 !== 0) {
throw new Error('storageCapacity must be 1,200, 2,400, or a multiple of 2,400 for PERSISTENT_1 SSD storage');
}
}
}
}
Expand Down
68 changes: 66 additions & 2 deletions packages/aws-cdk-lib/aws-fsx/test/lustre-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,15 @@ describe('FSx for Lustre File System', () => {
vpc,
vpcSubnet,
});
}).toThrowError('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB for PERSISTENT_1 deployment type, got: ' + invalidValue);
}).toThrowError('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB for PERSISTENT_1 SSD storage, got: ' + invalidValue);
});

test.each([12, 40])('valid perUnitStorageThroughput of %d for HDD storage', (validValue: number) => {
lustreConfiguration = {
deploymentType: LustreDeploymentType.PERSISTENT_1,
perUnitStorageThroughput: validValue,
};
storageCapacity = 18000;

new LustreFileSystem(stack, 'FsxFileSystem', {
lustreConfiguration,
Expand Down Expand Up @@ -596,7 +597,7 @@ describe('FSx for Lustre File System', () => {
vpcSubnet,
storageType: StorageType.HDD,
});
}).toThrow('perUnitStorageThroughput must be 12 or 40 MB/s/TiB for HDD storage type, got: ' + invalidValue);
}).toThrow('perUnitStorageThroughput must be 12 or 40 MB/s/TiB for PERSISTENT_1 HDD storage, got: ' + invalidValue);
});

test('setting perUnitStorageThroughput on wrong deploymentType', () => {
Expand Down Expand Up @@ -753,6 +754,69 @@ describe('FSx for Lustre File System', () => {
});
}).toThrowError(/storageCapacity must be 1,200, 2,400, 3,600, or a multiple of 3,600/);
});

test.each([
[6000, 12],
[12000, 12],
[1800, 40],
[3600, 40],
])('proper multiple for storage capacity using %d with PERSISTENT_1 HDD', (validValue: number, throughput: number) => {
lustreConfiguration = {
deploymentType: LustreDeploymentType.PERSISTENT_1,
perUnitStorageThroughput: throughput,
};

new LustreFileSystem(stack, 'FsxFileSystem', {
lustreConfiguration,
storageCapacityGiB: validValue,
vpc,
vpcSubnet,
storageType: StorageType.HDD,
});

Template.fromStack(stack).hasResourceProperties('AWS::FSx::FileSystem', {
LustreConfiguration: {
DeploymentType: LustreDeploymentType.PERSISTENT_1,
PerUnitStorageThroughput: throughput,
},
StorageCapacity: validValue,
StorageType: StorageType.HDD,
});
});

test.each([1, 6001])('invalid value of %d for storage capacity with PERSISTENT_1 HDD with 12 MB/s/TiB throughput', (invalidValue: number) => {
lustreConfiguration = {
deploymentType: LustreDeploymentType.PERSISTENT_1,
perUnitStorageThroughput: 12,
};

expect(() => {
new LustreFileSystem(stack, 'FsxFileSystem', {
lustreConfiguration,
storageCapacityGiB: invalidValue,
vpc,
vpcSubnet,
storageType: StorageType.HDD,
});
}).toThrow('storageCapacity must be a multiple of 6,000 for PERSISTENT_1 HDD storage with 12 MB/s/TiB throughput');
});

test.each([1, 1801])('invalid value of %d for storage capacity with PERSISTENT_1 HDD with 40 MB/s/TiB throughput', (invalidValue: number) => {
lustreConfiguration = {
deploymentType: LustreDeploymentType.PERSISTENT_1,
perUnitStorageThroughput: 40,
};

expect(() => {
new LustreFileSystem(stack, 'FsxFileSystem', {
lustreConfiguration,
storageCapacityGiB: invalidValue,
vpc,
vpcSubnet,
storageType: StorageType.HDD,
});
}).toThrow('storageCapacity must be a multiple of 1,800 for PERSISTENT_1 HDD storage with 40 MB/s/TiB throughput');
});
});

test.each([
Expand Down

0 comments on commit 9f1b1bb

Please sign in to comment.