mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(redshift-serverless): add release track, managed workgroup and reservation reads (#5691)
* feat(redshift-serverless): add release track, managed workgroup and reservation reads Add GetTrack, ListTracks, ListManagedWorkgroups, ListReservations, ListReservationOfferings, GetReservation, GetReservationOffering and CreateReservation so SDK, CLI and IaC clients no longer get an unknown operation error. Floci models no zero-ETL managed workgroups and sells no reservations, so the lists are empty and the reservation lookups answer ResourceNotFoundException. The two release tracks are current and trailing. Required members, patterns and lengths come from the AWS model through RedshiftServerlessRequestShapes; only the track names, which the model leaves unenumerated, are checked by hand. * refactor(redshift-serverless): reuse Pagination.paginate and remove unused admin handle method Rely on Pagination.paginate for maxResults and nextToken validation in listTracks and listWithoutItems, matching the other Redshift Serverless lists. Remove the unused handle method and its duplicate unknown-operation response in RedshiftServerlessAdminJsonHandler.
This commit is contained in:
1 parent
2ec88794b5
commit
d3fce14256
11 files changed
+319
-9
No files matched your search
+111
@@ -0,0 +1,111 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
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.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* The Redshift Serverless actions that only describe or record metadata. The main
|
||||
* {@link RedshiftServerlessJsonHandler} hands every action it does not know to this class. The
|
||||
* request constraints (required members, patterns, lengths) are checked against the AWS model by
|
||||
* {@link RedshiftServerlessRequestShapes} before the action reaches it.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RedshiftServerlessAdminJsonHandler {
|
||||
|
||||
private static final List<String> TRACK_NAMES = RedshiftServerlessService.TRACK_NAMES;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessAdminJsonHandler(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
Supplier<Response> operation(String action, JsonNode request, String region) {
|
||||
return switch (action) {
|
||||
case "GetTrack" -> () -> getTrack(ServerlessSupport.text(request, "trackName"));
|
||||
case "ListTracks" -> () -> listTracks(request);
|
||||
case "ListManagedWorkgroups" -> () -> listWithoutItems(request, "managedWorkgroups");
|
||||
case "ListReservations" -> () -> listWithoutItems(request, "reservationsList");
|
||||
case "ListReservationOfferings" -> () -> listWithoutItems(request, "reservationOfferingsList");
|
||||
case "GetReservation" -> () -> getReservation(request);
|
||||
case "GetReservationOffering" -> () -> getReservationOffering(request);
|
||||
case "CreateReservation" -> () -> createReservation(request);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private Response getReservation(JsonNode request) {
|
||||
throw ServerlessSupport.notFound("The reservation "
|
||||
+ ServerlessSupport.text(request, "reservationId") + " was not found.");
|
||||
}
|
||||
|
||||
private Response getReservationOffering(JsonNode request) {
|
||||
throw ServerlessSupport.notFound("The reservation offering "
|
||||
+ ServerlessSupport.text(request, "offeringId") + " was not found.");
|
||||
}
|
||||
|
||||
private Response createReservation(JsonNode request) {
|
||||
ServerlessSupport.integer(request, "capacity");
|
||||
ServerlessSupport.text(request, "clientToken");
|
||||
throw ServerlessSupport.notFound("The reservation offering "
|
||||
+ ServerlessSupport.text(request, "offeringId") + " was not found.");
|
||||
}
|
||||
|
||||
// ── Tracks, managed workgroups and reservations ────────────────────────
|
||||
|
||||
/**
|
||||
* The release tracks AWS defines. The model gives a track name only a pattern, not an enum, so an
|
||||
* unknown name is a not-found here. Floci runs one PostgreSQL version, so a track names no workgroup version.
|
||||
*/
|
||||
private Response getTrack(String trackName) {
|
||||
if (!TRACK_NAMES.contains(trackName)) {
|
||||
throw ServerlessSupport.notFound("The track " + trackName + " was not found.");
|
||||
}
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("track", trackNode(trackName));
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response listTracks(JsonNode request) {
|
||||
PaginatedResult<String> page = Pagination.paginate(TRACK_NAMES, name -> name,
|
||||
ServerlessSupport.maxResults(request), ServerlessSupport.text(request, "nextToken"),
|
||||
100, 100, "ValidationException");
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode items = response.putArray("tracks");
|
||||
page.items().forEach(name -> items.add(trackNode(name)));
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private ObjectNode trackNode(String trackName) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("trackName", trackName);
|
||||
node.putArray("updateTargets");
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list that is always empty, still validating the paging members the way AWS does. Floci models no
|
||||
* Glue zero-ETL managed workgroups, publishes no reservation offerings and sells no reservations.
|
||||
*/
|
||||
private Response listWithoutItems(JsonNode request, String listName) {
|
||||
Pagination.paginate(List.<String>of(), name -> name, ServerlessSupport.maxResults(request),
|
||||
ServerlessSupport.text(request, "nextToken"), 100, 100, "ValidationException");
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.putArray(listName);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -43,15 +43,18 @@ public class RedshiftServerlessJsonHandler {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final RedshiftIamDbUserResolver iamDbUserResolver;
|
||||
private final RedshiftServerlessUsageLimitService usageLimits;
|
||||
private final RedshiftServerlessAdminJsonHandler admin;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessJsonHandler(RedshiftServerlessService service, ObjectMapper objectMapper,
|
||||
RedshiftIamDbUserResolver iamDbUserResolver,
|
||||
RedshiftServerlessUsageLimitService usageLimits) {
|
||||
RedshiftServerlessUsageLimitService usageLimits,
|
||||
RedshiftServerlessAdminJsonHandler admin) {
|
||||
this.service = service;
|
||||
this.objectMapper = objectMapper;
|
||||
this.iamDbUserResolver = iamDbUserResolver;
|
||||
this.usageLimits = usageLimits;
|
||||
this.admin = admin;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region) {
|
||||
@@ -87,7 +90,7 @@ public class RedshiftServerlessJsonHandler {
|
||||
case "ListTagsForResource" -> () -> handleListTagsForResource(request, region);
|
||||
case "TagResource" -> () -> handleTagResource(request, region);
|
||||
case "UntagResource" -> () -> handleUntagResource(request, region);
|
||||
default -> null;
|
||||
default -> admin.operation(action, request, region);
|
||||
};
|
||||
if (operation == null) {
|
||||
return Response.status(400)
|
||||
|
||||
+3
-5
@@ -88,6 +88,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
public static final int DEFAULT_BASE_CAPACITY = 128;
|
||||
public static final int DEFAULT_PORT = 5439;
|
||||
public static final String DEFAULT_TRACK_NAME = "current";
|
||||
public static final List<String> TRACK_NAMES = List.of("current", "trailing");
|
||||
public static final String DEFAULT_IP_ADDRESS_TYPE = "ipv4";
|
||||
public static final String DEFAULT_ADMIN_USERNAME = "admin";
|
||||
public static final int DEFAULT_CREDENTIAL_DURATION_SECONDS = 900;
|
||||
@@ -97,7 +98,6 @@ public class RedshiftServerlessService implements Resettable {
|
||||
private static final int MAX_RETENTION_DAYS = 3653;
|
||||
private static final Pattern SNAPSHOT_NAME = Pattern.compile("[a-z0-9-]+");
|
||||
private static final Pattern WORKGROUP_NAME = Pattern.compile("[a-z0-9-]+");
|
||||
private static final Pattern TRACK_NAME = Pattern.compile("[a-zA-Z0-9_]+");
|
||||
private static final Set<String> IP_ADDRESS_TYPES = Set.of("ipv4", "dualstack");
|
||||
private static final Set<String> PERFORMANCE_TARGET_STATUSES = Set.of("ENABLED", "DISABLED");
|
||||
|
||||
@@ -993,10 +993,8 @@ public class RedshiftServerlessService implements Resettable {
|
||||
if (settings.ipAddressType() != null && !IP_ADDRESS_TYPES.contains(settings.ipAddressType())) {
|
||||
throw ServerlessSupport.validation("ipAddressType must be ipv4 or dualstack.");
|
||||
}
|
||||
if (settings.trackName() != null
|
||||
&& (settings.trackName().isEmpty() || settings.trackName().length() > 256
|
||||
|| !TRACK_NAME.matcher(settings.trackName()).matches())) {
|
||||
throw ServerlessSupport.validation("trackName must be 1-256 characters of letters, numbers, and underscores.");
|
||||
if (settings.trackName() != null && !TRACK_NAMES.contains(settings.trackName())) {
|
||||
throw ServerlessSupport.validation("trackName must be one of " + TRACK_NAMES + ".");
|
||||
}
|
||||
PricePerformanceTarget target = settings.pricePerformanceTarget();
|
||||
if (target != null) {
|
||||
|
||||
Reference in new issue
Block a user