mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(backup): paginate backup plan listings (#6714)
* fix(backup): paginate backup plan listings * test(backup): share SDK clients and seed large fixtures locally
This commit is contained in:
1 parent
64ad7a10a3
commit
ecb39dd7e0
6 files changed
+328
-8
No files matched your search
@@ -314,19 +314,30 @@ public class BackupController {
|
||||
|
||||
@GET
|
||||
@Path("/backup/plans/")
|
||||
public Response listBackupPlans() {
|
||||
List<BackupPlan> plans = service.listBackupPlans();
|
||||
public Response listBackupPlans(@Context HttpHeaders headers,
|
||||
@QueryParam("includeDeleted") @DefaultValue("false") boolean includeDeleted,
|
||||
@QueryParam("maxResults") String maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
PaginatedResult<BackupPlan> page = service.listBackupPlans(region, includeDeleted,
|
||||
Pagination.parseMaxResults(maxResults, "InvalidParameterValueException"), nextToken);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
ArrayNode list = out.putArray("BackupPlansList");
|
||||
for (BackupPlan plan : plans) {
|
||||
for (BackupPlan plan : page.items()) {
|
||||
ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("BackupPlanId", plan.getBackupPlanId());
|
||||
item.put("BackupPlanArn", plan.getBackupPlanArn());
|
||||
item.put("BackupPlanName", plan.getBackupPlanName());
|
||||
item.put("CreationDate", plan.getCreationDate());
|
||||
item.put("VersionId", plan.getVersionId());
|
||||
if (plan.getDeletionDate() != null) {
|
||||
item.put("DeletionDate", plan.getDeletionDate());
|
||||
}
|
||||
list.add(item);
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
out.put("NextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(out).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ApplicationScoped
|
||||
@Startup
|
||||
@@ -283,13 +284,18 @@ public class BackupService {
|
||||
|
||||
public PaginatedResult<BackupVault> listBackupVaults(String region, String byVaultType,
|
||||
Integer maxResults, String nextToken) {
|
||||
String namespace = "backup:ListBackupVaults:" + regionResolver.getAccountId() + ":" + region + ":"
|
||||
+ (byVaultType == null ? "all" : "type:" + byVaultType);
|
||||
return paginate(listBackupVaults(region, byVaultType), BackupVault::getBackupVaultName,
|
||||
maxResults, nextToken, namespace);
|
||||
}
|
||||
|
||||
private static <T> PaginatedResult<T> paginate(List<T> items, Function<T, String> cursorOf,
|
||||
Integer maxResults, String nextToken, String namespace) {
|
||||
if (maxResults != null && (maxResults < 1 || maxResults > 1000)) {
|
||||
throw new AwsException("InvalidParameterValueException", "maxResults must be between 1 and 1000", 400);
|
||||
}
|
||||
String namespace = "backup:ListBackupVaults:" + regionResolver.getAccountId() + ":" + region + ":"
|
||||
+ (byVaultType == null ? "all" : "type:" + byVaultType);
|
||||
return Pagination.paginate(listBackupVaults(region, byVaultType), BackupVault::getBackupVaultName,
|
||||
maxResults == null ? 1000 : maxResults, nextToken, namespace,
|
||||
return Pagination.paginate(items, cursorOf, maxResults == null ? 1000 : maxResults, nextToken, namespace,
|
||||
token -> new AwsException("InvalidParameterValueException", "Invalid nextToken.", 400));
|
||||
}
|
||||
|
||||
@@ -676,6 +682,17 @@ public class BackupService {
|
||||
return planStore.scan(k -> true);
|
||||
}
|
||||
|
||||
public PaginatedResult<BackupPlan> listBackupPlans(String region, boolean includeDeleted,
|
||||
Integer maxResults, String nextToken) {
|
||||
List<BackupPlan> plans = listBackupPlans().stream()
|
||||
.filter(plan -> region.equals(AwsArnUtils.regionOrDefault(plan.getBackupPlanArn(),
|
||||
regionResolver.getDefaultRegion())))
|
||||
.filter(plan -> includeDeleted || plan.getDeletionDate() == null)
|
||||
.toList();
|
||||
String namespace = "backup:ListBackupPlans:" + regionResolver.getAccountId() + ":" + region + ":" + includeDeleted;
|
||||
return paginate(plans, BackupPlan::getBackupPlanId, maxResults, nextToken, namespace);
|
||||
}
|
||||
|
||||
// ── Selection ──────────────────────────────────────────────────────────────
|
||||
|
||||
public BackupSelection createBackupSelection(String planId, String selectionName,
|
||||
|
||||
Reference in new issue
Block a user