feat(emr): ListReleaseLabels, DescribeReleaseLabel and ListSupportedInstanceTypes (#5748)

* feat(emr): ListReleaseLabels, DescribeReleaseLabel and ListSupportedInstanceTypes

None was served, so Terraform's aws_emr_release_labels and
aws_emr_supported_instance_types data sources failed against Floci.

A curated catalogue of EMR releases (emr-7.5.0, Floci's default, and
emr-7.4.0, emr-6.15.0, emr-6.14.0 and emr-5.36.2) carries each
release's applications and versions from the EMR Release Guide and its
recent Amazon Linux releases, with common instance types and their EC2
sizes. The three actions filter and page it as the API documents, and
answer InvalidRequestException for an unknown release, a bad token or
an out-of-range MaxResults. A configured default release outside the
catalogue is still listed.

Closes #5734

* fix(emr): report EMR architecture values and match application versions without regard to case

ListSupportedInstanceTypes returned the EC2 spellings x86_64 and arm64; the EMR model gives X86_64 and AARCH64 for Architecture. The ListReleaseLabels application filter matched the name without regard to case but not the version, so phoenix@4.14.3-hbase-1.4 missed emr-5.36.2.

* refactor(emr): page the release catalogue with the shared Pagination

ListReleaseLabels and ListSupportedInstanceTypes now page through
core.common.Pagination, with the filters in the token namespace so a token
replayed with other filters, or altered, is refused. DescribeReleaseLabel
answers every application, as AWS reserves its MaxResults and NextToken.
The EMR integration tests share one request helper.
This commit is contained in:
David authored and GitHub committed 2026-10-18 15:11:42 -04:00
1 parent e3e06a1122
commit 7dc514b52f
13 files changed
+696 -137

No files matched your search

@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsJson11Controller;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.services.emr.model.EmrBlockPublicAccess;
import io.github.hectorvent.floci.services.emr.model.EmrCluster;
import io.github.hectorvent.floci.services.emr.model.EmrInstanceFleet;
@@ -83,6 +84,9 @@ public class EmrHandler {
case "RemoveAutoTerminationPolicy" -> handleRemoveAutoTerminationPolicy(request);
case "PutAutoScalingPolicy" -> handlePutAutoScalingPolicy(request);
case "RemoveAutoScalingPolicy" -> handleRemoveAutoScalingPolicy(request);
case "ListReleaseLabels" -> handleListReleaseLabels(request);
case "DescribeReleaseLabel" -> handleDescribeReleaseLabel(request);
case "ListSupportedInstanceTypes" -> handleListSupportedInstanceTypes(request);
case "GetBlockPublicAccessConfiguration" -> handleGetBlockPublicAccessConfiguration(region);
case "PutBlockPublicAccessConfiguration" -> handlePutBlockPublicAccessConfiguration(request, region);
default -> Response.status(400)
@@ -329,6 +333,71 @@ public class EmrHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
// ──────────────────────────── Release catalogue ────────────────────────────
private Response handleListReleaseLabels(JsonNode request) {
JsonNode filters = request.path("Filters");
PaginatedResult<String> page = service.listReleaseLabels(
filters.path("Prefix").asText(null), filters.path("Application").asText(null),
request.path("NextToken").asText(null), intOrNull(request.path("MaxResults")));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode labels = response.putArray("ReleaseLabels");
page.items().forEach(labels::add);
if (page.nextToken() != null) {
response.put("NextToken", page.nextToken());
}
return Response.ok(response).build();
}
private Response handleDescribeReleaseLabel(JsonNode request) {
// MaxResults and NextToken are "reserved for future use" and AWS answers every application.
EmrReleaseCatalog.Release release = service.describeReleaseLabel(request.path("ReleaseLabel").asText(null));
ObjectNode response = objectMapper.createObjectNode();
response.put("ReleaseLabel", release.label());
ArrayNode apps = response.putArray("Applications");
for (EmrReleaseCatalog.Application app : release.applications()) {
apps.addObject().put("Name", app.name()).put("Version", app.version());
}
ArrayNode os = response.putArray("AvailableOSReleases");
release.osReleases().forEach(label -> os.addObject().put("Label", label));
return Response.ok(response).build();
}
private Response handleListSupportedInstanceTypes(JsonNode request) {
PaginatedResult<EmrReleaseCatalog.InstanceType> page = service.listSupportedInstanceTypes(
request.path("ReleaseLabel").asText(null), request.path("Marker").asText(null));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode types = response.putArray("SupportedInstanceTypes");
for (EmrReleaseCatalog.InstanceType t : page.items()) {
types.addObject()
.put("Type", t.type())
.put("MemoryGB", t.memoryGb())
.put("StorageGB", t.storageGb())
.put("VCPU", t.vcpu())
.put("Is64BitsOnly", true)
.put("InstanceFamilyId", t.instanceFamilyId())
.put("EbsOptimizedAvailable", true)
.put("EbsOptimizedByDefault", true)
.put("NumberOfDisks", t.numberOfDisks())
.put("EbsStorageOnly", t.ebsStorageOnly())
.put("Architecture", t.architecture());
}
if (page.nextToken() != null) {
response.put("Marker", page.nextToken());
}
return Response.ok(response).build();
}
private static Integer intOrNull(JsonNode node) {
if (node == null || node.isMissingNode() || node.isNull()) {
return null;
}
if (!node.canConvertToInt()) {
throw new AwsException("InvalidRequestException", "MaxResults must be an integer.", 400);
}
return node.asInt();
}
private Response handleListSecurityConfigurations() {
ObjectNode response = objectMapper.createObjectNode();
ArrayNode arr = response.putArray("SecurityConfigurations");
@@ -0,0 +1,207 @@
package io.github.hectorvent.floci.services.emr;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
/**
* The EMR releases ListReleaseLabels, DescribeReleaseLabel and ListSupportedInstanceTypes report: a
* curated set of recent releases, not AWS's full list. Each release's applications and versions come
* from its page in the Amazon EMR Release Guide (application names lowercased and versions without
* AWS's {@code -amzn-N} build suffix, as the API reports them), with the two most recent Amazon Linux
* releases that page lists. The instance types are common EMR families with their EC2 sizes, all of
* which these releases support.
*/
final class EmrReleaseCatalog {
record Application(String name, String version) {}
record Release(String label, List<Application> applications, List<String> osReleases) {}
record InstanceType(String type, int vcpu, float memoryGb, int storageGb, int numberOfDisks,
boolean ebsStorageOnly, String instanceFamilyId, String architecture) {}
/** Newest first, as ListReleaseLabels returns them. */
static final List<Release> RELEASES = List.of(
new Release("emr-7.5.0", List.of(
app("amazoncloudwatchagent", "1.300032.2"),
app("delta", "3.2.1"),
app("flink", "1.19.1"),
app("hadoop", "3.4.0"),
app("hbase", "2.5.10"),
app("hcatalog", "3.1.3"),
app("hive", "3.1.3"),
app("hudi", "0.15.0"),
app("hue", "4.11.0"),
app("iceberg", "1.6.1"),
app("jupyterenterprisegateway", "2.6.0"),
app("jupyterhub", "1.5.0"),
app("livy", "0.8.0-incubating"),
app("oozie", "5.2.1"),
app("phoenix", "5.2.0"),
app("pig", "0.17.0"),
app("presto", "0.287"),
app("spark", "3.5.2"),
app("tensorflow", "2.16.1"),
app("tez", "0.10.2"),
app("trino", "446"),
app("zeppelin", "0.11.1"),
app("zookeeper", "3.9.2")),
List.of("2023.12.20260803.3", "2023.12.20260727.0")),
new Release("emr-7.4.0", List.of(
app("amazoncloudwatchagent", "1.300032.2"),
app("delta", "3.2.0"),
app("flink", "1.19.1"),
app("hadoop", "3.4.0"),
app("hbase", "2.5.5"),
app("hcatalog", "3.1.3"),
app("hive", "3.1.3"),
app("hudi", "0.15.0"),
app("hue", "4.11.0"),
app("iceberg", "1.6.1"),
app("jupyterenterprisegateway", "2.6.0"),
app("jupyterhub", "1.5.0"),
app("livy", "0.8.0-incubating"),
app("oozie", "5.2.1"),
app("phoenix", "5.2.0"),
app("pig", "0.17.0"),
app("presto", "0.287"),
app("spark", "3.5.2"),
app("sqoop", "1.4.7"),
app("tensorflow", "2.16.1"),
app("tez", "0.10.2"),
app("trino", "446"),
app("zeppelin", "0.11.1"),
app("zookeeper", "3.9.2")),
List.of("2023.12.20260803.3", "2023.12.20260727.0")),
new Release("emr-6.15.0", List.of(
app("delta", "2.4.0"),
app("flink", "1.17.1"),
app("ganglia", "3.7.2"),
app("hadoop", "3.3.6"),
app("hbase", "2.4.17"),
app("hcatalog", "3.1.3"),
app("hive", "3.1.3"),
app("hudi", "0.14.0"),
app("hue", "4.11.0"),
app("iceberg", "1.4.0"),
app("jupyterenterprisegateway", "2.6.0"),
app("jupyterhub", "1.5.0"),
app("livy", "0.7.1-incubating"),
app("mxnet", "1.9.1"),
app("oozie", "5.2.1"),
app("phoenix", "5.1.3"),
app("pig", "0.17.0"),
app("presto", "0.283"),
app("spark", "3.4.1"),
app("sqoop", "1.4.7"),
app("tensorflow", "2.11.0"),
app("tez", "0.10.2"),
app("trino", "426"),
app("zeppelin", "0.10.1"),
app("zookeeper", "3.5.10")),
List.of("2.0.20260803.1", "2.0.20260727.0")),
new Release("emr-6.14.0", List.of(
app("delta", "2.4.0"),
app("flink", "1.17.1"),
app("ganglia", "3.7.2"),
app("hadoop", "3.3.3"),
app("hbase", "2.4.17"),
app("hcatalog", "3.1.3"),
app("hive", "3.1.3"),
app("hudi", "0.13.1"),
app("hue", "4.11.0"),
app("iceberg", "1.3.1"),
app("jupyterenterprisegateway", "2.6.0"),
app("jupyterhub", "1.5.0"),
app("livy", "0.7.1-incubating"),
app("mxnet", "1.9.1"),
app("oozie", "5.2.1"),
app("phoenix", "5.1.3"),
app("pig", "0.17.0"),
app("presto", "0.281"),
app("spark", "3.4.1"),
app("sqoop", "1.4.7"),
app("tensorflow", "2.11.0"),
app("tez", "0.10.2"),
app("trino", "422"),
app("zeppelin", "0.10.1"),
app("zookeeper", "3.5.10")),
List.of("2.0.20260803.1", "2.0.20260727.0")),
new Release("emr-5.36.2", List.of(
app("flink", "1.14.2"),
app("ganglia", "3.7.2"),
app("hadoop", "2.10.1"),
app("hbase", "1.4.13"),
app("hcatalog", "2.3.9"),
app("hive", "2.3.9"),
app("hudi", "0.10.1"),
app("hue", "4.10.0"),
app("jupyterenterprisegateway", "2.6.0"),
app("jupyterhub", "1.4.1"),
app("livy", "0.7.1-incubating"),
app("mahout", "0.13.0"),
app("mxnet", "1.8.0"),
app("oozie", "5.2.1"),
app("phoenix", "4.14.3-HBase-1.4"),
app("pig", "0.17.0"),
app("presto", "0.267"),
app("spark", "2.4.8"),
app("sqoop", "1.4.7"),
app("tensorflow", "2.4.1"),
app("tez", "0.9.2"),
app("zeppelin", "0.10.0"),
app("zookeeper", "3.4.14")),
List.of("2.0.20260803.1", "2.0.20260727.0")));
static final List<InstanceType> INSTANCE_TYPES = List.of(
new InstanceType("c5.xlarge", 4, 8f, 0, 0, true, "c5", "X86_64"),
new InstanceType("c5.2xlarge", 8, 16f, 0, 0, true, "c5", "X86_64"),
new InstanceType("m5.xlarge", 4, 16f, 0, 0, true, "m5", "X86_64"),
new InstanceType("m5.2xlarge", 8, 32f, 0, 0, true, "m5", "X86_64"),
new InstanceType("m5.4xlarge", 16, 64f, 0, 0, true, "m5", "X86_64"),
new InstanceType("m5d.xlarge", 4, 16f, 150, 1, false, "m5d", "X86_64"),
new InstanceType("m5d.2xlarge", 8, 32f, 300, 1, false, "m5d", "X86_64"),
new InstanceType("m6g.xlarge", 4, 16f, 0, 0, true, "m6g", "AARCH64"),
new InstanceType("m6g.2xlarge", 8, 32f, 0, 0, true, "m6g", "AARCH64"),
new InstanceType("r5.xlarge", 4, 32f, 0, 0, true, "r5", "X86_64"),
new InstanceType("r5.2xlarge", 8, 64f, 0, 0, true, "r5", "X86_64"),
new InstanceType("r6g.xlarge", 4, 32f, 0, 0, true, "r6g", "AARCH64"));
private EmrReleaseCatalog() {
}
private static Application app(String name, String version) {
return new Application(name, version);
}
static Optional<Release> release(String label) {
return RELEASES.stream().filter(r -> r.label().equals(label)).findFirst();
}
/** Numeric release order, so emr-6.15.0 sorts after emr-6.9.0. */
static final Comparator<String> NEWEST_FIRST = Comparator.comparing(EmrReleaseCatalog::versionKey,
(a, b) -> {
for (int i = 0; i < Math.max(a.length, b.length); i++) {
int x = i < a.length ? a[i] : 0;
int y = i < b.length ? b[i] : 0;
if (x != y) {
return Integer.compare(y, x);
}
}
return 0;
});
private static int[] versionKey(String label) {
String[] parts = label.replaceFirst("^emr-", "").split("\\.");
int[] key = new int[parts.length];
for (int i = 0; i < parts.length; i++) {
try {
key[i] = Integer.parseInt(parts[i]);
} catch (NumberFormatException e) {
key[i] = 0;
}
}
return key;
}
}
@@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -21,11 +23,14 @@ import jakarta.inject.Inject;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
/**
* EMR management-plane business logic. Cluster and step lifecycles are simulated
@@ -402,6 +407,97 @@ public class EmrService {
secConfigStore.delete(name);
}
// ──────────────────────────── Release catalogue ────────────────────────────
private static final int MAX_RESULTS = 100;
private static final int INSTANCE_TYPE_PAGE = 50;
/**
* The catalogue's releases, newest first. Floci's configured default release label is always
* among them, with no applications when the catalogue does not describe it, so a non-default
* setting never makes Floci's own default unknown.
*/
List<EmrReleaseCatalog.Release> releases() {
if (EmrReleaseCatalog.release(defaultReleaseLabel).isPresent()) {
return EmrReleaseCatalog.RELEASES;
}
List<EmrReleaseCatalog.Release> all = new ArrayList<>(EmrReleaseCatalog.RELEASES);
all.add(new EmrReleaseCatalog.Release(defaultReleaseLabel, List.of(), List.of()));
all.sort((a, b) -> EmrReleaseCatalog.NEWEST_FIRST.compare(a.label(), b.label()));
return all;
}
/**
* Release labels, newest first, narrowed by {@code prefix} (such as {@code emr-6}) and by
* {@code application}, a name or {@code name@version} (such as {@code spark@3.5.2}) matched
* without regard to case. A token belongs to the filters it was issued for, so one replayed
* with other filters, or altered, is refused.
*/
public PaginatedResult<String> listReleaseLabels(String prefix, String application, String nextToken,
Integer maxResults) {
if (maxResults != null && (maxResults < 1 || maxResults > MAX_RESULTS)) {
throw new AwsException("InvalidRequestException",
"MaxResults must be between 1 and " + MAX_RESULTS + ".", 400);
}
String appName = null;
String appVersion = null;
if (application != null && !application.isBlank()) {
int at = application.indexOf('@');
appName = (at < 0 ? application : application.substring(0, at)).trim();
appVersion = at < 0 ? null : application.substring(at + 1).trim();
}
String name = appName;
String version = appVersion;
List<String> labels = releases().stream()
.filter(r -> prefix == null || prefix.isBlank() || r.label().startsWith(prefix))
.filter(r -> name == null || r.applications().stream().anyMatch(a -> a.name().equalsIgnoreCase(name)
&& (version == null || version.isEmpty() || a.version().equalsIgnoreCase(version))))
.map(EmrReleaseCatalog.Release::label)
.toList();
String namespace = "ListReleaseLabels|" + Objects.toString(prefix, "") + "|" + Objects.toString(application, "");
return Pagination.paginate(labels, positionIn(labels), maxResults != null ? maxResults : MAX_RESULTS,
nextToken, namespace, EmrService::invalidToken);
}
/** A release's applications and OS releases; no label means the latest release. */
public EmrReleaseCatalog.Release describeReleaseLabel(String label) {
return label == null || label.isBlank() ? releases().get(0) : requireRelease(label);
}
public PaginatedResult<EmrReleaseCatalog.InstanceType> listSupportedInstanceTypes(String label, String marker) {
if (label == null || label.isBlank()) {
throw new AwsException("InvalidRequestException", "ReleaseLabel is required.", 400);
}
requireRelease(label);
List<EmrReleaseCatalog.InstanceType> types = EmrReleaseCatalog.INSTANCE_TYPES;
return Pagination.paginate(types, positionIn(types), INSTANCE_TYPE_PAGE, marker,
"ListSupportedInstanceTypes|" + label, EmrService::invalidToken);
}
private EmrReleaseCatalog.Release requireRelease(String label) {
return releases().stream()
.filter(r -> r.label().equals(label))
.findFirst()
.orElseThrow(() -> new AwsException("InvalidRequestException",
"The specified release label " + label + " is not valid.", 400));
}
/**
* A cursor that keeps the catalogue's own order: {@link Pagination} sorts by cursor, and the
* catalogue is newest first rather than alphabetical.
*/
private static <T> Function<T, String> positionIn(List<T> items) {
Map<T, String> positions = new HashMap<>();
for (int i = 0; i < items.size(); i++) {
positions.put(items.get(i), String.format("%06d", i));
}
return positions::get;
}
private static AwsException invalidToken(String token) {
return new AwsException("InvalidRequestException", "Invalid pagination token: " + token, 400);
}
public List<SecurityConfiguration> listSecurityConfigurations() {
return new ArrayList<>(secConfigStore.scan(k -> true));
}