Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deadline): adding version check for staging deadline #109

Merged
merged 17 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/aws-rfdk/lib/deadline/lib/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ export class Stage {
}

// Do minimum supported deadline version check
const minimumSupportedVersion = new Version([10, 1, 9, 2]);
const stagedVersion = Version.parse(version);
if (stagedVersion.isLessThan(minimumSupportedVersion)) {
throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion.toString()})`);
if (stagedVersion.isLessThan(Version.MINIMUM_SUPPORTED_DEADLINE_VERSION)) {
throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()})`);
}

return true;
Expand Down
69 changes: 46 additions & 23 deletions packages/aws-rfdk/lib/deadline/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ abstract class VersionQueryBase extends Construct implements IVersion {
/**
* This class is reposonsible to do basic operations on version format.
*/
export class Version {
export class Version implements IPatchVersion {

/**
* This variable holds the value for minimum supported deadline version.
*/
public static readonly MINIMUM_SUPPORTED_DEADLINE_VERSION = new Version([10, 1, 9, 2]);

/**
* This method parses the input string and returns the version object.
Expand Down Expand Up @@ -116,9 +121,47 @@ export class Version {
/**
* Numeric components of version.
*/
public readonly components: number[];
private readonly components: number[];

/**
* @inheritdoc
*/
public get majorVersion(): number {
return this.components[0];
}

/**
* @inheritdoc
*/
public get minorVersion(): number {
return this.components[1];
}

/**
* @inheritdoc
*/
public get releaseVersion(): number {
return this.components[2];
}

/**
* @inheritdoc
*/
public get patchVersion(): number {
return this.components[3];
}

constructor(components: number[]) {
// validations
if(components.length != 4) {
throw new TypeError('Invalid version format. Version should contain exactly 4 components.');
jusiskin marked this conversation as resolved.
Show resolved Hide resolved
}
components.forEach((component) => {
if (component < 0) {
throw new TypeError('Invalid version format. None of the version components can be negative.');
jusiskin marked this conversation as resolved.
Show resolved Hide resolved
}
});

this.components = components;
jusiskin marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -190,26 +233,6 @@ export class Version {
* constructs which version of Deadline you want them to use, and be configured for.
*/
export class VersionQuery extends VersionQueryBase {
/**
* Parses a version string of the format:
*
* <major>.<minor>.<release>.<patch>
*
* and extracts the components.
*
* @param versionstr The input version string
*/
public static parseVersionString(versionstr: string): IPatchVersion {
const version = Version.parse(versionstr);

return {
majorVersion: version.components[0],
minorVersion: version.components[1],
releaseVersion: version.components[2],
patchVersion: version.components[3],
};
}

/**
* Specify a Deadline version from a fully-qualified Deadline patch version.
*
Expand Down Expand Up @@ -285,7 +308,7 @@ export class VersionQuery extends VersionQueryBase {
* @param versionString A fully qualified version string (e.g. 10.1.9.2)
*/
public static exactString(scope: Construct, id: string, versionString: string) {
return VersionQuery.exact(scope, id, VersionQuery.parseVersionString(versionString));
return VersionQuery.exact(scope, id, Version.parse(versionString));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
import {
IRenderQueue,
} from './render-queue';
import { Version } from './version';

/**
* Interface for Deadline Worker Fleet.
Expand Down Expand Up @@ -548,6 +549,7 @@ export class WorkerInstanceFleet extends WorkerInstanceFleetBase {
`'${groups}'`,
`'${pools}'`,
`'${props.region || ''}'`,
`'${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`,
jusiskin marked this conversation as resolved.
Show resolved Hide resolved
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ param (
[Parameter(Mandatory=$True)]
$workerPools,
[Parameter(Mandatory=$True)]
$workerRegion
$workerRegion,
[Parameter(Mandatory=$True)]
$minimumSupportedDeadlineVersion
)

Set-PSDebug -Trace 1
Expand Down
70 changes: 55 additions & 15 deletions packages/aws-rfdk/lib/deadline/test/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Version', () => {
});
});

describe('.isLessThan constructor', () => {
describe('.isLessThan using constructor', () => {

// WHEN
const lhs = new Version([10, 0, 9, 2]);
Expand All @@ -123,39 +123,79 @@ describe('Version', () => {
expect(result).toEqual(true);
});

describe('.parse', () => {
test.each<[string, { version: string, expectedValue: boolean }]>([
describe('constructor validation', () => {
test.each<[string, { version: number[], expectedException?: RegExp }]>([
[
'incorrect component count',
{
version: [10, 1, 9],
expectedException: /Invalid version format/,
},
], [
'negative value',
{
version: [10, -1, 9],
expectedException: /Invalid version format/,
},
], [
'decimal value',
{
version: [10, 1, 9.2],
expectedException: /Invalid version format/,
},
], [
'correct value',
{
version: [10, 1, 9, 2],
},
],
])('%s', (_name, testcase) => {
const { version, expectedException } = testcase;

// WHEN
if (expectedException) {
expect(() => new Version(version)).toThrow(expectedException);
} else {
expect(() => new Version(version)).not.toThrow();
}
});
});

describe('.parse throws exception', () => {
test.each<[string, { version: string, expectedException?: RegExp }]>([
[
'ending with .',
{
version: '10.1.9.',
expectedValue: false,
expectedException: /Invalid version format/,
},
], [
'empty string',
{
version: '',
expectedValue: false,
expectedException: /Invalid version format/,
},
], [
'negative value',
{
version: '10.-1.9.2',
expectedException: /Invalid version format/,
},
], [
'correct version',
{
version: '10.1.9.2',
expectedValue: true,
},
],
])('%s', (_name, testcase) => {
const { version, expectedValue } = testcase;
const { version, expectedException } = testcase;

// WHEN
let result = false;
try {
Version.parse(version);
result = true;
} catch (error) {
} finally {
if(expectedException) {
expect(() => Version.parse(version)).toThrow(expectedException);
} else {
expect(() => Version.parse(version)).not.toThrow();
}

expect(result).toEqual(expectedValue);
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
Repository,
VersionQuery,
WorkerInstanceFleet,
Version,
} from '../lib';
import {
CONFIG_WORKER_ASSET_LINUX,
Expand Down Expand Up @@ -685,7 +686,7 @@ test('default worker fleet is created correctly custom subnet values', () => {
},
],
},
"' '6161' '' '' ''",
`' '6161' '' '' '' '${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`,
],
],
});
Expand Down Expand Up @@ -1085,7 +1086,7 @@ test('default worker fleet is created correctly with groups, pools and region',
},
],
},
"' '63415' 'a,b' 'c,d' 'E'",
`' '63415' 'a,b' 'c,d' 'E' '${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`,
]],
});
});
Expand Down