fix(emr): make a uniform RunJobFlow cluster's master and core instance groups (#9107)

RunJobFlow's uniform form, MasterInstanceType, SlaveInstanceType and
InstanceCount in place of InstanceGroups or InstanceFleets, made no
instance groups, so ListInstanceGroups listed none, ListInstances no
instances, and with runner-mode docker the cluster ran on its primary
node alone. It now makes the groups the API reference describes: "If
the value is 1, the same instance serves as both the master and core
and task node. If the value is greater than 1, one instance is the
master node and all others are core and task nodes."

That is a MASTER group of one MasterInstanceType instance and, for a
count above 1, a CORE group of the rest as SlaveInstanceType, both
ON_DEMAND. The master group is named "Master InstanceGroup", as in
DescribeJobFlows' sample response; no source names the core group, so
Floci names it "Core InstanceGroup". A request that gives
InstanceGroups or InstanceFleets keeps its own.

A request for more than one instance without SlaveInstanceType is
refused with a ValidationException, as JobFlowInstancesConfig says "all
three must be present"; a single instance needs none, as AWS runs one
without it. However many instances a cluster asks for, in this form or
any other, its core and task nodes are now built no further than
yarn-max-worker-nodes, where every one asked for was built before the
rest were dropped.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-20 15:03:53 -04:00
1 parent c9aad84192
commit 6b420b166f
5 files changed
+157 -16

No files matched your search

@@ -570,4 +570,65 @@ class EmrIntegrationTest {
.then().statusCode(200);
}
}
@Test
@Order(21)
void aClusterGivenAsItsInstanceTypesAndCountGetsAMasterGroupAndACoreGroupOfTheRest() {
String uniform = emr("RunJobFlow", "{\"Name\":\"uniform\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"MasterInstanceType\":\"m5.xlarge\",\"SlaveInstanceType\":\"m5.large\",\"InstanceCount\":3}}")
.then().statusCode(200).extract().path("JobFlowId");
// One instance serves as both the master and the core node.
String single = emr("RunJobFlow", "{\"Name\":\"single\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"MasterInstanceType\":\"m5.xlarge\",\"InstanceCount\":1}}")
.then().statusCode(200).extract().path("JobFlowId");
// Instance groups given are the cluster's, whatever else it names.
String grouped = emr("RunJobFlow", "{\"Name\":\"grouped\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"MasterInstanceType\":\"m5.xlarge\",\"SlaveInstanceType\":\"m5.large\",\"InstanceCount\":3,"
+ "\"InstanceGroups\":[{\"Name\":\"only\",\"InstanceRole\":\"MASTER\","
+ "\"InstanceType\":\"m5.2xlarge\",\"InstanceCount\":1}]}}")
.then().statusCode(200).extract().path("JobFlowId");
String master = "InstanceGroups.find { it.InstanceGroupType == 'MASTER' }.";
String core = "InstanceGroups.find { it.InstanceGroupType == 'CORE' }.";
// Core nodes need their instance type: "all three must be present".
emr("RunJobFlow", "{\"Name\":\"no-core-type\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"MasterInstanceType\":\"m5.xlarge\",\"InstanceCount\":3}}")
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("SlaveInstanceType is required when InstanceCount is greater than 1."));
emr("ListClusters", "{}")
.then().statusCode(200)
.body("Clusters.findAll { it.Name == 'no-core-type' }", hasSize(0));
try {
emr("ListInstanceGroups", "{\"ClusterId\":\"" + uniform + "\"}")
.then().statusCode(200)
.body("InstanceGroups", hasSize(2))
.body(master + "Name", equalTo("Master InstanceGroup"))
.body(master + "InstanceType", equalTo("m5.xlarge"))
.body(master + "Market", equalTo("ON_DEMAND"))
.body(master + "RequestedInstanceCount", equalTo(1))
.body(core + "Name", equalTo("Core InstanceGroup"))
.body(core + "InstanceType", equalTo("m5.large"))
.body(core + "Market", equalTo("ON_DEMAND"))
.body(core + "RequestedInstanceCount", equalTo(2));
emr("ListInstances", "{\"ClusterId\":\"" + uniform + "\"}")
.then().statusCode(200)
.body("Instances", hasSize(3));
emr("DescribeCluster", "{\"ClusterId\":\"" + uniform + "\"}")
.then().statusCode(200)
.body("Cluster.InstanceCollectionType", equalTo("INSTANCE_GROUP"));
emr("ListInstanceGroups", "{\"ClusterId\":\"" + single + "\"}")
.then().statusCode(200)
.body("InstanceGroups", hasSize(1))
.body(master + "Name", equalTo("Master InstanceGroup"))
.body(master + "RequestedInstanceCount", equalTo(1));
emr("ListInstanceGroups", "{\"ClusterId\":\"" + grouped + "\"}")
.then().statusCode(200)
.body("InstanceGroups", hasSize(1))
.body(master + "Name", equalTo("only"))
.body(master + "InstanceType", equalTo("m5.2xlarge"));
} finally {
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + uniform + "\",\"" + single + "\",\"" + grouped
+ "\"]}").then().statusCode(200);
}
}
}
@@ -800,6 +800,25 @@ class EmrServiceTest {
assertEquals(Map.of("ErrorCode", "INVALID_JOB_SHUT_DOWN"), refused.getExtendedData());
}
/**
* No more core and task nodes are built than {@code yarn-max-worker-nodes}, 4 in the fixture, however many a
* cluster asks for: core nodes first, and none past the setting, so a cluster asking for billions costs no more
* than one asking for 4.
*/
@Test
void noMoreWorkerNodesAreBuiltThanTheSettingAllowsHoweverManyAClusterAsksFor() {
EmrServiceFixture fixture = new EmrServiceFixture(0, 0, 0);
EmrCluster requested = cluster("huge", true);
requested.getInstanceGroups().addAll(List.of(group("MASTER", 1), group("CORE", Integer.MAX_VALUE),
group("TASK", Integer.MAX_VALUE)));
EmrCluster cluster = fixture.service.runJobFlow(requested, REGION);
List<ClusterStorage.Node> nodes = fixture.service.workerNodes(cluster);
assertEquals(4, nodes.size());
assertTrue(nodes.stream().allMatch(ClusterStorage.Node::core), nodes.toString());
}
/** ModifyInstanceFleet's answer for a cluster that is starting or bootstrapping. */
private static void assertNotRunningOrWaiting(AwsException refused) {
assertEquals("InvalidRequestException", refused.getErrorCode());