Skip to content

Commit 29356f6

Browse files
authored
Fix AWS Batch spot instance detection (nextflow-io#6722)
1 parent ebb0890 commit 29356f6

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

plugins/nf-amazon/src/main/nextflow/cloud/aws/batch/AwsBatchHelper.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import software.amazon.awssdk.services.batch.model.DescribeJobsRequest
2323
import software.amazon.awssdk.services.ec2.Ec2Client
2424
import software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest
2525
import software.amazon.awssdk.services.ec2.model.Instance
26+
import software.amazon.awssdk.services.ec2.model.InstanceLifecycleType
2627
import software.amazon.awssdk.services.ecs.EcsClient
2728
import software.amazon.awssdk.services.ecs.model.DescribeContainerInstancesRequest
2829
import software.amazon.awssdk.services.ecs.model.DescribeTasksRequest
@@ -171,7 +172,7 @@ class AwsBatchHelper {
171172
}
172173

173174
private PriceModel getPrice(Instance instance) {
174-
instance.instanceLifecycle()=='spot' ? PriceModel.spot : PriceModel.standard
175+
instance.instanceLifecycle() == InstanceLifecycleType.SPOT ? PriceModel.spot : PriceModel.standard
175176
}
176177

177178
CloudMachineInfo getCloudInfoByQueueAndTaskArn(String queue, String taskArn) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2013-2024, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nextflow.cloud.aws.batch
18+
19+
import nextflow.cloud.types.PriceModel
20+
import software.amazon.awssdk.services.batch.BatchClient
21+
import software.amazon.awssdk.services.ec2.model.Instance
22+
import software.amazon.awssdk.services.ec2.model.InstanceLifecycleType
23+
import spock.lang.Specification
24+
import spock.lang.Unroll
25+
26+
/**
27+
* Tests for AwsBatchHelper
28+
*
29+
* @author Rob Syme <rob.syme@seqera.io>
30+
*/
31+
class AwsBatchHelperTest extends Specification {
32+
33+
@Unroll
34+
def 'should detect spot instance pricing model'() {
35+
given:
36+
def helper = new AwsBatchHelper(Mock(BatchClient), null)
37+
def instance = Instance.builder()
38+
.instanceLifecycle(lifecycle)
39+
.build()
40+
41+
when:
42+
def result = helper.getPrice(instance)
43+
44+
then:
45+
result == expected
46+
47+
where:
48+
lifecycle | expected
49+
InstanceLifecycleType.SPOT | PriceModel.spot
50+
InstanceLifecycleType.SCHEDULED | PriceModel.standard
51+
null | PriceModel.standard // on-demand instances return null
52+
}
53+
}

0 commit comments

Comments
 (0)