Skip to content

Commit a344507

Browse files
authored
fix(batch): jobQueueName returns ARN instead of name (#25093)
`JobQueue.jobQueueName` returns the ARN. This fix parses the ARN to retrieve the name. Closes #23018 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e213a6d commit a344507

File tree

4 files changed

+91
-13
lines changed

4 files changed

+91
-13
lines changed

packages/@aws-cdk/aws-batch-alpha/README.md

+24-9
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ For example, if there are two shares defined as follows:
250250
The weight factors share the following relationship:
251251

252252
```math
253-
AvCpus / A_weight = BvCpus / B_weight
253+
A_{vCpus} / A_{Weight} = B_{vCpus} / B_{Weight}
254254
```
255255

256256
where `BvCpus` is the number of vCPUs allocated to jobs with share identifier `'B'`, and `B_weight` is the weight factor of `B`.
@@ -259,18 +259,33 @@ The total number of vCpus allocated to a share is equal to the amount of jobs in
259259
Let's say that each A job needs 32 VCpus (`A_requirement` = 32) and each B job needs 64 vCpus (`B_requirement` = 64):
260260

261261
```math
262-
A_vCpus = A_jobs * A_requirement
263-
B_vCpus = B_jobs * B_requirement
262+
A_{vCpus} = A_{Jobs} * A_{Requirement}
263+
```
264+
265+
```math
266+
B_{vCpus} = B_{Jobs} * B_{Requirement}
264267
```
265268

266269
We have:
267270

268271
```math
269-
A_vCpus / A_weight = B_vCpus / B_weight
270-
A_jobs * A_requirement / A_weight = B_jobs * B_requirement / B_weight
271-
A_jobs * 32 / 1 = B_jobs * 64 / 1
272-
A_jobs * 32 = B_jobs * 64
273-
A_jobs = B_jobs * 2
272+
A_{vCpus} / A_{Weight} = B_{vCpus} / B_{Weight}
273+
```
274+
275+
```math
276+
A_{Jobs} * A_{Requirement} / A_{Weight} = B_{Jobs} * B_{Requirement} / B_{Weight}
277+
```
278+
279+
```math
280+
A_{Jobs} * 32 / 1 = B_{Jobs} * 64 / 1
281+
```
282+
283+
```math
284+
A_{Jobs} * 32 = B_{Jobs} * 64
285+
```
286+
287+
```math
288+
A_{Jobs} = B_{Jobs} * 2
274289
```
275290

276291
Thus the scheduler will schedule two `'A'` jobs for each `'B'` job.
@@ -320,7 +335,7 @@ maximum vCPU capacity that should be reserved for shares that are *not in the qu
320335
The actual reserved percentage is defined by Batch as:
321336

322337
```math
323-
(computeReservation/100)^ActiveFairShares
338+
(\frac{computeReservation}{100}) ^ {ActiveFairShares}
324339
```
325340

326341
where `ActiveFairShares` is the number of shares for which there exists

packages/@aws-cdk/aws-batch-alpha/lib/ecs-container-definition.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ export interface IEcsContainerDefinition extends IConstruct {
309309
/**
310310
* The role that the container can assume.
311311
*
312+
* @default - no jobRole
313+
*
312314
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
313315
*/
314316
readonly jobRole?: iam.IRole;
@@ -414,7 +416,7 @@ export interface EcsContainerDefinitionProps {
414416
*
415417
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
416418
*
417-
* @default - a role will be created
419+
* @default - no job role
418420
*/
419421
readonly jobRole?: iam.IRole;
420422

packages/@aws-cdk/aws-batch-alpha/lib/job-queue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class JobQueue extends Resource implements IJobQueue {
198198
resource: 'job-queue',
199199
resourceName: this.physicalName,
200200
});
201-
this.jobQueueName = this.getResourceNameAttribute(resource.ref);
201+
this.jobQueueName = Stack.of(this).splitArn(this.jobQueueArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!;
202202

203203
this.node.addValidation({ validate: () => validateOrderedComputeEnvironments(this.computeEnvironments) });
204204
}
@@ -221,5 +221,5 @@ function validateOrderedComputeEnvironments(computeEnvironments: OrderedComputeE
221221
seenOrders.push(ce.order);
222222
}
223223

224-
return [];
224+
return seenOrders.length === 0 ? ['This JobQueue does not link any ComputeEnvironments'] : [];
225225
}

packages/@aws-cdk/aws-batch-alpha/test/job-queue.test.ts

+62-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Template } from 'aws-cdk-lib/assertions';
2-
import { Stack } from 'aws-cdk-lib';
2+
import { DefaultTokenResolver, Stack, StringConcat, Tokenization } from 'aws-cdk-lib';
33
import * as ec2 from 'aws-cdk-lib/aws-ec2';
44
import { FairshareSchedulingPolicy, JobQueue, ManagedEc2EcsComputeEnvironment } from '../lib';
55

@@ -87,6 +87,55 @@ test('JobQueue respects name', () => {
8787
});
8888
});
8989

90+
test('JobQueue name is parsed from arn', () => {
91+
// GIVEN
92+
const stack = new Stack();
93+
const vpc = new ec2.Vpc(stack, 'vpc');
94+
95+
// WHEN
96+
const queue = new JobQueue(stack, 'joBBQ', {
97+
computeEnvironments: [{
98+
computeEnvironment: new ManagedEc2EcsComputeEnvironment(stack, 'CE', {
99+
vpc,
100+
}),
101+
order: 1,
102+
}],
103+
priority: 10,
104+
jobQueueName: 'JoBBQ',
105+
});
106+
107+
// THEN
108+
expect(Tokenization.resolve(queue.jobQueueName, {
109+
scope: stack,
110+
resolver: new DefaultTokenResolver(new StringConcat()),
111+
})).toEqual({
112+
'Fn::Select': [
113+
1,
114+
{
115+
'Fn::Split': [
116+
'/',
117+
{
118+
'Fn::Select': [
119+
5,
120+
{
121+
'Fn::Split': [
122+
':',
123+
{
124+
'Fn::GetAtt': [
125+
'joBBQ74605869',
126+
'JobQueueArn',
127+
],
128+
},
129+
],
130+
},
131+
],
132+
},
133+
],
134+
},
135+
],
136+
});
137+
});
138+
90139
test('JobQueue respects schedulingPolicy', () => {
91140
// GIVEN
92141
const stack = new Stack();
@@ -199,3 +248,15 @@ test('JobQueue throws when the same order is assigned to multiple ComputeEnviron
199248
Template.fromStack(stack);
200249
}).toThrow(/assigns the same order to different ComputeEnvironments/);
201250
});
251+
252+
test('JobQueue throws when there are no linked ComputeEnvironments', () => {
253+
// GIVEN
254+
const stack = new Stack();
255+
256+
// WHEN
257+
new JobQueue(stack, 'joBBQ');
258+
259+
expect(() => {
260+
Template.fromStack(stack);
261+
}).toThrow(/This JobQueue does not link any ComputeEnvironments/);
262+
});

0 commit comments

Comments
 (0)