Light, fluffy, and always free - The AWS Local Emulator alternative
fix(emr): reject steps after cluster termination (#6115)
Jimmy Liu Jia0dab64637300
diff --git a/docs/services/emr.md b/docs/services/emr.mdindex 13ff27a27e..37cfab145f 100644--- a/docs/services/emr.md+++ b/docs/services/emr.md@@ -61,6 +61,8 @@ steps added later complete, reporting `ALL_STEPS_COMPLETED`. A cluster with no s`WAITING` until steps are added. Set `KeepJobFlowAliveWhenNoSteps` to `true` to keep the cluster`WAITING` after its steps complete. Automatic step-completion termination also applies whentermination protection is enabled.+`AddJobFlowSteps` rejects a terminated cluster without adding steps or changing its+termination status.After automatic or manual termination, instance groups and fleets report `TERMINATED` with zerorunning or provisioned capacity; their requested and target capacities remain recorded.`ListInstances` retains each group's instances with their original synthetic IDs and `TERMINATED`diff --git a/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java b/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.javaindex 8069d1ac37..bfe955869f 100644--- a/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java+++ b/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java@@ -201,6 +201,10 @@ public class EmrService {public synchronized List<String> addJobFlowSteps(String clusterId, List<EmrStep> steps) {EmrCluster cluster = requireCluster(clusterId);+ if ("TERMINATED".equals(cluster.getState())) {+ throw new AwsException("ValidationException",+ "A job flow that is shutting down, terminated, or finished may not be modified.", 400);+ }List<String> ids = new ArrayList<>();for (EmrStep step : steps) {initStep(step);diff --git a/src/test/java/io/github/hectorvent/floci/services/emr/EmrTransientIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/emr/EmrTransientIntegrationTest.javaindex 4e0cd0296d..30b82d88ce 100644--- a/src/test/java/io/github/hectorvent/floci/services/emr/EmrTransientIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/emr/EmrTransientIntegrationTest.java@@ -84,7 +84,7 @@ class EmrTransientIntegrationTest {}@Test- void addingStepsAfterUserTerminationPreservesReasonAndEndTime() {+ void addingStepsAfterUserTerminationIsRejectedWithoutChangingCluster() {String clusterId = emr("RunJobFlow", "{\"Name\":\"manually-ended-transient\",\"Instances\":{}}").then().statusCode(200).extract().path("JobFlowId");String clusterRequest = "{\"ClusterId\":\"" + clusterId + "\"}";@@ -97,14 +97,42 @@ class EmrTransientIntegrationTest {emr("AddJobFlowSteps","{\"JobFlowId\":\"" + clusterId + "\",\"Steps\":[{\"Name\":\"late\","+ "\"HadoopJarStep\":{\"Jar\":\"command-runner.jar\"}}]}")- .then().statusCode(200);- emr("ListSteps", clusterRequest).then().statusCode(200).body("Steps", hasSize(1));+ .then().statusCode(400)+ .body("__type", equalTo("ValidationException"))+ .body("message", equalTo(+ "A job flow that is shutting down, terminated, or finished may not be modified."));+ emr("ListSteps", clusterRequest).then().statusCode(200).body("Steps", hasSize(0));emr("DescribeCluster", clusterRequest).then().statusCode(200).body("Cluster.Status.State", equalTo("TERMINATED")).body("Cluster.Status.StateChangeReason.Code", equalTo("USER_REQUEST")).body("Cluster.Status.Timeline.EndDateTime", equalTo(endTime));}+ @Test+ void addingStepsAfterAutomaticTerminationIsRejected() {+ String clusterId = emr("RunJobFlow",+ "{\"Name\":\"auto-ended\",\"Instances\":{},"+ + "\"Steps\":[{\"Name\":\"initial\","+ + "\"HadoopJarStep\":{\"Jar\":\"command-runner.jar\"}}]}")+ .then().statusCode(200).extract().path("JobFlowId");+ String clusterRequest = "{\"ClusterId\":\"" + clusterId + "\"}";+ emr("DescribeCluster", clusterRequest).then().statusCode(200)+ .body("Cluster.Status.State", equalTo("TERMINATED"))+ .body("Cluster.Status.StateChangeReason.Code", equalTo("ALL_STEPS_COMPLETED"));++ emr("AddJobFlowSteps",+ "{\"JobFlowId\":\"" + clusterId + "\",\"Steps\":[{\"Name\":\"late\","+ + "\"HadoopJarStep\":{\"Jar\":\"command-runner.jar\"}}]}")+ .then().statusCode(400)+ .body("__type", equalTo("ValidationException"))+ .body("message", equalTo(+ "A job flow that is shutting down, terminated, or finished may not be modified."));+ emr("ListSteps", clusterRequest).then().statusCode(200).body("Steps", hasSize(1));+ emr("DescribeCluster", clusterRequest).then().statusCode(200)+ .body("Cluster.Status.State", equalTo("TERMINATED"))+ .body("Cluster.Status.StateChangeReason.Code", equalTo("ALL_STEPS_COMPLETED"));+ }+@Testvoid protectedCompletedClusterIsSkippedDuringMixedTermination() {String completedId = emr("RunJobFlow",