Skip to content

Commit

Permalink
Use storage: number when parsing account configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Nov 11, 2024
1 parent 4f9a86e commit fcfe092
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
39 changes: 32 additions & 7 deletions .tools/test/stacks/config/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ interface AccountConfig {
// https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html
vcpus?: string; // Count
memory?: string; // MiB, but limited based on vCPU count, see docs
storage?: string; // GiB, 20GiB to 200GiB
storage?: number; // GiB, 20GiB to 200GiB
}

type AccountConfigYaml = {
[K in keyof AccountConfig]: string
}

interface AccountConfigs {
Expand All @@ -20,17 +24,38 @@ interface AccountConfigs {
export function readAccountConfig(filePath: string): AccountConfigs {
try {
const fileContents = fs.readFileSync(filePath, "utf8");
const data: AccountConfigs = parse(fileContents);

Object.values(data).forEach((config) => {
if (!config.account_id || !config.status) {
throw new Error("Validation failed: Missing required account fields.");
const data = Object.entries(parse(fileContents) as Record<string, AccountConfigYaml>).reduce((data, [name, config]) => {
const {account_id, status, vcpus, memory, storage} = config;
if (!account_id) {
throw new Error(`Validation failed: Missing account_id field in ${name}`);
}
switch (status) {
case "enabled": // fallthrough
case "disabled":
break;
default:
throw new Error(`Validation failed: invalid status ${status} in ${name}`)
}
});
data[name] = {
account_id,
status,
vcpus,
memory,
storage: numberOrDefault(storage, 20),
}
return data;
}, {} as Record<string, AccountConfig>)

return data;
} catch (error) {
console.error("Failed to read or parse the YAML file:", { error });
throw error;
}
}

function numberOrDefault(storage: string | undefined, defaultValue: number) {
const batchStorage = Number(storage);
const batchStorageNumber = isNaN(batchStorage) ? defaultValue : batchStorage;
return batchStorageNumber;
}

26 changes: 26 additions & 0 deletions .tools/test/stacks/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es2020", "dom"],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": ["./node_modules/@types"],
"resolveJsonModule": true,
"esModuleInterop": true
},
"exclude": ["node_modules", "cdk.out"]
}
5 changes: 2 additions & 3 deletions .tools/test/stacks/plugin/typescript/plugin_stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class PluginStack extends cdk.Stack {
// https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html
this.batchMemory = acctConfig[`${toolName}`]?.memory ?? "16384"; // MiB
this.batchVcpus = acctConfig[`${toolName}`]?.vcpus ?? "4"; // CPUs
const batchStorage = Number(acctConfig[`${toolName}`]?.storage ?? undefined);
this.batchStorage = isNaN(batchStorage) ? 20 : batchStorage; // GiB
this.batchStorage = acctConfig[`${toolName}`]?.storage ?? 20; // GiB
}

const [jobDefinition, jobQueue] = this.initBatchFargate();
Expand Down Expand Up @@ -142,7 +141,7 @@ class PluginStack extends cdk.Stack {
},
],
ephemeralStorage: {
sizeInGiB: this.batchStorage,
sizeInGib: this.batchStorage,
},
environment: variableConfigJson,
},
Expand Down

0 comments on commit fcfe092

Please sign in to comment.