mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(rds): retain requested storage types (#6057)
* fix(rds): retain requested storage types Keep database storage settings across updates, copies and restarts. * fix(rds): retain Provisioned IOPS storage types
This commit is contained in:
1 parent
03f5730396
commit
08d5a9c742
13 files changed
+775
-27
No files matched your search
@@ -804,7 +804,8 @@ public class RdsQueryHandler {
|
||||
params.getFirst("EngineLifecycleSupport"),
|
||||
includeEncryption ? cloudwatchLogsExports(params) : null,
|
||||
includeEncryption ? null : cloudwatchLogsExportChanges(params),
|
||||
optionalInt(params.getFirst("MaxAllocatedStorage")));
|
||||
optionalInt(params.getFirst("MaxAllocatedStorage")),
|
||||
params.getFirst("StorageType"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1167,7 +1168,7 @@ public class RdsQueryHandler {
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"),
|
||||
optionalInt(params.getFirst("AllocatedStorage")),
|
||||
params.getFirst("ReplicaMode"),
|
||||
parseTags(params));
|
||||
parseTags(params), params.getFirst("StorageType"));
|
||||
DbInstance replica = service.createDbInstanceReadReplica(request, region);
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"CreateDBInstanceReadReplica", AwsNamespaces.RDS, dbInstanceXml(replica))).build();
|
||||
@@ -1982,7 +1983,7 @@ public class RdsQueryHandler {
|
||||
DbInstance instance = service.restoreDbInstanceFromDbSnapshot(instanceId, snapshotId,
|
||||
dbInstanceClass, availabilityZone, multiAz, dbSubnetGroupName,
|
||||
vpcSecurityGroupIds, tags, region, requestedPort,
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"));
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"), params.getFirst("StorageType"));
|
||||
String result = dbInstanceXml(instance);
|
||||
return Response.ok(AwsQueryResponse.envelope("RestoreDBInstanceFromDBSnapshot", AwsNamespaces.RDS, result)).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -2683,7 +2684,7 @@ public class RdsQueryHandler {
|
||||
parseIntegerParam(params, "BackupRetentionPeriod"),
|
||||
params.getFirst("PreferredBackupWindow"),
|
||||
parseOptionalBoolean(params, "DeletionProtection"),
|
||||
parseTags(params));
|
||||
parseTags(params), params.getFirst("StorageType"));
|
||||
DbInstance instance = service.restoreDbInstanceToPointInTime(request, region);
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"RestoreDBInstanceToPointInTime", AwsNamespaces.RDS, dbInstanceXml(instance))).build();
|
||||
@@ -2767,6 +2768,7 @@ public class RdsQueryHandler {
|
||||
.elem("Engine", engineStr)
|
||||
.elem("EngineVersion", s.getEngineVersion())
|
||||
.elem("AllocatedStorage", s.getAllocatedStorage())
|
||||
.elem("StorageType", s.getStorageType())
|
||||
.elem("Status", s.getStatus())
|
||||
.elem("MasterUsername", s.getMasterUsername())
|
||||
.elem("SnapshotType", s.getSnapshotType() != null
|
||||
@@ -2878,7 +2880,7 @@ public class RdsQueryHandler {
|
||||
xml.elem("IAMDatabaseAuthenticationEnabled", i.isIamDatabaseAuthenticationEnabled())
|
||||
.elem("MultiAZ", i.isMultiAz())
|
||||
.elem("AutoMinorVersionUpgrade", i.isAutoMinorVersionUpgrade())
|
||||
.elem("StorageType", DbInstance.DEFAULT_STORAGE_TYPE)
|
||||
.elem("StorageType", i.getStorageType())
|
||||
.elem("PubliclyAccessible", i.isPubliclyAccessible())
|
||||
.elem("AvailabilityZone", i.getAvailabilityZone() != null ? i.getAvailabilityZone() : config.defaultAvailabilityZone())
|
||||
.elem("PreferredMaintenanceWindow", i.getPreferredMaintenanceWindow() != null
|
||||
|
||||
@@ -731,6 +731,11 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
// resolved with the other validations, before a port is taken or a container started
|
||||
DbInstanceSettings resolvedSettings = withEffectiveWindows(settings, null)
|
||||
.withKmsKeyId(resolveKmsKeyArn(settings.kmsKeyId(), effectiveRegion));
|
||||
if (isBlank(dbClusterIdentifier) && !isAuroraEngine(engineParam)) {
|
||||
resolvedSettings.validateStorageType();
|
||||
} else {
|
||||
resolvedSettings = resolvedSettings.withStorageType(null);
|
||||
}
|
||||
DbInstanceSettings.validateMonitoringPairOnCreate(
|
||||
settings.monitoringInterval(), settings.monitoringRoleArn());
|
||||
boolean mock = config.services().rds().mock();
|
||||
@@ -956,6 +961,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
instance.getMasterUsername(), instance.getMasterPassword(), instance.getAvailabilityZone(), instance.getVpcId(),
|
||||
instance.getCreatedAt(), instance.getEndpoint() != null ? instance.getEndpoint().port() : instance.getProxyPort(),
|
||||
instance.isIamDatabaseAuthenticationEnabled(), instance.getDbiResourceId(), instance.getDbInstanceClass());
|
||||
snapshot.setStorageType(instance.getStorageType());
|
||||
snapshot.setDbName(instance.getDbName());
|
||||
snapshot.setSnapshotType("manual");
|
||||
snapshot.setOptionGroupName(instance.getOptionGroupName());
|
||||
@@ -1106,6 +1112,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
copy.setEngine(source.getEngine());
|
||||
copy.setEngineVersion(source.getEngineVersion());
|
||||
copy.setAllocatedStorage(source.getAllocatedStorage());
|
||||
copy.setStorageType(source.getStorageType());
|
||||
copy.setStatus(source.getStatus());
|
||||
copy.setMasterUsername(source.getMasterUsername());
|
||||
copy.setMasterPassword(source.getMasterPassword());
|
||||
@@ -1215,6 +1222,15 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Map<String, String> tags, String region,
|
||||
Integer requestedPort, Boolean iamEnabled) {
|
||||
return restoreDbInstanceFromDbSnapshot(instanceId, snapshotId, dbInstanceClass, availabilityZone,
|
||||
multiAz, dbSubnetGroupName, vpcSecurityGroupIds, tags, region, requestedPort, iamEnabled, null);
|
||||
}
|
||||
|
||||
public DbInstance restoreDbInstanceFromDbSnapshot(String instanceId, String snapshotId, String dbInstanceClass,
|
||||
String availabilityZone, boolean multiAz, String dbSubnetGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Map<String, String> tags, String region,
|
||||
Integer requestedPort, Boolean iamEnabled, String storageType) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
DbSnapshot snapshot = Optional.ofNullable(findSnapshotForScope(currentAccountId(), effectiveRegion, snapshotId))
|
||||
.orElseThrow(() -> new AwsException("DBSnapshotNotFound", "DBSnapshot " + snapshotId + " not found.", 404));
|
||||
@@ -1228,7 +1244,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
// Use the parameters from the snapshot
|
||||
DbInstanceSettings restoreSettings = new DbInstanceSettings(
|
||||
snapshot.isStorageEncrypted(), snapshot.getKmsKeyId(), null, null, null, null);
|
||||
snapshot.isStorageEncrypted(), snapshot.getKmsKeyId(), null, null, null, null)
|
||||
.withStorageType(storageType != null ? storageType : snapshot.getStorageType());
|
||||
DbInstance instance = createDbInstance(instanceId, snapshot.getEngine().name().toLowerCase(), snapshot.getEngineVersion(),
|
||||
snapshot.getMasterUsername(), snapshot.getMasterPassword(),
|
||||
snapshot.getDbName(), targetClass, snapshot.getAllocatedStorage(), Boolean.TRUE.equals(iamEnabled),
|
||||
@@ -1329,7 +1346,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
source.isStorageEncrypted() ? Boolean.TRUE : null,
|
||||
source.isStorageEncrypted() ? source.getKmsKeyId() : null,
|
||||
request.backupRetentionPeriod(), request.preferredBackupWindow(), null,
|
||||
request.copyTagsToSnapshot());
|
||||
request.copyTagsToSnapshot()).withStorageType(
|
||||
request.storageType() != null ? request.storageType() : source.getStorageType());
|
||||
DbInstance instance = createDbInstance(targetId, engineParam, source.getEngineVersion(),
|
||||
source.getMasterUsername(), source.getMasterPassword(), dbName,
|
||||
firstNonBlank(request.dbInstanceClass(), source.getDbInstanceClass()),
|
||||
@@ -1536,7 +1554,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
source.isStorageEncrypted() ? Boolean.TRUE : null,
|
||||
source.isStorageEncrypted() && sameRegion ? source.getKmsKeyId() : null,
|
||||
0, source.getPreferredBackupWindow(), source.getPreferredMaintenanceWindow(),
|
||||
copyTagsToSnapshot);
|
||||
copyTagsToSnapshot).withStorageType(
|
||||
request.storageType() != null ? request.storageType() : source.getStorageType());
|
||||
Map<String, String> tags = request.tags() != null ? request.tags() : Map.of();
|
||||
|
||||
DbInstance replica = createDbInstance(id, engineParam, source.getEngineVersion(),
|
||||
@@ -3081,6 +3100,11 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
// current size and engine version: a refusal here must leave the whole request unapplied.
|
||||
DbInstanceScalingChanges resolvedScaling = scaling.resolveFor(instance);
|
||||
DbInstanceSettings effective = withEffectiveWindows(settings, instance);
|
||||
if (isBlank(instance.getDbClusterIdentifier()) && !isAuroraEngine(engineName(instance))) {
|
||||
effective.validateStorageType();
|
||||
} else {
|
||||
effective = effective.withStorageType(null);
|
||||
}
|
||||
validateAutoscalingMinimum(instance, effective.maxAllocatedStorage());
|
||||
instance.setStatus(DbInstanceStatus.AVAILABLE);
|
||||
if (optionGroupName != null && !optionGroupName.isBlank()) {
|
||||
@@ -3389,7 +3413,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
List<SizeRange> sizes = smallestIncrease <= maximum
|
||||
? List.of(new SizeRange(current, current), new SizeRange(smallestIncrease, maximum))
|
||||
: List.of(new SizeRange(current, current));
|
||||
return List.of(new StorageModification(DbInstance.DEFAULT_STORAGE_TYPE, sizes));
|
||||
return List.of(new StorageModification("gp2", sizes), new StorageModification("gp3", sizes),
|
||||
new StorageModification("io1", sizes), new StorageModification("io2", sizes));
|
||||
}
|
||||
|
||||
// ── Stop, start and reboot ────────────────────────────────────────────────
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
@RegisterForReflection
|
||||
public class DbInstance {
|
||||
|
||||
/** The only storage type Floci models, and the one DescribeDBInstances reports. */
|
||||
/** The fallback for existing records and requests that do not name a storage type. */
|
||||
public static final String DEFAULT_STORAGE_TYPE = "gp2";
|
||||
|
||||
private String dbInstanceIdentifier;
|
||||
@@ -25,6 +25,7 @@ public class DbInstance {
|
||||
private String dbName;
|
||||
private String dbInstanceClass;
|
||||
private int allocatedStorage;
|
||||
private String storageType;
|
||||
private DbInstanceStatus status;
|
||||
private DbEndpoint endpoint;
|
||||
private boolean iamDatabaseAuthenticationEnabled;
|
||||
@@ -133,6 +134,9 @@ public class DbInstance {
|
||||
public String getDbInstanceClass() { return dbInstanceClass; }
|
||||
public void setDbInstanceClass(String dbInstanceClass) { this.dbInstanceClass = dbInstanceClass; }
|
||||
|
||||
public String getStorageType() { return storageType != null ? storageType : DEFAULT_STORAGE_TYPE; }
|
||||
public void setStorageType(String storageType) { this.storageType = storageType; }
|
||||
|
||||
public int getAllocatedStorage() { return allocatedStorage; }
|
||||
public void setAllocatedStorage(int allocatedStorage) { this.allocatedStorage = allocatedStorage; }
|
||||
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public record DbInstanceScalingChanges(String dbInstanceClass,
|
||||
if (allocatedStorage < current) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"Invalid storage size for engine name " + instance.getEngineIdentifier()
|
||||
+ " and storage type " + DbInstance.DEFAULT_STORAGE_TYPE + ": "
|
||||
+ " and storage type " + instance.getStorageType() + ": "
|
||||
+ allocatedStorage, 400);
|
||||
}
|
||||
if (!TEN_PERCENT_MINIMUM_INCREASE.contains(instance.getEngine())) {
|
||||
|
||||
+34
-3
@@ -26,7 +26,20 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
String engineLifecycleSupport,
|
||||
List<String> enabledCloudwatchLogsExports,
|
||||
LogExportChanges logExportChanges,
|
||||
Integer maxAllocatedStorage) {
|
||||
Integer maxAllocatedStorage,
|
||||
String storageType) {
|
||||
|
||||
public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow, String preferredMaintenanceWindow,
|
||||
Boolean copyTagsToSnapshot, Integer monitoringInterval, String monitoringRoleArn,
|
||||
Boolean performanceInsightsEnabled, Integer performanceInsightsRetentionPeriod,
|
||||
String engineLifecycleSupport, List<String> enabledCloudwatchLogsExports,
|
||||
LogExportChanges logExportChanges, Integer maxAllocatedStorage) {
|
||||
this(storageEncrypted, kmsKeyId, backupRetentionPeriod, preferredBackupWindow,
|
||||
preferredMaintenanceWindow, copyTagsToSnapshot, monitoringInterval, monitoringRoleArn,
|
||||
performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, null);
|
||||
}
|
||||
|
||||
/** The settings a caller that touches none of the monitoring members gives. */
|
||||
public DbInstanceSettings(Boolean storageEncrypted,
|
||||
@@ -174,7 +187,7 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
backupWindow, maintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage);
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType);
|
||||
}
|
||||
|
||||
public DbInstanceSettings withKmsKeyId(String resolvedKmsKeyId) {
|
||||
@@ -182,7 +195,22 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage);
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType);
|
||||
}
|
||||
|
||||
public DbInstanceSettings withStorageType(String resolvedStorageType) {
|
||||
return new DbInstanceSettings(storageEncrypted, kmsKeyId, backupRetentionPeriod,
|
||||
preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, resolvedStorageType);
|
||||
}
|
||||
|
||||
public void validateStorageType() {
|
||||
if (storageType != null && !Set.of("gp2", "gp3", "io1", "io2").contains(storageType)) {
|
||||
throw new AwsException("StorageTypeNotSupported",
|
||||
"Floci supports the gp2, gp3, io1 and io2 storage types for DB instances.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
public void applyTo(DbInstance instance) {
|
||||
@@ -227,6 +255,9 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
instance.setEnabledCloudwatchLogsExports(
|
||||
logExportChanges.applyTo(instance.getEnabledCloudwatchLogsExports()));
|
||||
}
|
||||
if (storageType != null) {
|
||||
instance.setStorageType(storageType);
|
||||
}
|
||||
if (maxAllocatedStorage != null) {
|
||||
instance.setMaxAllocatedStorage(maxAllocatedStorage);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class DbSnapshot {
|
||||
private DatabaseEngine engine;
|
||||
private String engineVersion;
|
||||
private int allocatedStorage;
|
||||
private String storageType;
|
||||
private String status;
|
||||
private String masterUsername;
|
||||
private String masterPassword;
|
||||
@@ -88,6 +89,9 @@ public class DbSnapshot {
|
||||
public String getEngineVersion() { return engineVersion; }
|
||||
public void setEngineVersion(String engineVersion) { this.engineVersion = engineVersion; }
|
||||
|
||||
public String getStorageType() { return storageType != null ? storageType : DbInstance.DEFAULT_STORAGE_TYPE; }
|
||||
public void setStorageType(String storageType) { this.storageType = storageType; }
|
||||
|
||||
public int getAllocatedStorage() { return allocatedStorage; }
|
||||
public void setAllocatedStorage(int allocatedStorage) { this.allocatedStorage = allocatedStorage; }
|
||||
|
||||
|
||||
+33
-1
@@ -35,5 +35,37 @@ public record PointInTimeRestoreRequest(String targetDbInstanceIdentifier,
|
||||
Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow,
|
||||
Boolean deletionProtection,
|
||||
Map<String, String> tags) {
|
||||
Map<String, String> tags,
|
||||
String storageType) {
|
||||
|
||||
public PointInTimeRestoreRequest(String targetDbInstanceIdentifier,
|
||||
String sourceDbInstanceIdentifier,
|
||||
String sourceDbiResourceId,
|
||||
String sourceDbInstanceAutomatedBackupsArn,
|
||||
Instant restoreTime,
|
||||
Boolean useLatestRestorableTime,
|
||||
String dbInstanceClass,
|
||||
Integer port,
|
||||
String availabilityZone,
|
||||
Boolean multiAz,
|
||||
Boolean autoMinorVersionUpgrade,
|
||||
String dbName,
|
||||
String optionGroupName,
|
||||
String dbParameterGroupName,
|
||||
Boolean publiclyAccessible,
|
||||
String dbSubnetGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Boolean copyTagsToSnapshot,
|
||||
Boolean iamDatabaseAuthenticationEnabled,
|
||||
Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow,
|
||||
Boolean deletionProtection,
|
||||
Map<String, String> tags) {
|
||||
this(targetDbInstanceIdentifier, sourceDbInstanceIdentifier, sourceDbiResourceId,
|
||||
sourceDbInstanceAutomatedBackupsArn, restoreTime, useLatestRestorableTime, dbInstanceClass,
|
||||
port, availabilityZone, multiAz, autoMinorVersionUpgrade, dbName, optionGroupName,
|
||||
dbParameterGroupName, publiclyAccessible, dbSubnetGroupName, vpcSecurityGroupIds,
|
||||
copyTagsToSnapshot, iamDatabaseAuthenticationEnabled, backupRetentionPeriod,
|
||||
preferredBackupWindow, deletionProtection, tags, null);
|
||||
}
|
||||
}
|
||||
+24
-1
@@ -26,5 +26,28 @@ public record ReadReplicaRequest(String dbInstanceIdentifier,
|
||||
Boolean iamDatabaseAuthenticationEnabled,
|
||||
Integer allocatedStorage,
|
||||
String replicaMode,
|
||||
Map<String, String> tags) {
|
||||
Map<String, String> tags,
|
||||
String storageType) {
|
||||
|
||||
public ReadReplicaRequest(String dbInstanceIdentifier,
|
||||
String sourceDbInstanceIdentifier,
|
||||
String dbInstanceClass,
|
||||
String availabilityZone,
|
||||
Boolean multiAz,
|
||||
Boolean autoMinorVersionUpgrade,
|
||||
String optionGroupName,
|
||||
String dbParameterGroupName,
|
||||
Boolean publiclyAccessible,
|
||||
String dbSubnetGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Boolean copyTagsToSnapshot,
|
||||
Boolean iamDatabaseAuthenticationEnabled,
|
||||
Integer allocatedStorage,
|
||||
String replicaMode,
|
||||
Map<String, String> tags) {
|
||||
this(dbInstanceIdentifier, sourceDbInstanceIdentifier, dbInstanceClass, availabilityZone, multiAz,
|
||||
autoMinorVersionUpgrade, optionGroupName, dbParameterGroupName, publiclyAccessible,
|
||||
dbSubnetGroupName, vpcSecurityGroupIds, copyTagsToSnapshot, iamDatabaseAuthenticationEnabled,
|
||||
allocatedStorage, replicaMode, tags, null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user