mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): provision EMR steps, instance groups and instance fleets (#9159)
A template can now create AWS::EMR::Step, AWS::EMR::InstanceGroupConfig and AWS::EMR::InstanceFleetConfig. None was served, so the stack reported CREATE_COMPLETE with nothing behind it. EmrCfnProvisioner adds them through AddJobFlowSteps, AddInstanceGroups and AddInstanceFleet, reading each as those calls read their requests, from methods EmrHandler now shares, and against the registry schemas, now in the vendored property types. - A step's Ref and Id are its id, and its LogUri and EncryptionKeyArn are its StepMonitoringConfiguration. Every property is create-only, so a change adds a new step, and a step stays in its cluster's history when deleted, as the schema's delete handler calls nothing. - An instance group's Ref and InstanceGroupId are its id. Its InstanceCount and AutoScalingPolicy change in place, and the delete removes its policy and shrinks it to nothing, as a group cannot be removed from its cluster. - An instance fleet's Ref and InstanceFleetId are its id. Its target capacities change in place through ModifyInstanceFleet, and a change to InstanceTypeConfigs or ResizeSpecifications is accepted with a warning and not applied, as Floci's ModifyInstanceFleet changes the capacities alone. The delete shrinks it to nothing. - A create-only change adds a new group or fleet; a later resource's failure, or a failure of the update itself, puts back what it had changed; and a group or fleet whose cluster has ended is left alone. A group's role and a fleet's type must be TASK, the one value the template reference allows, and a delete shrinks one once its cluster is running or waiting, waiting for one still starting, and removes a policy the group has.
This commit is contained in:
1 parent
2f99c0ae8c
commit
5db8d098e7
11 files changed
+1112
-21
No files matched your search
@@ -220,7 +220,7 @@ cross-resource references.
|
||||
| ECS | `Cluster`, `TaskDefinition`, `Service`, `CapacityProvider`, `ClusterCapacityProviderAssociations` |
|
||||
| EFS | `FileSystem` (metadata only, there is no NFS data plane), `MountTarget` (`SecurityGroups` update in place, every other property replaces), `AccessPoint` (`AccessPointTags` update in place, every other property replaces) |
|
||||
| EKS | `Cluster` (created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack, for `Logging`, for `AccessConfig.AuthenticationMode` (a mode cannot be moved back, so a stack update that does so fails, and a stack rollback restores it) and for `ResourcesVpcConfig` endpoint access and `PublicAccessCidrs`; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion`; a change to the subnets or security groups of `ResourcesVpcConfig` fails the resource, as the emulator's `UpdateClusterConfig` does not change them), `Nodegroup` (created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place) |
|
||||
| EMR | `Cluster` (created through `RunJobFlow`, once it is waiting or running, its master, core and task groups or fleets as `RunJobFlow`'s `InstanceGroups` or `InstanceFleets`; `AdditionalInfo`, `KerberosAttributes`, `OSReleaseLabel`, `EbsRootVolumeIops`, `EbsRootVolumeThroughput`, `PlacementGroupConfigs`, `LogEncryptionKmsKeyId` and `MonitoringConfiguration`, `Instances`' `Ec2SubnetIds`, additional security groups and `HadoopVersion`, a group's `EbsConfiguration` and `CustomAmiId` and a fleet's launch and resize specifications are accepted with a warning and not stored; task groups and fleets need unique names; a template that sets the read-only `Id` or `MasterPublicDNS` is refused; updated in place for `AutoTerminationPolicy`, `ManagedScalingPolicy`, `StepConcurrencyLevel`, `VisibleToAllUsers`, `Tags` (keeping tags added outside the stack), `TerminationProtected`, `UnhealthyNodeReplacement`, a core or task group's `InstanceCount` and `AutoScalingPolicy` and a core or task fleet's target capacities, a dropped one taking its default; any other change, within `Instances` included, replaces the cluster and terminates the old one once the update commits; a termination-protected cluster refuses the delete), `SecurityConfiguration` (created with `Name`, generated when the template gives none, and the `SecurityConfiguration` JSON, as an object or its text; both are create-only, so any change replaces it and deletes the old one once the update commits, and a change that keeps a template's own `Name` is refused, as for every custom-named resource), `Studio` (created with every property; a template that sets the read-only `Arn`, `StudioId` or `Url` is refused; updated in place through `UpdateStudio` for `Name`, `Description`, `SubnetIds` and `DefaultS3Location`, a dropped setting kept as it is, and for `Tags`, keeping tags added outside the stack; a change to `IdpAuthUrl` or `IdpRelayStateParameterName` is accepted with a warning and not applied, as no Studio API changes them; a rollback puts back the name, description, location and tags, but not subnets an update added, which `UpdateStudio` cannot take away; a change to a create-only property replaces the Studio and deletes the old one once the update commits), `StudioSessionMapping` (`Ref` is `StudioId|IdentityType|IdentityName`, the schema's primary identifier; `SessionPolicyArn` updates in place, and a change to any of the three others replaces the mapping) |
|
||||
| EMR | `Cluster` (created through `RunJobFlow`, once it is waiting or running, its master, core and task groups or fleets as `RunJobFlow`'s `InstanceGroups` or `InstanceFleets`; `AdditionalInfo`, `KerberosAttributes`, `OSReleaseLabel`, `EbsRootVolumeIops`, `EbsRootVolumeThroughput`, `PlacementGroupConfigs`, `LogEncryptionKmsKeyId` and `MonitoringConfiguration`, `Instances`' `Ec2SubnetIds`, additional security groups and `HadoopVersion`, a group's `EbsConfiguration` and `CustomAmiId` and a fleet's launch and resize specifications are accepted with a warning and not stored; task groups and fleets need unique names; a template that sets the read-only `Id` or `MasterPublicDNS` is refused; updated in place for `AutoTerminationPolicy`, `ManagedScalingPolicy`, `StepConcurrencyLevel`, `VisibleToAllUsers`, `Tags` (keeping tags added outside the stack), `TerminationProtected`, `UnhealthyNodeReplacement`, a core or task group's `InstanceCount` and `AutoScalingPolicy` and a core or task fleet's target capacities, a dropped one taking its default; any other change, within `Instances` included, replaces the cluster and terminates the old one once the update commits; a termination-protected cluster refuses the delete), `InstanceGroupConfig` (a `TASK` group, the one role the reference allows, added through `AddInstanceGroups`; `InstanceCount` and `AutoScalingPolicy` update in place, and a create-only change adds a new group; the delete removes its policy and shrinks it to nothing, as a group cannot be removed from its cluster), `InstanceFleetConfig` (a `TASK` fleet, the one type the reference allows, added through `AddInstanceFleet`; `TargetOnDemandCapacity` and `TargetSpotCapacity` update in place through `ModifyInstanceFleet`, a change to `InstanceTypeConfigs` or `ResizeSpecifications` is accepted with a warning and not applied, and a create-only change adds a new fleet; the delete shrinks the fleet to nothing, as a fleet cannot be removed from its cluster), `Step` (added through `AddJobFlowSteps`, `LogUri` and `EncryptionKeyArn` as its `StepMonitoringConfiguration`; every property is create-only, so a change adds a new step, and a step stays in its cluster's history when deleted, as the schema's delete handler calls nothing), `SecurityConfiguration` (created with `Name`, generated when the template gives none, and the `SecurityConfiguration` JSON, as an object or its text; both are create-only, so any change replaces it and deletes the old one once the update commits, and a change that keeps a template's own `Name` is refused, as for every custom-named resource), `Studio` (created with every property; a template that sets the read-only `Arn`, `StudioId` or `Url` is refused; updated in place through `UpdateStudio` for `Name`, `Description`, `SubnetIds` and `DefaultS3Location`, a dropped setting kept as it is, and for `Tags`, keeping tags added outside the stack; a change to `IdpAuthUrl` or `IdpRelayStateParameterName` is accepted with a warning and not applied, as no Studio API changes them; a rollback puts back the name, description, location and tags, but not subnets an update added, which `UpdateStudio` cannot take away; a change to a create-only property replaces the Studio and deletes the old one once the update commits), `StudioSessionMapping` (`Ref` is `StudioId|IdentityType|IdentityName`, the schema's primary identifier; `SessionPolicyArn` updates in place, and a change to any of the three others replaces the mapping) |
|
||||
| EMR on EKS | `VirtualCluster` (created with `Name`, `ContainerProvider`, `SecurityConfigurationId`, `SessionEnabled` and `Tags`; a template that sets the read-only `Arn` or `Id` is refused; updated in place for `Tags` alone, which end as the template lists them, any other but an `aws:` one removed; a change to any other property replaces the virtual cluster, as the registry marks them create-only, and terminates the old one once the update commits; an update of a virtual cluster that is terminated or gone fails) |
|
||||
| EMR Serverless | `Application` (created with every property, `Name` and `Type` included; updated in place through `UpdateApplication` for the settings a template changes, a dropped setting kept as it is but for `InitialCapacity`, which is cleared, and for `Tags`, which end as the template lists them, any other removed; a change to `Name` or `Type` replaces the application and deletes the old one once the update commits; neither an update nor a delete stops a `STARTED` application, so one it refuses fails the resource, as on AWS) |
|
||||
| RDS | `DBInstance` (starts a real container), `DBCluster` (starts a real container), `DBSubnetGroup`, `DBParameterGroup`, `DBClusterParameterGroup`, `DBProxy`, `DBProxyTargetGroup` |
|
||||
|
||||
+367
-10
@@ -63,6 +63,29 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
private static final Logger LOG = Logger.getLogger(EmrCfnProvisioner.class);
|
||||
private static final String SECURITY_CONFIGURATION = "AWS::EMR::SecurityConfiguration";
|
||||
private static final String CLUSTER = "AWS::EMR::Cluster";
|
||||
private static final String STEP = "AWS::EMR::Step";
|
||||
private static final String INSTANCE_GROUP = "AWS::EMR::InstanceGroupConfig";
|
||||
private static final String INSTANCE_FLEET = "AWS::EMR::InstanceFleetConfig";
|
||||
/**
|
||||
* The cluster an instance group or fleet belongs to, which its update and delete need; a resource it uses, so a
|
||||
* replacement's rollback puts it back with the prior id.
|
||||
*/
|
||||
static final String CLUSTER_ID_ATTR = CfnRollback.USES_ATTR_PREFIX + "EmrCluster";
|
||||
/** What an in-place instance group or fleet update is about to change, for {@link #rollbackUpdate}. */
|
||||
static final String CAPACITY_SNAPSHOT_ATTR = "__FlociEmrCapacityUpdateSnapshot";
|
||||
/**
|
||||
* The auto scaling policy the stack last applied to an instance group, absent for none; kept beside the cluster id
|
||||
* so a replacement's rollback puts it back too.
|
||||
*/
|
||||
static final String GROUP_POLICY_ATTR = CfnRollback.USES_ATTR_PREFIX + "EmrInstanceGroupPolicy";
|
||||
/** The instance group properties AddInstanceGroups takes as the template writes them. */
|
||||
private static final List<String> INSTANCE_GROUP_MEMBERS = List.of("InstanceRole", "InstanceType",
|
||||
"InstanceCount", "Name", "Market", "BidPrice", "CustomAmiId", "Configurations", "EbsConfiguration",
|
||||
"AutoScalingPolicy");
|
||||
/** The instance fleet properties AddInstanceFleet takes as the template writes them. */
|
||||
private static final List<String> INSTANCE_FLEET_MEMBERS = List.of("InstanceFleetType", "Name",
|
||||
"TargetOnDemandCapacity", "TargetSpotCapacity", "InstanceTypeConfigs", "LaunchSpecifications",
|
||||
"ResizeSpecifications");
|
||||
private static final int NAME_MAX_LENGTH = 255;
|
||||
/** What an in-place cluster update is about to change, for {@link #rollbackUpdate} to put back. */
|
||||
static final String CLUSTER_SNAPSHOT_ATTR = "__FlociEmrClusterUpdateSnapshot";
|
||||
@@ -106,7 +129,7 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
|
||||
@Override
|
||||
public Set<String> resourceTypes() {
|
||||
return Set.of(SECURITY_CONFIGURATION, CLUSTER);
|
||||
return Set.of(SECURITY_CONFIGURATION, CLUSTER, STEP, INSTANCE_GROUP, INSTANCE_FLEET);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,6 +145,7 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
@Override
|
||||
public UpdateCleanupResult completeUpdate(StackResource resource) {
|
||||
resource.getAttributes().remove(CLUSTER_SNAPSHOT_ATTR);
|
||||
resource.getAttributes().remove(CAPACITY_SNAPSHOT_ATTR);
|
||||
return ReplacementCleanup.complete(resource, this::delete);
|
||||
}
|
||||
|
||||
@@ -131,12 +155,13 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
*/
|
||||
@Override
|
||||
public void mergeFailedUpdateResourceTracking(StackResource previous, StackResource attempted) {
|
||||
CfnRollback.carryFailedUndoSnapshot(previous, attempted, CLUSTER_SNAPSHOT_ATTR);
|
||||
CfnRollback.carryFailedUndoSnapshot(previous, attempted, CLUSTER_SNAPSHOT_ATTR, CAPACITY_SNAPSHOT_ATTR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearUpdate(StackResource resource) {
|
||||
resource.getAttributes().remove(CLUSTER_SNAPSHOT_ATTR);
|
||||
resource.getAttributes().remove(CAPACITY_SNAPSHOT_ATTR);
|
||||
ReplacementCleanup.clear(resource);
|
||||
}
|
||||
|
||||
@@ -149,6 +174,21 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (ReplacementCleanup.rollback(resource, this::delete)) {
|
||||
return true;
|
||||
}
|
||||
JsonNode capacity = CfnRollback.updateSnapshot(resource, CAPACITY_SNAPSHOT_ATTR);
|
||||
if (capacity != null) {
|
||||
restoreCapacity(capacity, true, true);
|
||||
if (capacity.has("groupId")) {
|
||||
// The policy the group has again, which the next update and the delete are compared with.
|
||||
JsonNode policy = capacity.get("policy");
|
||||
if (policy == null || policy.isNull()) {
|
||||
resource.getAttributes().remove(GROUP_POLICY_ATTR);
|
||||
} else {
|
||||
resource.getAttributes().put(GROUP_POLICY_ATTR, policy.toString());
|
||||
}
|
||||
}
|
||||
resource.getAttributes().remove(CAPACITY_SNAPSHOT_ATTR);
|
||||
return true;
|
||||
}
|
||||
JsonNode snapshot = CfnRollback.updateSnapshot(resource, CLUSTER_SNAPSHOT_ATTR);
|
||||
if (snapshot == null) {
|
||||
return false;
|
||||
@@ -166,6 +206,7 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
@Override
|
||||
public void provision(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
r.getAttributes().remove(CLUSTER_SNAPSHOT_ATTR);
|
||||
r.getAttributes().remove(CAPACITY_SNAPSHOT_ATTR);
|
||||
if (ctx.isUpdate()) {
|
||||
ReplacementCleanup.endRollbackRetry(r);
|
||||
}
|
||||
@@ -174,6 +215,9 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
switch (r.getResourceType()) {
|
||||
case SECURITY_CONFIGURATION -> provisionSecurityConfiguration(r, props, ctx, stub);
|
||||
case CLUSTER -> provisionCluster(r, props, ctx, stub);
|
||||
case STEP -> provisionStep(r, props, ctx, stub);
|
||||
case INSTANCE_GROUP -> provisionInstanceGroup(r, props, ctx, stub);
|
||||
case INSTANCE_FLEET -> provisionInstanceFleet(r, props, ctx, stub);
|
||||
default -> throw new IllegalStateException("EmrCfnProvisioner cannot provision " + r.getResourceType());
|
||||
}
|
||||
ReplacementCleanup.record(r, ctx, attributesBefore);
|
||||
@@ -303,14 +347,7 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
if (template.has("Steps")) {
|
||||
ArrayNode steps = request.putArray("Steps");
|
||||
template.get("Steps").forEach(step -> {
|
||||
ObjectNode copy = step.deepCopy();
|
||||
JsonNode jar = copy.path("HadoopJarStep");
|
||||
if (jar instanceof ObjectNode hadoop && hadoop.has("StepProperties")) {
|
||||
hadoop.set("Properties", hadoop.remove("StepProperties"));
|
||||
}
|
||||
steps.add(copy);
|
||||
});
|
||||
template.get("Steps").forEach(step -> steps.add(stepRequest(step)));
|
||||
}
|
||||
ObjectNode instances = template.get("Instances") instanceof ObjectNode given ? given.deepCopy()
|
||||
: MAPPER.createObjectNode();
|
||||
@@ -334,6 +371,15 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
return request;
|
||||
}
|
||||
|
||||
/** A step as the API names it: the template's {@code StepProperties} are its {@code HadoopJarStep}'s Properties. */
|
||||
private static ObjectNode stepRequest(JsonNode step) {
|
||||
ObjectNode copy = step.deepCopy();
|
||||
if (copy.path("HadoopJarStep") instanceof ObjectNode hadoop && hadoop.has("StepProperties")) {
|
||||
hadoop.set("Properties", hadoop.remove("StepProperties"));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static void addRole(ArrayNode into, String roleMember, String role, JsonNode config) {
|
||||
if (config == null || !config.isObject()) {
|
||||
return;
|
||||
@@ -645,6 +691,24 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
}
|
||||
|
||||
/** The cluster once it is running, waiting or has ended, or as it is when the wait runs out. */
|
||||
private EmrCluster awaitSettled(String id) {
|
||||
Instant deadline = Instant.now().plus(READY_TIMEOUT);
|
||||
while (true) {
|
||||
EmrCluster cluster = emrService.describeCluster(id);
|
||||
if (READY.contains(cluster.getState()) || ENDED.contains(cluster.getState())
|
||||
|| Instant.now().isAfter(deadline)) {
|
||||
return cluster;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted waiting for EMR cluster " + id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void publishCluster(StackResource r, EmrCluster cluster) {
|
||||
r.setPhysicalId(cluster.getId());
|
||||
r.getAttributes().put("Id", cluster.getId());
|
||||
@@ -653,6 +717,290 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Steps, instance groups and fleets ────────────────────────────
|
||||
|
||||
/**
|
||||
* A step is added through AddJobFlowSteps; every property of it is create-only, so a change adds the new one, and
|
||||
* the old one stays in the cluster's history, as the schema's delete handler calls nothing. Its {@code LogUri} and
|
||||
* {@code EncryptionKeyArn} are AddJobFlowSteps' {@code StepMonitoringConfiguration}.
|
||||
*/
|
||||
private void provisionStep(StackResource r, JsonNode props, ProvisionContext ctx, boolean stub) {
|
||||
JsonNode template = new CfnPropertyTypes.HandlerReader(ctx.engine()).read(STEP, props);
|
||||
refuseReadOnly(template, "Id");
|
||||
if (ctx.isUpdate() && !stub && !ctx.changes(STEP, props).requiresReplacement()) {
|
||||
r.setPhysicalId(ctx.priorPhysicalId());
|
||||
r.getAttributes().put("Id", ctx.priorPhysicalId());
|
||||
return;
|
||||
}
|
||||
ObjectNode step = MAPPER.createObjectNode();
|
||||
step.set("Name", template.get("Name"));
|
||||
step.set("ActionOnFailure", template.get("ActionOnFailure"));
|
||||
step.set("HadoopJarStep", stepRequest(template).get("HadoopJarStep"));
|
||||
if (template.has("LogUri") || template.has("EncryptionKeyArn")) {
|
||||
ObjectNode s3 = step.putObject("StepMonitoringConfiguration").putObject("S3MonitoringConfiguration");
|
||||
if (template.has("LogUri")) {
|
||||
s3.set("LogUri", template.get("LogUri"));
|
||||
}
|
||||
if (template.has("EncryptionKeyArn")) {
|
||||
s3.set("EncryptionKeyArn", template.get("EncryptionKeyArn"));
|
||||
}
|
||||
}
|
||||
List<String> ids = emrService.addJobFlowSteps(template.path("JobFlowId").asText(),
|
||||
emrHandler.stepsFrom(MAPPER.createArrayNode().add(step), null));
|
||||
r.setPhysicalId(ids.get(0));
|
||||
r.getAttributes().put("Id", ids.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* An instance group is added through AddInstanceGroups; its {@code InstanceCount} and {@code AutoScalingPolicy}
|
||||
* change in place through ModifyInstanceGroups and Put/RemoveAutoScalingPolicy, as the update handler's permissions
|
||||
* say, and any create-only change adds a new group. A rollback puts back the count and policy it had changed.
|
||||
*/
|
||||
private void provisionInstanceGroup(StackResource r, JsonNode props, ProvisionContext ctx, boolean stub) {
|
||||
JsonNode template = new CfnPropertyTypes.HandlerReader(ctx.engine()).read(INSTANCE_GROUP, props);
|
||||
refuseReadOnly(template, "InstanceGroupId");
|
||||
requireTask(template, "InstanceRole");
|
||||
String clusterId = template.path("JobFlowId").asText();
|
||||
JsonNode policy = template.get("AutoScalingPolicy");
|
||||
if (ctx.isUpdate() && !stub && !ctx.changes(INSTANCE_GROUP, props).requiresReplacement()) {
|
||||
String id = ctx.priorPhysicalId();
|
||||
liveCluster(clusterId);
|
||||
EmrInstanceGroup live = emrService.listInstanceGroups(clusterId).stream()
|
||||
.filter(group -> id.equals(group.getId())).findFirst()
|
||||
.orElseThrow(() -> notFound(INSTANCE_GROUP, id));
|
||||
JsonNode lastPolicy = CfnRollback.updateSnapshot(r, GROUP_POLICY_ATTR);
|
||||
int count = template.path("InstanceCount").asInt();
|
||||
ObjectNode snapshot = MAPPER.createObjectNode();
|
||||
snapshot.put("clusterId", clusterId);
|
||||
snapshot.put("groupId", id);
|
||||
snapshot.put("region", ctx.region());
|
||||
snapshot.put("count", live.getRequestedInstanceCount());
|
||||
snapshot.set("policy", lastPolicy);
|
||||
publishCapacity(r, id, clusterId);
|
||||
r.getAttributes().put("InstanceGroupId", id);
|
||||
r.getAttributes().put(CAPACITY_SNAPSHOT_ATTR, snapshot.toString());
|
||||
AtomicBoolean countChanged = new AtomicBoolean();
|
||||
AtomicBoolean policyChanged = new AtomicBoolean();
|
||||
CfnRollback.guarded(r, ctx, false, () -> { },
|
||||
() -> restoreCapacity(snapshot, countChanged.get(), policyChanged.get()), () -> {
|
||||
if (count != live.getRequestedInstanceCount()) {
|
||||
emrService.modifyInstanceGroups(clusterId, ctx.region(),
|
||||
List.of(new InstanceGroupModification(id, count, null)));
|
||||
countChanged.set(true);
|
||||
}
|
||||
if (!Objects.equals(policy, lastPolicy)) {
|
||||
applyGroupPolicy(clusterId, id, policy);
|
||||
policyChanged.set(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ObjectNode group = MAPPER.createObjectNode();
|
||||
for (String name : INSTANCE_GROUP_MEMBERS) {
|
||||
if (template.has(name)) {
|
||||
group.set(name, template.get(name));
|
||||
}
|
||||
}
|
||||
if (group.has("Configurations")) {
|
||||
group.set("Configurations", configurations(group.get("Configurations")));
|
||||
}
|
||||
List<String> ids = emrService.addInstanceGroups(clusterId,
|
||||
emrHandler.instanceGroupsFrom(MAPPER.createArrayNode().add(group)));
|
||||
publishCapacity(r, ids.get(0), clusterId);
|
||||
r.getAttributes().put("InstanceGroupId", ids.get(0));
|
||||
}
|
||||
if (policy == null) {
|
||||
r.getAttributes().remove(GROUP_POLICY_ATTR);
|
||||
} else {
|
||||
r.getAttributes().put(GROUP_POLICY_ATTR, policy.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An instance fleet is added through AddInstanceFleet; its target capacities change in place through
|
||||
* ModifyInstanceFleet, and any create-only change adds a new fleet. Floci's ModifyInstanceFleet changes the
|
||||
* capacities alone, so a change to {@code InstanceTypeConfigs} or {@code ResizeSpecifications} is accepted with a
|
||||
* warning and not applied. A rollback puts back the capacities it had changed.
|
||||
*/
|
||||
private void provisionInstanceFleet(StackResource r, JsonNode props, ProvisionContext ctx, boolean stub) {
|
||||
JsonNode template = new CfnPropertyTypes.HandlerReader(ctx.engine()).read(INSTANCE_FLEET, props);
|
||||
refuseReadOnly(template, "InstanceFleetId");
|
||||
requireTask(template, "InstanceFleetType");
|
||||
String clusterId = template.path("ClusterId").asText();
|
||||
PropertyChanges changes = ctx.isUpdate() && !stub ? ctx.changes(INSTANCE_FLEET, props) : null;
|
||||
if (changes != null && !changes.requiresReplacement()) {
|
||||
String id = ctx.priorPhysicalId();
|
||||
liveCluster(clusterId);
|
||||
EmrInstanceFleet live = emrService.listInstanceFleets(clusterId).stream()
|
||||
.filter(fleet -> id.equals(fleet.getId())).findFirst()
|
||||
.orElseThrow(() -> notFound(INSTANCE_FLEET, id));
|
||||
for (String name : List.of("InstanceTypeConfigs", "ResizeSpecifications")) {
|
||||
PropertyChanges.Kind kind = changes.kindOf(name);
|
||||
if (kind != null && kind != PropertyChanges.Kind.UNCHANGED) {
|
||||
LOG.warnv("EMR instance fleet {0}: {1} is not applied, as ModifyInstanceFleet changes the "
|
||||
+ "target capacities alone", id, name);
|
||||
}
|
||||
}
|
||||
int onDemand = template.path("TargetOnDemandCapacity").asInt(0);
|
||||
int spot = template.path("TargetSpotCapacity").asInt(0);
|
||||
ObjectNode snapshot = MAPPER.createObjectNode();
|
||||
snapshot.put("clusterId", clusterId);
|
||||
snapshot.put("fleetId", id);
|
||||
snapshot.put("region", ctx.region());
|
||||
snapshot.put("onDemand", live.getTargetOnDemandCapacity());
|
||||
snapshot.put("spot", live.getTargetSpotCapacity());
|
||||
publishCapacity(r, id, clusterId);
|
||||
r.getAttributes().put("InstanceFleetId", id);
|
||||
r.getAttributes().put(CAPACITY_SNAPSHOT_ATTR, snapshot.toString());
|
||||
AtomicBoolean changed = new AtomicBoolean();
|
||||
CfnRollback.guarded(r, ctx, false, () -> { }, () -> restoreCapacity(snapshot, changed.get(), false), () -> {
|
||||
if (onDemand != live.getTargetOnDemandCapacity() || spot != live.getTargetSpotCapacity()) {
|
||||
emrService.modifyInstanceFleet(clusterId, id, onDemand, spot);
|
||||
changed.set(true);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
ObjectNode fleet = MAPPER.createObjectNode();
|
||||
for (String name : INSTANCE_FLEET_MEMBERS) {
|
||||
if (template.has(name)) {
|
||||
fleet.set(name, template.get(name).deepCopy());
|
||||
}
|
||||
}
|
||||
fleet.path("InstanceTypeConfigs").forEach(type -> {
|
||||
if (type instanceof ObjectNode typeConfig && typeConfig.has("Configurations")) {
|
||||
typeConfig.set("Configurations", configurations(typeConfig.get("Configurations")));
|
||||
}
|
||||
});
|
||||
String id = emrService.addInstanceFleet(clusterId, emrHandler.instanceFleetFrom(fleet));
|
||||
publishCapacity(r, id, clusterId);
|
||||
r.getAttributes().put("InstanceFleetId", id);
|
||||
}
|
||||
|
||||
private void applyGroupPolicy(String clusterId, String groupId, JsonNode policy) {
|
||||
if (policy == null) {
|
||||
emrService.removeAutoScalingPolicy(clusterId, groupId);
|
||||
} else {
|
||||
emrService.putAutoScalingPolicy(clusterId, groupId, policy);
|
||||
}
|
||||
}
|
||||
|
||||
/** Puts back a group's count and policy, or a fleet's capacities, each once the update had changed it. */
|
||||
private void restoreCapacity(JsonNode snapshot, boolean first, boolean second) {
|
||||
String clusterId = snapshot.path("clusterId").asText();
|
||||
if (snapshot.has("fleetId")) {
|
||||
if (first) {
|
||||
emrService.modifyInstanceFleet(clusterId, snapshot.path("fleetId").asText(),
|
||||
snapshot.path("onDemand").asInt(), snapshot.path("spot").asInt());
|
||||
}
|
||||
return;
|
||||
}
|
||||
String groupId = snapshot.path("groupId").asText();
|
||||
if (first) {
|
||||
emrService.modifyInstanceGroups(clusterId, snapshot.path("region").asText(),
|
||||
List.of(new InstanceGroupModification(groupId, snapshot.path("count").asInt(), null)));
|
||||
}
|
||||
if (second) {
|
||||
JsonNode policy = snapshot.get("policy");
|
||||
applyGroupPolicy(clusterId, groupId, policy == null || policy.isNull() ? null : policy);
|
||||
}
|
||||
}
|
||||
|
||||
private static void publishCapacity(StackResource r, String id, String clusterId) {
|
||||
r.setPhysicalId(id);
|
||||
r.getAttributes().put(CLUSTER_ID_ATTR, clusterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* The template reference's one allowed value for an instance group's role and an instance fleet's type, "Allowed
|
||||
* Values: TASK": a master or core group or fleet is the cluster's own. No source gives AWS's refusal, so the
|
||||
* wording is Floci's.
|
||||
*/
|
||||
private static void requireTask(JsonNode template, String name) {
|
||||
String role = template.path(name).asText();
|
||||
if (!"TASK".equals(role)) {
|
||||
throw new AwsException("InvalidRequest", name + " must be TASK, the one value the template reference "
|
||||
+ "allows, not " + role + ".", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void refuseReadOnly(JsonNode template, String name) {
|
||||
if (template.has(name)) {
|
||||
throw new AwsException("InvalidRequest",
|
||||
name + " is a ReadOnly property which cannot be specified in the template", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException notFound(String type, String id) {
|
||||
return new AwsException("NotFound", "Resource of type '" + type + "' with identifier '" + id
|
||||
+ "' was not found.", 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* An instance group or fleet cannot be removed from its cluster, so its delete shrinks it to nothing, as the
|
||||
* delete handler's ModifyInstanceGroups and ModifyInstanceFleet permissions say, removing a group's policy first.
|
||||
* One whose cluster has terminated or is gone is done.
|
||||
*/
|
||||
@Override
|
||||
public void delete(StackResource resource, String region) {
|
||||
String type = resource.getResourceType();
|
||||
String clusterId = resource.getAttributes().get(CLUSTER_ID_ATTR);
|
||||
if ((INSTANCE_GROUP.equals(type) || INSTANCE_FLEET.equals(type)) && clusterId != null) {
|
||||
shrink(type, clusterId, resource.getPhysicalId(), region);
|
||||
return;
|
||||
}
|
||||
delete(type, resource.getPhysicalId(), region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shrinks the group or fleet to nothing once its cluster is running or waiting, the states ModifyInstanceGroups
|
||||
* and ModifyInstanceFleet take, removing a group's policy first when it has one. A cluster still starting is waited
|
||||
* for, as the create waits, since a group can be added to it then; one that is gone, or has ended, is left be.
|
||||
*/
|
||||
private void shrink(String type, String clusterId, String id, String region) {
|
||||
EmrCluster cluster;
|
||||
try {
|
||||
cluster = emrService.describeCluster(clusterId);
|
||||
} catch (AwsException e) {
|
||||
if ("InvalidRequestException".equals(e.getErrorCode())) {
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
if (!READY.contains(cluster.getState()) && !ENDED.contains(cluster.getState())) {
|
||||
cluster = awaitSettled(clusterId);
|
||||
}
|
||||
if (!READY.contains(cluster.getState())) {
|
||||
return;
|
||||
}
|
||||
if (INSTANCE_FLEET.equals(type)) {
|
||||
emrService.modifyInstanceFleet(clusterId, id, 0, 0);
|
||||
return;
|
||||
}
|
||||
boolean policy = emrService.listInstanceGroups(clusterId).stream()
|
||||
.anyMatch(group -> id.equals(group.getId()) && group.getAutoScalingPolicy() != null);
|
||||
if (policy) {
|
||||
emrService.removeAutoScalingPolicy(clusterId, id);
|
||||
}
|
||||
emrService.modifyInstanceGroups(clusterId, region, List.of(new InstanceGroupModification(id, 0, null)));
|
||||
}
|
||||
|
||||
/** The live cluster in the Region that holds the instance group or fleet {@code id}, for a delete by id alone. */
|
||||
private String clusterHolding(String type, String id, String region) {
|
||||
for (EmrCluster cluster : emrService.listClusters(region, null, null, null)) {
|
||||
if (ENDED.contains(cluster.getState())) {
|
||||
continue;
|
||||
}
|
||||
String clusterId = cluster.getId();
|
||||
boolean holds = INSTANCE_GROUP.equals(type)
|
||||
? emrService.listInstanceGroups(clusterId).stream().anyMatch(group -> id.equals(group.getId()))
|
||||
: emrService.listInstanceFleets(clusterId).stream().anyMatch(fleet -> id.equals(fleet.getId()));
|
||||
if (holds) {
|
||||
return cluster.getId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the security configuration, unless the Region lists none of that name, it being gone, or terminates the
|
||||
* cluster, which TerminateJobFlows leaves be when it has terminated or is gone, and refuses when it is termination
|
||||
@@ -668,6 +1016,15 @@ public class EmrCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
}
|
||||
case CLUSTER -> emrService.terminateJobFlows(List.of(physicalId));
|
||||
// The schema's delete handler calls nothing: a step stays in its cluster's history.
|
||||
case STEP -> LOG.debugv("EMR step {0} stays in its cluster's history", physicalId);
|
||||
case INSTANCE_GROUP, INSTANCE_FLEET -> {
|
||||
// Reached by id alone for a replaced group or fleet, whose cluster is found by looking.
|
||||
String clusterId = clusterHolding(resourceType, physicalId, region);
|
||||
if (clusterId != null) {
|
||||
shrink(resourceType, clusterId, physicalId, region);
|
||||
}
|
||||
}
|
||||
default -> throw new IllegalStateException("EmrCfnProvisioner cannot delete " + resourceType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,19 +985,44 @@ public class EmrHandler {
|
||||
}
|
||||
|
||||
private Response handleAddInstanceFleet(JsonNode request) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
EmrInstanceFleet fleet = parseInstanceFleet(request.path("InstanceFleet"), "instanceFleet", violations);
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationException(violations);
|
||||
}
|
||||
requireEbsVolumeLimit(request.path("InstanceFleet"));
|
||||
String id = service.addInstanceFleet(text(request, "ClusterId"), fleet);
|
||||
String id = service.addInstanceFleet(text(request, "ClusterId"),
|
||||
instanceFleetFrom(request.path("InstanceFleet")));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("ClusterId", text(request, "ClusterId"));
|
||||
response.put("InstanceFleetId", id);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance fleet an AddInstanceFleet request's {@code InstanceFleet} describes, read and checked as
|
||||
* AddInstanceFleet reads it, for this handler and for CloudFormation's {@code AWS::EMR::InstanceFleetConfig}.
|
||||
*/
|
||||
public EmrInstanceFleet instanceFleetFrom(JsonNode fleetNode) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
EmrInstanceFleet fleet = parseInstanceFleet(fleetNode, "instanceFleet", violations);
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationException(violations);
|
||||
}
|
||||
requireEbsVolumeLimit(fleetNode);
|
||||
return fleet;
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance groups an AddInstanceGroups request's {@code InstanceGroups} describe, read as AddInstanceGroups
|
||||
* reads them, for this handler and for CloudFormation's {@code AWS::EMR::InstanceGroupConfig}.
|
||||
*/
|
||||
public List<EmrInstanceGroup> instanceGroupsFrom(JsonNode groupsNode) {
|
||||
return parseInstanceGroups(groupsNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* The steps an AddJobFlowSteps request's {@code Steps} describe, read as AddJobFlowSteps reads them, for this
|
||||
* handler and for CloudFormation's {@code AWS::EMR::Step}.
|
||||
*/
|
||||
public List<EmrStep> stepsFrom(JsonNode stepsNode, String executionRoleArn) {
|
||||
return parseSteps(stepsNode, executionRoleArn);
|
||||
}
|
||||
|
||||
private Response handleListInstanceFleets(JsonNode request) {
|
||||
List<EmrInstanceFleet> fleets = service.listInstanceFleets(text(request, "ClusterId"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
"AWS::ECS::TaskDefinition": "AWS::ECS::TaskDefinition",
|
||||
"AWS::EKS::Cluster": "AWS::EKS::Cluster",
|
||||
"AWS::EMR::Cluster": "AWS::EMR::Cluster",
|
||||
"AWS::EMR::InstanceFleetConfig": "AWS::EMR::InstanceFleetConfig",
|
||||
"AWS::EMR::InstanceGroupConfig": "AWS::EMR::InstanceGroupConfig",
|
||||
"AWS::EMR::SecurityConfiguration": "AWS::EMR::SecurityConfiguration",
|
||||
"AWS::EMR::Step": "AWS::EMR::Step",
|
||||
"AWS::EMR::Studio": "AWS::EMR::Studio",
|
||||
"AWS::EMR::StudioSessionMapping": "AWS::EMR::StudioSessionMapping",
|
||||
"AWS::EMRContainers::VirtualCluster": "AWS::EMRContainers::VirtualCluster",
|
||||
@@ -2519,6 +2522,340 @@
|
||||
"VolumeType"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"InstanceFleetType": "String",
|
||||
"TargetOnDemandCapacity": "Integer",
|
||||
"ClusterId": "String",
|
||||
"TargetSpotCapacity": "Integer",
|
||||
"LaunchSpecifications": "AWS::EMR::InstanceFleetConfig/InstanceFleetProvisioningSpecifications",
|
||||
"ResizeSpecifications": "AWS::EMR::InstanceFleetConfig/InstanceFleetResizingSpecifications",
|
||||
"InstanceFleetId": "String",
|
||||
"InstanceTypeConfigs": "AWS::EMR::InstanceFleetConfig.InstanceTypeConfigs",
|
||||
"Name": "String"
|
||||
},
|
||||
"required": [
|
||||
"InstanceFleetType",
|
||||
"ClusterId"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig.InstanceTypeConfigs": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceFleetConfig/InstanceTypeConfig"
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/ApplicationConfiguration": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"ConfigurationProperties": "AWS::EMR::InstanceFleetConfig/ApplicationConfiguration.ConfigurationProperties",
|
||||
"Configurations": "AWS::EMR::InstanceFleetConfig/ApplicationConfiguration.Configurations",
|
||||
"Classification": "String"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/ApplicationConfiguration.ConfigurationProperties": {
|
||||
"type": "map",
|
||||
"value": "String"
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/ApplicationConfiguration.Configurations": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceFleetConfig/ApplicationConfiguration"
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/EbsBlockDeviceConfig": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"VolumeSpecification": "AWS::EMR::InstanceFleetConfig/VolumeSpecification",
|
||||
"VolumesPerInstance": "Integer"
|
||||
},
|
||||
"required": [
|
||||
"VolumeSpecification"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/EbsConfiguration": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"EbsBlockDeviceConfigs": "AWS::EMR::InstanceFleetConfig/EbsConfiguration.EbsBlockDeviceConfigs",
|
||||
"EbsOptimized": "Boolean"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/EbsConfiguration.EbsBlockDeviceConfigs": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceFleetConfig/EbsBlockDeviceConfig"
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/InstanceFleetProvisioningSpecifications": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"SpotSpecification": "AWS::EMR::InstanceFleetConfig/SpotProvisioningSpecification",
|
||||
"OnDemandSpecification": "AWS::EMR::InstanceFleetConfig/OnDemandProvisioningSpecification"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/InstanceFleetResizingSpecifications": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"OnDemandResizeSpecification": "AWS::EMR::InstanceFleetConfig/OnDemandResizingSpecification",
|
||||
"SpotResizeSpecification": "AWS::EMR::InstanceFleetConfig/SpotResizingSpecification"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/InstanceTypeConfig": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"BidPrice": "String",
|
||||
"WeightedCapacity": "Integer",
|
||||
"EbsConfiguration": "AWS::EMR::InstanceFleetConfig/EbsConfiguration",
|
||||
"BidPriceAsPercentageOfOnDemandPrice": "Double",
|
||||
"CustomAmiId": "String",
|
||||
"Configurations": "AWS::EMR::InstanceFleetConfig/InstanceTypeConfig.Configurations",
|
||||
"InstanceType": "String",
|
||||
"Priority": "Double"
|
||||
},
|
||||
"required": [
|
||||
"InstanceType"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/InstanceTypeConfig.Configurations": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceFleetConfig/ApplicationConfiguration"
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/OnDemandCapacityReservationOptions": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"UsageStrategy": "String",
|
||||
"CapacityReservationResourceGroupArn": "String",
|
||||
"CapacityReservationPreference": "String"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/OnDemandProvisioningSpecification": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"CapacityReservationOptions": "AWS::EMR::InstanceFleetConfig/OnDemandCapacityReservationOptions",
|
||||
"AllocationStrategy": "String"
|
||||
},
|
||||
"required": [
|
||||
"AllocationStrategy"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/OnDemandResizingSpecification": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"CapacityReservationOptions": "AWS::EMR::InstanceFleetConfig/OnDemandCapacityReservationOptions",
|
||||
"AllocationStrategy": "String",
|
||||
"TimeoutDurationMinutes": "Integer"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/SpotProvisioningSpecification": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"AllocationStrategy": "String",
|
||||
"TimeoutDurationMinutes": "Integer",
|
||||
"TimeoutAction": "String",
|
||||
"BlockDurationMinutes": "Integer"
|
||||
},
|
||||
"required": [
|
||||
"TimeoutDurationMinutes",
|
||||
"TimeoutAction"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/SpotResizingSpecification": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"AllocationStrategy": "String",
|
||||
"TimeoutDurationMinutes": "Integer"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceFleetConfig/VolumeSpecification": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"SizeInGB": "Integer",
|
||||
"VolumeType": "String",
|
||||
"Throughput": "Integer",
|
||||
"Iops": "Integer"
|
||||
},
|
||||
"required": [
|
||||
"SizeInGB",
|
||||
"VolumeType"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"JobFlowId": "String",
|
||||
"AutoScalingPolicy": "AWS::EMR::InstanceGroupConfig/AutoScalingPolicy",
|
||||
"BidPrice": "String",
|
||||
"InstanceCount": "Integer",
|
||||
"EbsConfiguration": "AWS::EMR::InstanceGroupConfig/EbsConfiguration",
|
||||
"InstanceRole": "String",
|
||||
"CustomAmiId": "String",
|
||||
"InstanceGroupId": "String",
|
||||
"Configurations": "AWS::EMR::InstanceGroupConfig.Configurations",
|
||||
"InstanceType": "String",
|
||||
"Market": "String",
|
||||
"Name": "String"
|
||||
},
|
||||
"required": [
|
||||
"JobFlowId",
|
||||
"InstanceCount",
|
||||
"InstanceRole",
|
||||
"InstanceType"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig.Configurations": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceGroupConfig/AppConfiguration"
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/AppConfiguration": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"ConfigurationProperties": "AWS::EMR::InstanceGroupConfig/AppConfiguration.ConfigurationProperties",
|
||||
"Configurations": "AWS::EMR::InstanceGroupConfig/AppConfiguration.Configurations",
|
||||
"Classification": "String"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/AppConfiguration.ConfigurationProperties": {
|
||||
"type": "map",
|
||||
"value": "String"
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/AppConfiguration.Configurations": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceGroupConfig/AppConfiguration"
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/AutoScalingPolicy": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Rules": "AWS::EMR::InstanceGroupConfig/AutoScalingPolicy.Rules",
|
||||
"Constraints": "AWS::EMR::InstanceGroupConfig/ScalingConstraints"
|
||||
},
|
||||
"required": [
|
||||
"Constraints",
|
||||
"Rules"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/AutoScalingPolicy.Rules": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceGroupConfig/ScalingRule"
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/CloudWatchAlarmDefinition": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"MetricName": "String",
|
||||
"ComparisonOperator": "String",
|
||||
"Statistic": "String",
|
||||
"Dimensions": "AWS::EMR::InstanceGroupConfig/CloudWatchAlarmDefinition.Dimensions",
|
||||
"Period": "Integer",
|
||||
"EvaluationPeriods": "Integer",
|
||||
"Unit": "String",
|
||||
"Namespace": "String",
|
||||
"Threshold": "Double"
|
||||
},
|
||||
"required": [
|
||||
"MetricName",
|
||||
"ComparisonOperator",
|
||||
"Period",
|
||||
"Threshold"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/CloudWatchAlarmDefinition.Dimensions": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceGroupConfig/MetricDimension"
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/EbsBlockDeviceConfig": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"VolumeSpecification": "AWS::EMR::InstanceGroupConfig/VolumeSpecification",
|
||||
"VolumesPerInstance": "Integer"
|
||||
},
|
||||
"required": [
|
||||
"VolumeSpecification"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/EbsConfiguration": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"EbsBlockDeviceConfigs": "AWS::EMR::InstanceGroupConfig/EbsConfiguration.EbsBlockDeviceConfigs",
|
||||
"EbsOptimized": "Boolean"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/EbsConfiguration.EbsBlockDeviceConfigs": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::InstanceGroupConfig/EbsBlockDeviceConfig"
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/MetricDimension": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Value": "String",
|
||||
"Key": "String"
|
||||
},
|
||||
"required": [
|
||||
"Value",
|
||||
"Key"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/ScalingAction": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Market": "String",
|
||||
"SimpleScalingPolicyConfiguration": "AWS::EMR::InstanceGroupConfig/SimpleScalingPolicyConfiguration"
|
||||
},
|
||||
"required": [
|
||||
"SimpleScalingPolicyConfiguration"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/ScalingConstraints": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"MinCapacity": "Integer",
|
||||
"MaxCapacity": "Integer"
|
||||
},
|
||||
"required": [
|
||||
"MinCapacity",
|
||||
"MaxCapacity"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/ScalingRule": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Action": "AWS::EMR::InstanceGroupConfig/ScalingAction",
|
||||
"Description": "String",
|
||||
"Trigger": "AWS::EMR::InstanceGroupConfig/ScalingTrigger",
|
||||
"Name": "String"
|
||||
},
|
||||
"required": [
|
||||
"Action",
|
||||
"Trigger",
|
||||
"Name"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/ScalingTrigger": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"CloudWatchAlarmDefinition": "AWS::EMR::InstanceGroupConfig/CloudWatchAlarmDefinition"
|
||||
},
|
||||
"required": [
|
||||
"CloudWatchAlarmDefinition"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/SimpleScalingPolicyConfiguration": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"ScalingAdjustment": "Integer",
|
||||
"CoolDown": "Integer",
|
||||
"AdjustmentType": "String"
|
||||
},
|
||||
"required": [
|
||||
"ScalingAdjustment"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::InstanceGroupConfig/VolumeSpecification": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"SizeInGB": "Integer",
|
||||
"Throughput": "Integer",
|
||||
"VolumeType": "String",
|
||||
"Iops": "Integer"
|
||||
},
|
||||
"required": [
|
||||
"SizeInGB",
|
||||
"VolumeType"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::SecurityConfiguration": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
@@ -2529,6 +2866,51 @@
|
||||
"SecurityConfiguration"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::Step": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Id": "String",
|
||||
"ActionOnFailure": "String",
|
||||
"HadoopJarStep": "AWS::EMR::Step/HadoopJarStepConfig",
|
||||
"JobFlowId": "String",
|
||||
"Name": "String",
|
||||
"LogUri": "String",
|
||||
"EncryptionKeyArn": "String"
|
||||
},
|
||||
"required": [
|
||||
"JobFlowId",
|
||||
"HadoopJarStep",
|
||||
"ActionOnFailure",
|
||||
"Name"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::Step/HadoopJarStepConfig": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Args": "AWS::EMR::Step/HadoopJarStepConfig.Args",
|
||||
"Jar": "String",
|
||||
"MainClass": "String",
|
||||
"StepProperties": "AWS::EMR::Step/HadoopJarStepConfig.StepProperties"
|
||||
},
|
||||
"required": [
|
||||
"Jar"
|
||||
]
|
||||
},
|
||||
"AWS::EMR::Step/HadoopJarStepConfig.Args": {
|
||||
"type": "list",
|
||||
"member": "String"
|
||||
},
|
||||
"AWS::EMR::Step/HadoopJarStepConfig.StepProperties": {
|
||||
"type": "list",
|
||||
"member": "AWS::EMR::Step/KeyValue"
|
||||
},
|
||||
"AWS::EMR::Step/KeyValue": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"Key": "String",
|
||||
"Value": "String"
|
||||
}
|
||||
},
|
||||
"AWS::EMR::Studio": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
|
||||
@@ -553,10 +553,35 @@
|
||||
"MonitoringConfiguration",
|
||||
"SessionEnabled"
|
||||
],
|
||||
"AWS::EMR::InstanceFleetConfig": [
|
||||
"Name",
|
||||
"LaunchSpecifications",
|
||||
"ClusterId",
|
||||
"InstanceFleetType"
|
||||
],
|
||||
"AWS::EMR::InstanceGroupConfig": [
|
||||
"InstanceRole",
|
||||
"JobFlowId",
|
||||
"Name",
|
||||
"InstanceType",
|
||||
"CustomAmiId",
|
||||
"Configurations",
|
||||
"EbsConfiguration",
|
||||
"Market",
|
||||
"BidPrice"
|
||||
],
|
||||
"AWS::EMR::SecurityConfiguration": [
|
||||
"Name",
|
||||
"SecurityConfiguration"
|
||||
],
|
||||
"AWS::EMR::Step": [
|
||||
"JobFlowId",
|
||||
"HadoopJarStep",
|
||||
"Name",
|
||||
"ActionOnFailure",
|
||||
"LogUri",
|
||||
"EncryptionKeyArn"
|
||||
],
|
||||
"AWS::EMR::Studio": [
|
||||
"AuthMode",
|
||||
"EngineSecurityGroupId",
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.floci.aws.testing.CfnStackWaits;
|
||||
import io.floci.aws.testing.CfnTestStack;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import software.amazon.awssdk.services.cloudformation.model.Stack;
|
||||
|
||||
import static io.floci.aws.testing.CfnStackWaits.output;
|
||||
import static io.floci.aws.testing.EmrRequests.emr;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Provisions {@code AWS::EMR::Step}, {@code AWS::EMR::InstanceGroupConfig} and {@code AWS::EMR::InstanceFleetConfig}
|
||||
* on clusters of the same stack and reads them back through EMR: each {@code Ref} and {@code Fn::GetAtt} names its
|
||||
* step, group or fleet, an update resizes the group and the fleet in place, a later resource's failure puts the sizes
|
||||
* back, and deleting the stack shrinks them with their clusters.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class EmrStepGroupFleetCfnIntegrationTest {
|
||||
|
||||
@RegisterExtension
|
||||
final CfnTestStack stack = new CfnTestStack("emr-step-group-fleet-cfn-it");
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void addResizeRollBackAndDeleteAStepAnInstanceGroupAndAnInstanceFleet() {
|
||||
Stack created = stack.create(template(1, 1, false));
|
||||
String groups = output(created, "Groups");
|
||||
String fleets = output(created, "Fleets");
|
||||
String stepId = output(created, "StepRef");
|
||||
String groupId = output(created, "GroupRef");
|
||||
String fleetId = output(created, "FleetRef");
|
||||
assertEquals(stepId, output(created, "StepId"));
|
||||
assertEquals(groupId, output(created, "GroupId"));
|
||||
assertEquals(fleetId, output(created, "FleetId"));
|
||||
emr("ListSteps", "{\"ClusterId\": \"" + groups + "\"}").then().statusCode(200)
|
||||
.body("Steps.Id", hasItem(stepId));
|
||||
groupCount(groups, groupId, 1);
|
||||
fleetCapacity(fleets, fleetId, 1);
|
||||
|
||||
Stack resized = stack.update(template(2, 2, false), "UPDATE_COMPLETE");
|
||||
assertEquals(groupId, output(resized, "GroupRef"));
|
||||
assertEquals(fleetId, output(resized, "FleetRef"));
|
||||
groupCount(groups, groupId, 2);
|
||||
fleetCapacity(fleets, fleetId, 2);
|
||||
|
||||
stack.update(template(3, 3, true), "UPDATE_ROLLBACK_COMPLETE");
|
||||
groupCount(groups, groupId, 2);
|
||||
fleetCapacity(fleets, fleetId, 2);
|
||||
|
||||
CfnStackWaits.deleteStack(stack.name());
|
||||
|
||||
emr("DescribeCluster", "{\"ClusterId\": \"" + groups + "\"}").then().statusCode(200)
|
||||
.body("Cluster.Status.State", equalTo("TERMINATED"));
|
||||
emr("DescribeCluster", "{\"ClusterId\": \"" + fleets + "\"}").then().statusCode(200)
|
||||
.body("Cluster.Status.State", equalTo("TERMINATED"));
|
||||
}
|
||||
|
||||
private static String template(int taskCount, int fleetCapacity, boolean laterFails) {
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"Groups": {
|
||||
"Type": "AWS::EMR::Cluster",
|
||||
"Properties": {
|
||||
"Name": "groups", "ReleaseLabel": "emr-7.5.0", "JobFlowRole": "EMR_EC2_DefaultRole",
|
||||
"ServiceRole": "EMR_DefaultRole",
|
||||
"Instances": {"KeepJobFlowAliveWhenNoSteps": true,
|
||||
"MasterInstanceGroup": {"InstanceCount": 1, "InstanceType": "m5.xlarge"},
|
||||
"CoreInstanceGroup": {"InstanceCount": 1, "InstanceType": "m5.xlarge"}}
|
||||
}
|
||||
},
|
||||
"Fleets": {
|
||||
"Type": "AWS::EMR::Cluster",
|
||||
"Properties": {
|
||||
"Name": "fleets", "ReleaseLabel": "emr-7.5.0", "JobFlowRole": "EMR_EC2_DefaultRole",
|
||||
"ServiceRole": "EMR_DefaultRole",
|
||||
"Instances": {"KeepJobFlowAliveWhenNoSteps": true,
|
||||
"MasterInstanceFleet": {"TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]},
|
||||
"CoreInstanceFleet": {"TargetOnDemandCapacity": 1,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}}
|
||||
}
|
||||
},
|
||||
"Step": {
|
||||
"Type": "AWS::EMR::Step",
|
||||
"Properties": {
|
||||
"JobFlowId": {"Ref": "Groups"}, "Name": "pi", "ActionOnFailure": "CONTINUE",
|
||||
"HadoopJarStep": {"Jar": "command-runner.jar", "Args": ["spark-example", "SparkPi"]}
|
||||
}
|
||||
},
|
||||
"Group": {
|
||||
"Type": "AWS::EMR::InstanceGroupConfig",
|
||||
"Properties": {
|
||||
"JobFlowId": {"Ref": "Groups"}, "InstanceRole": "TASK", "InstanceType": "m5.xlarge",
|
||||
"InstanceCount": %d, "Name": "spot"
|
||||
}
|
||||
},
|
||||
"Fleet": {
|
||||
"Type": "AWS::EMR::InstanceFleetConfig",
|
||||
"Properties": {
|
||||
"ClusterId": {"Ref": "Fleets"}, "InstanceFleetType": "TASK", "Name": "tasks",
|
||||
"TargetOnDemandCapacity": %d, "InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]
|
||||
}
|
||||
}%s
|
||||
},
|
||||
"Outputs": {
|
||||
"Groups": {"Value": {"Ref": "Groups"}},
|
||||
"Fleets": {"Value": {"Ref": "Fleets"}},
|
||||
"StepRef": {"Value": {"Ref": "Step"}},
|
||||
"StepId": {"Value": {"Fn::GetAtt": ["Step", "Id"]}},
|
||||
"GroupRef": {"Value": {"Ref": "Group"}},
|
||||
"GroupId": {"Value": {"Fn::GetAtt": ["Group", "InstanceGroupId"]}},
|
||||
"FleetRef": {"Value": {"Ref": "Fleet"}},
|
||||
"FleetId": {"Value": {"Fn::GetAtt": ["Fleet", "InstanceFleetId"]}}
|
||||
}
|
||||
}
|
||||
""".formatted(taskCount, fleetCapacity, laterFails ? CfnStackWaits.failingResourceAfter("Fleet") : "");
|
||||
}
|
||||
|
||||
private static void groupCount(String clusterId, String groupId, int count) {
|
||||
emr("ListInstanceGroups", "{\"ClusterId\": \"" + clusterId + "\"}").then().statusCode(200)
|
||||
.body("InstanceGroups.find { it.Id == '" + groupId + "' }.RequestedInstanceCount", equalTo(count));
|
||||
}
|
||||
|
||||
private static void fleetCapacity(String clusterId, String fleetId, int capacity) {
|
||||
emr("ListInstanceFleets", "{\"ClusterId\": \"" + clusterId + "\"}").then().statusCode(200)
|
||||
.body("InstanceFleets.find { it.Id == '" + fleetId + "' }.TargetOnDemandCapacity", equalTo(capacity));
|
||||
}
|
||||
}
|
||||
+153
-1
@@ -8,6 +8,7 @@ import io.floci.aws.services.emr.EmrHandler;
|
||||
import io.floci.aws.services.emr.EmrService;
|
||||
import io.floci.aws.services.emr.EmrService.InstanceGroupModification;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceFleet;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceGroup;
|
||||
import io.floci.aws.services.emr.model.SecurityConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -33,7 +34,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** {@code AWS::EMR::SecurityConfiguration} and {@code AWS::EMR::Cluster} in isolation, with EMR mocked. */
|
||||
/** Amazon EMR's own CloudFormation types over {@link EmrService} in isolation, with EMR mocked. */
|
||||
class EmrCfnProvisionerTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
@@ -329,4 +330,155 @@ class EmrCfnProvisionerTest {
|
||||
|
||||
verify(emr).terminateJobFlows(List.of(CLUSTER_ID));
|
||||
}
|
||||
|
||||
private static StackResource typed(String type, String physicalId) {
|
||||
StackResource r = resource(physicalId);
|
||||
r.setLogicalId("Child");
|
||||
r.setResourceType(type);
|
||||
return r;
|
||||
}
|
||||
|
||||
private static final String POLICY = """
|
||||
{"Constraints": {"MinCapacity": 1, "MaxCapacity": 4}, "Rules": []}""";
|
||||
|
||||
private static String groupProps(int count, String policy) {
|
||||
return """
|
||||
{"JobFlowId": "%s", "InstanceRole": "TASK", "InstanceType": "m5.xlarge", "InstanceCount": %d,
|
||||
"Name": "spot", "Configurations": [{"Classification": "yarn-site",
|
||||
"ConfigurationProperties": {"yarn.nodemanager.vmem-check-enabled": "false"}}]%s}
|
||||
""".formatted(CLUSTER_ID, count, policy == null ? "" : ", \"AutoScalingPolicy\": " + policy);
|
||||
}
|
||||
|
||||
private static String fleetProps(int onDemand) {
|
||||
return """
|
||||
{"ClusterId": "%s", "InstanceFleetType": "TASK", "Name": "tasks", "TargetOnDemandCapacity": %d,
|
||||
"InstanceTypeConfigs": [{"InstanceType": "m5.xlarge"}]}
|
||||
""".formatted(CLUSTER_ID, onDemand);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStepIsAddedWithItsPropertiesAndMonitoringInAddJobFlowStepsMembersAndStaysWhenDeleted() {
|
||||
when(emr.addJobFlowSteps(eq(CLUSTER_ID), any())).thenReturn(List.of("s-STEP1"));
|
||||
StackResource r = typed("AWS::EMR::Step", null);
|
||||
|
||||
provisioner.provision(r, json("""
|
||||
{"JobFlowId": "%s", "Name": "pi", "ActionOnFailure": "CONTINUE", "LogUri": "s3://logs/steps/",
|
||||
"HadoopJarStep": {"Jar": "command-runner.jar", "Args": ["spark-example", "SparkPi"],
|
||||
"StepProperties": [{"Key": "k", "Value": "v"}]}}
|
||||
""".formatted(CLUSTER_ID)), ctx(null, null));
|
||||
provisioner.delete(r, "us-east-1");
|
||||
|
||||
ArgumentCaptor<JsonNode> steps = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(handler).stepsFrom(steps.capture(), eq(null));
|
||||
JsonNode step = steps.getValue().get(0);
|
||||
assertEquals(json("[{\"Key\": \"k\", \"Value\": \"v\"}]"), step.path("HadoopJarStep").get("Properties"));
|
||||
assertEquals("s3://logs/steps/",
|
||||
step.path("StepMonitoringConfiguration").path("S3MonitoringConfiguration").path("LogUri").asText());
|
||||
assertEquals("s-STEP1", r.getPhysicalId());
|
||||
assertEquals("s-STEP1", r.getAttributes().get("Id"));
|
||||
verify(emr, never()).cancelSteps(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInstanceGroupIsAddedThenResizedAndGivenAPolicyInPlaceAndARollbackPutsThemBack() {
|
||||
when(emr.addInstanceGroups(eq(CLUSTER_ID), any())).thenReturn(List.of("ig-TASK"));
|
||||
StackResource r = typed("AWS::EMR::InstanceGroupConfig", null);
|
||||
provisioner.provision(r, json(groupProps(1, null)), ctx(null, null));
|
||||
ArgumentCaptor<JsonNode> groups = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(handler).instanceGroupsFrom(groups.capture());
|
||||
assertEquals("TASK", groups.getValue().get(0).path("InstanceRole").asText());
|
||||
assertEquals("false", groups.getValue().get(0).path("Configurations").get(0).path("Properties")
|
||||
.path("yarn.nodemanager.vmem-check-enabled").asText());
|
||||
assertEquals("ig-TASK", r.getAttributes().get("InstanceGroupId"));
|
||||
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
EmrInstanceGroup live = group("ig-TASK", "TASK", "spot");
|
||||
live.setRequestedInstanceCount(1);
|
||||
when(emr.listInstanceGroups(CLUSTER_ID)).thenReturn(List.of(live));
|
||||
provisioner.provision(r, json(groupProps(3, POLICY)), ctx("ig-TASK", groupProps(1, null)));
|
||||
provisioner.rollbackUpdate(r);
|
||||
|
||||
verify(emr).modifyInstanceGroups(CLUSTER_ID, "us-east-1",
|
||||
List.of(new InstanceGroupModification("ig-TASK", 3, null)));
|
||||
verify(emr).putAutoScalingPolicy(CLUSTER_ID, "ig-TASK", json(POLICY));
|
||||
verify(emr).modifyInstanceGroups(CLUSTER_ID, "us-east-1",
|
||||
List.of(new InstanceGroupModification("ig-TASK", 1, null)));
|
||||
verify(emr).removeAutoScalingPolicy(CLUSTER_ID, "ig-TASK");
|
||||
assertEquals("ig-TASK", r.getPhysicalId());
|
||||
// The policy the group has again is the one the next update and the delete compare with: none.
|
||||
assertFalse(r.getAttributes().containsKey(EmrCfnProvisioner.GROUP_POLICY_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInstanceFleetIsResizedInPlaceAndARollbackPutsItsCapacityBack() {
|
||||
when(handler.instanceFleetFrom(any())).thenReturn(new EmrInstanceFleet());
|
||||
when(emr.addInstanceFleet(eq(CLUSTER_ID), any())).thenReturn("if-TASK");
|
||||
StackResource r = typed("AWS::EMR::InstanceFleetConfig", null);
|
||||
provisioner.provision(r, json(fleetProps(1)), ctx(null, null));
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
EmrInstanceFleet live = new EmrInstanceFleet();
|
||||
live.setId("if-TASK");
|
||||
live.setTargetOnDemandCapacity(1);
|
||||
when(emr.listInstanceFleets(CLUSTER_ID)).thenReturn(List.of(live));
|
||||
|
||||
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);
|
||||
assertEquals("if-TASK", r.getAttributes().get("InstanceFleetId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInstanceGroupOrFleetDeleteShrinksItAndOneWhoseClusterEndedIsLeftAlone() {
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
EmrInstanceGroup withPolicy = group("ig-TASK", "TASK", "spot");
|
||||
withPolicy.setAutoScalingPolicy(POLICY);
|
||||
when(emr.listInstanceGroups(CLUSTER_ID)).thenReturn(List.of(withPolicy));
|
||||
StackResource group = typed("AWS::EMR::InstanceGroupConfig", "ig-TASK");
|
||||
group.getAttributes().put(EmrCfnProvisioner.CLUSTER_ID_ATTR, CLUSTER_ID);
|
||||
StackResource fleet = typed("AWS::EMR::InstanceFleetConfig", "if-TASK");
|
||||
fleet.getAttributes().put(EmrCfnProvisioner.CLUSTER_ID_ATTR, CLUSTER_ID);
|
||||
StackResource orphan = typed("AWS::EMR::InstanceGroupConfig", "ig-GONE");
|
||||
orphan.getAttributes().put(EmrCfnProvisioner.CLUSTER_ID_ATTR, "j-ENDED");
|
||||
when(emr.describeCluster("j-ENDED")).thenReturn(emrCluster("j-ENDED", "TERMINATED"));
|
||||
|
||||
provisioner.delete(group, "us-east-1");
|
||||
provisioner.delete(fleet, "us-east-1");
|
||||
provisioner.delete(orphan, "us-east-1");
|
||||
|
||||
verify(emr).removeAutoScalingPolicy(CLUSTER_ID, "ig-TASK");
|
||||
verify(emr).modifyInstanceGroups(CLUSTER_ID, "us-east-1",
|
||||
List.of(new InstanceGroupModification("ig-TASK", 0, null)));
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK", 0, 0);
|
||||
verify(emr, never()).modifyInstanceGroups(eq("j-ENDED"), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInstanceGroupOrFleetOfAnotherRoleThanTaskIsRefused() {
|
||||
AwsException group = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
typed("AWS::EMR::InstanceGroupConfig", null),
|
||||
json(groupProps(1, null).replace("\"TASK\"", "\"CORE\"")), ctx(null, null)));
|
||||
AwsException fleet = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
typed("AWS::EMR::InstanceFleetConfig", null),
|
||||
json(fleetProps(1).replace("\"TASK\"", "\"MASTER\"")), ctx(null, null)));
|
||||
|
||||
assertEquals("InstanceRole must be TASK, the one value the template reference allows, not CORE.",
|
||||
group.getMessage());
|
||||
assertEquals("InstanceFleetType must be TASK, the one value the template reference allows, not MASTER.",
|
||||
fleet.getMessage());
|
||||
verifyNoInteractions(emr);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFleetWhoseClusterIsStillStartingIsShrunkOnceItRuns() {
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "STARTING"),
|
||||
emrCluster(CLUSTER_ID, "BOOTSTRAPPING"), emrCluster(CLUSTER_ID, "WAITING"));
|
||||
StackResource fleet = typed("AWS::EMR::InstanceFleetConfig", "if-TASK");
|
||||
fleet.getAttributes().put(EmrCfnProvisioner.CLUSTER_ID_ATTR, CLUSTER_ID);
|
||||
|
||||
provisioner.delete(fleet, "us-east-1");
|
||||
|
||||
verify(emr).modifyInstanceFleet(CLUSTER_ID, "if-TASK", 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,10 @@ AWS::EFS::MountTarget Id FileSystemId,IpAddress,IpAddressType,Ipv6Address,Securi
|
||||
AWS::EKS::Cluster Arn,CertificateAuthorityData,ClusterSecurityGroupId,EncryptionConfigKeyArn,Endpoint,Id,OpenIdConnectIssuerUrl AccessConfig,ActiveCertificateAuthorityId,BootstrapSelfManagedAddons,CertificateAuthority,ComputeConfig,ControlPlaneScalingConfig,DeletionProtection,EncryptionConfig,Force,KubeApiServerConfig,KubeControllerManagerConfig,KubeSchedulerConfig,KubernetesNetworkConfig,Logging,Name,OutpostConfig,RemoteNetworkConfig,ResourcesVpcConfig,RoleArn,RollbackConfig,StorageConfig,Tags,UpgradePolicy,Version,ZonalShiftConfig
|
||||
AWS::EKS::Nodegroup Arn,Id AmiType,CapacityType,ClusterName,DiskSize,ForceUpdateEnabled,InstanceTypes,Labels,LaunchTemplate,NodeRepairConfig,NodeRole,NodegroupName,ReleaseVersion,RemoteAccess,ScalingConfig,Subnets,Tags,Taints,UpdateConfig,Version,WarmPoolConfig
|
||||
AWS::EMR::Cluster Id,MasterPublicDNS AdditionalInfo,Applications,AutoScalingRole,AutoTerminationPolicy,BootstrapActions,Configurations,CustomAmiId,EbsRootVolumeIops,EbsRootVolumeSize,EbsRootVolumeThroughput,Instances,JobFlowRole,KerberosAttributes,LogEncryptionKmsKeyId,LogUri,ManagedScalingPolicy,MonitoringConfiguration,Name,OSReleaseLabel,PlacementGroupConfigs,ReleaseLabel,ScaleDownBehavior,SecurityConfiguration,ServiceRole,SessionEnabled,StepConcurrencyLevel,Steps,Tags
|
||||
AWS::EMR::InstanceFleetConfig InstanceFleetId ClusterId,InstanceFleetType,InstanceTypeConfigs,LaunchSpecifications,Name,ResizeSpecifications,TargetOnDemandCapacity,TargetSpotCapacity
|
||||
AWS::EMR::InstanceGroupConfig InstanceGroupId AutoScalingPolicy,BidPrice,Configurations,CustomAmiId,EbsConfiguration,InstanceCount,InstanceRole,InstanceType,JobFlowId,Market,Name
|
||||
AWS::EMR::SecurityConfiguration Name,SecurityConfiguration
|
||||
AWS::EMR::Step Id ActionOnFailure,EncryptionKeyArn,HadoopJarStep,JobFlowId,LogUri,Name
|
||||
AWS::EMR::Studio Arn,StudioId,Url AuthMode,DefaultS3Location,Description,EncryptionKeyArn,EngineSecurityGroupId,IdcInstanceArn,IdcUserAssignment,IdpAuthUrl,IdpRelayStateParameterName,Name,ServiceRole,SubnetIds,Tags,TrustedIdentityPropagationEnabled,UserRole,VpcId,WorkspaceSecurityGroupId
|
||||
AWS::EMR::StudioSessionMapping IdentityName,IdentityType,SessionPolicyArn,StudioId
|
||||
AWS::EMRContainers::VirtualCluster Arn,Id ContainerProvider,Name,SecurityConfigurationId,SessionEnabled,Tags
|
||||
|
||||
|
@@ -110,7 +110,10 @@ AWS::EFS::MountTarget EfsCfnProvisioner
|
||||
AWS::EKS::Cluster EksCfnProvisioner
|
||||
AWS::EKS::Nodegroup EksCfnProvisioner
|
||||
AWS::EMR::Cluster EmrCfnProvisioner
|
||||
AWS::EMR::InstanceFleetConfig EmrCfnProvisioner
|
||||
AWS::EMR::InstanceGroupConfig EmrCfnProvisioner
|
||||
AWS::EMR::SecurityConfiguration EmrCfnProvisioner
|
||||
AWS::EMR::Step EmrCfnProvisioner
|
||||
AWS::EMR::Studio EmrStudioCfnProvisioner
|
||||
AWS::EMR::StudioSessionMapping EmrStudioCfnProvisioner
|
||||
AWS::EMRContainers::VirtualCluster EmrContainersCfnProvisioner
|
||||
|
||||
|
@@ -52,7 +52,8 @@ FETCH_TIMEOUT_SECONDS = 60
|
||||
# The resource types whose provisioners read their properties through CfnPropertyTypes.
|
||||
RESOURCE_TYPES = ["AWS::AutoScaling::LaunchConfiguration", "AWS::DSQL::Cluster", "AWS::EC2::Instance",
|
||||
"AWS::EC2::LaunchTemplate", "AWS::ECS::TaskDefinition", "AWS::EKS::Cluster",
|
||||
"AWS::EMR::Cluster", "AWS::EMR::SecurityConfiguration", "AWS::EMR::Studio",
|
||||
"AWS::EMR::Cluster", "AWS::EMR::InstanceFleetConfig", "AWS::EMR::InstanceGroupConfig",
|
||||
"AWS::EMR::SecurityConfiguration", "AWS::EMR::Step", "AWS::EMR::Studio",
|
||||
"AWS::EMR::StudioSessionMapping",
|
||||
"AWS::EMRContainers::VirtualCluster", "AWS::EMRServerless::Application",
|
||||
"AWS::Events::Connection", "AWS::Events::Rule",
|
||||
|
||||
@@ -100,7 +100,7 @@ type_order:
|
||||
AWS::ECS: [Cluster, TaskDefinition, Service]
|
||||
AWS::EFS: [FileSystem, MountTarget, AccessPoint]
|
||||
AWS::EKS: [Cluster, Nodegroup]
|
||||
AWS::EMR: [Cluster, SecurityConfiguration, Studio, StudioSessionMapping]
|
||||
AWS::EMR: [Cluster, InstanceGroupConfig, InstanceFleetConfig, Step, SecurityConfiguration, Studio, StudioSessionMapping]
|
||||
AWS::RDS:
|
||||
[DBInstance, DBCluster, DBSubnetGroup, DBParameterGroup, DBClusterParameterGroup]
|
||||
AWS::ElastiCache:
|
||||
@@ -236,7 +236,10 @@ notes:
|
||||
AWS::EKS::Cluster: 'created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack, for `Logging`, for `AccessConfig.AuthenticationMode` (a mode cannot be moved back, so a stack update that does so fails, and a stack rollback restores it) and for `ResourcesVpcConfig` endpoint access and `PublicAccessCidrs`; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion`; a change to the subnets or security groups of `ResourcesVpcConfig` fails the resource, as the emulator''s `UpdateClusterConfig` does not change them'
|
||||
AWS::EKS::Nodegroup: 'created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place'
|
||||
AWS::EMR::Cluster: 'created through `RunJobFlow`, once it is waiting or running, its master, core and task groups or fleets as `RunJobFlow`''s `InstanceGroups` or `InstanceFleets`; `AdditionalInfo`, `KerberosAttributes`, `OSReleaseLabel`, `EbsRootVolumeIops`, `EbsRootVolumeThroughput`, `PlacementGroupConfigs`, `LogEncryptionKmsKeyId` and `MonitoringConfiguration`, `Instances`'' `Ec2SubnetIds`, additional security groups and `HadoopVersion`, a group''s `EbsConfiguration` and `CustomAmiId` and a fleet''s launch and resize specifications are accepted with a warning and not stored; task groups and fleets need unique names; a template that sets the read-only `Id` or `MasterPublicDNS` is refused; updated in place for `AutoTerminationPolicy`, `ManagedScalingPolicy`, `StepConcurrencyLevel`, `VisibleToAllUsers`, `Tags` (keeping tags added outside the stack), `TerminationProtected`, `UnhealthyNodeReplacement`, a core or task group''s `InstanceCount` and `AutoScalingPolicy` and a core or task fleet''s target capacities, a dropped one taking its default; any other change, within `Instances` included, replaces the cluster and terminates the old one once the update commits; a termination-protected cluster refuses the delete'
|
||||
AWS::EMR::InstanceFleetConfig: 'a `TASK` fleet, the one type the reference allows, added through `AddInstanceFleet`; `TargetOnDemandCapacity` and `TargetSpotCapacity` update in place through `ModifyInstanceFleet`, a change to `InstanceTypeConfigs` or `ResizeSpecifications` is accepted with a warning and not applied, and a create-only change adds a new fleet; the delete shrinks the fleet to nothing, as a fleet cannot be removed from its cluster'
|
||||
AWS::EMR::InstanceGroupConfig: 'a `TASK` group, the one role the reference allows, added through `AddInstanceGroups`; `InstanceCount` and `AutoScalingPolicy` update in place, and a create-only change adds a new group; the delete removes its policy and shrinks it to nothing, as a group cannot be removed from its cluster'
|
||||
AWS::EMR::SecurityConfiguration: 'created with `Name`, generated when the template gives none, and the `SecurityConfiguration` JSON, as an object or its text; both are create-only, so any change replaces it and deletes the old one once the update commits, and a change that keeps a template''s own `Name` is refused, as for every custom-named resource'
|
||||
AWS::EMR::Step: 'added through `AddJobFlowSteps`, `LogUri` and `EncryptionKeyArn` as its `StepMonitoringConfiguration`; every property is create-only, so a change adds a new step, and a step stays in its cluster''s history when deleted, as the schema''s delete handler calls nothing'
|
||||
AWS::EMR::Studio: 'created with every property; a template that sets the read-only `Arn`, `StudioId` or `Url` is refused; updated in place through `UpdateStudio` for `Name`, `Description`, `SubnetIds` and `DefaultS3Location`, a dropped setting kept as it is, and for `Tags`, keeping tags added outside the stack; a change to `IdpAuthUrl` or `IdpRelayStateParameterName` is accepted with a warning and not applied, as no Studio API changes them; a rollback puts back the name, description, location and tags, but not subnets an update added, which `UpdateStudio` cannot take away; a change to a create-only property replaces the Studio and deletes the old one once the update commits'
|
||||
AWS::EMR::StudioSessionMapping: '`Ref` is `StudioId|IdentityType|IdentityName`, the schema''s primary identifier; `SessionPolicyArn` updates in place, and a change to any of the three others replaces the mapping'
|
||||
AWS::EMRContainers::VirtualCluster: 'created with `Name`, `ContainerProvider`, `SecurityConfigurationId`, `SessionEnabled` and `Tags`; a template that sets the read-only `Arn` or `Id` is refused; updated in place for `Tags` alone, which end as the template lists them, any other but an `aws:` one removed; a change to any other property replaces the virtual cluster, as the registry marks them create-only, and terminates the old one once the update commits; an update of a virtual cluster that is terminated or gone fails'
|
||||
|
||||
Reference in new issue
Block a user