mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr): keep instance fleets' launch and resize specifications, and modify their configs (#9168)
An instance fleet dropped the LaunchSpecifications, ResizeSpecifications and Context that RunJobFlow and AddInstanceFleet gave it, and ModifyInstanceFleet changed its target capacities alone, ignoring the ResizeSpecifications, InstanceTypeConfigs and Context it took. - A fleet keeps its LaunchSpecifications, ResizeSpecifications and Context, and ListInstanceFleets gives them back. - ModifyInstanceFleet changes the ResizeSpecifications, InstanceTypeConfigs and Context it gives. The configs replace the fleet's own, as the Management Guide warns that "Not including fields can result in overwriting specifications you declared at launch", and must name every instance type the fleet has, as "You must include all instance types that are part of your instance fleet in the modify request". A request that leaves one out is refused with InvalidRequestException. Its configs are checked as AddInstanceFleet checks them, and on both calls specifications that are not an object, or a Context that is not a string, are refused with SerializationException. - AWS::EMR::Cluster no longer warns that a fleet's launch and resize specifications are not stored, and AWS::EMR::InstanceFleetConfig now applies a change to InstanceTypeConfigs or ResizeSpecifications in place rather than warning. A rollback puts them back, but not an instance type the update added, which every later request must include, nor resize specifications where the fleet had none, which no request can clear. The update is checked as ModifyInstanceFleet checks its request, before anything changes, and dropped configs or resize specifications are kept.
This commit is contained in:
1 parent
26eb1e9264
commit
cff222a6f1
9 files changed
+464
-49
No files matched your search
+119
-2
@@ -6,6 +6,7 @@ import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.emr.EmrHandler;
|
||||
import io.floci.aws.services.emr.EmrService;
|
||||
import io.floci.aws.services.emr.EmrService.InstanceFleetModification;
|
||||
import io.floci.aws.services.emr.EmrService.InstanceGroupModification;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceFleet;
|
||||
@@ -14,6 +15,7 @@ import io.floci.aws.services.emr.model.SecurityConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -22,6 +24,7 @@ import static io.floci.aws.services.cloudformation.provisioners.ProvisionContext
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -30,6 +33,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -424,11 +428,62 @@ class EmrCfnProvisionerTest {
|
||||
provisioner.provision(r, json(fleetProps(4)), ctx("if-TASK", fleetProps(1)));
|
||||
provisioner.rollbackUpdate(r);
|
||||
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK", 4, 0);
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK", 1, 0);
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK",
|
||||
new InstanceFleetModification(4, 0, null, null, null, null));
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK",
|
||||
new InstanceFleetModification(1, 0, null, null, null, null));
|
||||
assertEquals("if-TASK", r.getAttributes().get("InstanceFleetId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInstanceFleetsConfigsAndResizeSpecificationsChangeInPlaceAndARollbackKeepsAnAddedType() {
|
||||
String before = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}
|
||||
""".formatted(CLUSTER_ID);
|
||||
String after = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge", "WeightedCapacity": 2,
|
||||
"Configurations": [{"Classification": "spark", "ConfigurationProperties": {"a": "b"}}]},
|
||||
{"InstanceType": "r5.xlarge"}],
|
||||
"ResizeSpecifications": {"SpotResizeSpecification": {"TimeoutDurationMinutes": 20}}}
|
||||
""".formatted(CLUSTER_ID);
|
||||
StackResource r = typed("AWS::EMR::InstanceFleetConfig", "if-TASK");
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
EmrInstanceFleet live = new EmrInstanceFleet();
|
||||
live.setId("if-TASK");
|
||||
live.setTargetOnDemandCapacity(1);
|
||||
live.setInstanceTypeConfigs("[{\"InstanceType\":\"m5.xlarge\"}]");
|
||||
EmrInstanceFleet updated = new EmrInstanceFleet();
|
||||
updated.setId("if-TASK");
|
||||
updated.setInstanceTypeConfigs("[{\"InstanceType\":\"m5.xlarge\",\"WeightedCapacity\":2},"
|
||||
+ "{\"InstanceType\":\"r5.xlarge\"}]");
|
||||
updated.setInstanceTypes(new ArrayList<>(List.of("m5.xlarge", "r5.xlarge")));
|
||||
when(emr.listInstanceFleets(CLUSTER_ID)).thenReturn(List.of(live), List.of(updated));
|
||||
|
||||
provisioner.provision(r, json(after), ctx("if-TASK", before));
|
||||
provisioner.rollbackUpdate(r);
|
||||
|
||||
ArgumentCaptor<InstanceFleetModification> modifications =
|
||||
ArgumentCaptor.forClass(InstanceFleetModification.class);
|
||||
verify(emr, times(2)).modifyInstanceFleet(eq(CLUSTER_ID), eq("if-TASK"), modifications.capture());
|
||||
InstanceFleetModification update = modifications.getAllValues().get(0);
|
||||
assertEquals(json("{\"SpotResizeSpecification\":{\"TimeoutDurationMinutes\":20}}"),
|
||||
json(update.resizeSpecifications()));
|
||||
assertEquals(json("""
|
||||
[{"InstanceType": "m5.xlarge", "WeightedCapacity": 2,
|
||||
"Configurations": [{"Classification": "spark", "Properties": {"a": "b"}}]},
|
||||
{"InstanceType": "r5.xlarge"}]"""), json(update.instanceTypeConfigs()));
|
||||
assertEquals(List.of("m5.xlarge", "r5.xlarge"), update.instanceTypes());
|
||||
// The configs go back, but r5.xlarge stays: ModifyInstanceFleet refuses configs that leave a type out. The
|
||||
// fleet had no resize specifications, which no request can clear, so they stay too.
|
||||
InstanceFleetModification restore = modifications.getAllValues().get(1);
|
||||
assertNull(restore.resizeSpecifications());
|
||||
assertEquals(json("[{\"InstanceType\":\"m5.xlarge\"},{\"InstanceType\":\"r5.xlarge\"}]"),
|
||||
json(restore.instanceTypeConfigs()));
|
||||
assertEquals(List.of("m5.xlarge", "r5.xlarge"), restore.instanceTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInstanceGroupOrFleetDeleteShrinksItAndOneWhoseClusterEndedIsLeftAlone() {
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
@@ -481,4 +536,66 @@ class EmrCfnProvisionerTest {
|
||||
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK", 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void droppedFleetConfigsAreKeptAndAFleetStoredWithItsTypesAloneGetsThemBackOnRollback() {
|
||||
String before = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}
|
||||
""".formatted(CLUSTER_ID);
|
||||
String dropped = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 2}
|
||||
""".formatted(CLUSTER_ID);
|
||||
String weighted = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge", "WeightedCapacity": 4}]}
|
||||
""".formatted(CLUSTER_ID);
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
EmrInstanceFleet live = new EmrInstanceFleet();
|
||||
live.setId("if-TASK");
|
||||
live.setTargetOnDemandCapacity(1);
|
||||
live.setInstanceTypes(new ArrayList<>(List.of("m5.xlarge")));
|
||||
when(emr.listInstanceFleets(CLUSTER_ID)).thenReturn(List.of(live));
|
||||
|
||||
// Dropping the configs resizes the fleet and leaves its configs as they are.
|
||||
provisioner.provision(typed("AWS::EMR::InstanceFleetConfig", "if-TASK"), json(dropped),
|
||||
ctx("if-TASK", before));
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK",
|
||||
new InstanceFleetModification(2, 0, null, null, null, null));
|
||||
|
||||
// A fleet stored with its instance types alone gets a config naming each back, not the update's weight.
|
||||
StackResource r = typed("AWS::EMR::InstanceFleetConfig", "if-TASK");
|
||||
provisioner.provision(r, json(weighted), ctx("if-TASK", before));
|
||||
provisioner.rollbackUpdate(r);
|
||||
ArgumentCaptor<InstanceFleetModification> modifications =
|
||||
ArgumentCaptor.forClass(InstanceFleetModification.class);
|
||||
verify(emr, times(3)).modifyInstanceFleet(eq(CLUSTER_ID), eq("if-TASK"), modifications.capture());
|
||||
assertEquals(json("[{\"InstanceType\":\"m5.xlarge\"}]"),
|
||||
json(modifications.getAllValues().get(2).instanceTypeConfigs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFleetUpdateWhoseConfigsBreakTheVolumeLimitIsRefusedBeforeAnythingChanges() {
|
||||
String before = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}
|
||||
""".formatted(CLUSTER_ID);
|
||||
String tooMany = """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": 3,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge", "EbsConfiguration": {"EbsBlockDeviceConfigs": [
|
||||
{"VolumeSpecification": {"VolumeType": "gp3", "SizeInGB": 10}, "VolumesPerInstance": 26}]}}]}
|
||||
""".formatted(CLUSTER_ID);
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
EmrInstanceFleet live = new EmrInstanceFleet();
|
||||
live.setId("if-TASK");
|
||||
live.setTargetOnDemandCapacity(1);
|
||||
live.setInstanceTypeConfigs("[{\"InstanceType\":\"m5.xlarge\"}]");
|
||||
when(emr.listInstanceFleets(CLUSTER_ID)).thenReturn(List.of(live));
|
||||
|
||||
AwsException refused = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
typed("AWS::EMR::InstanceFleetConfig", "if-TASK"), json(tooMany), ctx("if-TASK", before)));
|
||||
|
||||
assertEquals("There is a limit of 25 volumes per instance.", refused.getMessage());
|
||||
verify(emr, never()).modifyInstanceFleet(eq(CLUSTER_ID), eq("if-TASK"), any(InstanceFleetModification.class));
|
||||
}
|
||||
}
|
||||
+82
@@ -97,6 +97,88 @@ class EmrInstanceTypeSpecificationsIntegrationTest {
|
||||
.body(specifications + "[0].WeightedCapacity", equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFleetsLaunchAndResizeSpecificationsAndContextAreKeptAndModifyInstanceFleetChangesThem() {
|
||||
String id = cluster("""
|
||||
[{"InstanceFleetType": "MASTER", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]},
|
||||
{"InstanceFleetType": "CORE", "TargetOnDemandCapacity": 1, "TargetSpotCapacity": 2,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}], "Context": "etl",
|
||||
"LaunchSpecifications": {"OnDemandSpecification": {"AllocationStrategy": "lowest-price"},
|
||||
"SpotSpecification": {"TimeoutDurationMinutes": 10, "TimeoutAction": "SWITCH_TO_ON_DEMAND",
|
||||
"AllocationStrategy": "capacity-optimized"}},
|
||||
"ResizeSpecifications": {"SpotResizeSpecification": {"TimeoutDurationMinutes": 20},
|
||||
"OnDemandResizeSpecification": {"TimeoutDurationMinutes": 30}}}]""");
|
||||
String core = "InstanceFleets.find { it.InstanceFleetType == 'CORE' }";
|
||||
String coreId = emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
|
||||
.body(core + ".Context", equalTo("etl"))
|
||||
.body(core + ".LaunchSpecifications.SpotSpecification.TimeoutAction", equalTo("SWITCH_TO_ON_DEMAND"))
|
||||
.body(core + ".LaunchSpecifications.OnDemandSpecification.AllocationStrategy", equalTo("lowest-price"))
|
||||
.body(core + ".ResizeSpecifications.OnDemandResizeSpecification.TimeoutDurationMinutes", equalTo(30))
|
||||
.extract().path(core + ".Id");
|
||||
|
||||
emr("ModifyInstanceFleet", """
|
||||
{"ClusterId": "%s", "InstanceFleet": {"InstanceFleetId": "%s", "TargetSpotCapacity": 3,
|
||||
"Context": "nightly", "InstanceTypeConfigs": [{"InstanceType": "m5.xlarge", "WeightedCapacity": 2,
|
||||
"Configurations": [{"Classification": "spark",
|
||||
"Properties": {"maximizeResourceAllocation": "true"}}]}],
|
||||
"ResizeSpecifications": {"SpotResizeSpecification": {"TimeoutDurationMinutes": 45}}}}
|
||||
""".formatted(id, coreId)).then().statusCode(200);
|
||||
|
||||
emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
|
||||
.body(core + ".TargetSpotCapacity", equalTo(3))
|
||||
.body(core + ".Context", equalTo("nightly"))
|
||||
.body(core + ".InstanceTypeSpecifications.InstanceType", equalTo(List.of("m5.xlarge")))
|
||||
.body(core + ".InstanceTypeSpecifications[0].WeightedCapacity", equalTo(2))
|
||||
.body(core + ".InstanceTypeSpecifications[0].Configurations[0].Classification", equalTo("spark"))
|
||||
.body(core + ".ResizeSpecifications.SpotResizeSpecification.TimeoutDurationMinutes", equalTo(45))
|
||||
.body(core + ".LaunchSpecifications.SpotSpecification.TimeoutDurationMinutes", equalTo(10));
|
||||
emr("ModifyInstanceFleet", """
|
||||
{"ClusterId": "%s", "InstanceFleet": {"InstanceFleetId": "%s",
|
||||
"InstanceTypeConfigs": [{"WeightedCapacity": 2}]}}
|
||||
""".formatted(id, coreId)).then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
// The Management Guide: "You must include all instance types that are part of your instance fleet".
|
||||
emr("ModifyInstanceFleet", """
|
||||
{"ClusterId": "%s", "InstanceFleet": {"InstanceFleetId": "%s",
|
||||
"InstanceTypeConfigs": [{"InstanceType": "r5.2xlarge"}]}}
|
||||
""".formatted(id, coreId)).then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"))
|
||||
.body("message", equalTo("The instance type configs must include every instance type of instance "
|
||||
+ "fleet " + coreId + "; missing m5.xlarge."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFleetMemberOfTheWrongJsonTypeIsRefusedAndLeavesTheFleetAsItWas() {
|
||||
String id = cluster("""
|
||||
[{"InstanceFleetType": "MASTER", "TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}]""");
|
||||
String fleet = """
|
||||
{"ClusterId": "%s", "InstanceFleet": {"InstanceFleetType": "TASK", "TargetSpotCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "c5.xlarge"}], %s}}""";
|
||||
emr("AddInstanceFleet", fleet.formatted(id, "\"LaunchSpecifications\": \"fast\""))
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
emr("AddInstanceFleet", fleet.formatted(id, "\"Context\": 7"))
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
String task = emr("AddInstanceFleet", fleet.formatted(id, "\"Context\": \"etl\""))
|
||||
.then().statusCode(200).extract().path("InstanceFleetId");
|
||||
|
||||
emr("ModifyInstanceFleet", """
|
||||
{"ClusterId": "%s", "InstanceFleet": {"InstanceFleetId": "%s", "TargetSpotCapacity": 2,
|
||||
"ResizeSpecifications": "slow"}}""".formatted(id, task))
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
emr("ModifyInstanceFleet", """
|
||||
{"ClusterId": "%s", "InstanceFleet": {"InstanceFleetId": "%s", "InstanceTypeConfigs": "c5.xlarge"}}
|
||||
""".formatted(id, task))
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
|
||||
String added = "InstanceFleets.find { it.Id == '" + task + "' }";
|
||||
emr("ListInstanceFleets", "{\"ClusterId\":\"" + id + "\"}").then().statusCode(200)
|
||||
.body(added + ".TargetSpotCapacity", equalTo(1))
|
||||
.body(added + ".Context", equalTo("etl"))
|
||||
.body("InstanceFleets", hasSize(2));
|
||||
}
|
||||
|
||||
/** The Management Guide: "There is a limit of 25 volumes per instance." */
|
||||
@Test
|
||||
void aConfigAttachingMoreThan25VolumesPerInstanceIsRefused() {
|
||||
|
||||
Reference in new issue
Block a user