fix(emr): list each instance fleet's InstanceTypeSpecifications (#8354)

ListInstanceFleets wrote no InstanceTypeSpecifications: the fleet kept
only the names of the instance types it was created with. The Terraform
AWS provider reads instance_type_configs back from that member, a
ForceNew set in both aws_emr_cluster and aws_emr_instance_fleet, so a
fleet cluster read back empty after apply and every later plan replaced
it.

A fleet keeps the InstanceTypeConfigs it was given, from RunJobFlow and
AddInstanceFleet, and ListInstanceFleets returns each as the
InstanceTypeSpecification it describes: its type, bid price, custom AMI,
priority and configurations as given, a WeightedCapacity of 1 where it
sets none and a BidPriceAsPercentageOfOnDemandPrice of 100 where it sets
neither bid price, the defaults the API reference gives for both, and its
EbsConfiguration as one EbsBlockDevice per volume. The reference names no
devices, so they are /dev/sdb, /dev/sdc and on. A fleet stored before
this has its instance types alone, with the same defaults.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 15:19:19 -04:00
1 parent 7981cadc7c
commit c99d8ee5ea
4 files changed
+252

No files matched your search

@@ -0,0 +1,131 @@
package io.floci.aws.services.emr;
import io.floci.aws.testing.PartitionCleanup;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.util.List;
import static io.floci.aws.testing.EmrRequests.emr;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* {@code ListInstanceFleets} gives each fleet's {@code InstanceTypeConfigs} back as its
* {@code InstanceTypeSpecifications}, with the defaults the API reference gives where a config leaves them out, which is
* what a client reading a fleet's configuration back compares its own against.
*/
@QuarkusTest
class EmrInstanceTypeSpecificationsIntegrationTest {
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void eachInstanceTypeConfigIsListedAsTheSpecificationItDescribes() {
String id = cluster("""
[{"InstanceFleetType": "MASTER", "TargetOnDemandCapacity": 1,
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]},
{"InstanceFleetType": "CORE", "TargetOnDemandCapacity": 2, "TargetSpotCapacity": 4,
"InstanceTypeConfigs": [
{"InstanceType": "r5.2xlarge", "WeightedCapacity": 2, "BidPrice": "0.5",
"CustomAmiId": "ami-0123456789abcdef0", "Priority": 1.0,
"Configurations": [{"Classification": "spark", "Properties": {"maximizeResourceAllocation": "true"}}],
"EbsConfiguration": {"EbsOptimized": true, "EbsBlockDeviceConfigs": [
{"VolumeSpecification": {"VolumeType": "gp3", "SizeInGB": 64, "Iops": 3000, "Throughput": 125},
"VolumesPerInstance": 2},
{"VolumeSpecification": {"VolumeType": "gp2", "SizeInGB": 32}}]}},
{"InstanceType": "m5.2xlarge", "BidPriceAsPercentageOfOnDemandPrice": 60}]}]""");
String master = "InstanceFleets.find { it.InstanceFleetType == 'MASTER' }.InstanceTypeSpecifications";
String core = "InstanceFleets.find { it.InstanceFleetType == 'CORE' }.InstanceTypeSpecifications";
ValidatableResponse fleets = emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200);
fleets.body(master, hasSize(1))
.body(master + "[0].InstanceType", equalTo("m5.xlarge"))
.body(master + "[0].WeightedCapacity", equalTo(1))
.body(master + "[0].BidPriceAsPercentageOfOnDemandPrice", equalTo(100.0f))
.body(master + "[0]", not(hasKey("BidPrice")))
.body(master + "[0]", not(hasKey("EbsBlockDevices")))
.body(core, hasSize(2))
.body(core + "[0].InstanceType", equalTo("r5.2xlarge"))
.body(core + "[0].WeightedCapacity", equalTo(2))
.body(core + "[0].BidPrice", equalTo("0.5"))
.body(core + "[0]", not(hasKey("BidPriceAsPercentageOfOnDemandPrice")))
.body(core + "[0].CustomAmiId", equalTo("ami-0123456789abcdef0"))
.body(core + "[0].Priority", equalTo(1.0f))
.body(core + "[0].Configurations[0].Classification", equalTo("spark"))
// GPath answers null for a key named Properties read as ".Properties" or "['Properties']".
.body(core + "[0].Configurations[0].get('Properties').maximizeResourceAllocation", equalTo("true"))
.body(core + "[0].EbsOptimized", equalTo(true))
.body(core + "[0].EbsBlockDevices.Device", equalTo(List.of("/dev/sdb", "/dev/sdc", "/dev/sdd")))
.body(core + "[0].EbsBlockDevices.VolumeSpecification.VolumeType", equalTo(List.of("gp3", "gp3", "gp2")))
.body(core + "[0].EbsBlockDevices[1].VolumeSpecification.SizeInGB", equalTo(64))
.body(core + "[0].EbsBlockDevices[1].VolumeSpecification.Iops", equalTo(3000))
.body(core + "[0].EbsBlockDevices[1].VolumeSpecification.Throughput", equalTo(125))
.body(core + "[1].InstanceType", equalTo("m5.2xlarge"))
.body(core + "[1].WeightedCapacity", equalTo(1))
.body(core + "[1].BidPriceAsPercentageOfOnDemandPrice", equalTo(60.0f))
.body(core + "[1]", not(hasKey("BidPrice")));
}
@Test
void anAddedFleetListsItsSpecificationsToo() {
String id = cluster("""
[{"InstanceFleetType": "MASTER", "TargetOnDemandCapacity": 1,
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}]""");
String task = emr("AddInstanceFleet", "{\"ClusterId\":\"" + id + "\",\"InstanceFleet\":"
+ "{\"InstanceFleetType\":\"TASK\",\"TargetSpotCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"c5.xlarge\",\"BidPrice\":\"0.2\"}]}}")
.then().statusCode(200).extract().path("InstanceFleetId");
String specifications = "InstanceFleets.find { it.Id == '" + task + "' }.InstanceTypeSpecifications";
emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
.body(specifications + ".InstanceType", equalTo(List.of("c5.xlarge")))
.body(specifications + "[0].BidPrice", equalTo("0.2"))
.body(specifications + "[0].WeightedCapacity", equalTo(1));
}
/** The Management Guide: "There is a limit of 25 volumes per instance." */
@Test
void aConfigAttachingMoreThan25VolumesPerInstanceIsRefused() {
String tooMany = """
[{"InstanceFleetType": "MASTER", "TargetOnDemandCapacity": 1,
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge", "EbsConfiguration": {"EbsBlockDeviceConfigs": [
{"VolumeSpecification": {"VolumeType": "gp3", "SizeInGB": 32}, "VolumesPerInstance": 20},
{"VolumeSpecification": {"VolumeType": "gp2", "SizeInGB": 32}, "VolumesPerInstance": 6}]}}]}]""";
emr("RunJobFlow", "{\"Name\":\"too-many-volumes\",\"ReleaseLabel\":\"emr-7.2.0\","
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,\"InstanceFleets\":" + tooMany + "}}")
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("There is a limit of 25 volumes per instance."));
}
@Test
void devicesAreNamedPastSdzAsLinuxNamesThem() {
assertEquals("/dev/sdb", EmrHandler.deviceName(0));
assertEquals("/dev/sdz", EmrHandler.deviceName(24));
assertEquals("/dev/sdaa", EmrHandler.deviceName(25));
assertEquals("/dev/sdab", EmrHandler.deviceName(26));
}
/** A cluster with {@code fleets}, terminated after the test. */
private String cluster(String fleets) {
String id = emr("RunJobFlow", "{\"Name\":\"fleet-specifications\",\"ReleaseLabel\":\"emr-7.2.0\","
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,\"InstanceFleets\":" + fleets + "}}")
.then().statusCode(200).extract().path("JobFlowId");
cleanup.register(() -> emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\"]}").then().statusCode(200));
return id;
}
}