mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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
This commit is contained in:
1 parent
1c3a6b615e
commit
72b746be13
7 files changed
+319
-1
No files matched your search
@@ -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.*`
|
||||
|
||||
@@ -387,6 +387,8 @@ public class RdsQueryHandler {
|
||||
|
||||
try {
|
||||
DbInstanceSettings settings = instanceSettings(params);
|
||||
Integer promotionTier = parseIntegerParam(params, "PromotionTier");
|
||||
RdsService.validatePromotionTier(promotionTier);
|
||||
List<String> 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<String> 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<String> exports = cloudwatchLogsExports(params);
|
||||
List<DbRoleAssociation> 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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> 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<String> DATA_API_ENGINES = Set.of("aurora-postgresql", "aurora-mysql");
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,8 @@ public class DbCluster {
|
||||
private String engineMode;
|
||||
private boolean storageEncrypted;
|
||||
private int backupRetentionPeriod = 1;
|
||||
private boolean copyTagsToSnapshot;
|
||||
private List<String> 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<String> getEnabledCloudwatchLogsExports() { return enabledCloudwatchLogsExports; }
|
||||
public void setEnabledCloudwatchLogsExports(List<String> value) {
|
||||
enabledCloudwatchLogsExports = value == null ? new ArrayList<>() : new ArrayList<>(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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<DBCluster> 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());
|
||||
}
|
||||
}
|
||||
@@ -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<String, DbCluster>(clusters, new TypeReference<Map<String, DbCluster>>() {})
|
||||
.put(cluster.getDbClusterIdentifier(), cluster);
|
||||
Path instances = directory.resolve("rds-instances.json");
|
||||
new PersistentStorage<String, DbInstance>(instances, new TypeReference<Map<String, DbInstance>>() {})
|
||||
.put(instance.getDbInstanceIdentifier(), instance);
|
||||
|
||||
PersistentStorage<String, DbCluster> clusterReader = new PersistentStorage<>(
|
||||
clusters, new TypeReference<Map<String, DbCluster>>() {});
|
||||
clusterReader.load();
|
||||
DbCluster restored = clusterReader.get("settings-cluster").orElseThrow();
|
||||
assertTrue(restored.isCopyTagsToSnapshot());
|
||||
assertEquals(List.of("postgresql", "iam-db-auth-error"), restored.getEnabledCloudwatchLogsExports());
|
||||
PersistentStorage<String, DbInstance> instanceReader = new PersistentStorage<>(
|
||||
instances, new TypeReference<Map<String, DbInstance>>() {});
|
||||
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<String, DbCluster> clusterReader = new PersistentStorage<>(
|
||||
clusters, new TypeReference<Map<String, DbCluster>>() {});
|
||||
clusterReader.load();
|
||||
DbCluster restored = clusterReader.get("legacy").orElseThrow();
|
||||
assertFalse(restored.isCopyTagsToSnapshot());
|
||||
assertTrue(restored.getEnabledCloudwatchLogsExports().isEmpty());
|
||||
PersistentStorage<String, DbInstance> instanceReader = new PersistentStorage<>(
|
||||
instances, new TypeReference<Map<String, DbInstance>>() {});
|
||||
instanceReader.load();
|
||||
assertEquals(1, instanceReader.get("legacy").orElseThrow().getPromotionTier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverlessV2ScalingConfigurationPersistsAcrossInstances(@TempDir Path directory) {
|
||||
Path file = directory.resolve("rds-clusters.json");
|
||||
|
||||
Reference in new issue
Block a user