Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(backup): AWS Backup management-plane API (#734)

Hector Venturac2cc053853be
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f037307da2..793f2f0caf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- **backup:** AWS Backup Phase 1 — vaults, plans, selections, on-demand jobs with simulated CREATED→RUNNING→COMPLETED lifecycle, recovery points, tagging via `SharedTagsController`, and `GetSupportedResourceTypes`
- **codedeploy:** Server platform (Phase 4) — on-premises instance management (`RegisterOnPremisesInstance`, `DeregisterOnPremisesInstance`, `GetOnPremisesInstance`, `BatchGetOnPremisesInstances`, `ListOnPremisesInstances`, `AddTagsToOnPremisesInstances`, `RemoveTagsFromOnPremisesInstances`); Server AppSpec YAML parsing; EC2 and on-premises instance resolution by tag filters; full lifecycle event execution (`ApplicationStop` → `DownloadBundle` → `BeforeInstall` → `Install` → `AfterInstall` → `ApplicationStart` → `ValidateService`); SSM Run Command integration for hook script execution with graceful degradation when SSM is unavailable; per-instance `InstanceTarget` tracking in `ListDeploymentTargets`/`BatchGetDeploymentTargets`
- **elbv2:** Lambda target type — ALB listeners forward requests to Lambda functions using the full ALB→Lambda event format (`httpMethod`, `path`, `queryStringParameters`, `multiValueQueryStringParameters`, `headers`, `multiValueHeaders`, `body`, `isBase64Encoded`); Lambda→ALB response mapping (`statusCode`, `headers`, `multiValueHeaders`, `body`, `isBase64Encoded`); Lambda target groups always report as healthy in `DescribeTargetHealth` without HTTP probing
- **eventbridge:** Archive and Replay support — `CreateArchive`, `DescribeArchive`, `UpdateArchive`, `DeleteArchive`, `ListArchives`, `StartReplay`, `DescribeReplay`, `CancelReplay`, `ListReplays`; events captured automatically to matching archives and replayed on demand ([#702](https://github.com/floci-io/floci/pull/702))
diff --git a/README.md b/README.md
index b9678e0a86..ecc4c3ff47 100644
--- a/README.md
+++ b/README.md
@@ -116,7 +116,7 @@ flowchart LR
Router["HTTP Router\n(JAX-RS / Vert.x)"]
subgraph Stateless ["Stateless Services"]
- A["SSM · SQS · SNS\nIAM · STS · KMS\nSecrets Manager · SES\nCognito · Kinesis\nEventBridge · Scheduler · AppConfig\nCloudWatch · Step Functions\nCloudFormation · ACM\nAPI Gateway · ELB v2 · Auto Scaling\nCodeDeploy · Bedrock Runtime · Route53"]
+ A["SSM · SQS · SNS\nIAM · STS · KMS\nSecrets Manager · SES\nCognito · Kinesis\nEventBridge · Scheduler · AppConfig\nCloudWatch · Step Functions\nCloudFormation · ACM\nAPI Gateway · ELB v2 · Auto Scaling\nCodeDeploy · Backup · Bedrock Runtime · Route53 · Transfer"]
end
subgraph Stateful ["Stateful Services"]
@@ -251,6 +251,7 @@ All default images are configurable via environment variables, useful for pinnin
| **CodeBuild** | In-process + **real Docker containers** | Projects, report groups, source credentials; `StartBuild` runs real Docker containers, streams logs to CloudWatch, uploads artifacts to S3 via `docker cp` (works in Docker-in-Docker) |
| **CodeDeploy** | In-process + **Lambda traffic shifting** | Applications, deployment groups, deployment configs; 17 `CodeDeployDefault.*` built-ins pre-seeded; `CreateDeployment` shifts Lambda alias `RoutingConfig` weights, invokes lifecycle hooks, auto-rolls back on failure |
| **Auto Scaling** | In-process + **background reconciler** | Launch configurations, auto scaling groups with min/max/desired capacity; background loop (10 s) calls `RunInstances` / `TerminateInstances` to meet desired capacity; lifecycle hooks, scaling policies, ELB v2 target group auto-registration |
+| **AWS Backup** | In-process | Vaults, backup plans with rules, resource selections, on-demand jobs with simulated lifecycle (CREATED → RUNNING → COMPLETED), recovery points, tagging |
| **Route53** | In-process | Hosted zones with auto-created SOA + NS records, resource record sets (CREATE/UPSERT/DELETE with atomic validation), change tracking (always INSYNC), health checks, and per-resource tagging |
> **Lambda, ElastiCache, RDS, MSK, ECS, EC2, EKS, OpenSearch, and CodeBuild** spin up real Docker containers and support IAM authentication and SigV4 request signing — the same auth flow as production AWS. **ECR** runs a shared `registry:2` container so the stock `docker` client can push and pull image bytes against repositories returned by the AWS-shaped control plane.
diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index d31b2c27f4..087f7378fe 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -239,6 +239,11 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>codedeploy</artifactId>
</dependency>
+ <!-- AWS Backup client -->
+ <dependency>
+ <groupId>software.amazon.awssdk</groupId>
+ <artifactId>backup</artifactId>
+ </dependency>
<!-- AppConfig and AppConfigData clients -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 60852cb4a1..d658a5a7de 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -48,6 +48,7 @@ import software.amazon.awssdk.services.eks.EksClient;
import software.amazon.awssdk.services.scheduler.SchedulerClient;
import software.amazon.awssdk.services.appconfig.AppConfigClient;
import software.amazon.awssdk.services.appconfigdata.AppConfigDataClient;
+import software.amazon.awssdk.services.backup.BackupClient;
import software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client;
import software.amazon.awssdk.core.SdkBytes;
@@ -552,4 +553,12 @@ public final class TestFixtures {
.credentialsProvider(CREDENTIALS)
.build();
}
+
+ public static BackupClient backupClient() {
+ return BackupClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ .build();
+ }
}
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/BackupTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/BackupTest.java
new file mode 100644
index 0000000000..2ee8b7ed58
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/BackupTest.java
@@ -0,0 +1,432 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.*;
+import software.amazon.awssdk.services.backup.BackupClient;
+import software.amazon.awssdk.services.backup.model.*;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+@DisplayName("AWS Backup")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class BackupTest {
+
+ private static BackupClient backup;
+
+ private static final String VAULT_NAME = "compat-test-vault";
+ private static final String IAM_ROLE = "arn:aws:iam::000000000000:role/backup-role";
+ private static final String RESOURCE_ARN = "arn:aws:dynamodb:us-east-1:000000000000:table/my-table";
+
+ private static String vaultArn;
+ private static String planId;
+ private static String planArn;
+ private static String selectionId;
+ private static String jobId;
+ private static String recoveryPointArn;
+
+ @BeforeAll
+ static void setup() {
+ backup = TestFixtures.backupClient();
+ }
+
+ @AfterAll
+ static void cleanup() {
+ if (backup == null) return;
+ try { backup.deleteBackupSelection(r -> r.backupPlanId(planId).selectionId(selectionId)); } catch (Exception ignored) {}
+ try { backup.deleteBackupPlan(r -> r.backupPlanId(planId)); } catch (Exception ignored) {}
+ try {
+ backup.listRecoveryPointsByBackupVault(r -> r.backupVaultName(VAULT_NAME))
+ .recoveryPoints()
+ .forEach(rp -> {
+ try {
+ backup.deleteRecoveryPoint(r -> r
+ .backupVaultName(VAULT_NAME)
+ .recoveryPointArn(rp.recoveryPointArn()));
+ } catch (Exception ignored2) {}
+ });
+ } catch (Exception ignored) {}
+ try { backup.deleteBackupVault(r -> r.backupVaultName(VAULT_NAME)); } catch (Exception ignored) {}
+ backup.close();
+ }
+
+ // ── Vault ──────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(10)
+ @DisplayName("CreateBackupVault - creates vault with tags")
+ void createBackupVault() {
+ CreateBackupVaultResponse resp = backup.createBackupVault(r -> r
+ .backupVaultName(VAULT_NAME)
+ .backupVaultTags(Map.of("env", "compat-test")));
+
+ vaultArn = resp.backupVaultArn();
+ assertThat(resp.backupVaultName()).isEqualTo(VAULT_NAME);
+ assertThat(vaultArn).contains("backup-vault:" + VAULT_NAME);
+ assertThat(resp.creationDate()).isNotNull();
+ }
+
+ @Test
+ @Order(11)
+ @DisplayName("CreateBackupVault - duplicate returns AlreadyExistsException")
+ void createVaultDuplicateFails() {
+ assertThatThrownBy(() -> backup.createBackupVault(r -> r.backupVaultName(VAULT_NAME)))
+ .isInstanceOf(AlreadyExistsException.class);
+ }
+
+ @Test
+ @Order(12)
+ @DisplayName("DescribeBackupVault - returns vault metadata")
+ void describeBackupVault() {
+ DescribeBackupVaultResponse resp = backup.describeBackupVault(r -> r.backupVaultName(VAULT_NAME));
+
+ assertThat(resp.backupVaultName()).isEqualTo(VAULT_NAME);
+ assertThat(resp.backupVaultArn()).isEqualTo(vaultArn);
+ assertThat(resp.numberOfRecoveryPoints()).isEqualTo(0);
+ assertThat(resp.creationDate()).isNotNull();
+ }
+
+ @Test
+ @Order(13)
+ @DisplayName("ListBackupVaults - includes created vault")
+ void listBackupVaults() {
+ ListBackupVaultsResponse resp = backup.listBackupVaults(r -> r.build());
+
+ assertThat(resp.backupVaultList()).isNotEmpty();
+ assertThat(resp.backupVaultList())
+ .anyMatch(v -> VAULT_NAME.equals(v.backupVaultName()));
+ }
+
+ @Test
+ @Order(14)
+ @DisplayName("DescribeBackupVault - non-existent returns ResourceNotFoundException")
+ void describeNonExistentVaultFails() {
+ assertThatThrownBy(() -> backup.describeBackupVault(r -> r.backupVaultName("no-such-vault")))
+ .isInstanceOf(ResourceNotFoundException.class);
+ }
+
+ // ── Plan ───────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(20)
+ @DisplayName("CreateBackupPlan - creates plan with rules")
+ void createBackupPlan() {
+ CreateBackupPlanResponse resp = backup.createBackupPlan(r -> r
+ .backupPlan(p -> p
+ .backupPlanName("compat-daily")
+ .rules(BackupRuleInput.builder()
+ .ruleName("daily")
+ .targetBackupVaultName(VAULT_NAME)
+ .scheduleExpression("cron(0 12 * * ? *)")
+ .startWindowMinutes(60L)
+ .completionWindowMinutes(120L)
+ .build())));
+
+ planId = resp.backupPlanId();
+ planArn = resp.backupPlanArn();
+ assertThat(planId).isNotNull();
+ assertThat(planArn).contains("backup-plan:");
+ assertThat(resp.versionId()).isNotNull();
+ assertThat(resp.creationDate()).isNotNull();
+ }
+
+ @Test
+ @Order(21)
+ @DisplayName("GetBackupPlan - returns plan with rules")
+ void getBackupPlan() {
+ GetBackupPlanResponse resp = backup.getBackupPlan(r -> r.backupPlanId(planId));
+
+ assertThat(resp.backupPlanId()).isEqualTo(planId);
+ assertThat(resp.backupPlan().backupPlanName()).isEqualTo("compat-daily");
+ assertThat(resp.backupPlan().rules()).hasSize(1);
+ assertThat(resp.backupPlan().rules().get(0).ruleName()).isEqualTo("daily");
+ assertThat(resp.backupPlan().rules().get(0).ruleId()).isNotNull();
+ }
+
+ @Test
+ @Order(22)
+ @DisplayName("UpdateBackupPlan - replaces rules and bumps versionId")
+ void updateBackupPlan() {
+ String oldVersionId = backup.getBackupPlan(r -> r.backupPlanId(planId)).versionId();
+
+ UpdateBackupPlanResponse resp = backup.updateBackupPlan(r -> r
+ .backupPlanId(planId)
+ .backupPlan(p -> p
+ .backupPlanName("compat-daily-v2")
+ .rules(BackupRuleInput.builder()
+ .ruleName("daily-v2")
+ .targetBackupVaultName(VAULT_NAME)
+ .scheduleExpression("cron(0 6 * * ? *)")
+ .build())));
+
+ assertThat(resp.backupPlanId()).isEqualTo(planId);
+ assertThat(resp.versionId()).isNotEqualTo(oldVersionId);
+ }
+
+ @Test
+ @Order(23)
+ @DisplayName("ListBackupPlans - includes created plan")
+ void listBackupPlans() {
+ ListBackupPlansResponse resp = backup.listBackupPlans(r -> r.build());
+
+ assertThat(resp.backupPlansList()).isNotEmpty();
+ assertThat(resp.backupPlansList())
+ .anyMatch(p -> planId.equals(p.backupPlanId()));
+ }
+
+ // ── Selection ──────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(30)
+ @DisplayName("CreateBackupSelection - creates selection")
+ void createBackupSelection() {
+ CreateBackupSelectionResponse resp = backup.createBackupSelection(r -> r
+ .backupPlanId(planId)
+ .backupSelection(s -> s
+ .selectionName("compat-selection")
+ .iamRoleArn(IAM_ROLE)
+ .resources(RESOURCE_ARN)));
+
+ selectionId = resp.selectionId();
+ assertThat(selectionId).isNotNull();
+ assertThat(resp.backupPlanId()).isEqualTo(planId);
+ assertThat(resp.creationDate()).isNotNull();
+ }
+
+ @Test
+ @Order(31)
+ @DisplayName("GetBackupSelection - returns selection detail")
+ void getBackupSelection() {
+ GetBackupSelectionResponse resp = backup.getBackupSelection(r -> r
+ .backupPlanId(planId)
+ .selectionId(selectionId));
+
+ assertThat(resp.selectionId()).isEqualTo(selectionId);
+ assertThat(resp.backupSelection().selectionName()).isEqualTo("compat-selection");
+ assertThat(resp.backupSelection().iamRoleArn()).isEqualTo(IAM_ROLE);
+ assertThat(resp.backupSelection().resources()).contains(RESOURCE_ARN);
+ }
+
+ @Test
+ @Order(32)
+ @DisplayName("ListBackupSelections - includes created selection")
+ void listBackupSelections() {
+ ListBackupSelectionsResponse resp = backup.listBackupSelections(r -> r.backupPlanId(planId));
+
+ assertThat(resp.backupSelectionsList()).hasSize(1);
+ assertThat(resp.backupSelectionsList().get(0).selectionId()).isEqualTo(selectionId);
+ assertThat(resp.backupSelectionsList().get(0).selectionName()).isEqualTo("compat-selection");
+ }
+
+ @Test
+ @Order(33)
+ @DisplayName("DeleteBackupPlan with active selection returns InvalidRequestException")
+ void deletePlanWithSelectionFails() {
+ assertThatThrownBy(() -> backup.deleteBackupPlan(r -> r.backupPlanId(planId)))
+ .isInstanceOf(InvalidRequestException.class);
+ }
+
+ // ── Job ────────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(40)
+ @DisplayName("StartBackupJob - returns job ID in CREATED state")
+ void startBackupJob() {
+ StartBackupJobResponse resp = backup.startBackupJob(r -> r
+ .backupVaultName(VAULT_NAME)
+ .resourceArn(RESOURCE_ARN)
+ .iamRoleArn(IAM_ROLE));
+
+ jobId = resp.backupJobId();
+ assertThat(jobId).isNotNull();
+ assertThat(resp.creationDate()).isNotNull();
+ }
+
+ @Test
+ @Order(41)
+ @DisplayName("DescribeBackupJob - job is in progress shortly after start")
+ void describeBackupJobInProgress() {
+ DescribeBackupJobResponse resp = backup.describeBackupJob(r -> r.backupJobId(jobId));
+
+ assertThat(resp.backupJobId()).isEqualTo(jobId);
+ assertThat(resp.state().toString()).isIn("CREATED", "RUNNING", "COMPLETED");
+ assertThat(resp.backupVaultName()).isEqualTo(VAULT_NAME);
+ assertThat(resp.resourceArn()).isEqualTo(RESOURCE_ARN);
+ }
+
+ @Test
+ @Order(42)
+ @DisplayName("DescribeBackupJob - job completes within 10 seconds")
+ void describeBackupJobCompleted() throws InterruptedException {
+ BackupJobState state = null;
+ for (int i = 0; i < 10; i++) {
+ Thread.sleep(1000);
+ DescribeBackupJobResponse resp = backup.describeBackupJob(r -> r.backupJobId(jobId));
+ state = resp.state();
+ if (state == BackupJobState.COMPLETED) {
+ recoveryPointArn = resp.recoveryPointArn();
+ assertThat(recoveryPointArn).contains("recovery-point:");
+ assertThat(resp.completionDate()).isNotNull();
+ return;
+ }
+ }
+ Assertions.fail("Backup job did not complete within 10 seconds, last state: " + state);
+ }
+
+ @Test
+ @Order(43)
+ @DisplayName("ListBackupJobs - filter by vault name")
+ void listBackupJobsByVault() {
+ ListBackupJobsResponse resp = backup.listBackupJobs(r -> r.byBackupVaultName(VAULT_NAME));
+
+ assertThat(resp.backupJobs()).isNotEmpty();
+ assertThat(resp.backupJobs()).allMatch(j -> VAULT_NAME.equals(j.backupVaultName()));
+ }
+
+ @Test
+ @Order(44)
+ @DisplayName("ListBackupJobs - filter by COMPLETED state")
+ void listBackupJobsByState() {
+ ListBackupJobsResponse resp = backup.listBackupJobs(r -> r.byState(BackupJobState.COMPLETED));
+
+ assertThat(resp.backupJobs()).isNotEmpty();
+ assertThat(resp.backupJobs()).allMatch(j -> j.state() == BackupJobState.COMPLETED);
+ }
+
+ // ── Recovery Point ─────────────────────────────────────────────────────────
+
+ @Test
+ @Order(50)
+ @DisplayName("DescribeRecoveryPoint - returns completed recovery point")
+ void describeRecoveryPoint() {
+ DescribeRecoveryPointResponse resp = backup.describeRecoveryPoint(r -> r
+ .backupVaultName(VAULT_NAME)
+ .recoveryPointArn(recoveryPointArn));
+
+ assertThat(resp.recoveryPointArn()).isEqualTo(recoveryPointArn);
+ assertThat(resp.backupVaultName()).isEqualTo(VAULT_NAME);
+ assertThat(resp.status()).isEqualTo(RecoveryPointStatus.COMPLETED);
+ assertThat(resp.resourceArn()).isEqualTo(RESOURCE_ARN);
+ assertThat(resp.completionDate()).isNotNull();
+ }
+
+ @Test
+ @Order(51)
+ @DisplayName("ListRecoveryPointsByBackupVault - returns created recovery point")
+ void listRecoveryPointsByBackupVault() {
+ ListRecoveryPointsByBackupVaultResponse resp = backup.listRecoveryPointsByBackupVault(r -> r
+ .backupVaultName(VAULT_NAME));
+
+ assertThat(resp.recoveryPoints()).hasSize(1);
+ assertThat(resp.recoveryPoints().get(0).recoveryPointArn()).isEqualTo(recoveryPointArn);
+ }
+
+ @Test
+ @Order(52)
+ @DisplayName("DescribeBackupVault - NumberOfRecoveryPoints incremented")
+ void vaultCountAfterJob() {
+ DescribeBackupVaultResponse resp = backup.describeBackupVault(r -> r.backupVaultName(VAULT_NAME));
+ assertThat(resp.numberOfRecoveryPoints()).isEqualTo(1);
+ }
+
+ @Test
+ @Order(53)
+ @DisplayName("DeleteBackupVault - non-empty vault returns InvalidRequestException")
+ void deleteNonEmptyVaultFails() {
+ assertThatThrownBy(() -> backup.deleteBackupVault(r -> r.backupVaultName(VAULT_NAME)))
+ .isInstanceOf(InvalidRequestException.class);
+ }
+
+ @Test
+ @Order(54)
+ @DisplayName("DeleteRecoveryPoint - removes recovery point and decrements vault count")
+ void deleteRecoveryPoint() {
+ backup.deleteRecoveryPoint(r -> r
+ .backupVaultName(VAULT_NAME)
+ .recoveryPointArn(recoveryPointArn));
+
+ DescribeBackupVaultResponse vault = backup.describeBackupVault(r -> r.backupVaultName(VAULT_NAME));
+ assertThat(vault.numberOfRecoveryPoints()).isEqualTo(0);
+
+ assertThatThrownBy(() -> backup.describeRecoveryPoint(r -> r
+ .backupVaultName(VAULT_NAME)
+ .recoveryPointArn(recoveryPointArn)))
+ .isInstanceOf(ResourceNotFoundException.class);
+ }
+
+ // ── Tagging ────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(60)
+ @DisplayName("TagResource / ListTags / UntagResource - SDK round-trip")
+ void tagRoundTrip() {
+ backup.tagResource(r -> r
+ .resourceArn(vaultArn)
+ .tags(Map.of("team", "platform", "cost-center", "eng")));
+
+ ListTagsResponse listed = backup.listTags(r -> r.resourceArn(vaultArn));
+ assertThat(listed.tags())
+ .containsEntry("env", "compat-test")
+ .containsEntry("team", "platform")
+ .containsEntry("cost-center", "eng");
+
+ backup.untagResource(r -> r
+ .resourceArn(vaultArn)
+ .tagKeyList(List.of("team")));
+
+ ListTagsResponse afterUntag = backup.listTags(r -> r.resourceArn(vaultArn));
+ assertThat(afterUntag.tags())
+ .doesNotContainKey("team")
+ .containsEntry("cost-center", "eng")
+ .containsEntry("env", "compat-test");
+ }
+
+ // ── Supported Resource Types ────────────────────────────────────────────────
+
+ @Test
+ @Order(70)
+ @DisplayName("GetSupportedResourceTypes - returns non-empty list including S3 and DynamoDB")
+ void getSupportedResourceTypes() {
+ GetSupportedResourceTypesResponse resp = backup.getSupportedResourceTypes(
+ GetSupportedResourceTypesRequest.builder().build());
+
+ assertThat(resp.resourceTypes()).isNotEmpty();
+ assertThat(resp.resourceTypes()).contains("S3", "DynamoDB");
+ }
+
+ // ── Teardown ───────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(80)
+ @DisplayName("DeleteBackupSelection - removes selection")
+ void deleteBackupSelection() {
+ backup.deleteBackupSelection(r -> r
+ .backupPlanId(planId)
+ .selectionId(selectionId));
+
+ assertThat(backup.listBackupSelections(r -> r.backupPlanId(planId))
+ .backupSelectionsList()).isEmpty();
+ }
+
+ @Test
+ @Order(81)
+ @DisplayName("DeleteBackupPlan - removes plan")
+ void deleteBackupPlan() {
+ backup.deleteBackupPlan(r -> r.backupPlanId(planId));
+
+ assertThatThrownBy(() -> backup.getBackupPlan(r -> r.backupPlanId(planId)))
+ .isInstanceOf(ResourceNotFoundException.class);
+ }
+
+ @Test
+ @Order(82)
+ @DisplayName("DeleteBackupVault - removes empty vault")
+ void deleteBackupVault() {
+ backup.deleteBackupVault(r -> r.backupVaultName(VAULT_NAME));
+
+ assertThatThrownBy(() -> backup.describeBackupVault(r -> r.backupVaultName(VAULT_NAME)))
+ .isInstanceOf(ResourceNotFoundException.class);
+ }
+}
diff --git a/docs/services/backup.md b/docs/services/backup.md
new file mode 100644
index 0000000000..ea0f78f47b
--- /dev/null
+++ b/docs/services/backup.md
@@ -0,0 +1,186 @@
+# AWS Backup
+
+**Protocol:** REST JSON
+**Endpoint:** `http://localhost:4566/`
+**Credential scope:** `backup`
+
+## Supported Actions
+
+### Backup Vaults
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `CreateBackupVault` | `PUT` | `/backup-vaults/{backupVaultName}` | Create a backup vault |
+| `DescribeBackupVault` | `GET` | `/backup-vaults/{backupVaultName}` | Describe a backup vault |
+| `DeleteBackupVault` | `DELETE` | `/backup-vaults/{backupVaultName}` | Delete an empty backup vault |
+| `ListBackupVaults` | `GET` | `/backup-vaults/` | List all backup vaults |
+
+### Backup Plans
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `CreateBackupPlan` | `PUT` | `/backup/plans/` | Create a backup plan with rules |
+| `GetBackupPlan` | `GET` | `/backup/plans/{backupPlanId}/` | Get backup plan details |
+| `UpdateBackupPlan` | `POST` | `/backup/plans/{backupPlanId}` | Update a backup plan |
+| `DeleteBackupPlan` | `DELETE` | `/backup/plans/{backupPlanId}` | Delete a backup plan (fails if selections exist) |
+| `ListBackupPlans` | `GET` | `/backup/plans/` | List all backup plans |
+
+### Backup Selections
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `CreateBackupSelection` | `PUT` | `/backup/plans/{backupPlanId}/selections/` | Assign resources to a backup plan |
+| `GetBackupSelection` | `GET` | `/backup/plans/{backupPlanId}/selections/{selectionId}` | Get selection details |
+| `DeleteBackupSelection` | `DELETE` | `/backup/plans/{backupPlanId}/selections/{selectionId}` | Remove a resource selection |
+| `ListBackupSelections` | `GET` | `/backup/plans/{backupPlanId}/selections/` | List selections for a plan |
+
+### Backup Jobs
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `StartBackupJob` | `PUT` | `/backup-jobs` | Start an on-demand backup job |
+| `DescribeBackupJob` | `GET` | `/backup-jobs/{backupJobId}` | Get backup job status |
+| `StopBackupJob` | `POST` | `/backup-jobs/{backupJobId}` | Stop a running backup job |
+| `ListBackupJobs` | `GET` | `/backup-jobs/` | List backup jobs with optional filters |
+
+### Recovery Points
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `DescribeRecoveryPoint` | `GET` | `/backup-vaults/{backupVaultName}/recovery-points/{recoveryPointArn}` | Describe a recovery point |
+| `ListRecoveryPointsByBackupVault` | `GET` | `/backup-vaults/{backupVaultName}/recovery-points/` | List recovery points in a vault |
+| `DeleteRecoveryPoint` | `DELETE` | `/backup-vaults/{backupVaultName}/recovery-points/{recoveryPointArn}` | Delete a recovery point |
+
+### Tagging
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `ListTags` | `GET` | `/tags/{resourceArn}` | List tags on a backup resource |
+| `TagResource` | `POST` | `/tags/{resourceArn}` | Add tags to a backup resource |
+| `UntagResource` | `POST` | `/untag/{resourceArn}` | Remove tags from a backup resource |
+
+### Other
+
+| Action | Method | Path | Description |
+|---|---|---|---|
+| `GetSupportedResourceTypes` | `GET` | `/supported-resource-types` | List resource types supported for backup |
+
+## Job Lifecycle
+
+Backup jobs transition through states automatically after `StartBackupJob`:
+
+```
+CREATED → RUNNING (after ~1 s) → COMPLETED (after job-completion-delay-seconds)
+```
+
+When a job reaches `COMPLETED`:
+- A recovery point is created in the target vault
+- The vault's `NumberOfRecoveryPoints` counter is incremented
+- `StopBackupJob` on a `CREATED` or `RUNNING` job transitions it to `ABORTING → ABORTED`
+
+The completion delay is configurable:
+
+```yaml
+floci:
+ services:
+ backup:
+ job-completion-delay-seconds: 3 # default
+```
+
+Use a shorter delay (e.g. `1`) in test environments to speed up job-completion assertions.
+
+## Supported Resource Types
+
+`GetSupportedResourceTypes` returns the following resource type codes:
+
+`S3`, `RDS`, `DynamoDB`, `EFS`, `EC2`, `EBS`, `Aurora`, `DocumentDB`, `Neptune`, `FSx`, `VirtualMachine`
+
+Actual backup is simulated — no data is read from or written to the referenced resources.
+
+## Constraints
+
+- **DeleteBackupVault** returns `InvalidRequestException` (400) if the vault contains recovery points.
+- **DeleteBackupPlan** returns `InvalidRequestException` (400) if the plan has active selections.
+- **CreateBackupVault** returns `AlreadyExistsException` (400) on duplicate vault names within the same region.
+
+## Configuration
+
+| Property | Env var | Default | Description |
+|---|---|---|---|
+| `floci.services.backup.enabled` | `FLOCI_SERVICES_BACKUP_ENABLED` | `true` | Enable / disable the service |
+| `floci.services.backup.job-completion-delay-seconds` | `FLOCI_SERVICES_BACKUP_JOB_COMPLETION_DELAY_SECONDS` | `3` | Seconds from job start until `COMPLETED` |
+
+## Not Yet Supported
+
+- Restore jobs (`StartRestoreJob`, `DescribeRestoreJob`, `ListRestoreJobs`)
+- Backup vaults with notifications (`PutBackupVaultNotifications`, `GetBackupVaultNotifications`)
+- Backup vaults with access policy (`PutBackupVaultAccessPolicy`, `GetBackupVaultAccessPolicy`)
+- Copy jobs (`StartCopyJob`, `DescribeCopyJob`, `ListCopyJobs`)
+- Report plans (`CreateReportPlan`, `DescribeReportPlan`, etc.)
+- Framework operations (`CreateFramework`, etc.)
+- Legal holds
+- Pagination tokens on list operations
+
+## Examples
+
+```bash
+export AWS_ENDPOINT_URL=http://localhost:4566
+
+# Create a backup vault
+aws backup create-backup-vault \
+ --backup-vault-name my-vault \
+ --backup-vault-tags env=dev
+
+# Describe the vault
+aws backup describe-backup-vault \
+ --backup-vault-name my-vault
+
+# Create a backup plan
+aws backup create-backup-plan \
+ --backup-plan '{
+ "BackupPlanName": "daily-backup",
+ "Rules": [{
+ "RuleName": "daily",
+ "TargetBackupVaultName": "my-vault",
+ "ScheduleExpression": "cron(0 12 * * ? *)",
+ "StartWindowMinutes": 60,
+ "CompletionWindowMinutes": 120
+ }]
+ }'
+
+# Assign resources to the plan
+aws backup create-backup-selection \
+ --backup-plan-id <plan-id> \
+ --backup-selection '{
+ "SelectionName": "my-tables",
+ "IamRoleArn": "arn:aws:iam::000000000000:role/backup-role",
+ "Resources": ["arn:aws:dynamodb:us-east-1:000000000000:table/my-table"]
+ }'
+
+# Start an on-demand backup job
+aws backup start-backup-job \
+ --backup-vault-name my-vault \
+ --resource-arn arn:aws:dynamodb:us-east-1:000000000000:table/my-table \
+ --iam-role-arn arn:aws:iam::000000000000:role/backup-role
+
+# Poll job status
+aws backup describe-backup-job --backup-job-id <job-id>
+
+# List recovery points
+aws backup list-recovery-points-by-backup-vault \
+ --backup-vault-name my-vault
+
+# Tag a vault
+aws backup tag-resource \
+ --resource-arn arn:aws:backup:us-east-1:000000000000:backup-vault:my-vault \
+ --tags team=platform
+
+# List tags
+aws backup list-tags \
+ --resource-arn arn:aws:backup:us-east-1:000000000000:backup-vault:my-vault
+
+# Untag a vault
+aws backup untag-resource \
+ --resource-arn arn:aws:backup:us-east-1:000000000000:backup-vault:my-vault \
+ --tag-key-list team
+```
diff --git a/docs/services/index.md b/docs/services/index.md
index 8ad01e844b..fa9a1aa37e 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -1,6 +1,6 @@
# Services Overview
-Floci emulates 43 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification.
+Floci emulates 44 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification.
This page is the canonical reference for supported service and operation counts. Some services expose separate control-plane and data-plane rows below. Other docs (and the README) should link here rather than duplicating the table.
@@ -56,6 +56,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [Data Firehose](firehose.md) | `POST /` + `X-Amz-Target: Firehose_20150804.*` | JSON 1.1 | 6 |
| [CodeBuild](codebuild.md) | `POST /` + `X-Amz-Target: CodeBuild_20161006.*` | JSON 1.1 | 20 |
| [CodeDeploy](codedeploy.md) | `POST /` + `X-Amz-Target: CodeDeploy_20141006.*` | JSON 1.1 | 30 |
+| [AWS Backup](backup.md) | `/backup-vaults/*`, `/backup/plans/*`, `/backup-jobs/*`, `/supported-resource-types` | REST JSON | 20 |
| [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*` | REST XML | 17 |
**Lambda, ElastiCache, RDS, MSK, ECS, EKS, and OpenSearch** spin up real Docker containers and support IAM authentication and SigV4 request signing, the same auth flow as production AWS.
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index 7d338a6c2d..9d3b220a49 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -116,6 +116,7 @@ public interface EmulatorConfig {
AppConfigDataStorageConfig appconfigdata();
ElastiCacheStorageConfig elasticache();
RdsStorageConfig rds();
+ BackupStorageConfig backup();
}
interface SsmStorageConfig {
@@ -214,6 +215,13 @@ public interface EmulatorConfig {
Optional<String> mode();
}
+ interface BackupStorageConfig {
+ Optional<String> mode();
+
+ @WithDefault("5000")
+ long flushIntervalMs();
+ }
+
interface WalConfig {
@WithDefault("30000")
long compactionIntervalMs();
@@ -273,7 +281,17 @@ public interface EmulatorConfig {
CodeBuildServiceConfig codebuild();
CodeDeployServiceConfig codedeploy();
AutoScalingServiceConfig autoscaling();
+ BackupServiceConfig backup();
Route53ServiceConfig route53();
+ TransferServiceConfig transfer();
+ }
+
+ interface BackupServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+
+ @WithDefault("3")
+ int jobCompletionDelaySeconds();
}
interface Route53ServiceConfig {
@@ -293,6 +311,11 @@ public interface EmulatorConfig {
String defaultNameserver4();
}
+ interface TransferServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface AutoScalingServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 724f4d5c86..be68bcf58a 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.core.common;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.appconfig.AppConfigController;
+import io.github.hectorvent.floci.services.backup.BackupController;
import io.github.hectorvent.floci.services.appconfig.AppConfigDataController;
import io.github.hectorvent.floci.services.bedrockruntime.BedrockRuntimeController;
import io.github.hectorvent.floci.services.cognito.CognitoOAuthController;
@@ -222,6 +223,11 @@ public class ResolvedServiceCatalog {
"autoscaling", config.storage().mode(), 5000L, AwsNamespaces.AUTOSCALING, ServiceProtocol.QUERY,
protocols(ServiceProtocol.QUERY),
Set.of(), Set.of("autoscaling"), Set.of(), Set.of()),
+ descriptor("backup", "backup", config.services().backup().enabled(), true,
+ "backup", storageMode(config.storage().services().backup().mode(), config.storage().mode()),
+ config.storage().services().backup().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON),
+ Set.of(), Set.of("backup"), Set.of(), Set.of(BackupController.class)),
descriptor("ec2messages", "ec2messages", config.services().ssm().enabled(), false,
null, null, 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
@@ -229,7 +235,11 @@ public class ResolvedServiceCatalog {
descriptor("route53", "route53", config.services().route53().enabled(), true,
"route53", config.storage().mode(), 5000L, null, ServiceProtocol.REST_XML,
protocols(ServiceProtocol.REST_XML),
- Set.of(), Set.of("route53"), Set.of(), Set.of(Route53Controller.class))
+ Set.of(), Set.of("route53"), Set.of(), Set.of(Route53Controller.class)),
+ descriptor("transfer", "transfer", config.services().transfer().enabled(), true,
+ "transfer", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON),
+ Set.of("TransferService."), Set.of("transfer"), Set.of(), Set.of())
));
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java b/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java
new file mode 100644
index 0000000000..de6f11ab59
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java
@@ -0,0 +1,377 @@
+package io.github.hectorvent.floci.services.backup;
+
+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.RegionResolver;
+import io.github.hectorvent.floci.services.backup.model.*;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.*;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.jboss.logging.Logger;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class BackupController {
+
+ private static final Logger LOG = Logger.getLogger(BackupController.class);
+
+ private final BackupService service;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public BackupController(BackupService service, RegionResolver regionResolver, ObjectMapper objectMapper) {
+ this.service = service;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ // ── Vault ──────────────────────────────────────────────────────────────────
+
+ @PUT
+ @Path("/backup-vaults/{backupVaultName}")
+ public Response createBackupVault(@Context HttpHeaders headers,
+ @PathParam("backupVaultName") String vaultName,
+ String body) throws IOException {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode req = objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
+ String encryptionKeyArn = textOrNull(req, "EncryptionKeyArn");
+ String creatorRequestId = textOrNull(req, "CreatorRequestId");
+ Map<String, String> tags = readStringMap(req, "BackupVaultTags");
+
+ BackupVault vault = service.createBackupVault(vaultName, encryptionKeyArn, creatorRequestId, tags, region);
+
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("BackupVaultName", vault.getBackupVaultName());
+ out.put("BackupVaultArn", vault.getBackupVaultArn());
+ out.put("CreationDate", vault.getCreationDate());
+ return Response.status(200).entity(out).build();
+ }
+
+ @GET
+ @Path("/backup-vaults/{backupVaultName}")
+ public Response describeBackupVault(@Context HttpHeaders headers,
+ @PathParam("backupVaultName") String vaultName) {
+ String region = regionResolver.resolveRegion(headers);
+ return Response.ok(service.describeBackupVault(vaultName, region)).build();
+ }
+
+ @DELETE
+ @Path("/backup-vaults/{backupVaultName}")
+ public Response deleteBackupVault(@Context HttpHeaders headers,
+ @PathParam("backupVaultName") String vaultName) {
+ String region = regionResolver.resolveRegion(headers);
+ service.deleteBackupVault(vaultName, region);
+ return Response.noContent().build();
+ }
+
+ @GET
+ @Path("/backup-vaults/")
+ public Response listBackupVaults(@Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ List<BackupVault> vaults = service.listBackupVaults(region);
+ ObjectNode out = objectMapper.createObjectNode();
+ ArrayNode list = out.putArray("BackupVaultList");
+ vaults.forEach(list::addPOJO);
+ return Response.ok(out).build();
+ }
+
+ // ── Plan ───────────────────────────────────────────────────────────────────
+
+ @PUT
+ @Path("/backup/plans/")
+ public Response createBackupPlan(@Context HttpHeaders headers, String body) throws IOException {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode req = objectMapper.readTree(body);
+ JsonNode planNode = req.path("BackupPlan");
+ String planName = planNode.path("BackupPlanName").asText();
+ List<BackupRule> rules = readRules(planNode.path("Rules"));
+ String creatorRequestId = textOrNull(req, "CreatorRequestId");
+
+ BackupPlan plan = service.createBackupPlan(planName, rules, creatorRequestId, region);
+
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("BackupPlanId", plan.getBackupPlanId());
+ out.put("BackupPlanArn", plan.getBackupPlanArn());
+ out.put("CreationDate", plan.getCreationDate());
+ out.put("VersionId", plan.getVersionId());
+ return Response.status(200).entity(out).build();
+ }
+
+ @GET
+ @Path("/backup/plans/{backupPlanId}/")
+ public Response getBackupPlan(@PathParam("backupPlanId") String planId) {
+ BackupPlan plan = service.getBackupPlan(planId);
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("BackupPlanId", plan.getBackupPlanId());
+ out.put("BackupPlanArn", plan.getBackupPlanArn());
+ out.put("CreationDate", plan.getCreationDate());
+ out.put("VersionId", plan.getVersionId());
+ ObjectNode planBody = out.putObject("BackupPlan");
+ planBody.put("BackupPlanName", plan.getBackupPlanName());
+ planBody.set("Rules", objectMapper.valueToTree(plan.getRules()));
+ return Response.ok(out).build();
+ }
+
+ @POST
+ @Path("/backup/plans/{backupPlanId}")
+ public Response updateBackupPlan(@PathParam("backupPlanId") String planId, String body) throws IOException {
+ JsonNode req = objectMapper.readTree(body);
+ JsonNode planNode = req.path("BackupPlan");
+ String planName = planNode.has("BackupPlanName") ? planNode.path("BackupPlanName").asText() : null;
+ List<BackupRule> rules = readRules(planNode.path("Rules"));
+
+ BackupPlan plan = service.updateBackupPlan(planId, planName, rules);
+
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("BackupPlanId", plan.getBackupPlanId());
+ out.put("BackupPlanArn", plan.getBackupPlanArn());
+ out.put("VersionId", plan.getVersionId());
+ return Response.ok(out).build();
+ }
+
+ @DELETE
+ @Path("/backup/plans/{backupPlanId}")
+ public Response deleteBackupPlan(@PathParam("backupPlanId") String planId) {
+ service.deleteBackupPlan(planId);
+ return Response.noContent().build();
+ }
+
+ @GET
+ @Path("/backup/plans/")
+ public Response listBackupPlans() {
+ List<BackupPlan> plans = service.listBackupPlans();
+ ObjectNode out = objectMapper.createObjectNode();
+ ArrayNode list = out.putArray("BackupPlansList");
+ for (BackupPlan plan : plans) {
+ 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());
+ list.add(item);
+ }
+ return Response.ok(out).build();
+ }
+
+ // ── Selection ──────────────────────────────────────────────────────────────
+
+ @PUT
+ @Path("/backup/plans/{backupPlanId}/selections/")
+ public Response createBackupSelection(@PathParam("backupPlanId") String planId,
+ String body) throws IOException {
+ JsonNode req = objectMapper.readTree(body);
+ JsonNode selNode = req.path("BackupSelection");
+ String selectionName = selNode.path("SelectionName").asText();
+ String iamRoleArn = selNode.path("IamRoleArn").asText();
+ List<String> resources = readStringList(selNode.path("Resources"));
+ List<String> notResources = readStringList(selNode.path("NotResources"));
+ String creatorRequestId = textOrNull(req, "CreatorRequestId");
+
+ BackupSelection sel = service.createBackupSelection(planId, selectionName, iamRoleArn,
+ resources, notResources, creatorRequestId);
+
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("SelectionId", sel.getSelectionId());
+ out.put("BackupPlanId", sel.getBackupPlanId());
+ out.put("CreationDate", sel.getCreationDate());
+ return Response.status(200).entity(out).build();
+ }
+
+ @GET
+ @Path("/backup/plans/{backupPlanId}/selections/{selectionId}")
+ public Response getBackupSelection(@PathParam("backupPlanId") String planId,
+ @PathParam("selectionId") String selectionId) {
+ BackupSelection sel = service.getBackupSelection(planId, selectionId);
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("BackupPlanId", sel.getBackupPlanId());
+ out.put("SelectionId", sel.getSelectionId());
+ out.put("CreationDate", sel.getCreationDate());
+ ObjectNode selBody = out.putObject("BackupSelection");
+ selBody.put("SelectionName", sel.getSelectionName());
+ selBody.put("IamRoleArn", sel.getIamRoleArn());
+ selBody.set("Resources", objectMapper.valueToTree(sel.getResources()));
+ selBody.set("NotResources", objectMapper.valueToTree(sel.getNotResources()));
+ return Response.ok(out).build();
+ }
+
+ @DELETE
+ @Path("/backup/plans/{backupPlanId}/selections/{selectionId}")
+ public Response deleteBackupSelection(@PathParam("backupPlanId") String planId,
+ @PathParam("selectionId") String selectionId) {
+ service.deleteBackupSelection(planId, selectionId);
+ return Response.noContent().build();
+ }
+
+ @GET
+ @Path("/backup/plans/{backupPlanId}/selections/")
+ public Response listBackupSelections(@PathParam("backupPlanId") String planId) {
+ List<BackupSelection> selections = service.listBackupSelections(planId);
+ ObjectNode out = objectMapper.createObjectNode();
+ ArrayNode list = out.putArray("BackupSelectionsList");
+ for (BackupSelection sel : selections) {
+ ObjectNode item = objectMapper.createObjectNode();
+ item.put("SelectionId", sel.getSelectionId());
+ item.put("SelectionName", sel.getSelectionName());
+ item.put("BackupPlanId", sel.getBackupPlanId());
+ item.put("IamRoleArn", sel.getIamRoleArn());
+ item.put("CreationDate", sel.getCreationDate());
+ list.add(item);
+ }
+ return Response.ok(out).build();
+ }
+
+ // ── Job ────────────────────────────────────────────────────────────────────
+
+ @PUT
+ @Path("/backup-jobs")
+ public Response startBackupJob(@Context HttpHeaders headers, String body) throws IOException {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode req = objectMapper.readTree(body);
+ String vaultName = req.path("BackupVaultName").asText();
+ String resourceArn = req.path("ResourceArn").asText();
+ String iamRoleArn = req.path("IamRoleArn").asText();
+ Lifecycle lifecycle = req.has("Lifecycle")
+ ? objectMapper.treeToValue(req.path("Lifecycle"), Lifecycle.class)
+ : null;
+
+ BackupJob job = service.startBackupJob(vaultName, resourceArn, iamRoleArn, lifecycle, region);
+
+ ObjectNode out = objectMapper.createObjectNode();
+ out.put("BackupJobId", job.getBackupJobId());
+ out.put("BackupVaultArn", job.getBackupVaultArn());
+ out.put("CreationDate", job.getCreationDate());
+ out.put("RecoveryPointArn", "");
+ return Response.status(200).entity(out).build();
+ }
+
+ @GET
+ @Path("/backup-jobs/{backupJobId}")
+ public Response describeBackupJob(@PathParam("backupJobId") String jobId) {
+ return Response.ok(service.describeBackupJob(jobId)).build();
+ }
+
+ @POST
+ @Path("/backup-jobs/{backupJobId}")
+ public Response stopBackupJob(@PathParam("backupJobId") String jobId) {
+ service.stopBackupJob(jobId);
+ return Response.noContent().build();
+ }
+
+ @GET
+ @Path("/backup-jobs/")
+ public Response listBackupJobs(@QueryParam("byBackupVaultName") String byVaultName,
+ @QueryParam("byState") String byState,
+ @QueryParam("byResourceArn") String byResourceArn,
+ @QueryParam("byResourceType") String byResourceType) {
+ List<BackupJob> jobs = service.listBackupJobs(byVaultName, byState, byResourceArn, byResourceType);
+ ObjectNode out = objectMapper.createObjectNode();
+ ArrayNode list = out.putArray("BackupJobs");
+ jobs.forEach(list::addPOJO);
+ return Response.ok(out).build();
+ }
+
+ // ── Recovery Point ─────────────────────────────────────────────────────────
+
+ @GET
+ @Path("/backup-vaults/{backupVaultName}/recovery-points/{recoveryPointArn}")
+ public Response describeRecoveryPoint(@Context HttpHeaders headers,
+ @PathParam("backupVaultName") String vaultName,
+ @PathParam("recoveryPointArn") String recoveryPointArn) {
+ String region = regionResolver.resolveRegion(headers);
+ return Response.ok(service.describeRecoveryPoint(vaultName, recoveryPointArn, region)).build();
+ }
+
+ @GET
+ @Path("/backup-vaults/{backupVaultName}/recovery-points/")
+ public Response listRecoveryPointsByBackupVault(@Context HttpHeaders headers,
+ @PathParam("backupVaultName") String vaultName) {
+ String region = regionResolver.resolveRegion(headers);
+ List<RecoveryPoint> points = service.listRecoveryPointsByBackupVault(vaultName, region);
+ ObjectNode out = objectMapper.createObjectNode();
+ ArrayNode list = out.putArray("RecoveryPoints");
+ points.forEach(list::addPOJO);
+ return Response.ok(out).build();
+ }
+
+ @DELETE
+ @Path("/backup-vaults/{backupVaultName}/recovery-points/{recoveryPointArn}")
+ public Response deleteRecoveryPoint(@Context HttpHeaders headers,
+ @PathParam("backupVaultName") String vaultName,
+ @PathParam("recoveryPointArn") String recoveryPointArn) {
+ String region = regionResolver.resolveRegion(headers);
+ service.deleteRecoveryPoint(vaultName, recoveryPointArn, region);
+ return Response.noContent().build();
+ }
+
+ // ── Untag (POST /untag/{arn} with body — distinct from shared DELETE /tags pattern) ──
+
+ @POST
+ @Path("/untag/{resourceArn: .*}")
+ public Response untagResource(@PathParam("resourceArn") String resourceArn,
+ String body) throws IOException {
+ JsonNode req = objectMapper.readTree(body);
+ List<String> tagKeys = readStringList(req.path("TagKeyList"));
+ service.untagResource(resourceArn, tagKeys);
+ return Response.noContent().build();
+ }
+
+ // ── Supported resource types ───────────────────────────────────────────────
+
+ @GET
+ @Path("/supported-resource-types")
+ public Response getSupportedResourceTypes() {
+ ObjectNode out = objectMapper.createObjectNode();
+ ArrayNode list = out.putArray("ResourceTypes");
+ service.getSupportedResourceTypes().forEach(list::add);
+ return Response.ok(out).build();
+ }
+
+ // ── Helpers ────────────────────────────────────────────────────────────────
+
+ private static String textOrNull(JsonNode node, String field) {
+ JsonNode n = node.path(field);
+ return n.isMissingNode() || n.isNull() ? null : n.asText();
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, String> readStringMap(JsonNode node, String field) {
+ JsonNode mapNode = node.path(field);
+ if (mapNode.isMissingNode() || mapNode.isNull()) {
+ return new java.util.HashMap<>();
+ }
+ return objectMapper.convertValue(mapNode, Map.class);
+ }
+
+ private static List<String> readStringList(JsonNode node) {
+ List<String> result = new ArrayList<>();
+ if (node == null || node.isMissingNode() || node.isNull()) {
+ return result;
+ }
+ node.forEach(n -> result.add(n.asText()));
+ return result;
+ }
+
+ private List<BackupRule> readRules(JsonNode rulesNode) throws IOException {
+ List<BackupRule> rules = new ArrayList<>();
+ if (rulesNode == null || rulesNode.isMissingNode() || !rulesNode.isArray()) {
+ return rules;
+ }
+ for (JsonNode ruleNode : rulesNode) {
+ rules.add(objectMapper.treeToValue(ruleNode, BackupRule.class));
+ }
+ return rules;
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java b/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java
new file mode 100644
index 0000000000..6428ee56d2
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java
@@ -0,0 +1,456 @@
+package io.github.hectorvent.floci.services.backup;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.backup.model.*;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.time.Instant;
+import java.util.*;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+@ApplicationScoped
+public class BackupService {
+
+ private static final Logger LOG = Logger.getLogger(BackupService.class);
+
+ private static final List<String> SUPPORTED_RESOURCE_TYPES = List.of(
+ "S3", "RDS", "DynamoDB", "EFS", "EC2", "EBS",
+ "Aurora", "DocumentDB", "Neptune", "FSx", "VirtualMachine"
+ );
+
+ private final StorageBackend<String, BackupVault> vaultStore;
+ private final StorageBackend<String, BackupPlan> planStore;
+ private final StorageBackend<String, BackupSelection> selectionStore;
+ private final StorageBackend<String, BackupJob> jobStore;
+ private final StorageBackend<String, RecoveryPoint> recoveryStore;
+
+ private final RegionResolver regionResolver;
+ private final int jobCompletionDelaySeconds;
+
+ private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
+ Thread t = new Thread(r, "backup-job-scheduler");
+ t.setDaemon(true);
+ return t;
+ });
+
+ @Inject
+ public BackupService(StorageFactory storageFactory, EmulatorConfig config, RegionResolver regionResolver) {
+ this.vaultStore = storageFactory.create("backup", "backup-vaults.json", new TypeReference<>() {});
+ this.planStore = storageFactory.create("backup", "backup-plans.json", new TypeReference<>() {});
+ this.selectionStore = storageFactory.create("backup", "backup-selections.json", new TypeReference<>() {});
+ this.jobStore = storageFactory.create("backup", "backup-jobs.json", new TypeReference<>() {});
+ this.recoveryStore = storageFactory.create("backup", "backup-recovery-points.json", new TypeReference<>() {});
+ this.regionResolver = regionResolver;
+ this.jobCompletionDelaySeconds = config.services().backup().jobCompletionDelaySeconds();
+ }
+
+ @PreDestroy
+ void shutdown() {
+ scheduler.shutdownNow();
+ }
+
+ // ── Vault ──────────────────────────────────────────────────────────────────
+
+ public BackupVault createBackupVault(String vaultName, String encryptionKeyArn,
+ String creatorRequestId, Map<String, String> tags,
+ String region) {
+ String key = vaultKey(region, vaultName);
+ if (vaultStore.get(key).isPresent()) {
+ throw new AwsException("AlreadyExistsException", "Backup vault already exists: " + vaultName, 400);
+ }
+ BackupVault vault = new BackupVault();
+ vault.setBackupVaultName(vaultName);
+ vault.setBackupVaultArn(regionResolver.buildArn("backup", region, "backup-vault:" + vaultName));
+ vault.setEncryptionKeyArn(encryptionKeyArn);
+ vault.setCreationDate(Instant.now().getEpochSecond());
+ vault.setCreatorRequestId(creatorRequestId);
+ vault.setNumberOfRecoveryPoints(0);
+ vault.setTags(tags);
+ vaultStore.put(key, vault);
+ LOG.infov("Created backup vault {0} in {1}", vaultName, region);
+ return vault;
+ }
+
+ public BackupVault describeBackupVault(String vaultName, String region) {
+ return vaultStore.get(vaultKey(region, vaultName))
+ .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Backup vault not found: " + vaultName, 404));
+ }
+
+ public void deleteBackupVault(String vaultName, String region) {
+ BackupVault vault = describeBackupVault(vaultName, region);
+ if (vault.getNumberOfRecoveryPoints() > 0) {
+ throw new AwsException("InvalidRequestException",
+ "Non-empty backup vault cannot be deleted: " + vaultName, 400);
+ }
+ vaultStore.delete(vaultKey(region, vaultName));
+ }
+
+ public List<BackupVault> listBackupVaults(String region) {
+ String prefix = region + ":";
+ return vaultStore.scan(k -> k.startsWith(prefix));
+ }
+
+ // ── Plan ───────────────────────────────────────────────────────────────────
+
+ public BackupPlan createBackupPlan(String planName, List<BackupRule> rules,
+ String creatorRequestId, String region) {
+ String planId = UUID.randomUUID().toString();
+ BackupPlan plan = new BackupPlan();
+ plan.setBackupPlanId(planId);
+ plan.setBackupPlanArn(regionResolver.buildArn("backup", region, "backup-plan:" + planId));
+ plan.setBackupPlanName(planName);
+ plan.setCreationDate(Instant.now().getEpochSecond());
+ plan.setVersionId(shortId());
+ assignRuleIds(rules);
+ plan.setRules(rules);
+ planStore.put(planId, plan);
+ return plan;
+ }
+
+ public BackupPlan getBackupPlan(String planId) {
+ return planStore.get(planId)
+ .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Backup plan not found: " + planId, 404));
+ }
+
+ public BackupPlan updateBackupPlan(String planId, String planName, List<BackupRule> rules) {
+ BackupPlan plan = getBackupPlan(planId);
+ if (planName != null) {
+ plan.setBackupPlanName(planName);
+ }
+ assignRuleIds(rules);
+ plan.setRules(rules);
+ plan.setVersionId(shortId());
+ planStore.put(planId, plan);
+ return plan;
+ }
+
+ public void deleteBackupPlan(String planId) {
+ getBackupPlan(planId);
+ long selectionCount = selectionStore.scan(k -> true).stream()
+ .filter(s -> planId.equals(s.getBackupPlanId()))
+ .count();
+ if (selectionCount > 0) {
+ throw new AwsException("InvalidRequestException",
+ "Backup plan has active selections and cannot be deleted", 400);
+ }
+ planStore.delete(planId);
+ }
+
+ public List<BackupPlan> listBackupPlans() {
+ return planStore.scan(k -> true);
+ }
+
+ // ── Selection ──────────────────────────────────────────────────────────────
+
+ public BackupSelection createBackupSelection(String planId, String selectionName,
+ String iamRoleArn, List<String> resources,
+ List<String> notResources, String creatorRequestId) {
+ getBackupPlan(planId);
+ String selectionId = UUID.randomUUID().toString();
+ BackupSelection selection = new BackupSelection();
+ selection.setSelectionId(selectionId);
+ selection.setSelectionName(selectionName);
+ selection.setBackupPlanId(planId);
+ selection.setIamRoleArn(iamRoleArn);
+ selection.setResources(resources);
+ selection.setNotResources(notResources);
+ selection.setCreationDate(Instant.now().getEpochSecond());
+ selection.setCreatorRequestId(creatorRequestId);
+ selectionStore.put(selectionId, selection);
+ return selection;
+ }
+
+ public BackupSelection getBackupSelection(String planId, String selectionId) {
+ BackupSelection sel = selectionStore.get(selectionId)
+ .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Backup selection not found: " + selectionId, 404));
+ if (!planId.equals(sel.getBackupPlanId())) {
+ throw new AwsException("ResourceNotFoundException", "Backup selection not found in plan: " + planId, 404);
+ }
+ return sel;
+ }
+
+ public void deleteBackupSelection(String planId, String selectionId) {
+ getBackupSelection(planId, selectionId);
+ selectionStore.delete(selectionId);
+ }
+
+ public List<BackupSelection> listBackupSelections(String planId) {
+ return selectionStore.scan(k -> true).stream()
+ .filter(s -> planId.equals(s.getBackupPlanId()))
+ .toList();
+ }
+
+ // ── Job ────────────────────────────────────────────────────────────────────
+
+ public BackupJob startBackupJob(String vaultName, String resourceArn, String iamRoleArn,
+ Lifecycle lifecycle, String region) {
+ BackupVault vault = describeBackupVault(vaultName, region);
+
+ String jobId = UUID.randomUUID().toString();
+ long now = Instant.now().getEpochSecond();
+
+ BackupJob job = new BackupJob();
+ job.setBackupJobId(jobId);
+ job.setBackupVaultName(vaultName);
+ job.setBackupVaultArn(vault.getBackupVaultArn());
+ job.setResourceArn(resourceArn);
+ job.setResourceType(inferResourceType(resourceArn));
+ job.setIamRoleArn(iamRoleArn);
+ job.setState("CREATED");
+ job.setPercentDone("0.0");
+ job.setCreationDate(now);
+ job.setExpectedCompletionDate(now + jobCompletionDelaySeconds);
+ job.setStartBy(now + 3600L);
+ job.setAccountId(regionResolver.getAccountId());
+ jobStore.put(jobId, job);
+
+ scheduler.schedule(() -> transitionJob(jobId, vaultName, region), 1, TimeUnit.SECONDS);
+ scheduler.schedule(() -> completeJob(jobId, vaultName, region), jobCompletionDelaySeconds, TimeUnit.SECONDS);
+
+ return job;
+ }
+
+ public BackupJob describeBackupJob(String jobId) {
+ return jobStore.get(jobId)
+ .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Backup job not found: " + jobId, 404));
+ }
+
+ public void stopBackupJob(String jobId) {
+ BackupJob job = describeBackupJob(jobId);
+ String state = job.getState();
+ if ("COMPLETED".equals(state) || "ABORTED".equals(state) || "FAILED".equals(state)) {
+ throw new AwsException("InvalidRequestException",
+ "Job cannot be stopped in state: " + state, 400);
+ }
+ job.setState("ABORTING");
+ job.setStatusMessage("Job stop requested");
+ jobStore.put(jobId, job);
+ scheduler.schedule(() -> abortJob(jobId), 1, TimeUnit.SECONDS);
+ }
+
+ public List<BackupJob> listBackupJobs(String byVaultName, String byState,
+ String byResourceArn, String byResourceType) {
+ return jobStore.scan(k -> true).stream()
+ .filter(j -> byVaultName == null || byVaultName.equals(j.getBackupVaultName()))
+ .filter(j -> byState == null || byState.equals(j.getState()))
+ .filter(j -> byResourceArn == null || byResourceArn.equals(j.getResourceArn()))
+ .filter(j -> byResourceType == null || byResourceType.equals(j.getResourceType()))
+ .toList();
+ }
+
+ // ── Recovery Point ─────────────────────────────────────────────────────────
+
+ public RecoveryPoint describeRecoveryPoint(String vaultName, String recoveryPointArn, String region) {
+ describeBackupVault(vaultName, region);
+ return recoveryStore.get(recoveryPointArn)
+ .filter(rp -> vaultName.equals(rp.getBackupVaultName()))
+ .orElseThrow(() -> new AwsException("ResourceNotFoundException",
+ "Recovery point not found: " + recoveryPointArn, 404));
+ }
+
+ public List<RecoveryPoint> listRecoveryPointsByBackupVault(String vaultName, String region) {
+ describeBackupVault(vaultName, region);
+ return recoveryStore.scan(k -> true).stream()
+ .filter(rp -> vaultName.equals(rp.getBackupVaultName()))
+ .toList();
+ }
+
+ public void deleteRecoveryPoint(String vaultName, String recoveryPointArn, String region) {
+ RecoveryPoint rp = describeRecoveryPoint(vaultName, recoveryPointArn, region);
+ recoveryStore.delete(recoveryPointArn);
+ decrementVaultCount(vaultName, region);
+ }
+
+ // ── Tags ───────────────────────────────────────────────────────────────────
+
+ public Map<String, String> listTags(String resourceArn) {
+ return findTagsByArn(resourceArn);
+ }
+
+ public void tagResource(String resourceArn, Map<String, String> tags) {
+ applyTags(resourceArn, tags);
+ }
+
+ public void untagResource(String resourceArn, List<String> tagKeys) {
+ removeTags(resourceArn, tagKeys);
+ }
+
+ // ── Supported resource types ───────────────────────────────────────────────
+
+ public List<String> getSupportedResourceTypes() {
+ return SUPPORTED_RESOURCE_TYPES;
+ }
+
+ // ── Private helpers ────────────────────────────────────────────────────────
+
+ private void transitionJob(String jobId, String vaultName, String region) {
+ jobStore.get(jobId).ifPresent(job -> {
+ if ("CREATED".equals(job.getState())) {
+ job.setState("RUNNING");
+ job.setPercentDone("50.0");
+ jobStore.put(jobId, job);
+ }
+ });
+ }
+
+ private void completeJob(String jobId, String vaultName, String region) {
+ jobStore.get(jobId).ifPresent(job -> {
+ if ("RUNNING".equals(job.getState())) {
+ long now = Instant.now().getEpochSecond();
+ String rpArn = regionResolver.buildArn("backup", region,
+ "recovery-point:" + UUID.randomUUID());
+
+ job.setState("COMPLETED");
+ job.setPercentDone("100.0");
+ job.setCompletionDate(now);
+ job.setRecoveryPointArn(rpArn);
+ job.setBackupSizeInBytes(0L);
+ job.setBytesTransferred(0L);
+ jobStore.put(jobId, job);
+
+ RecoveryPoint rp = new RecoveryPoint();
+ rp.setRecoveryPointArn(rpArn);
+ rp.setBackupVaultName(vaultName);
+ rp.setBackupVaultArn(job.getBackupVaultArn());
+ rp.setResourceArn(job.getResourceArn());
+ rp.setResourceType(job.getResourceType());
+ rp.setIamRoleArn(job.getIamRoleArn());
+ rp.setStatus("COMPLETED");
+ rp.setCreationDate(job.getCreationDate());
+ rp.setCompletionDate(now);
+ rp.setBackupSizeInBytes(0L);
+ rp.setStorageClass("WARM");
+ rp.setEncrypted(false);
+ recoveryStore.put(rpArn, rp);
+
+ incrementVaultCount(vaultName, region);
+ LOG.infov("Backup job {0} completed, recovery point: {1}", jobId, rpArn);
+ }
+ });
+ }
+
+ private void abortJob(String jobId) {
+ jobStore.get(jobId).ifPresent(job -> {
+ if ("ABORTING".equals(job.getState())) {
+ job.setState("ABORTED");
+ job.setCompletionDate(Instant.now().getEpochSecond());
+ jobStore.put(jobId, job);
+ }
+ });
+ }
+
+ private void incrementVaultCount(String vaultName, String region) {
+ vaultStore.get(vaultKey(region, vaultName)).ifPresent(vault -> {
+ vault.setNumberOfRecoveryPoints(vault.getNumberOfRecoveryPoints() + 1);
+ vaultStore.put(vaultKey(region, vaultName), vault);
+ });
+ }
+
+ private void decrementVaultCount(String vaultName, String region) {
+ vaultStore.get(vaultKey(region, vaultName)).ifPresent(vault -> {
+ vault.setNumberOfRecoveryPoints(Math.max(0, vault.getNumberOfRecoveryPoints() - 1));
+ vaultStore.put(vaultKey(region, vaultName), vault);
+ });
+ }
+
+ private Map<String, String> findTagsByArn(String arn) {
+ Optional<BackupVault> vault = vaultStore.scan(k -> true).stream()
+ .filter(v -> arn.equals(v.getBackupVaultArn()))
+ .findFirst();
+ if (vault.isPresent()) {
+ return vault.get().getTags();
+ }
+ Optional<BackupPlan> plan = planStore.scan(k -> true).stream()
+ .filter(p -> arn.equals(p.getBackupPlanArn()))
+ .findFirst();
+ if (plan.isPresent()) {
+ return new HashMap<>();
+ }
+ throw new AwsException("ResourceNotFoundException", "Resource not found: " + arn, 404);
+ }
+
+ private void applyTags(String arn, Map<String, String> newTags) {
+ Optional<BackupVault> vaultOpt = vaultStore.scan(k -> true).stream()
+ .filter(v -> arn.equals(v.getBackupVaultArn()))
+ .findFirst();
+ if (vaultOpt.isPresent()) {
+ BackupVault vault = vaultOpt.get();
+ vault.getTags().putAll(newTags);
+ vaultStore.put(vaultKey(vault), vault);
+ return;
+ }
+ throw new AwsException("ResourceNotFoundException", "Resource not found: " + arn, 404);
+ }
+
+ private void removeTags(String arn, List<String> tagKeys) {
+ Optional<BackupVault> vaultOpt = vaultStore.scan(k -> true).stream()
+ .filter(v -> arn.equals(v.getBackupVaultArn()))
+ .findFirst();
+ if (vaultOpt.isPresent()) {
+ BackupVault vault = vaultOpt.get();
+ tagKeys.forEach(vault.getTags()::remove);
+ vaultStore.put(vaultKey(vault), vault);
+ return;
+ }
+ throw new AwsException("ResourceNotFoundException", "Resource not found: " + arn, 404);
+ }
+
+ private static void assignRuleIds(List<BackupRule> rules) {
+ if (rules == null) {
+ return;
+ }
+ for (BackupRule rule : rules) {
+ if (rule.getRuleId() == null) {
+ rule.setRuleId(UUID.randomUUID().toString());
+ }
+ }
+ }
+
+ private static String inferResourceType(String resourceArn) {
+ if (resourceArn == null) {
+ return null;
+ }
+ if (resourceArn.contains(":s3:::")) {
+ return "S3";
+ }
+ if (resourceArn.contains(":rds:")) {
+ return "RDS";
+ }
+ if (resourceArn.contains(":dynamodb:")) {
+ return "DynamoDB";
+ }
+ if (resourceArn.contains(":ec2:")) {
+ return "EC2";
+ }
+ if (resourceArn.contains(":elasticfilesystem:")) {
+ return "EFS";
+ }
+ return null;
+ }
+
+ private static String vaultKey(String region, String vaultName) {
+ return region + ":" + vaultName;
+ }
+
+ private static String vaultKey(BackupVault vault) {
+ String arn = vault.getBackupVaultArn();
+ // arn:aws:backup:{region}:{account}:backup-vault:{name}
+ String[] parts = arn.split(":");
+ return parts[3] + ":" + vault.getBackupVaultName();
+ }
+
+ private static String shortId() {
+ return UUID.randomUUID().toString().replace("-", "").substring(0, 12);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/BackupTagHandler.java b/src/main/java/io/github/hectorvent/floci/services/backup/BackupTagHandler.java
new file mode 100644
index 0000000000..d9b067c4be
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/BackupTagHandler.java
@@ -0,0 +1,44 @@
+package io.github.hectorvent.floci.services.backup;
+
+import io.github.hectorvent.floci.core.common.TagHandler;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.util.List;
+import java.util.Map;
+
+@ApplicationScoped
+public class BackupTagHandler implements TagHandler {
+
+ private final BackupService service;
+
+ @Inject
+ public BackupTagHandler(BackupService service) {
+ this.service = service;
+ }
+
+ @Override
+ public String serviceKey() {
+ return "backup";
+ }
+
+ @Override
+ public String tagsBodyKey() {
+ return "Tags";
+ }
+
+ @Override
+ public Map<String, String> listTags(String region, String arn) {
+ return service.listTags(arn);
+ }
+
+ @Override
+ public void tagResource(String region, String arn, Map<String, String> tags) {
+ service.tagResource(arn, tags);
+ }
+
+ @Override
+ public void untagResource(String region, String arn, List<String> tagKeys) {
+ service.untagResource(arn, tagKeys);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupJob.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupJob.java
new file mode 100644
index 0000000000..d5dd8d7b50
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupJob.java
@@ -0,0 +1,116 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class BackupJob {
+
+ @JsonProperty("BackupJobId")
+ private String backupJobId;
+
+ @JsonProperty("BackupVaultName")
+ private String backupVaultName;
+
+ @JsonProperty("BackupVaultArn")
+ private String backupVaultArn;
+
+ @JsonProperty("RecoveryPointArn")
+ private String recoveryPointArn;
+
+ @JsonProperty("ResourceArn")
+ private String resourceArn;
+
+ @JsonProperty("ResourceType")
+ private String resourceType;
+
+ @JsonProperty("IamRoleArn")
+ private String iamRoleArn;
+
+ @JsonProperty("State")
+ private String state;
+
+ @JsonProperty("StatusMessage")
+ private String statusMessage;
+
+ @JsonProperty("CreationDate")
+ private long creationDate;
+
+ @JsonProperty("CompletionDate")
+ private Long completionDate;
+
+ @JsonProperty("ExpectedCompletionDate")
+ private Long expectedCompletionDate;
+
+ @JsonProperty("StartBy")
+ private Long startBy;
+
+ @JsonProperty("BytesTransferred")
+ private Long bytesTransferred;
+
+ @JsonProperty("BackupSizeInBytes")
+ private Long backupSizeInBytes;
+
+ @JsonProperty("PercentDone")
+ private String percentDone;
+
+ @JsonProperty("AccountId")
+ private String accountId;
+
+ public BackupJob() {}
+
+ public String getBackupJobId() { return backupJobId; }
+ public void setBackupJobId(String backupJobId) { this.backupJobId = backupJobId; }
+
+ public String getBackupVaultName() { return backupVaultName; }
+ public void setBackupVaultName(String backupVaultName) { this.backupVaultName = backupVaultName; }
+
+ public String getBackupVaultArn() { return backupVaultArn; }
+ public void setBackupVaultArn(String backupVaultArn) { this.backupVaultArn = backupVaultArn; }
+
+ public String getRecoveryPointArn() { return recoveryPointArn; }
+ public void setRecoveryPointArn(String recoveryPointArn) { this.recoveryPointArn = recoveryPointArn; }
+
+ public String getResourceArn() { return resourceArn; }
+ public void setResourceArn(String resourceArn) { this.resourceArn = resourceArn; }
+
+ public String getResourceType() { return resourceType; }
+ public void setResourceType(String resourceType) { this.resourceType = resourceType; }
+
+ public String getIamRoleArn() { return iamRoleArn; }
+ public void setIamRoleArn(String iamRoleArn) { this.iamRoleArn = iamRoleArn; }
+
+ public String getState() { return state; }
+ public void setState(String state) { this.state = state; }
+
+ public String getStatusMessage() { return statusMessage; }
+ public void setStatusMessage(String statusMessage) { this.statusMessage = statusMessage; }
+
+ public long getCreationDate() { return creationDate; }
+ public void setCreationDate(long creationDate) { this.creationDate = creationDate; }
+
+ public Long getCompletionDate() { return completionDate; }
+ public void setCompletionDate(Long completionDate) { this.completionDate = completionDate; }
+
+ public Long getExpectedCompletionDate() { return expectedCompletionDate; }
+ public void setExpectedCompletionDate(Long expectedCompletionDate) { this.expectedCompletionDate = expectedCompletionDate; }
+
+ public Long getStartBy() { return startBy; }
+ public void setStartBy(Long startBy) { this.startBy = startBy; }
+
+ public Long getBytesTransferred() { return bytesTransferred; }
+ public void setBytesTransferred(Long bytesTransferred) { this.bytesTransferred = bytesTransferred; }
+
+ public Long getBackupSizeInBytes() { return backupSizeInBytes; }
+ public void setBackupSizeInBytes(Long backupSizeInBytes) { this.backupSizeInBytes = backupSizeInBytes; }
+
+ public String getPercentDone() { return percentDone; }
+ public void setPercentDone(String percentDone) { this.percentDone = percentDone; }
+
+ public String getAccountId() { return accountId; }
+ public void setAccountId(String accountId) { this.accountId = accountId; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupPlan.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupPlan.java
new file mode 100644
index 0000000000..dccfd4921e
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupPlan.java
@@ -0,0 +1,65 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class BackupPlan {
+
+ @JsonProperty("BackupPlanId")
+ private String backupPlanId;
+
+ @JsonProperty("BackupPlanArn")
+ private String backupPlanArn;
+
+ @JsonProperty("BackupPlanName")
+ private String backupPlanName;
+
+ @JsonProperty("CreationDate")
+ private long creationDate;
+
+ @JsonProperty("DeletionDate")
+ private Long deletionDate;
+
+ @JsonProperty("LastExecutionDate")
+ private Long lastExecutionDate;
+
+ @JsonProperty("VersionId")
+ private String versionId;
+
+ @JsonProperty("Rules")
+ private List<BackupRule> rules = new ArrayList<>();
+
+ public BackupPlan() {}
+
+ public String getBackupPlanId() { return backupPlanId; }
+ public void setBackupPlanId(String backupPlanId) { this.backupPlanId = backupPlanId; }
+
+ public String getBackupPlanArn() { return backupPlanArn; }
+ public void setBackupPlanArn(String backupPlanArn) { this.backupPlanArn = backupPlanArn; }
+
+ public String getBackupPlanName() { return backupPlanName; }
+ public void setBackupPlanName(String backupPlanName) { this.backupPlanName = backupPlanName; }
+
+ public long getCreationDate() { return creationDate; }
+ public void setCreationDate(long creationDate) { this.creationDate = creationDate; }
+
+ public Long getDeletionDate() { return deletionDate; }
+ public void setDeletionDate(Long deletionDate) { this.deletionDate = deletionDate; }
+
+ public Long getLastExecutionDate() { return lastExecutionDate; }
+ public void setLastExecutionDate(Long lastExecutionDate) { this.lastExecutionDate = lastExecutionDate; }
+
+ public String getVersionId() { return versionId; }
+ public void setVersionId(String versionId) { this.versionId = versionId; }
+
+ public List<BackupRule> getRules() { return rules; }
+ public void setRules(List<BackupRule> rules) { this.rules = rules != null ? rules : new ArrayList<>(); }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java
new file mode 100644
index 0000000000..3ba221ac1e
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java
@@ -0,0 +1,83 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class BackupRule {
+
+ @JsonProperty("RuleName")
+ private String ruleName;
+
+ @JsonProperty("TargetBackupVaultName")
+ private String targetBackupVaultName;
+
+ @JsonProperty("ScheduleExpression")
+ private String scheduleExpression;
+
+ @JsonProperty("ScheduleExpressionTimezone")
+ private String scheduleExpressionTimezone;
+
+ @JsonProperty("StartWindowMinutes")
+ private Long startWindowMinutes;
+
+ @JsonProperty("CompletionWindowMinutes")
+ private Long completionWindowMinutes;
+
+ @JsonProperty("Lifecycle")
+ private Lifecycle lifecycle;
+
+ @JsonProperty("RecoveryPointTags")
+ private Map<String, String> recoveryPointTags = new HashMap<>();
+
+ @JsonProperty("RuleId")
+ private String ruleId;
+
+ @JsonProperty("CopyActions")
+ private List<CopyAction> copyActions = new ArrayList<>();
+
+ @JsonProperty("EnableContinuousBackup")
+ private Boolean enableContinuousBackup;
+
+ public BackupRule() {}
+
+ public String getRuleName() { return ruleName; }
+ public void setRuleName(String ruleName) { this.ruleName = ruleName; }
+
+ public String getTargetBackupVaultName() { return targetBackupVaultName; }
+ public void setTargetBackupVaultName(String targetBackupVaultName) { this.targetBackupVaultName = targetBackupVaultName; }
+
+ public String getScheduleExpression() { return scheduleExpression; }
+ public void setScheduleExpression(String scheduleExpression) { this.scheduleExpression = scheduleExpression; }
+
+ public String getScheduleExpressionTimezone() { return scheduleExpressionTimezone; }
+ public void setScheduleExpressionTimezone(String scheduleExpressionTimezone) { this.scheduleExpressionTimezone = scheduleExpressionTimezone; }
+
+ public Long getStartWindowMinutes() { return startWindowMinutes; }
+ public void setStartWindowMinutes(Long startWindowMinutes) { this.startWindowMinutes = startWindowMinutes; }
+
+ public Long getCompletionWindowMinutes() { return completionWindowMinutes; }
+ public void setCompletionWindowMinutes(Long completionWindowMinutes) { this.completionWindowMinutes = completionWindowMinutes; }
+
+ public Lifecycle getLifecycle() { return lifecycle; }
+ public void setLifecycle(Lifecycle lifecycle) { this.lifecycle = lifecycle; }
+
+ public Map<String, String> getRecoveryPointTags() { return recoveryPointTags; }
+ public void setRecoveryPointTags(Map<String, String> recoveryPointTags) { this.recoveryPointTags = recoveryPointTags != null ? recoveryPointTags : new HashMap<>(); }
+
+ public String getRuleId() { return ruleId; }
+ public void setRuleId(String ruleId) { this.ruleId = ruleId; }
+
+ public List<CopyAction> getCopyActions() { return copyActions; }
+ public void setCopyActions(List<CopyAction> copyActions) { this.copyActions = copyActions != null ? copyActions : new ArrayList<>(); }
+
+ public Boolean getEnableContinuousBackup() { return enableContinuousBackup; }
+ public void setEnableContinuousBackup(Boolean enableContinuousBackup) { this.enableContinuousBackup = enableContinuousBackup; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupSelection.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupSelection.java
new file mode 100644
index 0000000000..d468ae58f9
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupSelection.java
@@ -0,0 +1,65 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class BackupSelection {
+
+ @JsonProperty("SelectionId")
+ private String selectionId;
+
+ @JsonProperty("SelectionName")
+ private String selectionName;
+
+ @JsonProperty("BackupPlanId")
+ private String backupPlanId;
+
+ @JsonProperty("IamRoleArn")
+ private String iamRoleArn;
+
+ @JsonProperty("Resources")
+ private List<String> resources = new ArrayList<>();
+
+ @JsonProperty("NotResources")
+ private List<String> notResources = new ArrayList<>();
+
+ @JsonProperty("CreationDate")
+ private long creationDate;
+
+ @JsonProperty("CreatorRequestId")
+ private String creatorRequestId;
+
+ public BackupSelection() {}
+
+ public String getSelectionId() { return selectionId; }
+ public void setSelectionId(String selectionId) { this.selectionId = selectionId; }
+
+ public String getSelectionName() { return selectionName; }
+ public void setSelectionName(String selectionName) { this.selectionName = selectionName; }
+
+ public String getBackupPlanId() { return backupPlanId; }
+ public void setBackupPlanId(String backupPlanId) { this.backupPlanId = backupPlanId; }
+
+ public String getIamRoleArn() { return iamRoleArn; }
+ public void setIamRoleArn(String iamRoleArn) { this.iamRoleArn = iamRoleArn; }
+
+ public List<String> getResources() { return resources; }
+ public void setResources(List<String> resources) { this.resources = resources != null ? resources : new ArrayList<>(); }
+
+ public List<String> getNotResources() { return notResources; }
+ public void setNotResources(List<String> notResources) { this.notResources = notResources != null ? notResources : new ArrayList<>(); }
+
+ public long getCreationDate() { return creationDate; }
+ public void setCreationDate(long creationDate) { this.creationDate = creationDate; }
+
+ public String getCreatorRequestId() { return creatorRequestId; }
+ public void setCreatorRequestId(String creatorRequestId) { this.creatorRequestId = creatorRequestId; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupVault.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupVault.java
new file mode 100644
index 0000000000..36f2b35330
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupVault.java
@@ -0,0 +1,59 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class BackupVault {
+
+ @JsonProperty("BackupVaultName")
+ private String backupVaultName;
+
+ @JsonProperty("BackupVaultArn")
+ private String backupVaultArn;
+
+ @JsonProperty("EncryptionKeyArn")
+ private String encryptionKeyArn;
+
+ @JsonProperty("CreationDate")
+ private long creationDate;
+
+ @JsonProperty("CreatorRequestId")
+ private String creatorRequestId;
+
+ @JsonProperty("NumberOfRecoveryPoints")
+ private long numberOfRecoveryPoints;
+
+ @JsonProperty("Tags")
+ private Map<String, String> tags = new HashMap<>();
+
+ public BackupVault() {}
+
+ public String getBackupVaultName() { return backupVaultName; }
+ public void setBackupVaultName(String backupVaultName) { this.backupVaultName = backupVaultName; }
+
+ public String getBackupVaultArn() { return backupVaultArn; }
+ public void setBackupVaultArn(String backupVaultArn) { this.backupVaultArn = backupVaultArn; }
+
+ public String getEncryptionKeyArn() { return encryptionKeyArn; }
+ public void setEncryptionKeyArn(String encryptionKeyArn) { this.encryptionKeyArn = encryptionKeyArn; }
+
+ public long getCreationDate() { return creationDate; }
+ public void setCreationDate(long creationDate) { this.creationDate = creationDate; }
+
+ public String getCreatorRequestId() { return creatorRequestId; }
+ public void setCreatorRequestId(String creatorRequestId) { this.creatorRequestId = creatorRequestId; }
+
+ public long getNumberOfRecoveryPoints() { return numberOfRecoveryPoints; }
+ public void setNumberOfRecoveryPoints(long numberOfRecoveryPoints) { this.numberOfRecoveryPoints = numberOfRecoveryPoints; }
+
+ public Map<String, String> getTags() { return tags; }
+ public void setTags(Map<String, String> tags) { this.tags = tags != null ? tags : new HashMap<>(); }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/CopyAction.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/CopyAction.java
new file mode 100644
index 0000000000..6a4eebe2d8
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/CopyAction.java
@@ -0,0 +1,24 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class CopyAction {
+
+ @JsonProperty("DestinationBackupVaultArn")
+ private String destinationBackupVaultArn;
+
+ @JsonProperty("Lifecycle")
+ private Lifecycle lifecycle;
+
+ public CopyAction() {}
+
+ public String getDestinationBackupVaultArn() { return destinationBackupVaultArn; }
+ public void setDestinationBackupVaultArn(String destinationBackupVaultArn) { this.destinationBackupVaultArn = destinationBackupVaultArn; }
+
+ public Lifecycle getLifecycle() { return lifecycle; }
+ public void setLifecycle(Lifecycle lifecycle) { this.lifecycle = lifecycle; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/Lifecycle.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/Lifecycle.java
new file mode 100644
index 0000000000..c590d60d19
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/Lifecycle.java
@@ -0,0 +1,24 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Lifecycle {
+
+ @JsonProperty("MoveToColdStorageAfterDays")
+ private Long moveToColdStorageAfterDays;
+
+ @JsonProperty("DeleteAfterDays")
+ private Long deleteAfterDays;
+
+ public Lifecycle() {}
+
+ public Long getMoveToColdStorageAfterDays() { return moveToColdStorageAfterDays; }
+ public void setMoveToColdStorageAfterDays(Long moveToColdStorageAfterDays) { this.moveToColdStorageAfterDays = moveToColdStorageAfterDays; }
+
+ public Long getDeleteAfterDays() { return deleteAfterDays; }
+ public void setDeleteAfterDays(Long deleteAfterDays) { this.deleteAfterDays = deleteAfterDays; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/RecoveryPoint.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/RecoveryPoint.java
new file mode 100644
index 0000000000..46d76c0124
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/RecoveryPoint.java
@@ -0,0 +1,110 @@
+package io.github.hectorvent.floci.services.backup.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class RecoveryPoint {
+
+ @JsonProperty("RecoveryPointArn")
+ private String recoveryPointArn;
+
+ @JsonProperty("BackupVaultName")
+ private String backupVaultName;
+
+ @JsonProperty("BackupVaultArn")
+ private String backupVaultArn;
+
+ @JsonProperty("ResourceArn")
+ private String resourceArn;
+
+ @JsonProperty("ResourceType")
+ private String resourceType;
+
+ @JsonProperty("IamRoleArn")
+ private String iamRoleArn;
+
+ @JsonProperty("Status")
+ private String status;
+
+ @JsonProperty("StatusMessage")
+ private String statusMessage;
+
+ @JsonProperty("CreationDate")
+ private long creationDate;
+
+ @JsonProperty("CompletionDate")
+ private Long completionDate;
+
+ @JsonProperty("BackupSizeInBytes")
+ private Long backupSizeInBytes;
+
+ @JsonProperty("Lifecycle")
+ private Lifecycle lifecycle;
+
+ @JsonProperty("EncryptionKeyArn")
+ private String encryptionKeyArn;
+
+ @JsonProperty("IsEncrypted")
+ private boolean isEncrypted;
+
+ @JsonProperty("StorageClass")
+ private String storageClass;
+
+ @JsonProperty("LastRestoreTime")
+ private Long lastRestoreTime;
+
+ public RecoveryPoint() {}
+
+ public String getRecoveryPointArn() { return recoveryPointArn; }
+ public void setRecoveryPointArn(String recoveryPointArn) { this.recoveryPointArn = recoveryPointArn; }
+
+ public String getBackupVaultName() { return backupVaultName; }
+ public void setBackupVaultName(String backupVaultName) { this.backupVaultName = backupVaultName; }
+
+ public String getBackupVaultArn() { return backupVaultArn; }
+ public void setBackupVaultArn(String backupVaultArn) { this.backupVaultArn = backupVaultArn; }
+
+ public String getResourceArn() { return resourceArn; }
+ public void setResourceArn(String resourceArn) { this.resourceArn = resourceArn; }
+
+ public String getResourceType() { return resourceType; }
+ public void setResourceType(String resourceType) { this.resourceType = resourceType; }
+
+ public String getIamRoleArn() { return iamRoleArn; }
+ public void setIamRoleArn(String iamRoleArn) { this.iamRoleArn = iamRoleArn; }
+
+ public String getStatus() { return status; }
+ public void setStatus(String status) { this.status = status; }
+
+ public String getStatusMessage() { return statusMessage; }
+ public void setStatusMessage(String statusMessage) { this.statusMessage = statusMessage; }
+
+ public long getCreationDate() { return creationDate; }
+ public void setCreationDate(long creationDate) { this.creationDate = creationDate; }
+
+ public Long getCompletionDate() { return completionDate; }
+ public void setCompletionDate(Long completionDate) { this.completionDate = completionDate; }
+
+ public Long getBackupSizeInBytes() { return backupSizeInBytes; }
+ public void setBackupSizeInBytes(Long backupSizeInBytes) { this.backupSizeInBytes = backupSizeInBytes; }
+
+ public Lifecycle getLifecycle() { return lifecycle; }
+ public void setLifecycle(Lifecycle lifecycle) { this.lifecycle = lifecycle; }
+
+ public String getEncryptionKeyArn() { return encryptionKeyArn; }
+ public void setEncryptionKeyArn(String encryptionKeyArn) { this.encryptionKeyArn = encryptionKeyArn; }
+
+ public boolean isEncrypted() { return isEncrypted; }
+ public void setEncrypted(boolean encrypted) { isEncrypted = encrypted; }
+
+ public String getStorageClass() { return storageClass; }
+ public void setStorageClass(String storageClass) { this.storageClass = storageClass; }
+
+ public Long getLastRestoreTime() { return lastRestoreTime; }
+ public void setLastRestoreTime(Long lastRestoreTime) { this.lastRestoreTime = lastRestoreTime; }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index c64947c47f..4ea1567a17 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -241,5 +241,10 @@ floci:
enabled: true
autoscaling:
enabled: true
+ backup:
+ enabled: true
+ job-completion-delay-seconds: 3
route53:
enabled: true
+ transfer:
+ enabled: true
diff --git a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorInfoControllerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorInfoControllerIntegrationTest.java
index 570e216f98..b233b16268 100644
--- a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorInfoControllerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorInfoControllerIntegrationTest.java
@@ -58,7 +58,9 @@ class EmulatorInfoControllerIntegrationTest {
"codebuild": "running",
"codedeploy": "running",
"autoscaling": "running",
- "route53": "running"
+ "backup": "running",
+ "route53": "running",
+ "transfer": "running"
}
""";
diff --git a/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java
new file mode 100644
index 0000000000..f6cce28cd2
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java
@@ -0,0 +1,527 @@
+package io.github.hectorvent.floci.services.backup;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.*;
+
+/**
+ * Integration tests for AWS Backup via REST JSON protocol.
+ */
+@QuarkusTest
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class BackupIntegrationTest {
+
+ private static final String AUTH = "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/backup/aws4_request";
+ private static final String VAULT_NAME = "test-vault";
+ private static final String IAM_ROLE = "arn:aws:iam::000000000000:role/backup-role";
+ private static final String RESOURCE_ARN = "arn:aws:dynamodb:us-east-1:000000000000:table/my-table";
+
+ private static String planId;
+ private static String selectionId;
+ private static String jobId;
+ private static String recoveryPointArn;
+
+ // ── Vault ──────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(10)
+ void createBackupVault() {
+ given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("{\"BackupVaultTags\":{\"env\":\"test\"}}")
+ .when()
+ .put("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(200)
+ .body("BackupVaultName", equalTo(VAULT_NAME))
+ .body("BackupVaultArn", containsString("backup-vault:" + VAULT_NAME));
+ }
+
+ @Test
+ @Order(11)
+ void describeBackupVault() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(200)
+ .body("BackupVaultName", equalTo(VAULT_NAME))
+ .body("NumberOfRecoveryPoints", equalTo(0));
+ }
+
+ @Test
+ @Order(12)
+ void listBackupVaults() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/")
+ .then()
+ .statusCode(200)
+ .body("BackupVaultList", hasSize(greaterThanOrEqualTo(1)))
+ .body("BackupVaultList[0].BackupVaultName", notNullValue());
+ }
+
+ @Test
+ @Order(13)
+ void createVaultAlreadyExistsReturns400() {
+ given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("{}")
+ .when()
+ .put("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(400);
+ }
+
+ // ── Plan ───────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(20)
+ void createBackupPlan() {
+ planId = given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("""
+ {
+ "BackupPlan": {
+ "BackupPlanName": "daily-backup",
+ "Rules": [{
+ "RuleName": "daily",
+ "TargetBackupVaultName": "%s",
+ "ScheduleExpression": "cron(0 12 * * ? *)",
+ "StartWindowMinutes": 60,
+ "CompletionWindowMinutes": 120
+ }]
+ }
+ }
+ """.formatted(VAULT_NAME))
+ .when()
+ .put("/backup/plans/")
+ .then()
+ .statusCode(200)
+ .body("BackupPlanId", notNullValue())
+ .body("BackupPlanArn", containsString("backup-plan:"))
+ .body("VersionId", notNullValue())
+ .extract().path("BackupPlanId");
+ }
+
+ @Test
+ @Order(21)
+ void getBackupPlan() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup/plans/" + planId + "/")
+ .then()
+ .statusCode(200)
+ .body("BackupPlanId", equalTo(planId))
+ .body("BackupPlan.BackupPlanName", equalTo("daily-backup"))
+ .body("BackupPlan.Rules[0].RuleName", equalTo("daily"))
+ .body("BackupPlan.Rules[0].RuleId", notNullValue());
+ }
+
+ @Test
+ @Order(22)
+ void updateBackupPlan() {
+ given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("""
+ {
+ "BackupPlan": {
+ "BackupPlanName": "daily-backup-v2",
+ "Rules": [{
+ "RuleName": "daily-v2",
+ "TargetBackupVaultName": "%s",
+ "ScheduleExpression": "cron(0 6 * * ? *)"
+ }]
+ }
+ }
+ """.formatted(VAULT_NAME))
+ .when()
+ .post("/backup/plans/" + planId)
+ .then()
+ .statusCode(200)
+ .body("BackupPlanId", equalTo(planId))
+ .body("VersionId", notNullValue());
+ }
+
+ @Test
+ @Order(23)
+ void listBackupPlans() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup/plans/")
+ .then()
+ .statusCode(200)
+ .body("BackupPlansList", hasSize(greaterThanOrEqualTo(1)))
+ .body("BackupPlansList[0].BackupPlanId", notNullValue());
+ }
+
+ // ── Selection ──────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(30)
+ void createBackupSelection() {
+ selectionId = given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("""
+ {
+ "BackupSelection": {
+ "SelectionName": "my-selection",
+ "IamRoleArn": "%s",
+ "Resources": ["%s"]
+ }
+ }
+ """.formatted(IAM_ROLE, RESOURCE_ARN))
+ .when()
+ .put("/backup/plans/" + planId + "/selections/")
+ .then()
+ .statusCode(200)
+ .body("SelectionId", notNullValue())
+ .body("BackupPlanId", equalTo(planId))
+ .extract().path("SelectionId");
+ }
+
+ @Test
+ @Order(31)
+ void getBackupSelection() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup/plans/" + planId + "/selections/" + selectionId)
+ .then()
+ .statusCode(200)
+ .body("SelectionId", equalTo(selectionId))
+ .body("BackupSelection.SelectionName", equalTo("my-selection"))
+ .body("BackupSelection.IamRoleArn", equalTo(IAM_ROLE));
+ }
+
+ @Test
+ @Order(32)
+ void listBackupSelections() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup/plans/" + planId + "/selections/")
+ .then()
+ .statusCode(200)
+ .body("BackupSelectionsList", hasSize(1))
+ .body("BackupSelectionsList[0].SelectionId", equalTo(selectionId));
+ }
+
+ @Test
+ @Order(33)
+ void deleteBackupPlanWithSelectionReturns400() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .delete("/backup/plans/" + planId)
+ .then()
+ .statusCode(400);
+ }
+
+ // ── Job ────────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(40)
+ void startBackupJob() {
+ jobId = given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("""
+ {
+ "BackupVaultName": "%s",
+ "ResourceArn": "%s",
+ "IamRoleArn": "%s"
+ }
+ """.formatted(VAULT_NAME, RESOURCE_ARN, IAM_ROLE))
+ .when()
+ .put("/backup-jobs")
+ .then()
+ .statusCode(200)
+ .body("BackupJobId", notNullValue())
+ .body("BackupVaultArn", containsString("backup-vault:"))
+ .extract().path("BackupJobId");
+ }
+
+ @Test
+ @Order(41)
+ void describeBackupJobCreated() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-jobs/" + jobId)
+ .then()
+ .statusCode(200)
+ .body("BackupJobId", equalTo(jobId))
+ .body("State", oneOf("CREATED", "RUNNING", "COMPLETED"))
+ .body("BackupVaultName", equalTo(VAULT_NAME));
+ }
+
+ @Test
+ @Order(42)
+ void describeBackupJobCompleted() throws InterruptedException {
+ Thread.sleep(2000); // job-completion-delay-seconds=1 in test config
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-jobs/" + jobId)
+ .then()
+ .statusCode(200)
+ .body("State", equalTo("COMPLETED"))
+ .body("RecoveryPointArn", containsString("recovery-point:"))
+ .body("CompletionDate", notNullValue());
+
+ recoveryPointArn = given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-jobs/" + jobId)
+ .then()
+ .extract().path("RecoveryPointArn");
+ }
+
+ @Test
+ @Order(43)
+ void listBackupJobsByVault() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-jobs/?byBackupVaultName=" + VAULT_NAME)
+ .then()
+ .statusCode(200)
+ .body("BackupJobs", hasSize(greaterThanOrEqualTo(1)))
+ .body("BackupJobs[0].BackupVaultName", equalTo(VAULT_NAME));
+ }
+
+ @Test
+ @Order(44)
+ void listBackupJobsByState() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-jobs/?byState=COMPLETED")
+ .then()
+ .statusCode(200)
+ .body("BackupJobs", hasSize(greaterThanOrEqualTo(1)));
+ }
+
+ // ── Recovery Point ─────────────────────────────────────────────────────────
+
+ @Test
+ @Order(50)
+ void describeRecoveryPoint() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME + "/recovery-points/" + recoveryPointArn)
+ .then()
+ .statusCode(200)
+ .body("RecoveryPointArn", equalTo(recoveryPointArn))
+ .body("BackupVaultName", equalTo(VAULT_NAME))
+ .body("Status", equalTo("COMPLETED"));
+ }
+
+ @Test
+ @Order(51)
+ void listRecoveryPointsByBackupVault() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME + "/recovery-points/")
+ .then()
+ .statusCode(200)
+ .body("RecoveryPoints", hasSize(1))
+ .body("RecoveryPoints[0].RecoveryPointArn", equalTo(recoveryPointArn));
+ }
+
+ @Test
+ @Order(52)
+ void vaultCountIncrementedAfterJob() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(200)
+ .body("NumberOfRecoveryPoints", equalTo(1));
+ }
+
+ @Test
+ @Order(53)
+ void deleteVaultWithRecoveryPointsReturns400() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .delete("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(400);
+ }
+
+ @Test
+ @Order(54)
+ void deleteRecoveryPoint() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .delete("/backup-vaults/" + VAULT_NAME + "/recovery-points/" + recoveryPointArn)
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ @Order(55)
+ void vaultCountDecrementedAfterDelete() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(200)
+ .body("NumberOfRecoveryPoints", equalTo(0));
+ }
+
+ // ── Tags ───────────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(60)
+ void tagBackupVault() {
+ String vaultArn = given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .extract().path("BackupVaultArn");
+
+ given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("{\"Tags\":{\"team\":\"platform\"}}")
+ .when()
+ .post("/tags/" + vaultArn)
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ @Order(61)
+ void listTagsForVault() {
+ String vaultArn = given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .extract().path("BackupVaultArn");
+
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/tags/" + vaultArn)
+ .then()
+ .statusCode(200)
+ .body("Tags.env", equalTo("test"))
+ .body("Tags.team", equalTo("platform"));
+ }
+
+ @Test
+ @Order(62)
+ void untagBackupVault() {
+ String vaultArn = given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .extract().path("BackupVaultArn");
+
+ given()
+ .header("Authorization", AUTH)
+ .contentType("application/json")
+ .body("{\"TagKeyList\":[\"team\"]}")
+ .when()
+ .post("/untag/" + vaultArn)
+ .then()
+ .statusCode(204);
+
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/tags/" + vaultArn)
+ .then()
+ .statusCode(200)
+ .body("Tags.team", nullValue())
+ .body("Tags.env", equalTo("test"));
+ }
+
+ // ── Supported Resource Types ───────────────────────────────────────────────
+
+ @Test
+ @Order(70)
+ void getSupportedResourceTypes() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/supported-resource-types")
+ .then()
+ .statusCode(200)
+ .body("ResourceTypes", hasSize(greaterThan(0)))
+ .body("ResourceTypes", hasItem("S3"))
+ .body("ResourceTypes", hasItem("DynamoDB"));
+ }
+
+ // ── Teardown ───────────────────────────────────────────────────────────────
+
+ @Test
+ @Order(80)
+ void deleteBackupSelection() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .delete("/backup/plans/" + planId + "/selections/" + selectionId)
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ @Order(81)
+ void deleteBackupPlan() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .delete("/backup/plans/" + planId)
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ @Order(82)
+ void deleteBackupVault() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .delete("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ @Order(83)
+ void describeDeletedVaultReturns404() {
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/backup-vaults/" + VAULT_NAME)
+ .then()
+ .statusCode(404);
+ }
+}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index f7cd4b55de..3d481f2818 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -162,5 +162,10 @@ floci:
enabled: true
autoscaling:
enabled: true
+ backup:
+ enabled: true
+ job-completion-delay-seconds: 1
route53:
enabled: true
+ transfer:
+ enabled: true