mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(emr): refuse reading the managed scaling policy of an ended cluster (#8065)
GetManagedScalingPolicy returned the policy of a cluster that was shutting down or had ended. AWS answers ValidationException "A job flow that is shutting down, terminated, or finished may not be modified." there, as Terraform's acceptance runs recorded, and Terraform's provider reads that answer as the policy being gone. Floci kept returning it, so a refresh after termination kept a policy AWS reports gone. A TERMINATING, TERMINATED or TERMINATED_WITH_ERRORS cluster now gets that answer. emr.md no longer says no answer is recorded for the managed scaling calls: Terraform's provider also expects it from RemoveManagedScalingPolicy.
This commit is contained in:
1 parent
31fdfedc5c
commit
c9d9ba24f4
4 files changed
+40
-12
No files matched your search
@@ -104,9 +104,11 @@ A cluster that is `TERMINATING`, `TERMINATED` or `TERMINATED_WITH_ERRORS` also r
|
||||
the four `Set*` setters, and `Put` and `Remove` of its managed scaling, auto-termination and automatic
|
||||
scaling policies, with the same "shutting down" message: `ModifyCluster` as `InvalidRequestException`
|
||||
with `ErrorCode` `INVALID_JOB_SHUT_DOWN`, since its model declares that exception, and the others as
|
||||
`ValidationException`, since theirs declare none. AWS documents these operations for running clusters,
|
||||
but no answer for an ended one is recorded, so this is Floci's reading, taken from the operations whose
|
||||
answer is. A `Set*` request naming such a cluster changes none of the clusters it names. `AddTags` and
|
||||
`ValidationException`, since theirs declare none. `GetManagedScalingPolicy` gives such a cluster that
|
||||
`ValidationException` in place of its policy, as AWS was recorded doing, and Terraform's provider expects the
|
||||
same answer from `RemoveManagedScalingPolicy`. For the other operations, which AWS documents for running
|
||||
clusters, no answer for an ended one is recorded, so theirs is Floci's reading, taken from the operations
|
||||
whose answer is. A `Set*` request naming such a cluster changes none of the clusters it names. `AddTags` and
|
||||
`RemoveTags` refuse a `TERMINATED` or `TERMINATED_WITH_ERRORS` cluster, as the Management Guide says "you
|
||||
cannot add, edit, or remove tags from a terminated cluster", with `InvalidRequestException` "Tags cannot
|
||||
be modified on terminated clusters." The guide names no error: the message is the one a tagging tool
|
||||
|
||||
@@ -888,9 +888,16 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
});
|
||||
}
|
||||
|
||||
/** The cluster's managed scaling policy as raw JSON, or null when it has none. */
|
||||
/**
|
||||
* The cluster's managed scaling policy as raw JSON, or null when it has none. A cluster shutting down or ended
|
||||
* answers with the job flow message instead, as AWS was recorded doing (terraform-provider-aws#15541).
|
||||
*/
|
||||
public String getManagedScalingPolicy(String clusterId) {
|
||||
return call(() -> requireCluster(clusterId).getManagedScalingPolicy());
|
||||
return call(() -> {
|
||||
EmrCluster cluster = requireCluster(clusterId);
|
||||
rejectShutDownCluster(cluster, EmrService::jobFlowShutDownValidation);
|
||||
return cluster.getManagedScalingPolicy();
|
||||
});
|
||||
}
|
||||
|
||||
public void removeManagedScalingPolicy(String clusterId) {
|
||||
@@ -1130,18 +1137,19 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
}
|
||||
|
||||
/**
|
||||
* AddJobFlowSteps' answer for a job flow that is shutting down or ended. The operations whose models,
|
||||
* like AddJobFlowSteps', declare no InvalidRequestException give it too: AddInstanceGroups, the Set*
|
||||
* setters, and Put and Remove of the managed scaling, auto-termination and automatic scaling policies.
|
||||
* AddJobFlowSteps' and GetManagedScalingPolicy's answer for a job flow that is shutting down or ended. The
|
||||
* operations whose models, like theirs, declare no InvalidRequestException give it too: AddInstanceGroups, the
|
||||
* Set* setters, and Put and Remove of the managed scaling, auto-termination and automatic scaling policies.
|
||||
*/
|
||||
private static AwsException jobFlowShutDownValidation() {
|
||||
return new AwsException("ValidationException", JOB_FLOW_SHUT_DOWN, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses a change to a cluster that is shutting down or ended with {@code answer}, the job flow message in
|
||||
* the code the operation's model points at. AWS's answer is recorded for AddJobFlowSteps and
|
||||
* ModifyInstanceFleet only; the operations calling this, documented for running clusters, take it from them.
|
||||
* Refuses a call on a cluster that is shutting down or ended with {@code answer}, the job flow message in the
|
||||
* code the operation's model points at. AWS's answer is recorded for AddJobFlowSteps, ModifyInstanceFleet and
|
||||
* GetManagedScalingPolicy, and Terraform's provider expects it from RemoveManagedScalingPolicy; the other
|
||||
* operations calling this, documented for running clusters, take it from them.
|
||||
*/
|
||||
private static void rejectShutDownCluster(EmrCluster cluster, Supplier<AwsException> answer) {
|
||||
if (isShutDown(cluster)) {
|
||||
|
||||
@@ -183,12 +183,15 @@ class EmrPoliciesIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void anEndedClustersPoliciesCannotBePutOrRemoved() {
|
||||
void anEndedClustersPoliciesCannotBeChangedNorItsManagedScalingPolicyRead() {
|
||||
String core = ",\"InstanceGroupId\":\"" + coreGroupId + "\"";
|
||||
emr("PutManagedScalingPolicy", cluster() + ",\"ManagedScalingPolicy\":" + MANAGED_SCALING + "}")
|
||||
.then().statusCode(200);
|
||||
emr("PutAutoScalingPolicy", cluster() + core + ",\"AutoScalingPolicy\":" + AUTO_SCALING + "}")
|
||||
.then().statusCode(200);
|
||||
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}").then().statusCode(200);
|
||||
|
||||
assertShutDown("GetManagedScalingPolicy", cluster() + "}");
|
||||
assertShutDown("PutManagedScalingPolicy", cluster() + ",\"ManagedScalingPolicy\":" + MANAGED_SCALING + "}");
|
||||
assertShutDown("RemoveManagedScalingPolicy", cluster() + "}");
|
||||
assertShutDown("PutAutoTerminationPolicy", cluster() + ",\"AutoTerminationPolicy\":{\"IdleTimeout\":3600}}");
|
||||
|
||||
@@ -396,6 +396,21 @@ class EmrServiceTest {
|
||||
assertEquals(json(AUTO_SCALING).toString(), after.getInstanceGroups().get(0).getAutoScalingPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterShuttingDownHasNoManagedScalingPolicyToRead() {
|
||||
EmrServiceFixture fixture = new EmrServiceFixture(0, 0, 30);
|
||||
EmrService service = fixture.service;
|
||||
String id = service.runJobFlow(cluster("scaled", true), REGION).getId();
|
||||
service.putManagedScalingPolicy(id, json(MANAGED_SCALING));
|
||||
service.terminateJobFlows(List.of(id));
|
||||
|
||||
AwsException reading = assertThrows(AwsException.class, () -> service.getManagedScalingPolicy(id));
|
||||
|
||||
assertEquals("TERMINATING", service.describeCluster(id).getState());
|
||||
assertEquals("ValidationException", reading.getErrorCode());
|
||||
assertEquals(SHUT_DOWN, reading.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsChangeUntilTheClusterHasEnded() {
|
||||
EmrServiceFixture fixture = new EmrServiceFixture(0, 0, 30);
|
||||
|
||||
Reference in new issue
Block a user