From 72b746be137ae10459040f1f1fd6ebc948dcc111 Mon Sep 17 00:00:00 2001 From: luiseterc Date: Wed, 18 Nov 2026 18:17:50 +0100 Subject: [PATCH] fix(rds): retain cluster settings and member promotion tiers (#8849) RDS accepted a cluster's CopyTagsToSnapshot and CloudWatch log exports and an Aurora member's PromotionTier but returned none of them, so Terraform planned changes right after a successful apply. CreateDBCluster and ModifyDBCluster now keep CopyTagsToSnapshot, an explicit false included, and the enabled log exports, with a modify applying CloudwatchLogsExportConfiguration as enable and disable deltas and leaving omitted fields alone. PromotionTier is kept from CreateDBInstance and ModifyDBInstance, defaults to 1 and is refused outside 0 to 15 before anything changes, and both the instance and the cluster member list report it. The new fields persist, and state saved before them loads with the defaults. Closes #8418 --- docs/services/rds.md | 13 ++ .../aws/services/rds/RdsQueryHandler.java | 30 ++- .../io/floci/aws/services/rds/RdsService.java | 40 ++++ .../aws/services/rds/model/DbCluster.java | 9 + .../aws/services/rds/model/DbInstance.java | 4 + .../RdsSettingsRoundTripIntegrationTest.java | 177 ++++++++++++++++++ .../rds/model/DbClusterPersistenceTest.java | 47 +++++ 7 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 src/test/java/io/floci/aws/services/rds/RdsSettingsRoundTripIntegrationTest.java diff --git a/docs/services/rds.md b/docs/services/rds.md index 29b752f58a..7966aa1ce6 100644 --- a/docs/services/rds.md +++ b/docs/services/rds.md @@ -232,6 +232,19 @@ checked against the instance's other window. Modifications apply immediately — one moment; as with `mysqldump --single-transaction` elsewhere, a MyISAM or other non-transactional table written to during the snapshot may not be. +## Cluster settings read-back + +`CreateDBCluster` and `ModifyDBCluster` retain `CopyTagsToSnapshot` and the enabled +CloudWatch log export types. Modify uses `CloudwatchLogsExportConfiguration` enable +and disable deltas; omitted fields preserve their values, including an explicit +false snapshot-copy flag. Create, modify and describe return the stored settings. + +Aurora member instances retain `PromotionTier` from create and modify, defaulting +to 1 and accepting 0 through 15. Both the instance response and the cluster member +list report that value. Invalid tiers are rejected before other requested changes +are applied. These additions cover configuration read-back; log shipping, snapshot +tag-copy execution, restore settings and failover target selection are unchanged. + ## Cluster parameter groups `DescribeDBClusterParameterGroups` includes `DBClusterParameterGroupArn` for managed `default.*` diff --git a/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java b/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java index 066a0a4045..7d1e939f66 100644 --- a/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java @@ -387,6 +387,8 @@ public class RdsQueryHandler { try { DbInstanceSettings settings = instanceSettings(params); + Integer promotionTier = parseIntegerParam(params, "PromotionTier"); + RdsService.validatePromotionTier(promotionTier); List vpcSecurityGroupIds = vpcSecurityGroupIds(params); Integer requestedPort = parseIntegerParam(params, "Port"); DbInstance instance = service.createDbInstance(id, engine, engineVersion, masterUsername, @@ -395,6 +397,9 @@ public class RdsQueryHandler { manageMasterUserPassword, masterUserSecretKmsKeyId, tags, vpcSecurityGroupIds, optionGroupName, region, autoMinorVersionUpgrade, settings, publiclyAccessible, requestedPort, deletionProtection); + if (promotionTier != null) { + instance = service.setInstancePromotionTier(region, id, promotionTier); + } String result = dbInstanceXml(instance); return Response.ok(AwsQueryResponse.envelope("CreateDBInstance", AwsNamespaces.RDS, result)).build(); } catch (AwsException e) { @@ -929,6 +934,8 @@ public class RdsQueryHandler { } try { DbInstanceSettings settings = instanceSettings(params, false); + Integer promotionTier = parseIntegerParam(params, "PromotionTier"); + RdsService.validatePromotionTier(promotionTier); DbInstanceScalingChanges scaling = scalingChanges(params); List vpcSecurityGroupIds = vpcSecurityGroupIds(params); DbInstance instance = service.modifyDbInstance( @@ -936,6 +943,9 @@ public class RdsQueryHandler { vpcSecurityGroupIds, optionGroupName, region, autoMinorVersionUpgrade, settings, publiclyAccessible, scaling, deletionProtection, params.getFirst("DBParameterGroupName")); + if (promotionTier != null) { + instance = service.setInstancePromotionTier(region, id, promotionTier); + } String result = dbInstanceXml(instance); return Response.ok(AwsQueryResponse.envelope("ModifyDBInstance", AwsNamespaces.RDS, result)).build(); } catch (AwsException e) { @@ -1429,6 +1439,8 @@ public class RdsQueryHandler { } try { + Boolean copyTagsToSnapshot = parseOptionalBoolean(params, "CopyTagsToSnapshot"); + List exports = cloudwatchLogsExports(params); List associatedRoles = parseAssociatedRoles(params); service.validateClusterRoleAssociations(id, engine, associatedRoles); boolean enableHttpEndpoint = Boolean.TRUE.equals(parseOptionalBoolean(params, "EnableHttpEndpoint")); @@ -1495,6 +1507,9 @@ public class RdsQueryHandler { if (backupRetentionPeriodParam != null) { cluster = service.setBackupRetentionPeriod(region, id, backupRetentionPeriod); } + if (copyTagsToSnapshot != null || exports != null) { + cluster = service.setClusterSnapshotAndLogSettings(region, id, copyTagsToSnapshot, exports, null); + } String result = dbClusterXml(cluster); return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build(); } catch (AwsException e) { @@ -1600,6 +1615,8 @@ public class RdsQueryHandler { Boolean manageMasterUserPassword = manageStr != null ? Boolean.parseBoolean(manageStr) : null; String masterUserSecretKmsKeyId = params.getFirst("MasterUserSecretKmsKeyId"); try { + Boolean copyTagsToSnapshot = parseOptionalBoolean(params, "CopyTagsToSnapshot"); + LogExportChanges exportChanges = cloudwatchLogsExportChanges(params); Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity"); Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity"); Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam( @@ -1624,6 +1641,9 @@ public class RdsQueryHandler { if (modifyBackupRetentionPeriod != null) { cluster = service.setBackupRetentionPeriod(region, id, modifyBackupRetentionPeriod); } + if (copyTagsToSnapshot != null || exportChanges != null) { + cluster = service.setClusterSnapshotAndLogSettings(region, id, copyTagsToSnapshot, null, exportChanges); + } String result = dbClusterXml(cluster); return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS, result)).build(); } catch (AwsException e) { @@ -3435,7 +3455,8 @@ public class RdsQueryHandler { xml.end("MasterUserSecret"); } if (i.getDbClusterIdentifier() != null && !i.getDbClusterIdentifier().isBlank()) { - xml.elem("DBClusterIdentifier", i.getDbClusterIdentifier()); + xml.elem("DBClusterIdentifier", i.getDbClusterIdentifier()) + .elem("PromotionTier", i.getPromotionTier()); } xml.raw(readReplicaXml(i)); writeAssociatedRoles(xml, i.getAssociatedRoles(), "DBInstanceRole"); @@ -3629,6 +3650,7 @@ public class RdsQueryHandler { .elem("MultiAZ", c.isMultiAz()) .elem("StorageEncrypted", c.isStorageEncrypted()) .elem("BackupRetentionPeriod", c.getBackupRetentionPeriod()) + .elem("CopyTagsToSnapshot", c.isCopyTagsToSnapshot()) .elem("KmsKeyId", c.getKmsKeyId()) .elem("AvailabilityZone", c.getAvailabilityZone() != null ? c.getAvailabilityZone() : config.defaultAvailabilityZone()) .elem("PreferredMaintenanceWindow", "mon:00:00-mon:03:00") @@ -3671,6 +3693,11 @@ public class RdsQueryHandler { if (c.getGlobalClusterIdentifier() != null && !c.getGlobalClusterIdentifier().isBlank()) { xml.elem("GlobalClusterIdentifier", c.getGlobalClusterIdentifier()); } + if (c.getEnabledCloudwatchLogsExports() != null && !c.getEnabledCloudwatchLogsExports().isEmpty()) { + xml.start("EnabledCloudwatchLogsExports"); + c.getEnabledCloudwatchLogsExports().forEach(type -> xml.elem("member", type)); + xml.end("EnabledCloudwatchLogsExports"); + } xml.start("DBClusterMembers"); if (c.getDbClusterMembers() != null) { String writer = c.resolveWriterIdentifier(); @@ -3678,6 +3705,7 @@ public class RdsQueryHandler { xml.start("member") .elem("DBInstanceIdentifier", memberId) .elem("IsClusterWriter", memberId.equals(writer)) + .elem("PromotionTier", service.clusterMemberPromotionTier(c, memberId)) .end("member"); } } diff --git a/src/main/java/io/floci/aws/services/rds/RdsService.java b/src/main/java/io/floci/aws/services/rds/RdsService.java index 746510cd3b..588991da83 100644 --- a/src/main/java/io/floci/aws/services/rds/RdsService.java +++ b/src/main/java/io/floci/aws/services/rds/RdsService.java @@ -60,6 +60,7 @@ import io.floci.aws.services.rds.model.DbSubnetGroup; import io.floci.aws.services.rds.model.EventSubscription; import io.floci.aws.services.rds.model.GlobalCluster; import io.floci.aws.services.rds.model.GlobalClusterMember; +import io.floci.aws.services.rds.model.LogExportChanges; import io.floci.aws.services.rds.model.OptionGroup; import io.floci.aws.services.rds.model.OptionGroupOption; import io.floci.aws.services.rds.model.PointInTimeRestoreRequest; @@ -11946,6 +11947,45 @@ public class RdsService implements Resettable, ResourceProvider { cluster.getDbClusterIdentifier()); return RESPONSE_COPIER.convertValue(cluster, DbCluster.class); } + + public synchronized DbCluster setClusterSnapshotAndLogSettings(String region, String clusterId, + Boolean copyTagsToSnapshot, List exports, LogExportChanges changes) { + String effectiveRegion = effectiveRegion(region); + DbCluster cluster = getDbCluster(clusterId, effectiveRegion); + if (copyTagsToSnapshot != null) { + cluster.setCopyTagsToSnapshot(copyTagsToSnapshot); + } + if (exports != null) { + cluster.setEnabledCloudwatchLogsExports(exports); + } + if (changes != null) { + cluster.setEnabledCloudwatchLogsExports(changes.applyTo(cluster.getEnabledCloudwatchLogsExports())); + } + putClusterForScope(currentAccountId(), effectiveRegion, cluster.getDbClusterIdentifier(), cluster); + return RESPONSE_COPIER.convertValue(cluster, DbCluster.class); + } + + public static void validatePromotionTier(Integer tier) { + if (tier != null && (tier < 0 || tier > 15)) { + throw new AwsException("InvalidParameterValue", "PromotionTier must be between 0 and 15.", 400); + } + } + + public synchronized DbInstance setInstancePromotionTier(String region, String instanceId, int tier) { + validatePromotionTier(tier); + String effectiveRegion = effectiveRegion(region); + DbInstance instance = getDbInstance(instanceId, effectiveRegion); + instance.setPromotionTier(tier); + putInstanceForScope(currentAccountId(), effectiveRegion, instance.getDbInstanceIdentifier(), instance); + return RESPONSE_COPIER.convertValue(instance, DbInstance.class); + } + + public int clusterMemberPromotionTier(DbCluster cluster, String memberId) { + DbInstance member = findInstanceForScope(accountIdFromArn(cluster.getDbClusterArn()), + AwsArnUtils.regionOrDefault(cluster.getDbClusterArn(), regionResolver.getDefaultRegion()), memberId); + return member == null ? 1 : member.getPromotionTier(); + } + private static final Set DATA_API_ENGINES = Set.of("aurora-postgresql", "aurora-mysql"); /** diff --git a/src/main/java/io/floci/aws/services/rds/model/DbCluster.java b/src/main/java/io/floci/aws/services/rds/model/DbCluster.java index 54bf1f3cdb..dc5087c449 100644 --- a/src/main/java/io/floci/aws/services/rds/model/DbCluster.java +++ b/src/main/java/io/floci/aws/services/rds/model/DbCluster.java @@ -48,6 +48,8 @@ public class DbCluster { private String engineMode; private boolean storageEncrypted; private int backupRetentionPeriod = 1; + private boolean copyTagsToSnapshot; + private List enabledCloudwatchLogsExports = new ArrayList<>(); private String kmsKeyId; private String dockerVolumeName; @@ -253,4 +255,11 @@ public class DbCluster { public void setServerlessV2SecondsUntilAutoPause(Integer serverlessV2SecondsUntilAutoPause) { this.serverlessV2SecondsUntilAutoPause = serverlessV2SecondsUntilAutoPause; } + public boolean isCopyTagsToSnapshot() { return copyTagsToSnapshot; } + public void setCopyTagsToSnapshot(boolean value) { copyTagsToSnapshot = value; } + public List getEnabledCloudwatchLogsExports() { return enabledCloudwatchLogsExports; } + public void setEnabledCloudwatchLogsExports(List value) { + enabledCloudwatchLogsExports = value == null ? new ArrayList<>() : new ArrayList<>(value); + } + } diff --git a/src/main/java/io/floci/aws/services/rds/model/DbInstance.java b/src/main/java/io/floci/aws/services/rds/model/DbInstance.java index 956f020942..9afe3bb1e7 100644 --- a/src/main/java/io/floci/aws/services/rds/model/DbInstance.java +++ b/src/main/java/io/floci/aws/services/rds/model/DbInstance.java @@ -52,6 +52,7 @@ public class DbInstance { private String preferredBackupWindow; private String preferredMaintenanceWindow; private boolean copyTagsToSnapshot; + private int promotionTier = 1; private boolean deletionProtection; private boolean publiclyAccessible; /** MonitoringInterval documents 0 as its default. */ @@ -357,4 +358,7 @@ public class DbInstance { public void setMaxAllocatedStorage(Integer maxAllocatedStorage) { this.maxAllocatedStorage = maxAllocatedStorage; } + public int getPromotionTier() { return promotionTier; } + public void setPromotionTier(int value) { promotionTier = value; } + } diff --git a/src/test/java/io/floci/aws/services/rds/RdsSettingsRoundTripIntegrationTest.java b/src/test/java/io/floci/aws/services/rds/RdsSettingsRoundTripIntegrationTest.java new file mode 100644 index 0000000000..d73e75bd31 --- /dev/null +++ b/src/test/java/io/floci/aws/services/rds/RdsSettingsRoundTripIntegrationTest.java @@ -0,0 +1,177 @@ +package io.floci.aws.services.rds; + +import io.floci.aws.testing.RdsMockProfile; +import io.quarkus.arc.ClientProxy; +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import jakarta.inject.Inject; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.rds.RdsClient; +import software.amazon.awssdk.services.rds.model.DBCluster; +import software.amazon.awssdk.services.rds.model.DBInstance; +import software.amazon.awssdk.services.rds.model.RdsException; + +import java.net.URI; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +@TestProfile(RdsMockProfile.class) +class RdsSettingsRoundTripIntegrationTest { + @TestHTTPResource + URI endpoint; + @Inject + RdsService service; + private RdsClient client; + private String cluster; + private String member; + + @BeforeEach + void setup() { + client = RdsClient.builder().endpointOverride(endpoint).region(Region.US_EAST_1) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test"))) + .build(); + cluster = "settings-" + UUID.randomUUID(); + member = cluster + "-member"; + } + + @AfterEach + void cleanup() { + try { + try { + client.deleteDBInstance(r -> r.dbInstanceIdentifier(member).skipFinalSnapshot(true)); + } catch (RdsException ignored) { + // Some cases intentionally reject creation before a resource exists. + } + try { + client.deleteDBCluster(r -> r.dbClusterIdentifier(cluster).skipFinalSnapshot(true)); + } catch (RdsException ignored) { + // A create rejected before mutation leaves no cluster to delete. + } + } finally { + client.close(); + } + } + + private DBCluster createCluster(boolean configured) { + return client.createDBCluster(r -> { + r.dbClusterIdentifier(cluster).engine("aurora-postgresql").engineVersion("16.3") + .masterUsername("admin").masterUserPassword(UUID.randomUUID().toString()); + if (configured) { + r.copyTagsToSnapshot(true).enableCloudwatchLogsExports("postgresql"); + } + }).dbCluster(); + } + + private DBCluster describeCluster() { + return client.describeDBClusters(r -> r.dbClusterIdentifier(cluster)).dbClusters().getFirst(); + } + + @Test + void clusterSnapshotAndLogSettingsRoundTripThroughCreateAndDescribe() { + DBCluster created = createCluster(true); + DBCluster described = describeCluster(); + assertAll(() -> assertEquals(true, created.copyTagsToSnapshot()), + () -> assertEquals(List.of("postgresql"), created.enabledCloudwatchLogsExports()), + () -> assertEquals(true, described.copyTagsToSnapshot()), + () -> assertEquals(List.of("postgresql"), described.enabledCloudwatchLogsExports())); + } + + @Test + void clusterModifyPreservesOmittedSettingsAndAppliesFalseAndLogDeltas() { + createCluster(true); + DBCluster unchanged = client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster).applyImmediately(true)).dbCluster(); + assertEquals(true, unchanged.copyTagsToSnapshot()); + assertEquals(List.of("postgresql"), unchanged.enabledCloudwatchLogsExports()); + DBCluster changed = client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster).copyTagsToSnapshot(false) + .cloudwatchLogsExportConfiguration(c -> c.enableLogTypes("iam-db-auth-error") + .disableLogTypes("postgresql")).applyImmediately(true)).dbCluster(); + assertEquals(false, changed.copyTagsToSnapshot()); + assertEquals(List.of("iam-db-auth-error"), changed.enabledCloudwatchLogsExports()); + client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster) + .cloudwatchLogsExportConfiguration(c -> c.disableLogTypes("iam-db-auth-error"))); + assertFalse(describeCluster().copyTagsToSnapshot()); + assertTrue(describeCluster().enabledCloudwatchLogsExports().isEmpty()); + } + + @Test + void clusterDefaultsAndEnableOnlyChangesPreserveExistingExports() { + DBCluster created = createCluster(false); + assertFalse(created.copyTagsToSnapshot()); + assertTrue(created.enabledCloudwatchLogsExports().isEmpty()); + client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster).copyTagsToSnapshot(true) + .cloudwatchLogsExportConfiguration(c -> c.enableLogTypes("postgresql"))); + DBCluster changed = client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster) + .cloudwatchLogsExportConfiguration(c -> c.enableLogTypes("iam-db-auth-error"))).dbCluster(); + assertTrue(changed.copyTagsToSnapshot()); + assertEquals(List.of("postgresql", "iam-db-auth-error"), changed.enabledCloudwatchLogsExports()); + assertEquals(changed.enabledCloudwatchLogsExports(), describeCluster().enabledCloudwatchLogsExports()); + } + + @Test + void memberPromotionTierRoundTripsAndTracksExplicitZero() { + createCluster(false); + DBInstance created = client.createDBInstance(r -> r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster) + .engine("aurora-postgresql").dbInstanceClass("db.r6g.large").promotionTier(7)).dbInstance(); + assertEquals(7, created.promotionTier()); + assertEquals(7, describeCluster().dbClusterMembers().getFirst().promotionTier()); + assertEquals(7, client.modifyDBInstance(r -> r.dbInstanceIdentifier(member) + .autoMinorVersionUpgrade(false)).dbInstance().promotionTier()); + assertEquals(0, client.modifyDBInstance(r -> r.dbInstanceIdentifier(member).promotionTier(0)) + .dbInstance().promotionTier()); + assertEquals(0, client.describeDBInstances(r -> r.dbInstanceIdentifier(member)) + .dbInstances().getFirst().promotionTier()); + assertEquals(0, describeCluster().dbClusterMembers().getFirst().promotionTier()); + assertEquals(15, client.modifyDBInstance(r -> r.dbInstanceIdentifier(member).promotionTier(15)) + .dbInstance().promotionTier()); + assertEquals(15, describeCluster().dbClusterMembers().getFirst().promotionTier()); + } + + @Test + void clusterDescribeDoesNotWaitForServiceMonitor() throws Exception { + createCluster(false); + client.createDBInstance(r -> r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster) + .engine("aurora-postgresql").dbInstanceClass("db.r6g.large").promotionTier(7)); + try (ExecutorService executor = Executors.newSingleThreadExecutor()) { + synchronized (ClientProxy.unwrap(service)) { + Future response = executor.submit(this::describeCluster); + assertEquals(7, response.get(10, TimeUnit.SECONDS).dbClusterMembers().getFirst().promotionTier()); + } + } + } + + @Test + void promotionTierDefaultsToOneAndInvalidChangesAreAtomic() { + createCluster(false); + for (int tier : List.of(-1, 16)) { + RdsException error = assertThrows(RdsException.class, () -> client.createDBInstance(r -> + r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster).engine("aurora-postgresql") + .dbInstanceClass("db.r6g.large").promotionTier(tier))); + assertEquals("InvalidParameterValue", error.awsErrorDetails().errorCode()); + assertTrue(describeCluster().dbClusterMembers().isEmpty()); + } + assertEquals(1, client.createDBInstance(r -> r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster) + .engine("aurora-postgresql").dbInstanceClass("db.r6g.large")).dbInstance().promotionTier()); + assertThrows(RdsException.class, () -> client.modifyDBInstance(r -> r.dbInstanceIdentifier(member) + .promotionTier(16).autoMinorVersionUpgrade(false))); + DBInstance unchanged = client.describeDBInstances(r -> r.dbInstanceIdentifier(member)).dbInstances().getFirst(); + assertEquals(1, unchanged.promotionTier()); + assertTrue(unchanged.autoMinorVersionUpgrade()); + } +} diff --git a/src/test/java/io/floci/aws/services/rds/model/DbClusterPersistenceTest.java b/src/test/java/io/floci/aws/services/rds/model/DbClusterPersistenceTest.java index cabc0b62ed..d39cb608a1 100644 --- a/src/test/java/io/floci/aws/services/rds/model/DbClusterPersistenceTest.java +++ b/src/test/java/io/floci/aws/services/rds/model/DbClusterPersistenceTest.java @@ -18,6 +18,53 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class DbClusterPersistenceTest { + @Test + void snapshotLogAndPromotionSettingsPersistAcrossInstances(@TempDir Path directory) { + DbCluster cluster = new DbCluster(); + cluster.setDbClusterIdentifier("settings-cluster"); + cluster.setCopyTagsToSnapshot(true); + cluster.setEnabledCloudwatchLogsExports(List.of("postgresql", "iam-db-auth-error")); + DbInstance instance = new DbInstance(); + instance.setDbInstanceIdentifier("settings-member"); + instance.setPromotionTier(0); + + Path clusters = directory.resolve("rds-clusters.json"); + new PersistentStorage(clusters, new TypeReference>() {}) + .put(cluster.getDbClusterIdentifier(), cluster); + Path instances = directory.resolve("rds-instances.json"); + new PersistentStorage(instances, new TypeReference>() {}) + .put(instance.getDbInstanceIdentifier(), instance); + + PersistentStorage clusterReader = new PersistentStorage<>( + clusters, new TypeReference>() {}); + clusterReader.load(); + DbCluster restored = clusterReader.get("settings-cluster").orElseThrow(); + assertTrue(restored.isCopyTagsToSnapshot()); + assertEquals(List.of("postgresql", "iam-db-auth-error"), restored.getEnabledCloudwatchLogsExports()); + PersistentStorage instanceReader = new PersistentStorage<>( + instances, new TypeReference>() {}); + instanceReader.load(); + assertEquals(0, instanceReader.get("settings-member").orElseThrow().getPromotionTier()); + } + + @Test + void stateSavedBeforeSettingsLoadsWithDefaults(@TempDir Path directory) throws Exception { + Path clusters = directory.resolve("rds-clusters.json"); + Files.writeString(clusters, "{\"legacy\":{\"dbClusterIdentifier\":\"legacy\"}}"); + Path instances = directory.resolve("rds-instances.json"); + Files.writeString(instances, "{\"legacy\":{\"dbInstanceIdentifier\":\"legacy\"}}"); + PersistentStorage clusterReader = new PersistentStorage<>( + clusters, new TypeReference>() {}); + clusterReader.load(); + DbCluster restored = clusterReader.get("legacy").orElseThrow(); + assertFalse(restored.isCopyTagsToSnapshot()); + assertTrue(restored.getEnabledCloudwatchLogsExports().isEmpty()); + PersistentStorage instanceReader = new PersistentStorage<>( + instances, new TypeReference>() {}); + instanceReader.load(); + assertEquals(1, instanceReader.get("legacy").orElseThrow().getPromotionTier()); + } + @Test void serverlessV2ScalingConfigurationPersistsAcrossInstances(@TempDir Path directory) { Path file = directory.resolve("rds-clusters.json");