fix(emr): apply MERGE reconfigurations, step log locations, the scaling index and ServerUrl (#9129)

Four members EMR accepted and ignored now act as AWS documents them.

ModifyInstanceGroups' ReconfigurationType MERGE merges the group's new
Configurations into its own, as the Release Guide's "Reconfigure an
instance group in a running cluster" has it: "This option only adds or
modifies the new configurations that you submit. It preserves existing
configurations." A classification it names takes its properties over
the group's, nested configurations merged the same way, and the others
stay; OVERWRITE, the default, still replaces them. MERGE is "supported
for Amazon EMR releases 5.35.0 and 6.6.0 and later", so an earlier
release refuses it with ValidationException, in Floci's wording, and a
type that is neither gets the framework's enum message.

A step's StepMonitoringConfiguration sends its logs, and its
applications' container logs, to its own LogUri from release 7.11, as
its options "take precedence over any cluster-wide logging settings",
still only on a cluster with a LogUri. The guide gives no layout under
the step's destination, so it is the cluster's. A node removed while
such steps run puts its containers' logs there when they share one.
DescribeStep and ListSteps give the step's LogUri and EncryptionKeyArn
back.

A managed scaling policy's UtilizationPerformanceIndex is one of 1, 25,
50, 75 and 100: "If you set the index to values other than these, it
results in a validation error." One outside the model's 1 to 100 gets
the framework's ValidationException, another Floci's wording.

A session whose Spark Connect server answers reports ServerUrl, Floci's
own address in Spark Connect's sc:// form, where a call still needs
GetSessionEndpoint's token to reach the server; an ended session has
none.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-21 09:11:48 -04:00
1 parent d22ea96ecf
commit 7ae2339100
14 files changed
+411 -12

No files matched your search

@@ -236,6 +236,37 @@ class EmrIntegrationTest {
.body("Step.Status.State", equalTo("COMPLETED"));
}
/** A step's own log destination and key, its StepMonitoringConfiguration, read back as DescribeStep's members. */
@Test
void aStepGivesBackItsOwnLogUriAndEncryptionKey() {
String cluster = emr("RunJobFlow", "{\"Name\":\"step-logs\",\"ReleaseLabel\":\"emr-7.11.0\","
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true}}")
.then().statusCode(200).extract().path("JobFlowId");
try {
List<String> ids = emr("AddJobFlowSteps", "{\"JobFlowId\":\"" + cluster + "\",\"Steps\":["
+ "{\"Name\":\"logged\",\"ActionOnFailure\":\"CONTINUE\",\"HadoopJarStep\":{"
+ "\"Jar\":\"command-runner.jar\",\"Args\":[\"true\"]},\"StepMonitoringConfiguration\":{"
+ "\"S3MonitoringConfiguration\":{\"LogUri\":\"s3://step-logs/\","
+ "\"EncryptionKeyArn\":\"arn:aws:kms:us-east-1:000000000000:key/k\"}}},"
+ "{\"Name\":\"plain\",\"ActionOnFailure\":\"CONTINUE\",\"HadoopJarStep\":{"
+ "\"Jar\":\"command-runner.jar\",\"Args\":[\"true\"]}}]}")
.then().statusCode(200).extract().jsonPath().getList("StepIds", String.class);
emr("DescribeStep", "{\"ClusterId\":\"" + cluster + "\",\"StepId\":\"" + ids.get(0) + "\"}")
.then().statusCode(200)
.body("Step.LogUri", equalTo("s3://step-logs/"))
.body("Step.EncryptionKeyArn", equalTo("arn:aws:kms:us-east-1:000000000000:key/k"));
emr("DescribeStep", "{\"ClusterId\":\"" + cluster + "\",\"StepId\":\"" + ids.get(1) + "\"}")
.then().statusCode(200)
.body("Step", not(hasKey("LogUri")));
emr("ListSteps", "{\"ClusterId\":\"" + cluster + "\",\"StepIds\":[\"" + ids.get(0) + "\"]}")
.then().statusCode(200)
.body("Steps[0].LogUri", equalTo("s3://step-logs/"));
} finally {
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + cluster + "\"]}").then().statusCode(200);
}
}
@Test
@Order(8)
void listStepsNewestFirst() {
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.TestMethodOrder;
import static io.floci.aws.testing.EmrRequests.emr;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
@@ -79,10 +80,11 @@ class EmrPoliciesIntegrationTest {
void managedScalingPolicyPutGetRemove() {
emr("PutManagedScalingPolicy", cluster() + ",\"ManagedScalingPolicy\":{\"ComputeLimits\":"
+ "{\"UnitType\":\"VCPU\",\"MinimumCapacityUnits\":4,\"MaximumCapacityUnits\":32},"
+ "\"ScalingStrategy\":\"ADVANCED\"}}").then().statusCode(200);
+ "\"ScalingStrategy\":\"ADVANCED\",\"UtilizationPerformanceIndex\":25}}").then().statusCode(200);
emr("GetManagedScalingPolicy", cluster() + "}").then().statusCode(200)
.body("ManagedScalingPolicy.ComputeLimits.UnitType", equalTo("VCPU"))
.body("ManagedScalingPolicy.ScalingStrategy", equalTo("ADVANCED"));
.body("ManagedScalingPolicy.ScalingStrategy", equalTo("ADVANCED"))
.body("ManagedScalingPolicy.UtilizationPerformanceIndex", equalTo(25));
emr("RemoveManagedScalingPolicy", cluster() + "}").then().statusCode(200);
emr("GetManagedScalingPolicy", cluster() + "}").then().statusCode(200)
.body("$", anEmptyMap());
@@ -102,6 +104,18 @@ class EmrPoliciesIntegrationTest {
.then().statusCode(400).body("__type", equalTo("InvalidRequestException"));
emr("PutManagedScalingPolicy", "{\"ClusterId\":\"j-MISSING\",\"ManagedScalingPolicy\":" + MANAGED_SCALING + "}")
.then().statusCode(400).body("__type", equalTo("InvalidRequestException"));
// "Possible values are 1, 25, 50, 75 and 100": the model's range first, then the guide's values.
String indexed = cluster() + ",\"ManagedScalingPolicy\":{\"ComputeLimits\":{\"UnitType\":\"VCPU\","
+ "\"MinimumCapacityUnits\":4,\"MaximumCapacityUnits\":32},\"ScalingStrategy\":\"ADVANCED\","
+ "\"UtilizationPerformanceIndex\":%s}}";
emr("PutManagedScalingPolicy", indexed.formatted("0")).then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", containsString("'managedScalingPolicy.utilizationPerformanceIndex'"));
emr("PutManagedScalingPolicy", indexed.formatted("30")).then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", containsString("1, 25, 50, 75, 100"));
emr("GetManagedScalingPolicy", cluster() + "}").then().statusCode(200)
.body("$", anEmptyMap());
}
@Test
@@ -10,8 +10,10 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.List;
import java.util.Map;
import static io.floci.aws.testing.EmrRequests.emr;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.nullValue;
@@ -449,4 +451,63 @@ class EmrResizeIntegrationTest {
.body("InstanceFleets", hasSize(1));
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\"]}").then().statusCode(200);
}
// A cluster on releaseLabel whose task group starts with these configurations: the cluster's id, then the group's.
private static List<String> clusterWithTaskConfigurations(String releaseLabel, String configurations) {
String id = emr("RunJobFlow", "{\"Name\":\"reconfigure\",\"ReleaseLabel\":\"" + releaseLabel + "\","
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,\"InstanceGroups\":["
+ "{\"InstanceRole\":\"MASTER\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1},"
+ "{\"InstanceRole\":\"TASK\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1,"
+ "\"Configurations\":" + configurations + "}]}}")
.then().statusCode(200).extract().path("JobFlowId");
return List.of(id, emr("ListInstanceGroups", "{\"ClusterId\":\"" + id + "\"}").jsonPath()
.getString("InstanceGroups.find { it.InstanceGroupType == 'TASK' }.Id"));
}
/**
* MERGE "only adds or modifies the new configurations that you submit. It preserves existing configurations",
* where OVERWRITE, the default, replaces them.
*/
@Test
void aMergeReconfigurationKeepsTheGroupsOtherConfigurationsAndOverwriteReplacesThem() {
List<String> ids = clusterWithTaskConfigurations("emr-7.5.0", "[{\"Classification\":\"yarn-site\","
+ "\"Properties\":{\"a\":\"1\",\"b\":\"2\"}},{\"Classification\":\"core-site\","
+ "\"Properties\":{\"x\":\"1\"}}]");
String listGroups = "{\"ClusterId\":\"" + ids.get(0) + "\"}";
String task = "InstanceGroups.find { it.Id == '" + ids.get(1) + "' }";
emr("ModifyInstanceGroups", "{\"InstanceGroups\":[{\"InstanceGroupId\":\"" + ids.get(1) + "\","
+ "\"ReconfigurationType\":\"MERGE\",\"Configurations\":[{\"Classification\":\"yarn-site\","
+ "\"Properties\":{\"b\":\"3\",\"c\":\"4\"}},{\"Classification\":\"hive-site\","
+ "\"Properties\":{\"h\":\"1\"}}]}]}").then().statusCode(200);
emr("ListInstanceGroups", listGroups).then().statusCode(200)
.body(task + ".Configurations.Classification", equalTo(List.of("yarn-site", "core-site", "hive-site")))
// GPath answers null for a key named Properties read as ".Properties".
.body(task + ".Configurations[0].get('Properties')", equalTo(Map.of("a", "1", "b", "3", "c", "4")))
.body(task + ".Configurations[1].get('Properties').x", equalTo("1"))
.body(task + ".ConfigurationsVersion", equalTo(1));
emr("ModifyInstanceGroups", "{\"InstanceGroups\":[{\"InstanceGroupId\":\"" + ids.get(1) + "\","
+ "\"Configurations\":[{\"Classification\":\"spark\",\"Properties\":{\"s\":\"1\"}}]}]}")
.then().statusCode(200);
emr("ListInstanceGroups", listGroups).then().statusCode(200)
.body(task + ".Configurations.Classification", equalTo(List.of("spark")))
.body(task + ".ConfigurationsVersion", equalTo(2));
}
@Test
void aMergeBeforeItsReleasesOrAnUnknownTypeIsRefused() {
String early = clusterWithTaskConfigurations("emr-6.5.0", "[]").get(1);
String current = clusterWithTaskConfigurations("emr-7.5.0", "[]").get(1);
String change = "\"Configurations\":[{\"Classification\":\"spark\",\"Properties\":{}}]";
emr("ModifyInstanceGroups", "{\"InstanceGroups\":[{\"InstanceGroupId\":\"" + early + "\","
+ "\"ReconfigurationType\":\"MERGE\"," + change + "}]}").then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", containsString("5.35.0 and 6.6.0"));
emr("ModifyInstanceGroups", "{\"InstanceGroups\":[{\"InstanceGroupId\":\"" + current + "\","
+ "\"ReconfigurationType\":\"REPLACE\"," + change + "}]}").then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", containsString("'instanceGroups.1.member.reconfigurationType'"));
}
}
@@ -55,6 +55,23 @@ class EmrServiceTest {
* A tag call's {@code ResourceId} is the cluster the tag handlers find by it: one in the request's Region, or one
* stored with no Region, which they find in any.
*/
/** A MERGE keeps the classifications it does not name, and merges the ones it does, nested ones included. */
@Test
void aMergeReconfigurationMergesNestedConfigurationsByClassification() {
String merged = EmrService.mergedConfigurations("""
[{"Classification":"hadoop-env","Configurations":[{"Classification":"export",
"Properties":{"JAVA_HOME":"/usr/lib/jvm/java-17"}}]},
{"Classification":"spark","Properties":{"maximizeResourceAllocation":"true"}}]""", """
[{"Classification":"hadoop-env","Configurations":[{"Classification":"export",
"Properties":{"HADOOP_HEAPSIZE":"2048"}}]}]""");
assertEquals("[{\"Classification\":\"hadoop-env\",\"Configurations\":[{\"Classification\":\"export\","
+ "\"Properties\":{\"JAVA_HOME\":\"/usr/lib/jvm/java-17\",\"HADOOP_HEAPSIZE\":\"2048\"}}]},"
+ "{\"Classification\":\"spark\",\"Properties\":{\"maximizeResourceAllocation\":\"true\"}}]", merged);
assertEquals("[{\"Classification\":\"spark\"}]", EmrService.mergedConfigurations(null,
"[{\"Classification\":\"spark\"}]"));
}
@Test
void aTagCallsResourceIdIsTheClusterTheTagHandlersFind() {
EmrServiceFixture fixture = new EmrServiceFixture(0, 0, 0);
@@ -58,8 +58,11 @@ class EmrSessionServerTest {
EmrSession idle = awaitState(clusterId, started.getId(), "IDLE");
assertEquals("SUBMITTED", started.getState());
assertNull(started.getServerUrl());
assertNotNull(idle.getStartedAt());
assertEquals(idle.getStartedAt(), idle.getIdleSince());
// Floci's own address, whose proxy takes only a call with GetSessionEndpoint's token on to the server.
assertEquals("sc://localhost:4566", idle.getServerUrl());
SparkJobRunner.Job job = runner.jobs.get(started.getId());
assertEquals(EmrSessions.SPARK_CONNECT_PORT, job.listenPort());
assertEquals(List.of("--class", "org.apache.spark.sql.connect.service.SparkConnectServer", "spark-internal"),
@@ -120,6 +123,7 @@ class EmrSessionServerTest {
assertEquals("TERMINATING", terminating.getState());
assertTrue(runner.stopped.contains(sessionId));
assertEquals(EmrSessions.USER_REQUEST, terminated.getStateChangeReason());
assertNull(terminated.getServerUrl(), "an ended session's server has gone");
assertTrue(service.route(token).isEmpty());
}
@@ -1,6 +1,7 @@
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.EmrStep;
import io.floci.aws.services.lambda.launcher.BootstrapProcess;
import org.junit.jupiter.api.Test;
@@ -10,6 +11,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -41,6 +43,52 @@ class EmrSparkStepsTest {
"s3://bucket/jobs/report.jar", "--master", "kept"), EmrSparkSteps.application(step, false));
}
/** From 7.11 a step's own LogUri "take[s] precedence", but only on a cluster that logs. */
@Test
void aStepsLogsGoToItsOwnLogUriFromRelease711OnAClusterThatLogs() {
EmrStep step = step("command-runner.jar", null, "true");
step.setId("s-1");
step.setLogUri("s3://step-logs/");
EmrCluster cluster = new EmrCluster();
cluster.setId("j-1");
cluster.setLogUri("s3://cluster-logs/");
cluster.setReleaseLabel("emr-7.11.0");
assertEquals("s3://step-logs/j-1/steps/s-1/", EmrSparkSteps.logFolder(cluster, step));
assertEquals("s3://step-logs/j-1/containers/", EmrSparkSteps.containerLogFolder(cluster, step));
cluster.setReleaseLabel("emr-spark-8.0.0");
assertEquals("s3://step-logs/j-1/steps/s-1/", EmrSparkSteps.logFolder(cluster, step));
cluster.setReleaseLabel("emr-7.10.0");
assertEquals("s3://cluster-logs/j-1/steps/s-1/", EmrSparkSteps.logFolder(cluster, step));
cluster.setReleaseLabel("emr-7.11.0");
cluster.setLogUri(null);
assertNull(EmrSparkSteps.logFolder(cluster, step));
}
/** A node removed while steps run puts its containers' logs where those steps' container logs go. */
@Test
void aRemovedNodesLogsGoWhereTheRunningStepsContainerLogsGoWhenTheyShareOne() {
EmrCluster cluster = new EmrCluster();
cluster.setId("j-1");
cluster.setLogUri("s3://cluster-logs/");
cluster.setReleaseLabel("emr-7.11.0");
EmrStep own = step("command-runner.jar", null, "true");
own.setId("s-1");
own.setLogUri("s3://step-logs/");
own.setState("RUNNING");
EmrStep plain = step("command-runner.jar", null, "true");
plain.setId("s-2");
plain.setState("PENDING");
cluster.setSteps(new ArrayList<>(List.of(own, plain)));
assertEquals("s3://step-logs/j-1/containers/", EmrSparkSteps.nodeLogFolder(cluster));
plain.setState("RUNNING");
assertEquals("s3://cluster-logs/j-1/containers/", EmrSparkSteps.nodeLogFolder(cluster));
own.setState("COMPLETED");
plain.setState("COMPLETED");
assertEquals("s3://cluster-logs/j-1/containers/", EmrSparkSteps.nodeLogFolder(cluster));
}
@Test
void sparkSubmitMayBeNamedByItsPath() {
assertEquals(List.of("s3://bucket/jobs/report.py"), EmrSparkSteps.application(