fix(emr): honor ListClusters creation time filters (#6123)

* fix(emr): honor ListClusters creation time filters

* fix(emr): preserve ListClusters timestamp precision

* fix(emr): share millisecond timestamp parsing
This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-21 08:23:14 -04:00
1 parent 89317831bb
commit 7c0d592b85
9 files changed
+171 -20

No files matched your search

@@ -0,0 +1,27 @@
package io.github.hectorvent.floci.core.common;
import com.fasterxml.jackson.databind.JsonNode;
import java.time.Instant;
/** Parses numeric epoch-second members in AWS JSON requests at millisecond precision. */
public final class AwsJsonTimestamp {
private AwsJsonTimestamp() {
}
public static Instant epochSeconds(JsonNode request, String field, String errorCode) {
JsonNode node = request.path(field);
if (node.isMissingNode() || node.isNull()) {
return null;
}
if (!node.isNumber()) {
throw new AwsException(errorCode, field + " must be a timestamp.", 400);
}
double epochMillis = node.asDouble() * 1000;
if (!Double.isFinite(epochMillis) || epochMillis < Long.MIN_VALUE || epochMillis >= 0x1.0p63) {
throw new AwsException(errorCode, field + " is outside the timestamp range.", 400);
}
return Instant.ofEpochMilli(Math.round(epochMillis));
}
}
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.AwsEndpoints;
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.AwsJsonTimestamp;
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;
@@ -167,9 +168,11 @@ public class EmrHandler {
private Response handleListClusters(JsonNode request, String region) {
List<String> states = stringList(request.path("ClusterStates"));
Instant createdAfter = AwsJsonTimestamp.epochSeconds(request, "CreatedAfter", "InvalidRequestException");
Instant createdBefore = AwsJsonTimestamp.epochSeconds(request, "CreatedBefore", "InvalidRequestException");
ObjectNode response = objectMapper.createObjectNode();
ArrayNode arr = response.putArray("Clusters");
for (EmrCluster c : service.listClusters(region, states)) {
for (EmrCluster c : service.listClusters(region, states, createdAfter, createdBefore)) {
arr.add(clusterSummaryNode(c));
}
return Response.ok(response).build();
@@ -126,7 +126,8 @@ public class EmrService {
return requireCluster(id);
}
public List<EmrCluster> listClusters(String region, List<String> states) {
public List<EmrCluster> listClusters(String region, List<String> states,
Instant createdAfter, Instant createdBefore) {
List<EmrCluster> result = new ArrayList<>();
for (EmrCluster c : clusterStore.scan(k -> true)) {
if (!region.equals(c.getRegion())) {
@@ -135,6 +136,13 @@ public class EmrService {
if (states != null && !states.isEmpty() && !states.contains(c.getState())) {
continue;
}
Instant createdAt = c.getCreationDateTime();
if (createdAfter != null && (createdAt == null || !createdAt.isAfter(createdAfter))) {
continue;
}
if (createdBefore != null && (createdAt == null || !createdAt.isBefore(createdBefore))) {
continue;
}
result.add(c);
}
return result;
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsJsonTimestamp;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
@@ -279,12 +280,12 @@ public class RedshiftServerlessAdminJsonHandler {
action.setRoleArn(ServerlessSupport.text(request, "roleArn"));
action.setDescription(ServerlessSupport.text(request, "scheduledActionDescription"));
action.setEnabled(ServerlessSupport.bool(request, "enabled"));
action.setStartTime(ServerlessSupport.epochSeconds(request, "startTime"));
action.setEndTime(ServerlessSupport.epochSeconds(request, "endTime"));
action.setStartTime(AwsJsonTimestamp.epochSeconds(request, "startTime", "ValidationException"));
action.setEndTime(AwsJsonTimestamp.epochSeconds(request, "endTime", "ValidationException"));
JsonNode schedule = ServerlessSupport.object(request, "schedule");
if (schedule != null) {
action.setScheduleSpecified(true);
action.setScheduleAt(ServerlessSupport.epochSeconds(schedule, "at"));
action.setScheduleAt(AwsJsonTimestamp.epochSeconds(schedule, "at", "ValidationException"));
action.setScheduleCron(ServerlessSupport.text(schedule, "cron"));
}
JsonNode target = ServerlessSupport.object(request, "targetAction");
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsJsonTimestamp;
import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.services.redshift.RedshiftIamDbUserResolver;
@@ -254,7 +255,8 @@ public class RedshiftServerlessJsonHandler {
private Response handleListSnapshots(JsonNode request, String region) {
PaginatedResult<RedshiftServerlessSnapshot> page = service.listSnapshots(
ServerlessSupport.text(request, "namespaceName"), ServerlessSupport.text(request, "namespaceArn"), ServerlessSupport.text(request, "ownerAccount"),
ServerlessSupport.epochSeconds(request, "startTime"), ServerlessSupport.epochSeconds(request, "endTime"), region,
AwsJsonTimestamp.epochSeconds(request, "startTime", "ValidationException"),
AwsJsonTimestamp.epochSeconds(request, "endTime", "ValidationException"), region,
ServerlessSupport.maxResults(request), ServerlessSupport.text(request, "nextToken"));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode items = response.putArray("snapshots");
@@ -6,7 +6,6 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -94,18 +93,6 @@ final class ServerlessSupport {
return node.asBoolean();
}
/** A timestamp member, which awsJson1.1 sends as epoch seconds unless the model says otherwise. */
static Instant epochSeconds(JsonNode request, String field) {
JsonNode node = request.path(field);
if (node.isMissingNode() || node.isNull()) {
return null;
}
if (!node.isNumber()) {
throw validation(field + " must be a timestamp.");
}
return Instant.ofEpochMilli(Math.round(node.asDouble() * 1000));
}
static List<String> stringList(JsonNode request, String field) {
JsonNode node = request.path(field);
if (node.isMissingNode() || node.isNull()) {