mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
* feat(redshift): support ModifyClusterSnapshot API action (#7755) * docs(redshift): update operation count after merging CopyClusterSnapshot * fix(redshift): enforce ModifyClusterSnapshot retention, Force, and expiry of manual snapshots (#7755) * fix(redshift): address snapshot retention review feedback
This commit is contained in:
1 parent
3700a6b6fa
commit
92eff0aca5
9 files changed
+331
-32
No files matched your search
+47
@@ -120,6 +120,53 @@ class RedshiftAutomatedSnapshotServiceTest {
|
||||
.stream().map(Snapshot::getSnapshotIdentifier).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifiedManualSnapshotExpiresOnceItsRetentionHasPassed() {
|
||||
Fixture fixture = fixture();
|
||||
seed(fixture, ACCOUNT, "warehouse", "us-east-1", null);
|
||||
Snapshot manual = fixture.service().createSnapshot("manual-backup", "warehouse");
|
||||
fixture.service().modifyClusterSnapshot("manual-backup", 5);
|
||||
|
||||
fixture.service().runSnapshotSchedules(Instant.now().plus(Duration.ofDays(4)));
|
||||
assertTrue(fixture.snapshots().getForAccount(ACCOUNT, "manual-backup").isPresent());
|
||||
assertTrue(Files.exists(Path.of(manual.getSqlDump())));
|
||||
|
||||
fixture.service().runSnapshotSchedules(Instant.now().plus(Duration.ofDays(6)));
|
||||
assertTrue(fixture.snapshots().getForAccount(ACCOUNT, "manual-backup").isEmpty());
|
||||
assertFalse(Files.exists(Path.of(manual.getSqlDump())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void manualSnapshotsWithoutAFiniteRetentionAreNeverExpired() {
|
||||
Fixture fixture = fixture();
|
||||
seed(fixture, ACCOUNT, "warehouse", null, null);
|
||||
Snapshot manual = fixture.service().createSnapshot("manual-backup", "warehouse");
|
||||
|
||||
fixture.service().runSnapshotSchedules(Instant.now().plus(Duration.ofDays(4000)));
|
||||
|
||||
assertTrue(fixture.snapshots().getForAccount(ACCOUNT, "manual-backup").isPresent());
|
||||
assertTrue(Files.exists(Path.of(manual.getSqlDump())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotRejectsAnElapsedRetentionUnlessForced() {
|
||||
Fixture fixture = fixture();
|
||||
seed(fixture, ACCOUNT, "warehouse", null, null);
|
||||
Snapshot manual = fixture.service().createSnapshot("manual-backup", "warehouse");
|
||||
manual.setSnapshotCreateTime(Instant.now().minus(Duration.ofDays(10)));
|
||||
fixture.snapshots().putForAccount(ACCOUNT, "manual-backup", manual);
|
||||
|
||||
AwsException rejected = assertThrows(AwsException.class,
|
||||
() -> fixture.service().modifyClusterSnapshot("manual-backup", 5, false));
|
||||
assertEquals("InvalidRetentionPeriodFault", rejected.getErrorCode());
|
||||
assertEquals(-1, fixture.snapshots().getForAccount(ACCOUNT, "manual-backup").orElseThrow()
|
||||
.getManualSnapshotRetentionPeriod());
|
||||
|
||||
fixture.service().modifyClusterSnapshot("manual-backup", 5, true);
|
||||
assertTrue(fixture.snapshots().getForAccount(ACCOUNT, "manual-backup").isEmpty());
|
||||
assertFalse(Files.exists(Path.of(manual.getSqlDump())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingClustersLoseAutomatedSnapshotsButKeepManualBackups() {
|
||||
Fixture fixture = fixture();
|
||||
|
||||
@@ -78,6 +78,10 @@ class RedshiftFinalSnapshotIntegrationTest {
|
||||
Snapshot snapshot = client.describeClusterSnapshots(request -> request.snapshotIdentifier(backup))
|
||||
.snapshots().getFirst();
|
||||
assertEquals(retention, snapshot.manualSnapshotRetentionPeriod());
|
||||
Snapshot unchanged = client.modifyClusterSnapshot(request -> request.snapshotIdentifier(backup).force(true))
|
||||
.snapshot();
|
||||
assertEquals(retention, unchanged.manualSnapshotRetentionPeriod());
|
||||
assertEquals(backup, unchanged.snapshotIdentifier());
|
||||
assertEquals(source, snapshot.clusterIdentifier());
|
||||
assertEquals("available", snapshot.status());
|
||||
assertNotNull(snapshot.snapshotCreateTime());
|
||||
|
||||
@@ -452,7 +452,23 @@ public class RedshiftOperationsTest {
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<SnapshotIdentifier>snap-test-1</SnapshotIdentifier>"));
|
||||
|
||||
// 3b. CopyClusterSnapshot rejects manual snapshot
|
||||
// 3b. ModifyClusterSnapshot updates retention period
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyClusterSnapshot")
|
||||
.formParam("SnapshotIdentifier", "snap-test-1")
|
||||
.formParam("ManualSnapshotRetentionPeriod", "45")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<ModifyClusterSnapshotResponse>"))
|
||||
.body(containsString("<SnapshotIdentifier>snap-test-1</SnapshotIdentifier>"))
|
||||
.body(containsString("<ManualSnapshotRetentionPeriod>45</ManualSnapshotRetentionPeriod>"));
|
||||
|
||||
// 3c. CopyClusterSnapshot rejects manual snapshot
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
@@ -466,7 +482,7 @@ public class RedshiftOperationsTest {
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<Code>InvalidClusterSnapshotState</Code>"));
|
||||
|
||||
// 3c. CopyClusterSnapshot succeeds when source is automated
|
||||
// 3d. CopyClusterSnapshot succeeds when source is automated
|
||||
service.getSnapshot("snap-test-1").ifPresent(s -> s.setSnapshotType("automated"));
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
|
||||
@@ -1478,6 +1478,62 @@ class RedshiftQueryHandlerTest {
|
||||
assertTrue(xml.contains("<DbUser>IAM:alice</DbUser>"));
|
||||
}
|
||||
|
||||
// ── ModifyClusterSnapshot ─────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotRequiresIdentifier() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
AwsException ex1 = assertThrows(AwsException.class, () -> handler.handle("ModifyClusterSnapshot", params));
|
||||
assertEquals("InvalidParameterValue", ex1.getErrorCode());
|
||||
assertTrue(ex1.getMessage().contains("SnapshotIdentifier is required"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotAllowsOmittedRetention() {
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setSnapshotIdentifier("my-snap");
|
||||
snapshot.setManualSnapshotRetentionPeriod(7);
|
||||
when(service.modifyClusterSnapshot("my-snap", null, null)).thenReturn(snapshot);
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("SnapshotIdentifier", "my-snap");
|
||||
|
||||
Response response = handler.handle("ModifyClusterSnapshot", params);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertTrue(response.getEntity().toString().contains("<ManualSnapshotRetentionPeriod>7</ManualSnapshotRetentionPeriod>"));
|
||||
verify(service).modifyClusterSnapshot("my-snap", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotDelegatesToServiceAndFormatsXml() {
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setSnapshotIdentifier("my-snap");
|
||||
snapshot.setClusterIdentifier("my-cluster");
|
||||
snapshot.setSnapshotType("manual");
|
||||
snapshot.setStatus("available");
|
||||
snapshot.setMasterUsername("admin");
|
||||
snapshot.setPort(5439);
|
||||
snapshot.setManualSnapshotRetentionPeriod(45);
|
||||
snapshot.setSnapshotArn("arn:aws:redshift:us-east-1:111111111111:snapshot:my-cluster/my-snap");
|
||||
|
||||
when(service.modifyClusterSnapshot("my-snap", 45, true)).thenReturn(snapshot);
|
||||
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("SnapshotIdentifier", "my-snap");
|
||||
params.putSingle("ManualSnapshotRetentionPeriod", "45");
|
||||
params.putSingle("Force", "true");
|
||||
|
||||
Response response = handler.handle("ModifyClusterSnapshot", params);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
String xml = (String) response.getEntity();
|
||||
assertTrue(xml.contains("<ModifyClusterSnapshotResponse>"));
|
||||
assertTrue(xml.contains("<ModifyClusterSnapshotResult>"));
|
||||
assertTrue(xml.contains("<SnapshotIdentifier>my-snap</SnapshotIdentifier>"));
|
||||
assertTrue(xml.contains("<ManualSnapshotRetentionPeriod>45</ManualSnapshotRetentionPeriod>"));
|
||||
verify(service).modifyClusterSnapshot("my-snap", 45, true);
|
||||
}
|
||||
|
||||
// ── CopyClusterSnapshot ──────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2539,6 +2539,87 @@ class RedshiftServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotSuccess() {
|
||||
Snapshot manualSnap = snapshotOf("snap-1", "my-cluster");
|
||||
manualSnap.setStatus("available");
|
||||
manualSnap.setManualSnapshotRetentionPeriod(-1);
|
||||
|
||||
when(snapshotBackend.get("snap-1")).thenReturn(Optional.of(manualSnap));
|
||||
when(snapshotCopyBackend.get(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
Snapshot modified = service.modifyClusterSnapshot("snap-1", 45);
|
||||
|
||||
assertNotNull(modified);
|
||||
assertEquals(45, modified.getManualSnapshotRetentionPeriod());
|
||||
verify(snapshotBackend).putAllAtomically(any());
|
||||
verify(snapshotBackend).flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotNotFound() {
|
||||
when(snapshotBackend.get("missing-snap")).thenReturn(Optional.empty());
|
||||
when(snapshotCopyBackend.get(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterSnapshot("missing-snap", 30));
|
||||
assertEquals("ClusterSnapshotNotFound", ex.getErrorCode());
|
||||
assertEquals(404, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotAutomatedSnapshotRejected() {
|
||||
automatedSnapshot("auto-snap-1");
|
||||
when(snapshotCopyBackend.get(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterSnapshot("auto-snap-1", 30));
|
||||
assertEquals("InvalidClusterSnapshotState", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotNotAvailableRejected() {
|
||||
Snapshot manualSnap = snapshotOf("snap-1", "my-cluster");
|
||||
manualSnap.setStatus("creating");
|
||||
|
||||
when(snapshotBackend.get("snap-1")).thenReturn(Optional.of(manualSnap));
|
||||
when(snapshotCopyBackend.get(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterSnapshot("snap-1", 30));
|
||||
assertEquals("InvalidClusterSnapshotState", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotInvalidRetentionPeriod() {
|
||||
AwsException ex1 = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterSnapshot("snap-1", 0));
|
||||
assertEquals("InvalidRetentionPeriodFault", ex1.getErrorCode());
|
||||
assertEquals(400, ex1.getHttpStatus());
|
||||
|
||||
AwsException ex2 = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterSnapshot("snap-1", 3654));
|
||||
assertEquals("InvalidRetentionPeriodFault", ex2.getErrorCode());
|
||||
assertEquals(400, ex2.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterSnapshotWithoutRetentionPreservesExistingSettings() {
|
||||
Snapshot snapshot = snapshotOf("snap-1", "my-cluster");
|
||||
snapshot.setStatus("available");
|
||||
snapshot.setManualSnapshotRetentionPeriod(7);
|
||||
when(snapshotBackend.get("snap-1")).thenReturn(Optional.of(snapshot));
|
||||
|
||||
Snapshot modified = service.modifyClusterSnapshot("snap-1", null, true);
|
||||
|
||||
assertSame(snapshot, modified);
|
||||
assertEquals(7, modified.getManualSnapshotRetentionPeriod());
|
||||
verify(snapshotBackend, never()).putAllAtomically(any());
|
||||
verify(snapshotBackend, never()).deleteAllAtomically(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterUpdatesMetadataAndPassword() {
|
||||
Cluster cluster = new Cluster();
|
||||
|
||||
Reference in new issue
Block a user