mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(athena): paginate ListWorkGroups (#6519)
* fix(athena): paginate ListWorkGroups * fix(athena): use stable workgroup pagination cursors
This commit is contained in:
1 parent
57889bbb45
commit
57257e198f
3 files changed
+238
-1
No files matched your search
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.athena;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.services.athena.model.CreateWorkGroupRequest;
|
||||
import io.github.hectorvent.floci.services.athena.model.QueryExecution;
|
||||
import io.github.hectorvent.floci.services.athena.model.QueryExecutionContext;
|
||||
@@ -73,7 +74,21 @@ public class AthenaJsonHandler {
|
||||
String name = request.has("WorkGroup") ? request.get("WorkGroup").asText() : "primary";
|
||||
yield Response.ok(Map.of("WorkGroup", athenaService.getWorkGroup(name, region))).build();
|
||||
}
|
||||
case "ListWorkGroups" -> Response.ok(Map.of("WorkGroups", athenaService.listWorkGroups(region))).build();
|
||||
case "ListWorkGroups" -> {
|
||||
JsonNode maxResults = request.get("MaxResults");
|
||||
if (maxResults != null && (!maxResults.isIntegralNumber() || !maxResults.canConvertToInt())) {
|
||||
throw new AwsException("InvalidRequestException", "Invalid MaxResults", 400);
|
||||
}
|
||||
int pageSize = maxResults == null ? 50 : maxResults.asInt();
|
||||
String nextToken = request.hasNonNull("NextToken") ? request.get("NextToken").asText() : null;
|
||||
PaginatedResult<Map<String, Object>> page = athenaService.listWorkGroupsPage(region, pageSize, nextToken);
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("WorkGroups", page.items());
|
||||
if (page.nextToken() != null) {
|
||||
response.put("NextToken", page.nextToken());
|
||||
}
|
||||
yield Response.ok(response).build();
|
||||
}
|
||||
case "CreateWorkGroup" -> {
|
||||
CreateWorkGroupRequest createRequest = mapper.treeToValue(request, CreateWorkGroupRequest.class);
|
||||
athenaService.createWorkGroup(createRequest, region);
|
||||
|
||||
@@ -5,6 +5,8 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.CsvParser;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.athena.model.CreateWorkGroupConfigurationRequest;
|
||||
@@ -363,6 +365,20 @@ public class AthenaService {
|
||||
return workGroups;
|
||||
}
|
||||
|
||||
public PaginatedResult<Map<String, Object>> listWorkGroupsPage(String region, int maxResults, String nextToken) {
|
||||
if (maxResults < 1 || maxResults > 50) {
|
||||
throw new AwsException("InvalidRequestException", "MaxResults must be between 1 and 50", 400);
|
||||
}
|
||||
if (nextToken != null && nextToken.isEmpty()) {
|
||||
throw new AwsException("InvalidRequestException", "Invalid NextToken", 400);
|
||||
}
|
||||
return Pagination.paginate(listWorkGroups(region), workGroup -> {
|
||||
String name = (String) workGroup.get("Name");
|
||||
return DEFAULT_WORKGROUP.equals(name) ? "0" : "1" + name;
|
||||
}, maxResults, nextToken, "ListWorkGroups:" + region,
|
||||
token -> new AwsException("InvalidRequestException", "Invalid NextToken", 400));
|
||||
}
|
||||
|
||||
/**
|
||||
* The account's built-in Glue catalog first, then the catalogs registered through
|
||||
* {@code CreateDataCatalog}, sorted by name.
|
||||
|
||||
Reference in new issue
Block a user