fix(rds): store and return VpcSecurityGroupIds, windows and DeletionProtection on DB clusters (#8042)

Store and return VpcSecurityGroupIds and the preferred backup and
maintenance windows on create, modify, restore and CloudFormation cluster
paths, validating them before any mutating call. A cluster that names no
group gets its VPC's default group. The window resolution moves into
BackupWindows, shared with DB instances and DocumentDB.

An update whose template no longer carries DeletionProtection leaves the
stored value alone, as the provider's null does, instead of turning it off.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-11-21 10:01:54 -04:00
1 parent 2b9ed9cd55
commit 347e2abd89
14 files changed
+798 -124

No files matched your search

@@ -87,6 +87,59 @@ public final class BackupWindows {
"The backup window and maintenance window must not overlap.", 400);
}
/**
* The {backup, maintenance} windows in effect after a request, checked against each other. On
* create a window given alone is paired with the default, or with one starting where the given
* one ends when the default would overlap it, as AWS picks a clear window itself. On modify the
* counterpart is the resource's current window ({@code currentBackup}, {@code currentMaintenance},
* either may be null for the default).
*/
public static String[] effectiveWindows(boolean create, String backup, String maintenance,
String currentBackup, String currentMaintenance) {
boolean backupGiven = backup != null;
boolean maintenanceGiven = maintenance != null;
if (backupGiven) {
parseBackupWindow(backup);
}
if (maintenanceGiven) {
parseMaintenanceWindow(maintenance);
}
if (create) {
if (!backupGiven) {
backup = maintenanceGiven && overlap(DEFAULT_BACKUP_WINDOW, maintenance)
? backupWindowAfter(maintenance) : DEFAULT_BACKUP_WINDOW;
}
if (!maintenanceGiven) {
maintenance = backupGiven && overlap(backup, DEFAULT_MAINTENANCE_WINDOW)
? maintenanceWindowAfter(backup) : DEFAULT_MAINTENANCE_WINDOW;
}
// a derived window is clear unless the given one leaves no 30-minute gap at all
if (overlap(backup, maintenance)) {
if (!maintenanceGiven) {
throw new AwsException("InvalidParameterValue", "The specified backup window overlaps all "
+ "available default maintenance windows. Shrink the backup window or specify a "
+ "non-overlapping maintenance window.", 400);
}
if (!backupGiven) {
throw new AwsException("InvalidParameterValue", "The specified maintenance window overlaps "
+ "all available default backup windows. Shrink the maintenance window or specify "
+ "a non-overlapping backup window.", 400);
}
}
} else {
if (!backupGiven) {
backup = currentBackup != null ? currentBackup : DEFAULT_BACKUP_WINDOW;
}
if (!maintenanceGiven) {
maintenance = currentMaintenance != null ? currentMaintenance : DEFAULT_MAINTENANCE_WINDOW;
}
}
if (overlap(backup, maintenance)) {
throw overlapping();
}
return new String[] {backup, maintenance};
}
/** A 30-minute maintenance window starting the minute the given daily window ends. */
public static String maintenanceWindowAfter(String backupWindow) {
int end = parseBackupWindow(backupWindow)[1] % MINUTES_PER_DAY;
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.BackupWindows;
import io.floci.aws.services.cloudformation.CloudFormationTemplateEngine;
import io.floci.aws.services.cloudformation.model.StackResource;
import io.floci.aws.services.rds.RdsService;
@@ -114,8 +115,8 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
private static final CreateOnlyInputs DB_INSTANCE_STORAGE_ENCRYPTED = new CreateOnlyInputs(
"__FlociDbInstanceStorageEncrypted", "__FlociDbInstanceStorageEncryptedPrior");
/**
* What an update that kept a DB instance needs for {@link #rollbackUpdate}: the region, the VPC
* security groups the instance had when the update changed them, and whether it changed anything
* What an update that kept a DB instance or cluster needs for {@link #rollbackUpdate}: the region,
* the VPC security groups it had when the update changed them, and whether it changed anything
* else, which has no rollback here.
*/
static final String DB_INSTANCE_PRIOR_IN_PLACE_ATTR = "__FlociDbInstancePriorInPlaceUpdate";
@@ -245,7 +246,8 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
/**
* Puts back the VPC security groups an update that kept the instance changed, and answers whether
* that undid the whole update. The saved record is dropped only once the groups are back, so an
* instance gone since the update fails the rollback, and a retried one tries again.
* instance gone since the update fails the rollback, and a retried one tries again. A record
* carrying the {@code cluster} flag puts back a DB cluster's groups the same way.
*/
private boolean restoreDbInstanceInPlaceUpdate(StackResource resource) {
String saved = resource.getAttributes().get(DB_INSTANCE_PRIOR_IN_PLACE_ATTR);
@@ -263,8 +265,13 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
if (groups.isArray()) {
List<String> groupIds = new ArrayList<>();
groups.forEach(group -> groupIds.add(group.asText()));
rdsService.setDbInstanceVpcSecurityGroups(prior.path("region").asText(), resource.getPhysicalId(),
groupIds);
if (prior.path("cluster").asBoolean(false)) {
rdsService.setDbClusterRequestSettings(resource.getPhysicalId(), prior.path("region").asText(),
groupIds, null, null);
} else {
rdsService.setDbInstanceVpcSecurityGroups(prior.path("region").asText(),
resource.getPhysicalId(), groupIds);
}
}
resource.getAttributes().remove(DB_INSTANCE_PRIOR_IN_PLACE_ATTR);
return !prior.path("otherChanges").asBoolean(true);
@@ -655,8 +662,23 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
// Refused before a new cluster exists, rather than leaving one behind.
RdsService.requireDataApiEngine(resolveOptional(props, "Engine", engine));
}
boolean deletionProtection = parseStrictBoolProp(props, "DeletionProtection", engine);
// null when the template drops it: an update then keeps the stored value, as AWS's null does
Boolean requestedDeletionProtection = parseOptionalStrictBoolProp(props, "DeletionProtection", engine);
boolean deletionProtection = Boolean.TRUE.equals(requestedDeletionProtection);
boolean created = cluster == null;
String backupWindow = resolveOptional(props, "PreferredBackupWindow", engine);
String maintenanceWindow = resolveOptional(props, "PreferredMaintenanceWindow", engine);
if (created) {
// validated before the cluster exists, so a bad window leaves none behind
String[] windows = BackupWindows.effectiveWindows(true, backupWindow, maintenanceWindow, null, null);
backupWindow = windows[0];
maintenanceWindow = windows[1];
} else {
// validated against the stored windows before the modify, so a bad window changes nothing
BackupWindows.effectiveWindows(false, backupWindow, maintenanceWindow,
cluster.getPreferredBackupWindow(), cluster.getPreferredMaintenanceWindow());
}
List<String> securityGroupIds = resolveStringList(props, "VpcSecurityGroupIds", engine);
if (cluster != null) {
cluster = rdsService.modifyDbCluster(
id,
@@ -683,13 +705,34 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
serverlessV2MinCapacity, serverlessV2MaxCapacity, serverlessV2SecondsUntilAutoPause,
false, null, engineMode, storageEncrypted, null, deletionProtection);
}
if (securityGroupIds.isEmpty()) {
// A list the previous template declared and this one drops puts the cluster on its VPC's
// default group, as AWS's handler does, and leaves them when there is none. Groups the
// stack never declared, and the other settings, keep what is stored.
List<String> defaultGroup = !created && ctx.previouslyDeclared("VpcSecurityGroupIds")
? rdsService.defaultClusterVpcSecurityGroupIds(region, cluster.getDbClusterIdentifier())
: List.of();
securityGroupIds = defaultGroup.isEmpty() ? null : defaultGroup;
}
// The groups an in-place update changes are saved, for rollbackUpdate, as an instance's are.
r.getAttributes().remove(DB_INSTANCE_PRIOR_IN_PLACE_ATTR);
if (!created && securityGroupIds != null
&& !Set.copyOf(securityGroupIds).equals(Set.copyOf(cluster.getVpcSecurityGroupIds()))) {
ObjectNode saved = MAPPER.createObjectNode().put("region", region).put("cluster", true)
.put("otherChanges", true);
ArrayNode priorGroups = saved.putArray("vpcSecurityGroups");
cluster.getVpcSecurityGroupIds().forEach(priorGroups::add);
r.getAttributes().put(DB_INSTANCE_PRIOR_IN_PLACE_ATTR, saved.toString());
}
rdsService.setDbClusterRequestSettings(cluster.getDbClusterIdentifier(), region,
securityGroupIds, backupWindow, maintenanceWindow);
cluster = reconcileClusterRoles(r, cluster, roles, created, region);
ASSOCIATED_ROLES.record(r, ctx, attributesBefore, associatedRolesRecord(roles));
// EnableHttpEndpoint updates with no interruption; a template that leaves it out wants it off.
if (httpEndpoint != cluster.isHttpEndpointEnabled()) {
cluster = rdsService.setHttpEndpoint(region, cluster.getDbClusterIdentifier(), httpEndpoint);
}
if (deletionProtection != cluster.isDeletionProtection()) {
if (requestedDeletionProtection != null && deletionProtection != cluster.isDeletionProtection()) {
cluster = rdsService.setDeletionProtection(region, cluster.getDbClusterIdentifier(), deletionProtection);
}
r.setPhysicalId(cluster.getDbClusterIdentifier());
@@ -342,46 +342,13 @@ public class DocDbService {
securityGroups = List.of(resolveDefaultSecurityGroupId(ec2Service, region));
}
String kmsKeyArn = resolveKmsKeyArn(settings.kmsKeyId(), region);
String backup = settings.preferredBackupWindow();
String maintenance = settings.preferredMaintenanceWindow();
boolean backupGiven = backup != null;
boolean maintenanceGiven = maintenance != null;
if (create) {
if (!backupGiven) {
backup = maintenanceGiven && BackupWindows.overlap(BackupWindows.DEFAULT_BACKUP_WINDOW, maintenance)
? BackupWindows.backupWindowAfter(maintenance) : BackupWindows.DEFAULT_BACKUP_WINDOW;
if (maintenanceGiven && BackupWindows.overlap(backup, maintenance)) {
// the given window leaves no daily half hour free
throw new AwsException("InvalidParameterValue", "The specified maintenance window overlaps "
+ "all available default backup windows. Shrink the maintenance window or specify "
+ "a non-overlapping backup window.", 400);
}
}
if (!maintenanceGiven) {
maintenance = backupGiven && BackupWindows.overlap(backup, BackupWindows.DEFAULT_MAINTENANCE_WINDOW)
? BackupWindows.maintenanceWindowAfter(backup) : BackupWindows.DEFAULT_MAINTENANCE_WINDOW;
if (BackupWindows.overlap(backup, maintenance)) {
throw new AwsException("InvalidParameterValue", "The specified backup window overlaps "
+ "all available default maintenance windows. Shrink the backup window or specify "
+ "a non-overlapping maintenance window.", 400);
}
}
} else {
if (!backupGiven) {
backup = current.getPreferredBackupWindow() != null
? current.getPreferredBackupWindow() : BackupWindows.DEFAULT_BACKUP_WINDOW;
}
if (!maintenanceGiven) {
maintenance = current.getPreferredMaintenanceWindow() != null
? current.getPreferredMaintenanceWindow() : BackupWindows.DEFAULT_MAINTENANCE_WINDOW;
}
}
if (BackupWindows.overlap(backup, maintenance)) {
throw BackupWindows.overlapping();
}
String[] windows = BackupWindows.effectiveWindows(create, settings.preferredBackupWindow(),
settings.preferredMaintenanceWindow(),
create ? null : current.getPreferredBackupWindow(),
create ? null : current.getPreferredMaintenanceWindow());
return new DocDbClusterSettings(subnetGroup, parameterGroup, securityGroups,
settings.storageEncrypted(), kmsKeyArn, settings.backupRetentionPeriod(),
backup, maintenance, settings.deletionProtection());
windows[0], windows[1], settings.deletionProtection());
}
/** The security group a cluster's VPC security group ids fall back to: the service's
@@ -8,6 +8,7 @@ import io.floci.aws.core.common.AwsNamespaces;
import io.floci.aws.core.common.AwsQueryLists;
import io.floci.aws.core.common.AwsQueryResponse;
import io.floci.aws.core.common.AwsRegionFacts;
import io.floci.aws.core.common.BackupWindows;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.XmlBuilder;
@@ -1463,6 +1464,11 @@ public class RdsQueryHandler {
Integer requestedPort = parseIntegerParam(params, "Port");
String globalClusterIdentifier = params.getFirst("GlobalClusterIdentifier");
boolean protectedCluster = Boolean.TRUE.equals(deletionProtection);
String[] windows = BackupWindows.effectiveWindows(true,
params.getFirst("PreferredBackupWindow"), params.getFirst("PreferredMaintenanceWindow"), null, null);
// parsed before any mutating call so a malformed value leaves no cluster behind
List<String> securityGroupIds = hasMemberKeys(params, "VpcSecurityGroupIds")
? vpcSecurityGroupIds(params) : null;
DbCluster cluster;
if (globalClusterIdentifier != null && !globalClusterIdentifier.isBlank()) {
cluster = service.createDbClusterInGlobalCluster(globalClusterIdentifier, id, engine,
@@ -1509,6 +1515,7 @@ public class RdsQueryHandler {
if (copyTagsToSnapshot != null || exports != null) {
cluster = service.setClusterSnapshotAndLogSettings(region, id, copyTagsToSnapshot, exports, null);
}
cluster = service.setDbClusterRequestSettings(id, region, securityGroupIds, windows[0], windows[1]);
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -1626,9 +1633,25 @@ public class RdsQueryHandler {
RdsService.validateBackupRetentionPeriod(modifyBackupRetentionPeriod);
}
Boolean deletionProtection = parseOptionalBoolean(params, "DeletionProtection");
if (Boolean.TRUE.equals(enableHttpEndpoint)) {
RdsService.requireDataApiEngine(service.getDbCluster(id, region).getEngineIdentifier());
DbCluster current;
try {
current = service.getDbCluster(id, region);
} catch (AwsException notFound) {
if (!"DBClusterNotFoundFault".equals(notFound.getErrorCode())) {
throw notFound;
}
// AWS words a modify of a missing cluster this way, unlike the describe and delete paths
throw new AwsException("DBClusterNotFoundFault", "DBCluster not found", 404);
}
if (Boolean.TRUE.equals(enableHttpEndpoint)) {
RdsService.requireDataApiEngine(current.getEngineIdentifier());
}
BackupWindows.effectiveWindows(false, params.getFirst("PreferredBackupWindow"),
params.getFirst("PreferredMaintenanceWindow"), current.getPreferredBackupWindow(),
current.getPreferredMaintenanceWindow());
// parsed before any mutating call so a malformed value changes nothing
List<String> securityGroupIds = hasMemberKeys(params, "VpcSecurityGroupIds")
? vpcSecurityGroupIds(params) : null;
DbCluster cluster = service.modifyDbCluster(id, newPassword, iamEnabled,
serverlessV2Min, serverlessV2Max, serverlessV2SecondsUntilAutoPause,
manageMasterUserPassword, masterUserSecretKmsKeyId,
@@ -1644,6 +1667,8 @@ public class RdsQueryHandler {
if (copyTagsToSnapshot != null || exportChanges != null) {
cluster = service.setClusterSnapshotAndLogSettings(region, id, copyTagsToSnapshot, null, exportChanges);
}
cluster = service.setDbClusterRequestSettings(id, region, securityGroupIds,
params.getFirst("PreferredBackupWindow"), params.getFirst("PreferredMaintenanceWindow"));
if (deletionProtection != null) {
cluster = service.setDeletionProtection(region, id, deletionProtection);
}
@@ -3051,6 +3076,7 @@ public class RdsQueryHandler {
return missing;
}
try {
RestoreSettings settings = RestoreSettings.parse(params);
DbCluster cluster = service.restoreDbClusterToPointInTime(clusterId,
params.getFirst("SourceDBClusterIdentifier"), params.getFirst("SourceDbClusterResourceId"),
params.getFirst("RestoreType"),
@@ -3062,6 +3088,7 @@ public class RdsQueryHandler {
params.getFirst("EngineMode"),
Boolean.TRUE.equals(parseOptionalBoolean(params, "DeletionProtection")),
parseTags(params), region);
cluster = settings.applyTo(service, clusterId, region);
return Response.ok(AwsQueryResponse.envelope("RestoreDBClusterToPointInTime", AwsNamespaces.RDS,
dbClusterXml(cluster))).build();
} catch (AwsException e) {
@@ -3080,17 +3107,37 @@ public class RdsQueryHandler {
if (missing != null) {
return missing;
}
DbCluster cluster = service.restoreDbClusterFromSnapshot(clusterId, snapshotId, engine,
params.getFirst("EngineVersion"), optionalInt(params.getFirst("Port")),
params.getFirst("DatabaseName"), params.getFirst("DBSubnetGroupName"),
params.getFirst("DBClusterParameterGroupName"),
params.getFirst("AvailabilityZones.member.1"),
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"),
params.getFirst("EngineMode"),
Boolean.TRUE.equals(parseOptionalBoolean(params, "DeletionProtection")),
parseTags(params), region);
return Response.ok(AwsQueryResponse.envelope("RestoreDBClusterFromSnapshot", AwsNamespaces.RDS,
dbClusterXml(cluster))).build();
try {
RestoreSettings settings = RestoreSettings.parse(params);
service.restoreDbClusterFromSnapshot(clusterId, snapshotId, engine,
params.getFirst("EngineVersion"), optionalInt(params.getFirst("Port")),
params.getFirst("DatabaseName"), params.getFirst("DBSubnetGroupName"),
params.getFirst("DBClusterParameterGroupName"),
params.getFirst("AvailabilityZones.member.1"),
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"),
params.getFirst("EngineMode"),
Boolean.TRUE.equals(parseOptionalBoolean(params, "DeletionProtection")),
parseTags(params), region);
DbCluster cluster = settings.applyTo(service, clusterId, region);
return Response.ok(AwsQueryResponse.envelope("RestoreDBClusterFromSnapshot", AwsNamespaces.RDS,
dbClusterXml(cluster))).build();
} catch (AwsException e) {
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus());
}
}
/** What a cluster restore request says about security groups, and backup window. */
private record RestoreSettings(List<String> securityGroupIds, String[] windows) {
// parsed before the restore so a malformed value leaves no cluster behind
static RestoreSettings parse(MultivaluedMap<String, String> params) {
return new RestoreSettings(
hasMemberKeys(params, "VpcSecurityGroupIds") ? vpcSecurityGroupIds(params) : null,
BackupWindows.effectiveWindows(true, params.getFirst("PreferredBackupWindow"), null, null, null));
}
DbCluster applyTo(RdsService service, String id, String region) {
return service.setDbClusterRequestSettings(id, region, securityGroupIds, windows[0], windows[1]);
}
}
private Response handleDescribeDbClusterSnapshotAttributes(MultivaluedMap<String, String> params, String region) {
@@ -3549,8 +3596,12 @@ public class RdsQueryHandler {
if (groupIds.isEmpty()) {
groupIds = List.of("sg-00000000");
}
return vpcSecurityGroupsXml(groupIds);
}
private String vpcSecurityGroupsXml(List<String> vpcSecurityGroupIds) {
XmlBuilder xml = new XmlBuilder().start("VpcSecurityGroups");
for (String groupId : groupIds) {
for (String groupId : vpcSecurityGroupIds) {
xml.start("VpcSecurityGroupMembership")
.elem("VpcSecurityGroupId", groupId)
.elem("Status", "active")
@@ -3696,14 +3747,11 @@ public class RdsQueryHandler {
.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")
.elem("PreferredBackupWindow", "04:00-06:00")
.start("VpcSecurityGroups")
.start("VpcSecurityGroupMembership")
.elem("VpcSecurityGroupId", "sg-00000000")
.elem("Status", "active")
.end("VpcSecurityGroupMembership")
.end("VpcSecurityGroups")
.elem("PreferredMaintenanceWindow", c.getPreferredMaintenanceWindow() != null
? c.getPreferredMaintenanceWindow() : BackupWindows.DEFAULT_MAINTENANCE_WINDOW)
.elem("PreferredBackupWindow", c.getPreferredBackupWindow() != null
? c.getPreferredBackupWindow() : BackupWindows.DEFAULT_BACKUP_WINDOW)
.raw(vpcSecurityGroupsXml(c.getVpcSecurityGroupIds()))
.elem("DBSubnetGroup", c.getDbSubnetGroupName() != null ? c.getDbSubnetGroupName() : "default");
String clusterParameterGroup = dbClusterParameterGroupName(c, engineStr);
if (clusterParameterGroup != null) {
@@ -4388,6 +4388,13 @@ public class RdsService implements Resettable, ResourceProvider {
: getDbSubnetGroup(dbSubnetGroupName, effectiveRegion).getVpcId();
}
/** As {@link #defaultVpcSecurityGroupIds(String, String, String)} for a DB cluster. */
public List<String> defaultClusterVpcSecurityGroupIds(String region, String clusterId) {
String effectiveRegion = effectiveRegion(region);
return RdsSecurityGroups.vpcDefault(ec2Service, effectiveRegion,
getDbCluster(clusterId, effectiveRegion).getVpcId());
}
private static void validateInstanceSettings(DbInstanceSettings settings) {
settings.validate();
}
@@ -4430,46 +4437,11 @@ public class RdsService implements Resettable, ResourceProvider {
* the instance's.
*/
private static DbInstanceSettings withEffectiveWindows(DbInstanceSettings settings, DbInstance current) {
String backup = settings.preferredBackupWindow();
String maintenance = settings.preferredMaintenanceWindow();
boolean backupGiven = backup != null;
boolean maintenanceGiven = maintenance != null;
if (current == null) {
if (!backupGiven) {
backup = maintenanceGiven && DbInstanceSettings.windowsOverlap(
DbInstanceSettings.DEFAULT_BACKUP_WINDOW, maintenance)
? DbInstanceSettings.backupWindowAfter(maintenance)
: DbInstanceSettings.DEFAULT_BACKUP_WINDOW;
}
if (!maintenanceGiven) {
maintenance = backupGiven && DbInstanceSettings.windowsOverlap(
backup, DbInstanceSettings.DEFAULT_MAINTENANCE_WINDOW)
? DbInstanceSettings.maintenanceWindowAfter(backup)
: DbInstanceSettings.DEFAULT_MAINTENANCE_WINDOW;
}
// a derived window is clear unless the given one leaves no 30-minute gap at all
if (DbInstanceSettings.windowsOverlap(backup, maintenance)) {
if (!maintenanceGiven) {
throw DbInstanceSettings.noRoomForMaintenanceWindow();
}
if (!backupGiven) {
throw DbInstanceSettings.noRoomForBackupWindow();
}
}
} else {
if (!backupGiven) {
backup = current.getPreferredBackupWindow() != null
? current.getPreferredBackupWindow() : DbInstanceSettings.DEFAULT_BACKUP_WINDOW;
}
if (!maintenanceGiven) {
maintenance = current.getPreferredMaintenanceWindow() != null
? current.getPreferredMaintenanceWindow() : DbInstanceSettings.DEFAULT_MAINTENANCE_WINDOW;
}
}
if (DbInstanceSettings.windowsOverlap(backup, maintenance)) {
throw DbInstanceSettings.overlappingWindows();
}
return settings.withWindows(backup, maintenance);
String[] windows = BackupWindows.effectiveWindows(current == null, settings.preferredBackupWindow(),
settings.preferredMaintenanceWindow(),
current == null ? null : current.getPreferredBackupWindow(),
current == null ? null : current.getPreferredMaintenanceWindow());
return settings.withWindows(windows[0], windows[1]);
}
/**
@@ -5909,6 +5881,8 @@ public class RdsService implements Resettable, ResourceProvider {
}
cluster.setDbSubnetGroupName(placement.dbSubnetGroupName());
cluster.setVpcId(placement.vpcId());
// none named yet: AWS puts the cluster in its VPC's default group; EC2 without one leaves none
cluster.setVpcSecurityGroupIds(RdsSecurityGroups.vpcDefault(ec2Service, effectiveRegion, placement.vpcId()));
cluster.setAvailabilityZone(placement.availabilityZone());
cluster.setMultiAz(placement.multiAz());
cluster.setSubnetAvailabilityZones(placement.subnetAvailabilityZones());
@@ -12081,6 +12055,26 @@ public class RdsService implements Resettable, ResourceProvider {
return member == null ? 1 : member.getPromotionTier();
}
/** Stores what a Create/ModifyDBCluster request carries; a null argument leaves that field as it is. */
public synchronized DbCluster setDbClusterRequestSettings(String id, String region,
List<String> vpcSecurityGroupIds, String backupWindow, String maintenanceWindow) {
String effectiveRegion = effectiveRegion(region);
DbCluster cluster = getDbCluster(id, effectiveRegion);
BackupWindows.effectiveWindows(false, backupWindow, maintenanceWindow,
cluster.getPreferredBackupWindow(), cluster.getPreferredMaintenanceWindow());
if (vpcSecurityGroupIds != null) {
cluster.setVpcSecurityGroupIds(vpcSecurityGroupIds);
}
if (backupWindow != null) {
cluster.setPreferredBackupWindow(backupWindow);
}
if (maintenanceWindow != null) {
cluster.setPreferredMaintenanceWindow(BackupWindows.lowerCase(maintenanceWindow));
}
putClusterForScope(currentAccountId(), effectiveRegion, id, cluster);
return RESPONSE_COPIER.convertValue(cluster, DbCluster.class);
}
private static final Set<String> DATA_API_ENGINES = Set.of("aurora-postgresql", "aurora-mysql");
/**
@@ -32,6 +32,10 @@ public class DbCluster {
private String parameterGroupName;
private String dbSubnetGroupName;
private String vpcId;
private List<String> vpcSecurityGroupIds = new ArrayList<>();
// Null until a request names them; the emitted XML then falls back to the defaults.
private String preferredBackupWindow;
private String preferredMaintenanceWindow;
private String availabilityZone;
private boolean multiAz;
private Map<String, String> subnetAvailabilityZones = new LinkedHashMap<>();
@@ -163,6 +167,19 @@ public class DbCluster {
public boolean isMultiAz() { return multiAz; }
public void setMultiAz(boolean multiAz) { this.multiAz = multiAz; }
public List<String> getVpcSecurityGroupIds() { return vpcSecurityGroupIds; }
public void setVpcSecurityGroupIds(List<String> vpcSecurityGroupIds) {
this.vpcSecurityGroupIds = vpcSecurityGroupIds != null ? new ArrayList<>(vpcSecurityGroupIds) : new ArrayList<>();
}
public String getPreferredBackupWindow() { return preferredBackupWindow; }
public void setPreferredBackupWindow(String preferredBackupWindow) { this.preferredBackupWindow = preferredBackupWindow; }
public String getPreferredMaintenanceWindow() { return preferredMaintenanceWindow; }
public void setPreferredMaintenanceWindow(String preferredMaintenanceWindow) {
this.preferredMaintenanceWindow = preferredMaintenanceWindow;
}
public Map<String, String> getSubnetAvailabilityZones() { return subnetAvailabilityZones; }
public void setSubnetAvailabilityZones(Map<String, String> subnetAvailabilityZones) {
this.subnetAvailabilityZones = subnetAvailabilityZones != null
@@ -195,19 +195,6 @@ public record DbInstanceSettings(Boolean storageEncrypted,
return BackupWindows.backupWindowAfter(maintenanceWindow);
}
/** A window given alone that leaves no room for the other kind, in AWS's words. */
public static AwsException noRoomForMaintenanceWindow() {
return new AwsException("InvalidParameterValue", "The specified backup window overlaps all "
+ "available default maintenance windows. Shrink the backup window or specify a "
+ "non-overlapping maintenance window.", 400);
}
public static AwsException noRoomForBackupWindow() {
return new AwsException("InvalidParameterValue", "The specified maintenance window overlaps "
+ "all available default backup windows. Shrink the maintenance window or specify a "
+ "non-overlapping backup window.", 400);
}
public static AwsException overlappingWindows() {
return BackupWindows.overlapping();
}