Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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;
}

4 changes: 2 additions & 2 deletions .tools/test/stacks/plugin/typescript/plugin_stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PluginStack extends cdk.Stack {
private adminAccountId: string;
private batchMemory: string;
private batchVcpus: string;
private batchStorage: string;
private batchStorage: number;

constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
Expand All @@ -44,7 +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
this.batchStorage = acctConfig[`${toolName}`]?.storage ?? "20"; // GiB
this.batchStorage = acctConfig[`${toolName}`]?.storage ?? 20; // GiB
}

const [jobDefinition, jobQueue] = this.initBatchFargate();
Expand Down
Loading