fix(emr): list an instance fleet's instances (#8183)

ListInstances listed only instance groups' instances, so a cluster made
of instance fleets listed none, though its core and task nodes run as
containers named by the private DNS names its instances would have.

- A fleet has an instance for each unit of its capacity, as its nodes
  do, its on-demand ones first, each of the first instance type in its
  InstanceTypeConfigs, which Floci now keeps, and with its
  InstanceFleetId.
- The primary fleet's instance is numbered first, i-00000000000000001
  at 10.0.0.1, as MasterPublicDnsName names it, and every other fleet's
  are at 10.<fleet>.0.<n>, the names its nodes run under, kept while
  another fleet resizes. One helper numbers groups and fleets for both.
- An ended fleet's instances stay listed as TERMINATED for 30 days, as
  an ended group's do, from its target capacities, which it can no
  longer change.
- InstanceGroupId, InstanceGroupTypes, InstanceFleetId and
  InstanceFleetType now narrow the listing, all given ones together;
  they were ignored.

A call lists at most 2,000 instances, building only that page, with a
Marker for the rest, so a fleet of any capacity costs one page, counted in longs, as a fleet's
two capacities add up past an int. A
cluster has instance groups or instance fleets, never both, as they
"cannot coexist in a cluster": RunJobFlow with both, AddInstanceGroups
on a cluster with fleets and AddInstanceFleet on one with groups are
refused, and so is a fleet without its required InstanceFleetType or an
InstanceTypeConfigs member without its required InstanceType.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-13 07:14:19 -04:00
1 parent babf8419f4
commit f5fd41a6ac
8 files changed
+467 -51

No files matched your search

@@ -248,4 +248,205 @@ class EmrResizeIntegrationTest {
equalTo(List.of("ip-10-2-0-1.ec2.internal", "ip-10-2-0-2.ec2.internal")));
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\"]}").then().statusCode(200);
}
@Test
@Order(11)
void aFleetsInstancesAreListedOnePerUnitOnDemandFirstAndKeepTheirAddresses() {
String id = emr("RunJobFlow", "{\"Name\":\"fleet-instances\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"CORE\",\"TargetOnDemandCapacity\":1,"
+ "\"TargetSpotCapacity\":2,\"InstanceTypeConfigs\":[{\"InstanceType\":\"r5.2xlarge\"},"
+ "{\"InstanceType\":\"m5.2xlarge\"}]},"
+ "{\"InstanceFleetType\":\"MASTER\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}")
.then().statusCode(200).extract().path("JobFlowId");
Response fleets = emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}");
String master = fleets.jsonPath().getString("InstanceFleets.find { it.InstanceFleetType == 'MASTER' }.Id");
String core = fleets.jsonPath().getString("InstanceFleets.find { it.InstanceFleetType == 'CORE' }.Id");
String task = emr("AddInstanceFleet", "{\"ClusterId\":\"" + id + "\",\"InstanceFleet\":"
+ "{\"InstanceFleetType\":\"TASK\",\"TargetSpotCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"c5.xlarge\"}]}}")
.then().statusCode(200).extract().path("InstanceFleetId");
String primary = "Instances.find { it.InstanceFleetId == '" + master + "' }";
String coreInstances = "Instances.findAll { it.InstanceFleetId == '" + core + "' }";
String taskInstances = "Instances.findAll { it.InstanceFleetId == '" + task + "' }";
// The primary node is numbered first, as DescribeCluster's MasterPublicDnsName names it, and each node as the
// cluster's containers are named.
emr("ListInstances", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
.body("Instances", hasSize(5))
.body("Instances.findAll { it.containsKey('InstanceGroupId') }", hasSize(0))
.body(primary + ".Ec2InstanceId", equalTo("i-00000000000000001"))
.body(primary + ".PrivateDnsName", equalTo("ip-10-0-0-1.ec2.internal"))
.body(primary + ".Market", equalTo("ON_DEMAND"))
.body(primary + ".InstanceType", equalTo("m5.xlarge"))
.body(coreInstances + ".PrivateIpAddress", equalTo(List.of("10.1.0.1", "10.1.0.2", "10.1.0.3")))
.body(coreInstances + ".Market", equalTo(List.of("ON_DEMAND", "SPOT", "SPOT")))
.body(coreInstances + ".InstanceType", equalTo(List.of("r5.2xlarge", "r5.2xlarge", "r5.2xlarge")))
.body(taskInstances + ".PrivateDnsName", equalTo(List.of("ip-10-2-0-1.ec2.internal")))
.body(taskInstances + ".Market", equalTo(List.of("SPOT")))
.body(taskInstances + ".InstanceType", equalTo(List.of("c5.xlarge")));
emr("DescribeCluster", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
.body("Cluster.MasterPublicDnsName", equalTo("ip-10-0-0-1.ec2.internal"));
emr("ModifyInstanceFleet", "{\"ClusterId\":\"" + id + "\",\"InstanceFleet\":"
+ "{\"InstanceFleetId\":\"" + core + "\",\"TargetSpotCapacity\":0}}").then().statusCode(200);
emr("ListInstances", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
.body("Instances", hasSize(3))
.body(primary + ".Ec2InstanceId", equalTo("i-00000000000000001"))
.body(coreInstances + ".PrivateIpAddress", equalTo(List.of("10.1.0.1")))
.body(taskInstances + ".PrivateIpAddress", equalTo(List.of("10.2.0.1")));
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\"]}").then().statusCode(200);
}
@Test
@Order(12)
void listInstancesKeepsTheGroupsOrFleetsItsFiltersName() {
String fleetsId = emr("RunJobFlow", "{\"Name\":\"fleet-filters\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"MASTER\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]},"
+ "{\"InstanceFleetType\":\"CORE\",\"TargetOnDemandCapacity\":2,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}")
.then().statusCode(200).extract().path("JobFlowId");
String core = emr("ListInstanceFleets", "{\"ClusterId\":\"" + fleetsId + "\"}").jsonPath()
.getString("InstanceFleets.find { it.InstanceFleetType == 'CORE' }.Id");
String fleets = "{\"ClusterId\":\"" + fleetsId + "\",";
emr("ListInstances", fleets + "\"InstanceFleetType\":\"CORE\"}").then().statusCode(200)
.body("Instances.Ec2InstanceId", equalTo(List.of("i-00000000000000002", "i-00000000000000003")));
emr("ListInstances", fleets + "\"InstanceFleetType\":\"MASTER\"}").then().statusCode(200)
.body("Instances.PrivateIpAddress", equalTo(List.of("10.0.0.1")));
emr("ListInstances", fleets + "\"InstanceFleetId\":\"" + core + "\"}").then().statusCode(200)
.body("Instances", hasSize(2));
emr("ListInstances", fleets + "\"InstanceFleetId\":\"" + core + "\",\"InstanceFleetType\":\"MASTER\"}")
.then().statusCode(200).body("Instances", hasSize(0));
emr("ListInstances", fleets + "\"InstanceGroupTypes\":[\"MASTER\"]}").then().statusCode(200)
.body("Instances", hasSize(0));
String groupsId = emr("RunJobFlow", "{\"Name\":\"group-filters\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceGroups\":[{\"InstanceRole\":\"MASTER\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1},"
+ "{\"InstanceRole\":\"CORE\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":2},"
+ "{\"InstanceRole\":\"TASK\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
.then().statusCode(200).extract().path("JobFlowId");
String task = emr("ListInstanceGroups", "{\"ClusterId\":\"" + groupsId + "\"}").jsonPath()
.getString("InstanceGroups.find { it.InstanceGroupType == 'TASK' }.Id");
String groups = "{\"ClusterId\":\"" + groupsId + "\",";
emr("ListInstances", groups + "\"InstanceGroupTypes\":[\"MASTER\"]}").then().statusCode(200)
.body("Instances.Ec2InstanceId", equalTo(List.of("i-00000000000000001")));
emr("ListInstances", groups + "\"InstanceGroupTypes\":[\"CORE\",\"TASK\"]}").then().statusCode(200)
.body("Instances.PrivateIpAddress", equalTo(List.of("10.1.0.1", "10.1.0.2", "10.2.0.1")));
emr("ListInstances", groups + "\"InstanceGroupId\":\"" + task + "\"}").then().statusCode(200)
.body("Instances.Ec2InstanceId", equalTo(List.of("i-00000000000000004")));
emr("ListInstances", groups + "\"InstanceGroupId\":\"" + task + "\",\"InstanceGroupTypes\":[\"CORE\"]}")
.then().statusCode(200).body("Instances", hasSize(0));
emr("ListInstances", groups + "\"InstanceFleetType\":\"MASTER\"}").then().statusCode(200)
.body("Instances", hasSize(0));
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + fleetsId + "\",\"" + groupsId + "\"]}").then().statusCode(200);
}
@Test
@Order(13)
void aListingGivesAtMostTwoThousandInstancesAndAMarkerForTheRest() {
// "up to a maximum of 2,000", a fleet of any capacity costing a page.
String id = emr("RunJobFlow", "{\"Name\":\"many-instances\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"MASTER\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]},"
+ "{\"InstanceFleetType\":\"CORE\",\"TargetOnDemandCapacity\":2500,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}")
.then().statusCode(200).extract().path("JobFlowId");
emr("ListInstances", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
.body("Instances", hasSize(2000))
.body("Instances[0].Ec2InstanceId", equalTo("i-00000000000000001"))
.body("Marker", equalTo("2000"));
emr("ListInstances", "{\"ClusterId\":\"" + id + "\",\"Marker\":\"2000\"}").then().statusCode(200)
.body("Instances", hasSize(501))
.body("Instances[0].Ec2InstanceId", equalTo("i-00000000000002001"))
.body("Instances[500].PrivateIpAddress", equalTo("10.1.9.214"))
.body("Marker", nullValue());
// The pages count what the filters keep.
emr("ListInstances", "{\"ClusterId\":\"" + id + "\",\"InstanceFleetType\":\"CORE\",\"Marker\":\"2000\"}")
.then().statusCode(200).body("Instances", hasSize(500));
emr("ListInstances", "{\"ClusterId\":\"" + id + "\",\"Marker\":\"next\"}").then().statusCode(400)
.body("__type", equalTo("InvalidRequestException"))
.body("message", equalTo("Invalid pagination token: next"));
// A fleet's two capacities add up past an int, and its last page is as cheap as its first.
String widest = emr("RunJobFlow", "{\"Name\":\"widest\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"MASTER\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]},"
+ "{\"InstanceFleetType\":\"CORE\",\"TargetOnDemandCapacity\":2147483647,"
+ "\"TargetSpotCapacity\":2147483647,\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}")
.then().statusCode(200).extract().path("JobFlowId");
emr("ListInstances", "{\"ClusterId\":\"" + widest + "\"}").then().statusCode(200)
.body("Instances", hasSize(2000)).body("Marker", equalTo("2000"));
emr("ListInstances", "{\"ClusterId\":\"" + widest + "\",\"Marker\":\"4294967293\"}").then().statusCode(200)
.body("Instances.Ec2InstanceId", equalTo(List.of("i-00000004294967294", "i-00000004294967295")))
.body("Instances.Market", equalTo(List.of("SPOT", "SPOT")))
.body("Marker", nullValue());
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\",\"" + widest + "\"]}").then().statusCode(200);
}
@Test
@Order(14)
void aClustersInstanceGroupsAndFleetsNeverMeet() {
// "instance fleets and instance groups cannot coexist in a cluster".
emr("RunJobFlow", "{\"Name\":\"both\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceGroups\":[{\"InstanceRole\":\"MASTER\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}],"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"CORE\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}").then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("The RunJobFlow request can contain InstanceFleets parameters or"
+ " InstanceGroups parameters, but not both."));
String fleetsId = emr("RunJobFlow", "{\"Name\":\"fleets\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"MASTER\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}")
.then().statusCode(200).extract().path("JobFlowId");
emr("AddInstanceGroups", "{\"JobFlowId\":\"" + fleetsId + "\",\"InstanceGroups\":[{\"InstanceRole\":\"TASK\","
+ "\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}").then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Cluster " + fleetsId + " uses instance fleets, and instance fleets and"
+ " instance groups cannot coexist in a cluster."));
String groupsId = emr("RunJobFlow", "{\"Name\":\"groups\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceGroups\":[{\"InstanceRole\":\"MASTER\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
.then().statusCode(200).extract().path("JobFlowId");
emr("AddInstanceFleet", "{\"ClusterId\":\"" + groupsId + "\",\"InstanceFleet\":{\"InstanceFleetType\":\"TASK\","
+ "\"TargetSpotCapacity\":1,\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}}")
.then().statusCode(400)
.body("__type", equalTo("InvalidRequestException"))
.body("message", equalTo("Cluster " + groupsId + " uses instance groups, and instance fleets and"
+ " instance groups cannot coexist in a cluster."));
emr("ListInstanceFleets", "{\"ClusterId\":\"" + groupsId + "\"}").then().statusCode(200)
.body("InstanceFleets", hasSize(0));
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + fleetsId + "\",\"" + groupsId + "\"]}").then().statusCode(200);
}
@Test
@Order(15)
void aFleetWithoutItsTypeOrAnInstanceTypeIsRefused() {
emr("RunJobFlow", "{\"Name\":\"typeless\",\"Instances\":{\"InstanceFleets\":["
+ "{\"TargetOnDemandCapacity\":1,\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"},"
+ "{\"WeightedCapacity\":1}]}]}}").then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("2 validation errors detected: Value null at"
+ " 'instances.instanceFleets.1.member.instanceFleetType' failed to satisfy constraint: Member"
+ " must not be null; Value null at"
+ " 'instances.instanceFleets.1.member.instanceTypeConfigs.2.member.instanceType' failed to"
+ " satisfy constraint: Member must not be null"));
String id = emr("RunJobFlow", "{\"Name\":\"typed\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceFleets\":[{\"InstanceFleetType\":\"MASTER\",\"TargetOnDemandCapacity\":1,"
+ "\"InstanceTypeConfigs\":[{\"InstanceType\":\"m5.xlarge\"}]}]}}")
.then().statusCode(200).extract().path("JobFlowId");
emr("AddInstanceFleet", "{\"ClusterId\":\"" + id + "\",\"InstanceFleet\":{\"InstanceFleetType\":\"TASK\","
+ "\"TargetSpotCapacity\":1,\"InstanceTypeConfigs\":[{\"BidPrice\":\"0.1\"}]}}").then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("1 validation error detected: Value null at"
+ " 'instanceFleet.instanceTypeConfigs.1.member.instanceType' failed to satisfy constraint:"
+ " Member must not be null"));
emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
.body("InstanceFleets", hasSize(1));
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\"]}").then().statusCode(200);
}
}
@@ -393,6 +393,21 @@ class EmrServiceContainerStepsTest {
fixture.clusterStorage.yarns.get(0).nodes());
}
@Test
void aFleetListedBeforeThePrimaryOneIsNamedAsListInstancesNamesIt() {
fixture.clusterStorage.ownNetwork = true;
EmrCluster requested = cluster("core-first", true, sparkStep("report", "CONTINUE"));
requested.setInstanceFleets(new ArrayList<>(List.of(fleet("CORE", 1, 0), fleet("MASTER", 1, 0),
fleet("TASK", 0, 1))));
service.runJobFlow(requested, REGION);
fixture.runStepThread();
assertEquals(List.of(new ClusterStorage.Node("1-1", "ip-10-1-0-1.ec2.internal", true),
new ClusterStorage.Node("2-1", "ip-10-2-0-1.ec2.internal", false)),
fixture.clusterStorage.yarns.get(0).nodes());
}
@Test
void noMoreNodesRunThanTheSettingAllowsCoreNodesFirst() {
fixture.clusterStorage.ownNetwork = true;
@@ -463,18 +463,21 @@ class EmrServiceTest {
EmrService service = fixture.service;
EmrCluster read = cluster("read", true, step("only"));
read.getInstanceGroups().add(group("CORE", 2));
read.getInstanceFleets().add(fleet("TASK", 2));
EmrCluster created = service.runJobFlow(read, REGION);
String id = created.getId();
String stepId = created.getSteps().get(0).getId();
// A cluster has instance groups or fleets, never both, so the fleet is another cluster's.
EmrCluster fleets = cluster("fleets", true, step("only"));
fleets.getInstanceFleets().add(fleet("TASK", 2));
String fleetsId = service.runJobFlow(fleets, REGION).getId();
List<EmrCluster> clusters = List.of(service.describeCluster(id),
service.listClusters(REGION, null, null, null).get(0), service.getClusterForInstances(id));
List<EmrStep> steps = List.of(service.describeStep(id, stepId), service.listSteps(id, null, null).get(0));
EmrInstanceGroup group = service.listInstanceGroups(id).get(0);
EmrInstanceFleet fleet = service.listInstanceFleets(id).get(0);
EmrInstanceFleet fleet = service.listInstanceFleets(fleetsId).get(0);
fixture.pass(Duration.ofSeconds(60));
service.terminateJobFlows(List.of(id));
service.terminateJobFlows(List.of(id, fleetsId));
fixture.pass(Duration.ofSeconds(30));
assertEquals("TERMINATED", service.describeCluster(id).getState());
@@ -1,6 +1,8 @@
package io.floci.aws.services.emr;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.services.emr.model.EmrCluster;
import io.floci.aws.services.emr.model.EmrInstanceFleet;
import io.floci.aws.services.emr.model.EmrInstanceGroup;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -9,6 +11,7 @@ import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
import static io.floci.aws.testing.EmrRequests.emr;
@@ -16,6 +19,7 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@QuarkusTest
@@ -170,6 +174,20 @@ class EmrTerminatedCapacityIntegrationTest {
assertEquals(2, EmrHandler.listedInstanceCount(legacy, false));
}
@Test
void aFleetStoredBeforeItsInstanceTypesWereKeptListsItsInstancesWithoutOne() throws Exception {
EmrCluster cluster = new EmrCluster();
cluster.getInstanceFleets().add(new ObjectMapper().readValue(
"{\"instanceFleetType\":\"CORE\",\"targetSpotCapacity\":2,\"provisionedSpotCapacity\":2}",
EmrInstanceFleet.class));
EmrHandler.ListedInstances listed = EmrHandler.listedInstances(cluster, false).getFirst();
assertEquals(2, listed.count());
assertNull(listed.instanceType());
assertEquals("SPOT", listed.marketOf(1));
}
private static String clusterRequest(String id) {
return "{\"ClusterId\":\"" + id + "\"}";
}
@@ -231,5 +249,13 @@ class EmrTerminatedCapacityIntegrationTest {
.body("InstanceFleets.find { it.InstanceFleetType == 'CORE' }.TargetSpotCapacity", equalTo(3))
.body("InstanceFleets.find { it.InstanceFleetType == 'CORE' }.ProvisionedOnDemandCapacity", equalTo(0))
.body("InstanceFleets.find { it.InstanceFleetType == 'CORE' }.ProvisionedSpotCapacity", equalTo(0));
// What the fleets ran, kept as the 30 days of ended instances.
emr("ListInstances", clusterRequest(id)).then().statusCode(200)
.body("Instances.Id", equalTo(List.of("ci-1" + id, "ci-2" + id, "ci-3" + id, "ci-4" + id,
"ci-5" + id, "ci-6" + id)))
.body("Instances.Market", equalTo(List.of("ON_DEMAND", "ON_DEMAND", "ON_DEMAND", "SPOT", "SPOT", "SPOT")))
.body("Instances.Status.State", equalTo(Collections.nCopies(6, "TERMINATED")));
emr("ListInstances", "{\"ClusterId\":\"" + id + "\",\"InstanceStates\":[\"RUNNING\"]}")
.then().statusCode(200).body("Instances", hasSize(0));
}
}