mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(rds): keep BackupRetentionPeriod on DB clusters (#7094)
This commit is contained in:
1 parent
d76343992f
commit
0f242e9ee0
4 files changed
+178
-4
No files matched your search
@@ -1310,6 +1310,9 @@ public class RdsQueryHandler {
|
||||
String masterUserSecretKmsKeyId = params.getFirst("MasterUserSecretKmsKeyId");
|
||||
String engineMode = params.getFirst("EngineMode");
|
||||
boolean storageEncrypted = "true".equalsIgnoreCase(params.getFirst("StorageEncrypted"));
|
||||
Integer backupRetentionPeriodParam = parseIntegerParam(params, "BackupRetentionPeriod");
|
||||
int backupRetentionPeriod = backupRetentionPeriodParam != null ? backupRetentionPeriodParam : 1;
|
||||
RdsService.validateBackupRetentionPeriod(backupRetentionPeriod);
|
||||
|
||||
if (engineVersion == null) {
|
||||
engineVersion = defaultEngineVersion(engine);
|
||||
@@ -1379,6 +1382,9 @@ public class RdsQueryHandler {
|
||||
if (enableHttpEndpoint) {
|
||||
cluster = service.setHttpEndpoint(region, id, true);
|
||||
}
|
||||
if (backupRetentionPeriodParam != null) {
|
||||
cluster = service.setBackupRetentionPeriod(region, id, backupRetentionPeriod);
|
||||
}
|
||||
String result = dbClusterXml(cluster);
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -1489,6 +1495,10 @@ public class RdsQueryHandler {
|
||||
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
|
||||
params, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause");
|
||||
Boolean enableHttpEndpoint = parseOptionalBoolean(params, "EnableHttpEndpoint");
|
||||
Integer modifyBackupRetentionPeriod = parseIntegerParam(params, "BackupRetentionPeriod");
|
||||
if (modifyBackupRetentionPeriod != null) {
|
||||
RdsService.validateBackupRetentionPeriod(modifyBackupRetentionPeriod);
|
||||
}
|
||||
if (Boolean.TRUE.equals(enableHttpEndpoint)) {
|
||||
RdsService.requireDataApiEngine(service.getDbCluster(id, region).getEngineIdentifier());
|
||||
}
|
||||
@@ -1501,6 +1511,9 @@ public class RdsQueryHandler {
|
||||
if (enableHttpEndpoint != null) {
|
||||
cluster = service.setHttpEndpoint(region, id, enableHttpEndpoint);
|
||||
}
|
||||
if (modifyBackupRetentionPeriod != null) {
|
||||
cluster = service.setBackupRetentionPeriod(region, id, modifyBackupRetentionPeriod);
|
||||
}
|
||||
String result = dbClusterXml(cluster);
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS, result)).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -3486,6 +3499,7 @@ public class RdsQueryHandler {
|
||||
.elem("HttpEndpointEnabled", c.isHttpEndpointEnabled())
|
||||
.elem("MultiAZ", c.isMultiAz())
|
||||
.elem("StorageEncrypted", c.isStorageEncrypted())
|
||||
.elem("BackupRetentionPeriod", c.getBackupRetentionPeriod())
|
||||
.elem("KmsKeyId", c.getKmsKeyId())
|
||||
.elem("AvailabilityZone", c.getAvailabilityZone() != null ? c.getAvailabilityZone() : config.defaultAvailabilityZone())
|
||||
.elem("PreferredMaintenanceWindow", "mon:00:00-mon:03:00")
|
||||
|
||||
@@ -1748,9 +1748,6 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
|
||||
/** AWS's default retention for replicated automated backups, in days. */
|
||||
static final int DEFAULT_REPLICATED_BACKUP_RETENTION_DAYS = 7;
|
||||
/** Floci does not model a cluster's backup retention period; one day is the AWS default. */
|
||||
static final int CLUSTER_BACKUP_RETENTION_DAYS = 1;
|
||||
|
||||
public record AutomatedBackupPage<T>(List<T> backups, String marker) {}
|
||||
|
||||
/**
|
||||
@@ -2010,7 +2007,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
backup.setRegion(region);
|
||||
backup.setEarliestTime(cluster.getCreatedAt() != null ? cluster.getCreatedAt() : now);
|
||||
backup.setLatestTime(now);
|
||||
backup.setBackupRetentionPeriod(CLUSTER_BACKUP_RETENTION_DAYS);
|
||||
backup.setBackupRetentionPeriod(cluster.getBackupRetentionPeriod());
|
||||
String dataKey = clusterBackupDataKey(region, cluster.getDbClusterResourceId());
|
||||
if (cluster.getStatus() == DbInstanceStatus.DELETING && snapshotData.get(dataKey).isPresent()) {
|
||||
backup.setDataSaved(true);
|
||||
@@ -11402,6 +11399,23 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
return RESPONSE_COPIER.convertValue(cluster, DbCluster.class);
|
||||
}
|
||||
|
||||
public static void validateBackupRetentionPeriod(int backupRetentionPeriod) {
|
||||
if (backupRetentionPeriod < 1 || backupRetentionPeriod > 35) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"BackupRetentionPeriod must be between 1 and 35.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized DbCluster setBackupRetentionPeriod(String region, String clusterId, int backupRetentionPeriod) {
|
||||
validateBackupRetentionPeriod(backupRetentionPeriod);
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
DbCluster cluster = getDbCluster(clusterId, effectiveRegion);
|
||||
cluster.setBackupRetentionPeriod(backupRetentionPeriod);
|
||||
putClusterForScope(currentAccountId(), effectiveRegion, cluster.getDbClusterIdentifier(), cluster);
|
||||
LOG.infov("Backup retention period set to {0} for DB cluster {1}", backupRetentionPeriod,
|
||||
cluster.getDbClusterIdentifier());
|
||||
return RESPONSE_COPIER.convertValue(cluster, DbCluster.class);
|
||||
}
|
||||
private static final Set<String> DATA_API_ENGINES = Set.of("aurora-postgresql", "aurora-mysql");
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,7 @@ public class DbCluster {
|
||||
private List<DbRoleAssociation> associatedRoles = new ArrayList<>();
|
||||
private String engineMode;
|
||||
private boolean storageEncrypted;
|
||||
private int backupRetentionPeriod = 1;
|
||||
private String kmsKeyId;
|
||||
|
||||
private String dockerVolumeName;
|
||||
@@ -202,6 +203,9 @@ public class DbCluster {
|
||||
public boolean isStorageEncrypted() { return storageEncrypted; }
|
||||
public void setStorageEncrypted(boolean storageEncrypted) { this.storageEncrypted = storageEncrypted; }
|
||||
|
||||
public int getBackupRetentionPeriod() { return backupRetentionPeriod; }
|
||||
public void setBackupRetentionPeriod(int backupRetentionPeriod) { this.backupRetentionPeriod = backupRetentionPeriod; }
|
||||
|
||||
public String getKmsKeyId() { return kmsKeyId; }
|
||||
public void setKmsKeyId(String kmsKeyId) { this.kmsKeyId = kmsKeyId; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user