Skip to content

Commit d370973

Browse files
committed
Use storage: number when parsing account configs.
1 parent 734b296 commit d370973

File tree

5 files changed

+94
-12
lines changed

5 files changed

+94
-12
lines changed

.tools/test/stacks/config/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.tools/test/stacks/config/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13+
"@types/node": "^22.9.0",
14+
"typescript": "^5.6.3",
1315
"yaml": "^2.4.2"
1416
}
1517
}

.tools/test/stacks/config/targets.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ interface AccountConfig {
1010
// https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html
1111
vcpus?: string; // Count
1212
memory?: string; // MiB, but limited based on vCPU count, see docs
13-
storage?: string; // GiB, 20GiB to 200GiB
13+
storage?: number; // GiB, 20GiB to 200GiB
14+
}
15+
16+
type AccountConfigYaml = {
17+
[K in keyof AccountConfig]: string
1418
}
1519

1620
interface AccountConfigs {
@@ -20,17 +24,38 @@ interface AccountConfigs {
2024
export function readAccountConfig(filePath: string): AccountConfigs {
2125
try {
2226
const fileContents = fs.readFileSync(filePath, "utf8");
23-
const data: AccountConfigs = parse(fileContents);
24-
25-
Object.values(data).forEach((config) => {
26-
if (!config.account_id || !config.status) {
27-
throw new Error("Validation failed: Missing required account fields.");
27+
const data = Object.entries(parse(fileContents) as Record<string, AccountConfigYaml>).reduce((data, [name, config]) => {
28+
const {account_id, status, vcpus, memory, storage} = config;
29+
if (!account_id) {
30+
throw new Error(`Validation failed: Missing account_id field in ${name}`);
31+
}
32+
switch (status) {
33+
case "enabled": // fallthrough
34+
case "disabled":
35+
break;
36+
default:
37+
throw new Error(`Validation failed: invalid status ${status} in ${name}`)
2838
}
29-
});
39+
data[name] = {
40+
account_id,
41+
status,
42+
vcpus,
43+
memory,
44+
storage: numberOrDefault(storage, 20),
45+
}
46+
return data;
47+
}, {} as Record<string, AccountConfig>)
3048

3149
return data;
3250
} catch (error) {
3351
console.error("Failed to read or parse the YAML file:", { error });
3452
throw error;
3553
}
3654
}
55+
56+
function numberOrDefault(storage: string | undefined, defaultValue: number) {
57+
const batchStorage = Number(storage);
58+
const batchStorageNumber = isNaN(batchStorage) ? defaultValue : batchStorage;
59+
return batchStorageNumber;
60+
}
61+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"lib": ["es2020", "dom"],
7+
"declaration": true,
8+
"strict": true,
9+
"noImplicitAny": true,
10+
"strictNullChecks": true,
11+
"noImplicitThis": true,
12+
"alwaysStrict": true,
13+
"noUnusedLocals": true,
14+
"noUnusedParameters": true,
15+
"noImplicitReturns": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"inlineSourceMap": true,
18+
"inlineSources": true,
19+
"experimentalDecorators": true,
20+
"strictPropertyInitialization": false,
21+
"typeRoots": ["./node_modules/@types"],
22+
"resolveJsonModule": true,
23+
"esModuleInterop": true
24+
},
25+
"exclude": ["node_modules", "cdk.out"]
26+
}

.tools/test/stacks/plugin/typescript/plugin_stack.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class PluginStack extends cdk.Stack {
4444
// https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html
4545
this.batchMemory = acctConfig[`${toolName}`]?.memory ?? "16384"; // MiB
4646
this.batchVcpus = acctConfig[`${toolName}`]?.vcpus ?? "4"; // CPUs
47-
const batchStorage = Number(acctConfig[`${toolName}`]?.storage ?? undefined);
48-
this.batchStorage = isNaN(batchStorage) ? 20 : batchStorage; // GiB
47+
this.batchStorage = acctConfig[`${toolName}`]?.storage ?? 20; // GiB
4948
}
5049

5150
const [jobDefinition, jobQueue] = this.initBatchFargate();
@@ -142,7 +141,7 @@ class PluginStack extends cdk.Stack {
142141
},
143142
],
144143
ephemeralStorage: {
145-
sizeInGiB: this.batchStorage,
144+
sizeInGib: this.batchStorage,
146145
},
147146
environment: variableConfigJson,
148147
},
@@ -193,7 +192,7 @@ class PluginStack extends cdk.Stack {
193192
);
194193

195194
return new lambda.Function(this, `SubmitBatchJob-${toolName}`, {
196-
runtime: lambda.Runtime.PYTHON_3_9,
195+
runtime: lambda.Runtime.PYTHON_3_8,
197196
handler: "submit_job.handler",
198197
code: lambda.Code.fromAsset("lambda"),
199198
environment: {
@@ -315,7 +314,7 @@ class PluginStack extends cdk.Stack {
315314

316315
// Define the Lambda function.
317316
const lambdaFunction = new lambda.Function(this, "BatchJobCompleteLambda", {
318-
runtime: lambda.Runtime.PYTHON_3_9,
317+
runtime: lambda.Runtime.PYTHON_3_8,
319318
handler: "export_logs.handler",
320319
role: executionRole,
321320
code: lambda.Code.fromAsset("lambda"),

0 commit comments

Comments
 (0)