diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java index 814a664c4b..8e03485b36 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java @@ -20,6 +20,7 @@ import software.amazon.awssdk.services.rds.model.CreateOptionGroupResponse; import software.amazon.awssdk.services.rds.model.DBCluster; import software.amazon.awssdk.services.rds.model.DBClusterEndpoint; import software.amazon.awssdk.services.rds.model.DBClusterSnapshot; +import software.amazon.awssdk.services.rds.model.DBEngineVersion; import software.amazon.awssdk.services.rds.model.DBInstance; import software.amazon.awssdk.services.rds.model.DBProxyTarget; import software.amazon.awssdk.services.rds.model.DBSnapshot; @@ -34,6 +35,7 @@ import software.amazon.awssdk.services.rds.model.DescribeDbProxyTargetsResponse; import software.amazon.awssdk.services.rds.model.DescribeDbSubnetGroupsResponse; import software.amazon.awssdk.services.rds.model.DescribeOptionGroupsResponse; import software.amazon.awssdk.services.rds.model.DescribeOrderableDbInstanceOptionsResponse; +import software.amazon.awssdk.services.rds.model.EngineDefaults; import software.amazon.awssdk.services.rds.model.InvalidDbInstanceStateException; import software.amazon.awssdk.services.rds.model.InvalidOptionGroupStateException; import software.amazon.awssdk.services.rds.model.InvalidRestoreException; @@ -49,6 +51,8 @@ import software.amazon.awssdk.services.rds.model.OptionSetting; import software.amazon.awssdk.services.rds.model.RdsException; import software.amazon.awssdk.services.rds.model.RegisterDbProxyTargetsResponse; import software.amazon.awssdk.services.rds.model.Tag; +import software.amazon.awssdk.services.rds.model.UpgradeTarget; +import software.amazon.awssdk.services.rds.model.ValidStorageOptions; import java.time.Instant; import java.util.List; @@ -753,6 +757,51 @@ class RdsControlPlaneTest { } } + @Test + @DisplayName("Catalogue reads: engine versions, engine defaults and valid instance modifications") + void sdkReadsTheEngineCatalogue() { + DBEngineVersion postgres = rds.describeDBEngineVersions(b -> b + .engine("postgres").engineVersion("16.3")).dbEngineVersions().get(0); + assertThat(postgres.dbParameterGroupFamily()).isEqualTo("postgres16"); + assertThat(postgres.validUpgradeTarget()).extracting(UpgradeTarget::engineVersion).contains("17.4"); + assertThat(postgres.supportedEngineModes()).containsExactly("provisioned"); + assertThat(postgres.exportableLogTypes()).containsExactly("postgresql", "upgrade"); + assertThat(postgres.supportsLogExportsToCloudwatchLogs()).isTrue(); + assertThat(postgres.supportsReadReplica()).isTrue(); + assertThat(postgres.supportedFeatureNames()).containsExactly("s3Import", "s3Export", "Lambda"); + assertThat(postgres.supportsParallelQuery()).isFalse(); + assertThat(postgres.supportsGlobalDatabases()).isFalse(); + assertThat(postgres.supportsBabelfish()).isFalse(); + + assertThat(rds.describeDBEngineVersions(b -> b.engine("mysql").defaultOnly(true)).dbEngineVersions()) + .extracting(DBEngineVersion::engineVersion).containsExactly("8.0.36"); + DBEngineVersion auroraMysql = rds.describeDBEngineVersions(b -> b + .engine("aurora-mysql").defaultOnly(true)).dbEngineVersions().get(0); + assertThat(auroraMysql.engineVersion()).isEqualTo("8.0.mysql_aurora.3.05.2"); + assertThat(auroraMysql.supportsGlobalDatabases()).isTrue(); + assertThat(auroraMysql.supportedFeatureNames()).isEmpty(); + + EngineDefaults defaults = rds.describeEngineDefaultParameters(b -> b + .dbParameterGroupFamily("postgres16")).engineDefaults(); + assertThat(defaults.dbParameterGroupFamily()).isEqualTo("postgres16"); + assertThat(rds.describeEngineDefaultClusterParameters(b -> b + .dbParameterGroupFamily("aurora-postgresql16")).engineDefaults().dbParameterGroupFamily()) + .isEqualTo("aurora-postgresql16"); + + String instanceName = TestFixtures.uniqueName("rds-valid-mods"); + try { + createDbInstance(rds, instanceName, "catalogue-secret"); + ValidStorageOptions storage = rds.describeValidDBInstanceModifications(b -> b + .dbInstanceIdentifier(instanceName)).validDBInstanceModificationsMessage().storage().get(0); + assertThat(storage.storageType()).isEqualTo("gp2"); + // 20 GiB stays as it is, and any increase stores at least 10% more (22 GiB). + assertThat(storage.storageSize()).extracting(r -> r.from() + "-" + r.to()) + .containsExactly("20-20", "22-65536"); + } finally { + deleteDbInstance(rds, instanceName); + } + } + private static CreateDbProxyResponse createIamProxy(RdsClient client, String name, List vpcSubnetIds) { return client.createDBProxy(b -> b .dbProxyName(name) diff --git a/docs/services/index.md b/docs/services/index.md index cda7b79b1e..32562840da 100644 --- a/docs/services/index.md +++ b/docs/services/index.md @@ -62,7 +62,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac | [Amazon Data Lifecycle Manager](dlm.md) | `/policies`, `/policies/{policyId}`, `/tags/{resourceArn}` | REST JSON | 8 | | [ElastiCache](elasticache.md) | `POST /` with `Action=` param + TCP proxy | Query + RESP | 30 | | [MemoryDB](memorydb.md) | `POST /` + `X-Amz-Target: AmazonMemoryDB.*` + TCP proxy | JSON 1.1 + RESP | 13 | -| [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 90 | +| [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 94 | | [RDS Data API](rds-data.md) | `/Execute`, `/BeginTransaction`, `/CommitTransaction`, `/RollbackTransaction` | REST JSON | 4 | | [Timestream for InfluxDB](timestream-influxdb.md) | `POST /` + `X-Amz-Target: AmazonTimestreamInfluxDB.*` + InfluxDB container | JSON 1.0 + InfluxDB HTTP | 24 | | [MSK](msk.md) | `/v1/clusters/...`, `/api/v2/clusters/...` + Redpanda broker | REST JSON + Kafka | 8 | diff --git a/docs/services/rds.md b/docs/services/rds.md index 986238d70a..f0dd22bdfe 100644 --- a/docs/services/rds.md +++ b/docs/services/rds.md @@ -57,7 +57,11 @@ RDS Data API (`rds-data`) is documented separately because it uses REST JSON rou | `PromoteReadReplica` | Detach a read replica into a standalone instance and turn automated backups on | | `SwitchoverReadReplica` | Refused with `InvalidDBInstanceState`: AWS supports switchover only for Oracle and SQL Server replicas, neither of which is emulated | | `PromoteReadReplicaDBCluster` | Refused with `InvalidDBClusterStateFault`: no cluster is created as a replica of an instance | -| `DescribeOrderableDBInstanceOptions` | List deterministic instance class options | +| `DescribeDBEngineVersions` | List the engine catalogue's versions with their parameter group family, default flag and upgrade targets | +| `DescribeEngineDefaultParameters` | Return a known family's default parameters (an empty list, as Floci's default groups hold none) | +| `DescribeEngineDefaultClusterParameters` | Return a known family's default cluster parameters (an empty list, as for instances) | +| `DescribeValidDBInstanceModifications` | Return the storage an instance can move to: its type and the sizes a modify stores as asked | +| `DescribeOrderableDBInstanceOptions` | List the orderable engine, version and instance class combinations from the engine catalogue; see [Engine catalogue](#engine-catalogue) | | `DescribeEvents` | - | | `CreateEventSubscription` | Create an event notification subscription (stored, nothing is published) | | `DescribeEventSubscriptions` | List subscriptions, or the one the request names | @@ -553,6 +557,33 @@ same-region replicas; a cross-region replica keeps its link with the replication `terminated` until it is promoted or deleted, which is what AWS does for PostgreSQL. Deleting a replica drops it from its source's list. +## Engine catalogue + +`DescribeDBEngineVersions` and `DescribeOrderableDBInstanceOptions` read one curated catalogue: a +representative version for each major version Floci knows through its managed parameter and option +groups (PostgreSQL 13 to 18, MySQL 8.0 and 8.4, MariaDB 10.11, 11.2 and 11.4, SQL Server Standard 15, +Aurora PostgreSQL 15 to 17 and Aurora MySQL 8.0). It is not AWS's full version list. Each version +reports the parameter group family the create path computes for it, its major version and its upgrade +targets (the engine's later versions, with `IsMajorVersionUpgrade` set across a major version). Each +engine's default is the version a create request that names none gets (instances, clusters and global +clusters alike), so `DefaultOnly` agrees with what Floci builds; for Aurora MySQL that is +`8.0.mysql_aurora.3.05.2`. Each version also reports what Floci supports for it: `SupportsReadReplica` +for PostgreSQL only, `SupportsGlobalDatabases` for the two Aurora engines, and `SupportsParallelQuery` +and `SupportsBabelfish` as false. `ExportableLogTypes` and `SupportedFeatureNames` list the engine's +documented log types and IAM role feature names. `EngineVersion` takes an exact version or a major version such as `16`, and the +documented filters (`db-parameter-group-family`, `engine`, `engine-mode`, `engine-version`, `status`) +apply. Every version is `available`, so `IncludeAll` changes nothing. + +`DescribeEngineDefaultParameters` and `DescribeEngineDefaultClusterParameters` accept a family from the +catalogue (`InvalidParameterValue` otherwise) and return an empty parameter list, consistent with +`DescribeDBParameters` on a default group, which lists only values set on the group. +`DescribeValidDBInstanceModifications` reports the instance's storage type and the sizes `ModifyDBInstance` +stores as asked: the current size, and from the smallest real increase up to the engine's maximum (16384 +GiB for SQL Server, 65536 GiB otherwise). Storage only grows, and for PostgreSQL, MySQL and MariaDB an +increase under 10% is rounded up to 10%, so at 40 GiB the second range starts at 44. An Aurora instance +has no storage of its own to modify, so its list is empty. `DescribeOrderableDBInstanceOptions` matches +`EngineVersion` exactly or as a major version prefix, so `8.0` finds the MySQL `8.0.36` rows. + ## Cluster endpoints `CreateDBClusterEndpoint` adds an Aurora custom endpoint to an available cluster. As the Aurora user diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java index d3a9339a74..14ff0cb5a6 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java @@ -554,7 +554,9 @@ public class AwsQueryController { private static final Set RDS_ACTIONS = Set.of( "CreateDBInstance", "DescribeDBInstances", "DeleteDBInstance", "ModifyDBInstance", "RebootDBInstance", - "DescribeOrderableDBInstanceOptions", + "DescribeOrderableDBInstanceOptions", "DescribeValidDBInstanceModifications", + "DescribeDBEngineVersions", "DescribeEngineDefaultParameters", + "DescribeEngineDefaultClusterParameters", "CreateDBSubnetGroup", "DescribeDBSubnetGroups", "ModifyDBSubnetGroup", "DeleteDBSubnetGroup", "AddTagsToResource", "ListTagsForResource", "RemoveTagsFromResource", "CreateDBCluster", "DescribeDBClusters", "DeleteDBCluster", "ModifyDBCluster", diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsEngineCatalog.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsEngineCatalog.java new file mode 100644 index 0000000000..1ea5fc7390 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsEngineCatalog.java @@ -0,0 +1,167 @@ +package io.github.hectorvent.floci.services.rds; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * The engine versions RDS reports through DescribeDBEngineVersions and + * DescribeOrderableDBInstanceOptions. It is a curated subset, one representative version per major + * version that Floci knows through its managed parameter and option groups, not AWS's full list. + * Each engine's default is the version Floci uses when a create request names none, and each + * family is the one the create path computes for that version. + */ +final class RdsEngineCatalog { + + /** One engine version; {@code instanceClasses} are its orderable classes. */ + record EngineVersion(String engine, String version, String majorVersion, String family, + String engineDescription, boolean isDefault, List instanceClasses, + List engineModes) { + + String versionDescription() { + return engineDescription + " " + version; + } + } + + private static final List PROVISIONED = List.of("provisioned"); + + static final List VERSIONS = List.of( + postgres("13.20", "13", false, List.of()), + postgres("14.17", "14", false, List.of()), + postgres("15.12", "15", false, List.of()), + postgres("16.3", "16", true, List.of("db.t3.micro", "db.t4g.micro", "db.t4g.small", "db.t4g.medium")), + postgres("16.14", "16", false, List.of("db.t3.micro", "db.t4g.small")), + postgres("17.4", "17", false, List.of()), + postgres("18.1", "18", false, List.of("db.t3.micro", "db.m8g.large")), + postgres("18.4", "18", false, List.of("db.m8g.large")), + new EngineVersion("mysql", "8.0.36", "8.0", "mysql8.0", "MySQL Community Edition", true, + List.of("db.t3.micro"), PROVISIONED), + new EngineVersion("mysql", "8.4.4", "8.4", "mysql8.4", "MySQL Community Edition", false, + List.of(), PROVISIONED), + new EngineVersion("mariadb", "10.11.11", "10.11", "mariadb10.11", "MariaDb Community Edition", false, + List.of(), PROVISIONED), + new EngineVersion("mariadb", "11.2", "11.2", "mariadb11.2", "MariaDb Community Edition", true, + List.of("db.t3.micro"), PROVISIONED), + new EngineVersion("mariadb", "11.4.5", "11.4", "mariadb11.4", "MariaDb Community Edition", false, + List.of(), PROVISIONED), + new EngineVersion("sqlserver-se", "15.00", "15.00", "sqlserver15", "SQL Server Standard Edition", true, + List.of("db.t3.micro"), PROVISIONED), + new EngineVersion("aurora-postgresql", "15.12", "15", "aurora-postgresql15", + "Aurora (PostgreSQL)", false, List.of(), PROVISIONED), + new EngineVersion("aurora-postgresql", "16.3", "16", "aurora-postgresql16", + "Aurora (PostgreSQL)", true, List.of(), PROVISIONED), + new EngineVersion("aurora-postgresql", "17.4", "17", "aurora-postgresql17", + "Aurora (PostgreSQL)", false, List.of(), PROVISIONED), + new EngineVersion("aurora-mysql", "8.0.mysql_aurora.3.05.2", "8.0", "aurora-mysql8.0", + "Aurora MySQL", true, List.of(), PROVISIONED), + new EngineVersion("aurora-mysql", "8.0.mysql_aurora.3.08.0", "8.0", "aurora-mysql8.0", + "Aurora MySQL", false, List.of(), PROVISIONED)); + + private RdsEngineCatalog() { + } + + private static EngineVersion postgres(String version, String major, boolean isDefault, List classes) { + return new EngineVersion("postgres", version, major, "postgres" + major, "PostgreSQL", isDefault, + classes, PROVISIONED); + } + + // The log types each engine has long published to CloudWatch Logs, per the RDS and Aurora user + // guides. Floci stores EnableCloudwatchLogsExports as given and ships nothing. + private static final Map> EXPORTABLE_LOG_TYPES = Map.of( + "postgres", List.of("postgresql", "upgrade"), + "mysql", List.of("audit", "error", "general", "slowquery"), + "mariadb", List.of("audit", "error", "general", "slowquery"), + "sqlserver-se", List.of("agent", "error"), + "aurora-mysql", List.of("audit", "error", "general", "slowquery"), + "aurora-postgresql", List.of("postgresql")); + + // The FeatureName values AddRoleToDBInstance and AddRoleToDBCluster accept for each engine, per + // the user guides; MySQL, MariaDB and Aurora MySQL take none (Aurora MySQL names its roles in + // cluster parameters instead). + private static final Map> FEATURE_NAMES = Map.of( + "postgres", List.of("s3Import", "s3Export", "Lambda"), + "sqlserver-se", List.of("S3_INTEGRATION"), + "aurora-postgresql", List.of("s3Import", "s3Export", "Lambda", "Comprehend", "SageMaker")); + + static List exportableLogTypes(EngineVersion version) { + return EXPORTABLE_LOG_TYPES.getOrDefault(version.engine(), List.of()); + } + + static List supportedFeatureNames(EngineVersion version) { + return FEATURE_NAMES.getOrDefault(version.engine(), List.of()); + } + + /** Floci creates read replicas of PostgreSQL instances only. */ + static boolean supportsReadReplica(EngineVersion version) { + return version.engine().equals("postgres"); + } + + static boolean supportsGlobalDatabases(EngineVersion version) { + return RdsService.GLOBAL_CLUSTER_ENGINES.contains(version.engine()); + } + + /** + * The version a create request that names none gets: the engine's flagged default. {@code aurora} + * is Aurora MySQL's older engine name and the SQL Server editions share one entry. Null when the + * catalogue does not know the engine; no engine at all means PostgreSQL. + */ + static String defaultVersion(String engine) { + String name = engine == null ? "postgres" : engine.toLowerCase(Locale.ROOT); + String catalogued = switch (name) { + case "aurora" -> "aurora-mysql"; + case "sqlserver-ee", "sqlserver-ex", "sqlserver-web" -> "sqlserver-se"; + default -> name; + }; + return VERSIONS.stream() + .filter(v -> v.isDefault() && v.engine().equals(catalogued)) + .map(EngineVersion::version) + .findFirst() + .orElse(null); + } + + /** + * Whether {@code requested} names {@code version}: the exact version, or a prefix of it ending + * at a dot, so {@code 16} and {@code 16.3} both name {@code 16.3}. + */ + static boolean versionMatches(String version, String requested) { + String wanted = requested.toLowerCase(Locale.ROOT); + String actual = version.toLowerCase(Locale.ROOT); + return actual.equals(wanted) || actual.startsWith(wanted + "."); + } + + /** The later versions of the same engine, oldest first, as ValidUpgradeTarget lists them. */ + static List upgradeTargets(EngineVersion from) { + List targets = new ArrayList<>(); + for (EngineVersion candidate : VERSIONS) { + if (candidate.engine().equals(from.engine()) && compareVersions(candidate.version(), from.version()) > 0) { + targets.add(candidate); + } + } + targets.sort(Comparator.comparing(EngineVersion::version, RdsEngineCatalog::compareVersions)); + return targets; + } + + /** Numeric parts compare as numbers and the rest as text, so 16.14 sorts after 16.3. */ + static int compareVersions(String left, String right) { + String[] a = left.split("\\."); + String[] b = right.split("\\."); + for (int i = 0; i < Math.max(a.length, b.length); i++) { + String x = i < a.length ? a[i] : ""; + String y = i < b.length ? b[i] : ""; + int cmp = x.matches("\\d+") && y.matches("\\d+") + ? Long.compare(Long.parseLong(x), Long.parseLong(y)) + : x.compareTo(y); + if (cmp != 0) { + return cmp; + } + } + return 0; + } + + /** Whether a parameter group family is one the catalogue's versions use. */ + static boolean knowsFamily(String family) { + return family != null && VERSIONS.stream().anyMatch(v -> v.family().equalsIgnoreCase(family)); + } +} diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 33980af5c5..8024531f9f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java @@ -92,6 +92,12 @@ public class RdsQueryHandler { case "PromoteReadReplica" -> handlePromoteReadReplica(params, region); case "SwitchoverReadReplica" -> handleSwitchoverReadReplica(params, region); case "PromoteReadReplicaDBCluster" -> handlePromoteReadReplicaDbCluster(params, region); + case "DescribeDBEngineVersions" -> handleDescribeDbEngineVersions(params); + case "DescribeEngineDefaultParameters" -> handleDescribeEngineDefaultParameters(params, + "DescribeEngineDefaultParameters"); + case "DescribeEngineDefaultClusterParameters" -> handleDescribeEngineDefaultParameters(params, + "DescribeEngineDefaultClusterParameters"); + case "DescribeValidDBInstanceModifications" -> handleDescribeValidDbInstanceModifications(params, region); case "DescribeOrderableDBInstanceOptions" -> handleDescribeOrderableDbInstanceOptions(params); case "DescribeEvents" -> handleDescribeEvents(params, region); case "CreateEventSubscription" -> handleCreateEventSubscription(params, region); @@ -715,6 +721,109 @@ public class RdsQueryHandler { } } + private Response handleDescribeDbEngineVersions(MultivaluedMap params) { + Map> filters = new LinkedHashMap<>(); + for (String name : List.of("db-parameter-group-family", "engine", "engine-mode", "engine-version", "status")) { + List values = extractRdsFilterValues(params, name); + if (!values.isEmpty()) { + filters.put(name, values); + } + } + RdsService.EngineVersionPage page = service.describeDbEngineVersions( + params.getFirst("Engine"), + params.getFirst("EngineVersion"), + params.getFirst("DBParameterGroupFamily"), + Boolean.parseBoolean(params.getFirst("DefaultOnly")), + filters, + optionalInt(params.getFirst("MaxRecords")), + params.getFirst("Marker")); + XmlBuilder xml = new XmlBuilder().start("DBEngineVersions"); + for (RdsEngineCatalog.EngineVersion v : page.versions()) { + xml.start("DBEngineVersion") + .elem("Engine", v.engine()) + .elem("MajorEngineVersion", v.majorVersion()) + .elem("EngineVersion", v.version()) + .elem("DBParameterGroupFamily", v.family()) + .elem("DBEngineDescription", v.engineDescription()) + .elem("DBEngineVersionDescription", v.versionDescription()) + .start("ValidUpgradeTarget"); + for (RdsEngineCatalog.EngineVersion target : RdsEngineCatalog.upgradeTargets(v)) { + xml.start("UpgradeTarget") + .elem("Engine", target.engine()) + .elem("EngineVersion", target.version()) + .elem("Description", target.versionDescription()) + .elem("AutoUpgrade", false) + .elem("IsMajorVersionUpgrade", !target.majorVersion().equals(v.majorVersion())) + .end("UpgradeTarget"); + } + xml.end("ValidUpgradeTarget").start("ExportableLogTypes"); + RdsEngineCatalog.exportableLogTypes(v).forEach(type -> xml.elem("member", type)); + xml.end("ExportableLogTypes") + .elem("SupportsLogExportsToCloudwatchLogs", !RdsEngineCatalog.exportableLogTypes(v).isEmpty()) + .elem("SupportsReadReplica", RdsEngineCatalog.supportsReadReplica(v)) + .start("SupportedEngineModes"); + v.engineModes().forEach(mode -> xml.elem("member", mode)); + xml.end("SupportedEngineModes").start("SupportedFeatureNames"); + RdsEngineCatalog.supportedFeatureNames(v).forEach(name -> xml.elem("member", name)); + xml.end("SupportedFeatureNames") + .elem("Status", "available") + .elem("SupportsParallelQuery", false) + .elem("SupportsGlobalDatabases", RdsEngineCatalog.supportsGlobalDatabases(v)) + .elem("SupportsBabelfish", false) + .end("DBEngineVersion"); + } + xml.end("DBEngineVersions"); + if (page.marker() != null) { + xml.elem("Marker", page.marker()); + } + return Response.ok(AwsQueryResponse.envelope("DescribeDBEngineVersions", AwsNamespaces.RDS, + xml.build())).build(); + } + + /** Serves both engine default calls; they share the request and the EngineDefaults shape. */ + private Response handleDescribeEngineDefaultParameters(MultivaluedMap params, String action) { + String family = params.getFirst("DBParameterGroupFamily"); + List> parameters = service.describeEngineDefaultParameters(family); + XmlBuilder xml = new XmlBuilder().start("EngineDefaults") + .elem("DBParameterGroupFamily", family) + .start("Parameters"); + for (Map parameter : parameters) { + xml.start("Parameter") + .elem("ParameterName", parameter.get("name")) + .elem("ParameterValue", parameter.get("value")) + .end("Parameter"); + } + xml.end("Parameters").end("EngineDefaults"); + return Response.ok(AwsQueryResponse.envelope(action, AwsNamespaces.RDS, xml.build())).build(); + } + + private Response handleDescribeValidDbInstanceModifications(MultivaluedMap params, String region) { + List storage = service.describeValidDbInstanceModifications( + params.getFirst("DBInstanceIdentifier"), region); + XmlBuilder xml = new XmlBuilder().start("ValidDBInstanceModificationsMessage").start("Storage"); + for (RdsService.StorageModification option : storage) { + xml.start("ValidStorageOptions") + .elem("StorageType", option.storageType()) + .start("StorageSize"); + for (RdsService.SizeRange range : option.sizes()) { + xml.start("Range") + .elem("From", range.from()) + .elem("To", range.to()) + .elem("Step", 1) + .end("Range"); + } + xml.end("StorageSize") + .elem("SupportsStorageAutoscaling", true) + .end("ValidStorageOptions"); + } + xml.end("Storage") + .start("ValidProcessorFeatures").end("ValidProcessorFeatures") + .elem("SupportsDedicatedLogVolume", false) + .end("ValidDBInstanceModificationsMessage"); + return Response.ok(AwsQueryResponse.envelope("DescribeValidDBInstanceModifications", AwsNamespaces.RDS, + xml.build())).build(); + } + private Response handleDescribeOrderableDbInstanceOptions(MultivaluedMap params) { Collection> options = service.describeOrderableDbInstanceOptions( params.getFirst("Engine"), @@ -3206,16 +3315,9 @@ public class RdsQueryHandler { } } + /** The catalogue's default for the engine, or {@code 1.0} for an engine it does not list. */ private static String defaultEngineVersion(String engine) { - if (engine == null) { - return "16.3"; - } - return switch (engine.toLowerCase()) { - case "postgres", "aurora-postgresql" -> "16.3"; - case "mysql", "aurora-mysql", "aurora" -> "8.0.36"; - case "mariadb" -> "11.2"; - case "sqlserver-ee", "sqlserver-se", "sqlserver-ex", "sqlserver-web" -> "15.00"; - default -> "1.0"; - }; + String version = RdsEngineCatalog.defaultVersion(engine); + return version != null ? version : "1.0"; } } diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java index f285ab802d..cad1249c18 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java @@ -3098,32 +3098,135 @@ public class RdsService implements Resettable, ResourceProvider { + "] does not exist, is not enabled or you do not have permissions to access it.", 400); } + /** + * The orderable classes the engine catalogue lists, narrowed by engine, version and class. The + * version matches exactly or as a prefix ending at a dot, so {@code 8.0} still finds the MySQL + * 8.0 rows now that the catalogue names {@code 8.0.36}. + */ public List> describeOrderableDbInstanceOptions(String engine, String engineVersion, String dbInstanceClass) { - List> options = List.of( - Map.of("engine", "postgres", "engineVersion", "16.3", "dbInstanceClass", "db.t3.micro"), - Map.of("engine", "postgres", "engineVersion", "16.14", "dbInstanceClass", "db.t3.micro"), - Map.of("engine", "postgres", "engineVersion", "18.1", "dbInstanceClass", "db.t3.micro"), - Map.of("engine", "postgres", "engineVersion", "18.1", "dbInstanceClass", "db.m8g.large"), - Map.of("engine", "postgres", "engineVersion", "18.4", "dbInstanceClass", "db.m8g.large"), - Map.of("engine", "postgres", "engineVersion", "16.3", "dbInstanceClass", "db.t4g.micro"), - Map.of("engine", "postgres", "engineVersion", "16.3", "dbInstanceClass", "db.t4g.small"), - Map.of("engine", "postgres", "engineVersion", "16.14", "dbInstanceClass", "db.t4g.small"), - Map.of("engine", "postgres", "engineVersion", "16.3", "dbInstanceClass", "db.t4g.medium"), - Map.of("engine", "mysql", "engineVersion", "8.0", "dbInstanceClass", "db.t3.micro"), - Map.of("engine", "mariadb", "engineVersion", "11", "dbInstanceClass", "db.t3.micro"), - Map.of("engine", "sqlserver-se", "engineVersion", "15.00", "dbInstanceClass", "db.t3.micro") - ); + List> options = new ArrayList<>(); + for (RdsEngineCatalog.EngineVersion version : RdsEngineCatalog.VERSIONS) { + for (String instanceClass : version.instanceClasses()) { + options.add(Map.of("engine", version.engine(), "engineVersion", version.version(), + "dbInstanceClass", instanceClass)); + } + } return options.stream() .filter(option -> engine == null || engine.isBlank() || engine.equalsIgnoreCase(option.get("engine"))) .filter(option -> engineVersion == null || engineVersion.isBlank() - || engineVersion.equalsIgnoreCase(option.get("engineVersion"))) + || RdsEngineCatalog.versionMatches(option.get("engineVersion"), engineVersion)) .filter(option -> dbInstanceClass == null || dbInstanceClass.isBlank() || dbInstanceClass.equalsIgnoreCase(option.get("dbInstanceClass"))) .toList(); } + // ── Catalogue reads ─────────────────────────────────────────────────────── + + // The largest allocation, in GiB, the RDS user guide gives for general purpose storage. + private static final int MAX_STORAGE_GIB = 65_536; + private static final int MAX_SQLSERVER_STORAGE_GIB = 16_384; + + public record EngineVersionPage(List versions, String marker) {} + + /** + * The catalogue's engine versions, narrowed by engine, version (exact, or a major version such + * as {@code 16}), family and the documented filters. Every version is available, so + * {@code IncludeAll} changes nothing. With {@code DefaultOnly}, each engine (or engine and major + * version, when the request names a version) contributes its default: the flagged one, or the + * latest of that major version. + */ + public EngineVersionPage describeDbEngineVersions(String engine, String engineVersion, String family, + boolean defaultOnly, Map> filters, + Integer maxRecords, String marker) { + requireValidMaxRecords(maxRecords); + List matching = RdsEngineCatalog.VERSIONS.stream() + .filter(v -> isBlank(engine) || v.engine().equalsIgnoreCase(engine)) + .filter(v -> isBlank(engineVersion) || RdsEngineCatalog.versionMatches(v.version(), engineVersion)) + .filter(v -> isBlank(family) || v.family().equalsIgnoreCase(family)) + .filter(v -> matchesFilter(filters, "engine", v.engine())) + .filter(v -> matchesFilter(filters, "db-parameter-group-family", v.family())) + .filter(v -> filterValues(filters, "engine-version").isEmpty() + || filterValues(filters, "engine-version").stream() + .anyMatch(w -> RdsEngineCatalog.versionMatches(v.version(), w))) + .filter(v -> filterValues(filters, "engine-mode").isEmpty() + || v.engineModes().stream().anyMatch(m -> matchesFilter(filters, "engine-mode", m))) + .filter(v -> matchesFilter(filters, "status", "available")) + .toList(); + if (defaultOnly) { + boolean byMajor = !isBlank(engineVersion); + Map defaults = new LinkedHashMap<>(); + for (RdsEngineCatalog.EngineVersion v : matching) { + String group = byMajor ? v.engine() + "/" + v.majorVersion() : v.engine(); + RdsEngineCatalog.EngineVersion current = defaults.get(group); + if (current == null || (!current.isDefault() && (v.isDefault() + || RdsEngineCatalog.compareVersions(v.version(), current.version()) > 0))) { + defaults.put(group, v); + } + } + matching = List.copyOf(defaults.values()); + } + OffsetPage page = offsetPage(matching, maxRecords, marker); + return new EngineVersionPage(page.items(), page.marker()); + } + + private static List filterValues(Map> filters, String name) { + List values = filters != null ? filters.get(name) : null; + return values != null ? values : List.of(); + } + + /** + * Checks a family for DescribeEngineDefaultParameters and DescribeEngineDefaultClusterParameters. + * Floci's default parameter groups hold no parameters (DescribeDBParameters lists only values set + * on a group), so a known family's defaults are an empty list. + */ + public List> describeEngineDefaultParameters(String family) { + if (isBlank(family)) { + throw new AwsException("InvalidParameterValue", "DBParameterGroupFamily is required.", 400); + } + if (!RdsEngineCatalog.knowsFamily(family)) { + throw new AwsException("InvalidParameterValue", + "DBParameterGroupFamily " + family + " is not supported.", 400); + } + return List.of(); + } + + /** What ModifyDBInstance can change about an instance's storage: its type and the sizes it can take. */ + public record StorageModification(String storageType, List sizes) {} + + public record SizeRange(int from, int to) {} + + /** + * The storage an instance can move to: its storage type and the sizes ModifyDBInstance stores as + * asked. Storage only grows. For PostgreSQL, MySQL and MariaDB an increase under 10% is rounded + * up to 10%, so the sizes are the current one (no change) and from 10% more up to the engine's + * maximum; SQL Server takes any larger size. An Aurora instance has no storage of its own to + * modify, so it has none. + */ + public List describeValidDbInstanceModifications(String id, String region) { + String effectiveRegion = effectiveRegion(region); + if (isBlank(id)) { + throw new AwsException("InvalidParameterValue", "DBInstanceIdentifier is required.", 400); + } + DbInstance instance = getDbInstance(id, effectiveRegion); + if (instance.getStatus() != null && instance.getStatus() != DbInstanceStatus.AVAILABLE) { + throw new AwsException("InvalidDBInstanceState", + "DB instance " + id + " is not in available state.", 400); + } + if (!isBlank(instance.getDbClusterIdentifier())) { + return List.of(); + } + int maximum = instance.getEngine() == DatabaseEngine.SQLSERVER ? MAX_SQLSERVER_STORAGE_GIB : MAX_STORAGE_GIB; + int current = Math.min(instance.getAllocatedStorage(), maximum); + int smallestIncrease = instance.getEngine() == DatabaseEngine.SQLSERVER + ? current + 1 : Math.ceilDiv(current * 11, 10); + List 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)); + } + // ── Stop, start and reboot ──────────────────────────────────────────────── /** Aurora members are stopped and started through their cluster; the model lists InvalidDBClusterStateFault for both calls. */ @@ -4618,7 +4721,7 @@ public class RdsService implements Resettable, ResourceProvider { // ── Global clusters (Aurora global databases) ───────────────────────────── - private static final Set GLOBAL_CLUSTER_ENGINES = Set.of("aurora-mysql", "aurora-postgresql"); + static final Set GLOBAL_CLUSTER_ENGINES = Set.of("aurora-mysql", "aurora-postgresql"); /** * Creates an Aurora global database, empty or with an existing cluster (named by ARN or, in @@ -4680,7 +4783,7 @@ public class RdsService implements Resettable, ResourceProvider { requireGlobalClusterEngine(engine, null); global.setEngine(engine.toLowerCase(Locale.ROOT)); global.setEngineVersion(hasText(engineVersion) - ? engineVersion : defaultGlobalEngineVersion(global.getEngine())); + ? engineVersion : RdsEngineCatalog.defaultVersion(global.getEngine())); global.setDatabaseName(hasText(databaseName) ? databaseName : null); global.setStorageEncrypted(Boolean.TRUE.equals(storageEncrypted)); } @@ -5131,9 +5234,6 @@ public class RdsService implements Resettable, ResourceProvider { } } - private static String defaultGlobalEngineVersion(String engine) { - return "aurora-mysql".equals(engine) ? "8.0.mysql_aurora.3.05.2" : "16.3"; - } private static boolean sameMajorVersion(String current, String requested) { if (current == null || requested == null) { @@ -6834,17 +6934,14 @@ public class RdsService implements Resettable, ResourceProvider { } } - private String expectedClusterParameterGroupFamily(String engineParam, String engineVersion) { + String expectedClusterParameterGroupFamily(String engineParam, String engineVersion) { String normalizedEngine = effectiveEngineName(engineParam).toLowerCase(); String effectiveVersion = engineVersion; if (effectiveVersion == null || effectiveVersion.isBlank()) { - effectiveVersion = switch (normalizedEngine) { - case "postgres", "aurora-postgresql" -> "16.3"; - case "mysql", "aurora", "aurora-mysql" -> "8.0.36"; - case "mariadb" -> "11.2"; - case "sqlserver-ee", "sqlserver-se", "sqlserver-ex", "sqlserver-web" -> "15.00"; - default -> throw new AwsException("InvalidParameterValue", invalidParameterValueMessage(), 400); - }; + effectiveVersion = RdsEngineCatalog.defaultVersion(normalizedEngine); + if (effectiveVersion == null) { + throw new AwsException("InvalidParameterValue", invalidParameterValueMessage(), 400); + } } Matcher matcher = IMAGE_TAG_VERSION_PATTERN.matcher(effectiveVersion.trim()); @@ -9222,6 +9319,35 @@ public class RdsService implements Resettable, ResourceProvider { private static final int MAX_MAX_RECORDS = 100; private static final int DEFAULT_MAX_RECORDS = 100; + private static void requireValidMaxRecords(Integer maxRecords) { + if (maxRecords != null && (maxRecords < MIN_MAX_RECORDS || maxRecords > MAX_MAX_RECORDS)) { + throw new AwsException("InvalidParameterValue", + "MaxRecords must be between " + MIN_MAX_RECORDS + " and " + MAX_MAX_RECORDS + ".", 400); + } + } + + private record OffsetPage(List items, String marker) {} + + /** + * One page of a list whose marker is the offset of the page's first item, as + * DescribeDBEngineVersions and DescribeDBClusterEndpoints page. The next marker is null on the + * last page. + */ + private static OffsetPage offsetPage(List matching, Integer maxRecords, String marker) { + int from = 0; + if (!isBlank(marker)) { + try { + from = Integer.parseInt(marker); + } catch (NumberFormatException e) { + throw new AwsException("InvalidParameterValue", "Invalid marker: " + marker, 400); + } + } + int limit = maxRecords == null ? DEFAULT_MAX_RECORDS : maxRecords; + int start = Math.min(Math.max(from, 0), matching.size()); + int to = Math.min(matching.size(), start + limit); + return new OffsetPage<>(matching.subList(start, to), to < matching.size() ? Integer.toString(to) : null); + } + /** * Nothing is published to the topic. The subscription is stored and reported back so a client * can manage it, and no RDS event reaches SNS through it. @@ -9377,10 +9503,7 @@ public class RdsService implements Resettable, ResourceProvider { // Ahead of the named-subscription shortcut, so a bad page size is rejected whether or not // the request also names a subscription. Request validation does not depend on which branch // serves the read. - if (maxRecords != null && (maxRecords < MIN_MAX_RECORDS || maxRecords > MAX_MAX_RECORDS)) { - throw new AwsException("InvalidParameterValue", - "MaxRecords must be between " + MIN_MAX_RECORDS + " and " + MAX_MAX_RECORDS + ".", 400); - } + requireValidMaxRecords(maxRecords); if (subscriptionName != null && !subscriptionName.isBlank()) { return new EventSubscriptionPage( List.of(requireEventSubscription(region, subscriptionName)), null); @@ -9538,10 +9661,7 @@ public class RdsService implements Resettable, ResourceProvider { Map> filters, Integer maxRecords, String marker) { String effectiveRegion = effectiveRegion(region); - if (maxRecords != null && (maxRecords < MIN_MAX_RECORDS || maxRecords > MAX_MAX_RECORDS)) { - throw new AwsException("InvalidParameterValue", - "MaxRecords must be between " + MIN_MAX_RECORDS + " and " + MAX_MAX_RECORDS + ".", 400); - } + requireValidMaxRecords(maxRecords); List scope = !isBlank(clusterId) ? List.of(getDbCluster(clusterId, effectiveRegion)) : listDbClusters(null, effectiveRegion).stream() @@ -9570,19 +9690,8 @@ public class RdsService implements Resettable, ResourceProvider { .filter(e -> matchesFilter(filters, "db-cluster-endpoint-id", e.getDbClusterEndpointIdentifier())) .filter(e -> matchesFilter(filters, "db-cluster-endpoint-status", e.getStatus())) .toList(); - int from = 0; - if (!isBlank(marker)) { - try { - from = Integer.parseInt(marker); - } catch (NumberFormatException e) { - throw new AwsException("InvalidParameterValue", "Invalid marker: " + marker, 400); - } - } - int limit = maxRecords == null ? DEFAULT_MAX_RECORDS : maxRecords; - int start = Math.min(Math.max(from, 0), matching.size()); - int to = Math.min(matching.size(), start + limit); - return new ClusterEndpointPage(matching.subList(start, to), - to < matching.size() ? Integer.toString(to) : null); + OffsetPage page = offsetPage(matching, maxRecords, marker); + return new ClusterEndpointPage(page.items(), page.marker()); } private static void requireAuroraCluster(DbCluster cluster) { diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsCatalogueReadIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsCatalogueReadIntegrationTest.java new file mode 100644 index 0000000000..59d124b9dd --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsCatalogueReadIntegrationTest.java @@ -0,0 +1,222 @@ +package io.github.hectorvent.floci.services.rds; + +import io.github.hectorvent.floci.testing.RdsMockProfile; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import io.restassured.specification.RequestSpecification; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static io.restassured.RestAssured.given; +import static io.restassured.http.ContentType.URLENC; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * The RDS catalogue reads over the Query protocol: engine versions with their families, defaults + * and upgrade targets, the engine default parameter calls, and the storage an instance can move to. + */ +@QuarkusTest +@TestProfile(RdsMockProfile.class) +class RdsCatalogueReadIntegrationTest { + + private static final String VERSIONS = + "DescribeDBEngineVersionsResponse.DescribeDBEngineVersionsResult.DBEngineVersions.DBEngineVersion"; + + private static final String AUTH = + "AWS4-HMAC-SHA256 Credential=test/20261006/us-east-1/rds/aws4_request, " + + "SignedHeaders=content-type;host, Signature=test"; + + private static RequestSpecification query(String action) { + return given().header("Authorization", AUTH) + .contentType(URLENC) + .formParam("Action", action) + .formParam("Version", "2014-10-31"); + } + + @Test + void describeDbEngineVersionsReportsFamiliesDefaultsAndUpgradeTargets() { + query("DescribeDBEngineVersions") + .formParam("Engine", "postgres") + .formParam("EngineVersion", "16.3") + .when().post("/").then() + .statusCode(200) + .body(VERSIONS + ".size()", equalTo(1)) + .body(VERSIONS + ".DBParameterGroupFamily", equalTo("postgres16")) + .body(VERSIONS + ".MajorEngineVersion", equalTo("16")) + .body(VERSIONS + ".DBEngineDescription", equalTo("PostgreSQL")) + .body(VERSIONS + ".Status", equalTo("available")) + .body(VERSIONS + ".SupportedEngineModes.member", equalTo("provisioned")) + .body(VERSIONS + ".ValidUpgradeTarget.UpgradeTarget.size()", equalTo(4)) + .body(VERSIONS + ".ValidUpgradeTarget.UpgradeTarget[0].EngineVersion", equalTo("16.14")) + .body(VERSIONS + ".ValidUpgradeTarget.UpgradeTarget[0].IsMajorVersionUpgrade", equalTo("false")) + .body(VERSIONS + ".ValidUpgradeTarget.UpgradeTarget[1].IsMajorVersionUpgrade", equalTo("true")); + + // A major version names every version in it; DefaultOnly then keeps that major's default. + query("DescribeDBEngineVersions").formParam("Engine", "postgres").formParam("EngineVersion", "18") + .when().post("/").then().statusCode(200).body(VERSIONS + ".size()", equalTo(2)); + query("DescribeDBEngineVersions").formParam("Engine", "postgres").formParam("EngineVersion", "18") + .formParam("DefaultOnly", "true") + .when().post("/").then().statusCode(200) + .body(VERSIONS + ".EngineVersion", equalTo("18.4")); + // Without a version, DefaultOnly gives the version Floci creates when none is named. + query("DescribeDBEngineVersions").formParam("Engine", "aurora-mysql").formParam("DefaultOnly", "true") + .when().post("/").then().statusCode(200) + .body(VERSIONS + ".EngineVersion", equalTo("8.0.mysql_aurora.3.05.2")) + .body(VERSIONS + ".DBParameterGroupFamily", equalTo("aurora-mysql8.0")); + + query("DescribeDBEngineVersions") + .formParam("Filters.Filter.1.Name", "db-parameter-group-family") + .formParam("Filters.Filter.1.Values.Value.1", "mysql8.4") + .when().post("/").then().statusCode(200) + .body(VERSIONS + ".EngineVersion", equalTo("8.4.4")); + query("DescribeDBEngineVersions").formParam("Engine", "oracle-ee") + .when().post("/").then().statusCode(200) + .body(not(containsString(""))); + query("DescribeDBEngineVersions").formParam("MaxRecords", "20") + .when().post("/").then().statusCode(200) + .body(VERSIONS + ".size()", equalTo(19)) + .body(not(containsString(""))); + } + + @Test + void engineVersionsReportWhatFlociSupports() { + query("DescribeDBEngineVersions").formParam("Engine", "postgres").formParam("EngineVersion", "16.3") + .when().post("/").then() + .statusCode(200) + .body(VERSIONS + ".ExportableLogTypes.member", contains("postgresql", "upgrade")) + .body(VERSIONS + ".SupportsLogExportsToCloudwatchLogs", equalTo("true")) + .body(VERSIONS + ".SupportsReadReplica", equalTo("true")) + .body(VERSIONS + ".SupportedFeatureNames.member", contains("s3Import", "s3Export", "Lambda")) + .body(VERSIONS + ".SupportsParallelQuery", equalTo("false")) + .body(VERSIONS + ".SupportsGlobalDatabases", equalTo("false")) + .body(VERSIONS + ".SupportsBabelfish", equalTo("false")); + query("DescribeDBEngineVersions").formParam("Engine", "aurora-mysql").formParam("DefaultOnly", "true") + .when().post("/").then() + .statusCode(200) + .body(VERSIONS + ".ExportableLogTypes.member", contains("audit", "error", "general", "slowquery")) + .body(VERSIONS + ".SupportsReadReplica", equalTo("false")) + .body(containsString("")) + .body(VERSIONS + ".SupportsGlobalDatabases", equalTo("true")); + } + + @Test + void engineVersionsPageByOffset() { + query("DescribeDBEngineVersions").formParam("Marker", "15") + .when().post("/").then().statusCode(200) + .body(VERSIONS + ".size()", equalTo(4)) + .body(not(containsString(""))); + query("DescribeDBEngineVersions").formParam("Marker", "next") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + query("DescribeDBEngineVersions").formParam("MaxRecords", "19") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + } + + /** A create that names no version gets the version DescribeDBEngineVersions calls the default. */ + @ParameterizedTest + @CsvSource({"postgres", "mysql", "mariadb", "sqlserver-se"}) + void instanceCreatedWithoutAVersionGetsTheCataloguesDefault(String engine) { + String id = "default-" + engine; + String created = query("CreateDBInstance") + .formParam("DBInstanceIdentifier", id) + .formParam("Engine", engine) + .formParam("MasterUsername", "admin") + .formParam("MasterUserPassword", "password123") + .formParam("DBInstanceClass", "db.t3.micro") + .formParam("AllocatedStorage", "20") + .when().post("/").then().statusCode(200) + .extract().xmlPath().getString("CreateDBInstanceResponse.CreateDBInstanceResult.DBInstance.EngineVersion"); + assertEquals(defaultVersion(engine), created); + query("DeleteDBInstance").formParam("DBInstanceIdentifier", id).formParam("SkipFinalSnapshot", "true") + .when().post("/").then().statusCode(200); + } + + @ParameterizedTest + @CsvSource({"aurora-mysql, 8.0.mysql_aurora.3.05.2", "aurora-postgresql, 16.3"}) + void clusterCreatedWithoutAVersionGetsTheCataloguesDefault(String engine, String expected) { + String id = "default-" + engine; + String created = query("CreateDBCluster") + .formParam("DBClusterIdentifier", id) + .formParam("Engine", engine) + .formParam("MasterUsername", "admin") + .formParam("MasterUserPassword", "password123") + .when().post("/").then().statusCode(200) + .extract().xmlPath().getString("CreateDBClusterResponse.CreateDBClusterResult.DBCluster.EngineVersion"); + assertEquals(expected, created); + assertEquals(defaultVersion(engine), created); + query("DeleteDBCluster").formParam("DBClusterIdentifier", id).formParam("SkipFinalSnapshot", "true") + .when().post("/").then().statusCode(200); + } + + private static String defaultVersion(String engine) { + return query("DescribeDBEngineVersions").formParam("Engine", engine).formParam("DefaultOnly", "true") + .when().post("/").then().statusCode(200) + .extract().xmlPath().getString(VERSIONS + ".EngineVersion"); + } + + @Test + void orderableOptionsComeFromTheSameCatalogue() { + query("DescribeOrderableDBInstanceOptions").formParam("Engine", "mysql") + .when().post("/").then().statusCode(200) + .body(containsString("8.0.36")); + // The versions the list used to name still find their rows. + query("DescribeOrderableDBInstanceOptions").formParam("Engine", "mysql").formParam("EngineVersion", "8.0") + .when().post("/").then().statusCode(200) + .body(containsString("db.t3.micro")); + query("DescribeOrderableDBInstanceOptions").formParam("Engine", "mariadb").formParam("EngineVersion", "11") + .when().post("/").then().statusCode(200) + .body(containsString("11.2")); + } + + @Test + void engineDefaultParametersCheckTheFamily() { + query("DescribeEngineDefaultParameters").formParam("DBParameterGroupFamily", "postgres16") + .when().post("/").then() + .statusCode(200) + .body(containsString("" + + "postgres16")); + query("DescribeEngineDefaultClusterParameters").formParam("DBParameterGroupFamily", "aurora-postgresql16") + .when().post("/").then() + .statusCode(200) + .body(containsString("")); + query("DescribeEngineDefaultParameters").formParam("DBParameterGroupFamily", "postgres9") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + query("DescribeEngineDefaultParameters") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + } + + @Test + void validModificationsGiveTheStorageRangeFromTheCurrentAllocation() { + query("CreateDBInstance") + .formParam("DBInstanceIdentifier", "catalogue-db") + .formParam("Engine", "postgres") + .formParam("MasterUsername", "admin") + .formParam("MasterUserPassword", "password123") + .formParam("DBInstanceClass", "db.t3.micro") + .formParam("AllocatedStorage", "40") + .when().post("/").then().statusCode(200); + + query("DescribeValidDBInstanceModifications").formParam("DBInstanceIdentifier", "catalogue-db") + .when().post("/").then() + .statusCode(200) + // 40 GiB stays as it is, and any increase stores at least 10% more (44 GiB). + .body(containsString("gp2" + + "40401" + + "44655361" + + "true")); + query("DescribeValidDBInstanceModifications").formParam("DBInstanceIdentifier", "catalogue-missing") + .when().post("/").then().statusCode(404) + .body(containsString("DBInstanceNotFound")); + + query("DeleteDBInstance").formParam("DBInstanceIdentifier", "catalogue-db") + .when().post("/").then().statusCode(200); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java index 82e6203c87..f789e08ea8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java @@ -2396,6 +2396,35 @@ class RdsServiceTest { any(), anyInt(), any(), any(), any(), any(), any(), any()); } + @Test + void engineCatalogueFamiliesMatchTheFamilyCreateComputes() { + for (RdsEngineCatalog.EngineVersion version : RdsEngineCatalog.VERSIONS) { + assertEquals(rdsService.expectedClusterParameterGroupFamily(version.engine(), version.version()), + version.family(), version.engine() + " " + version.version()); + } + } + + @Test + void engineCatalogueOffersEveryOrderableVersionAndOneDefaultPerEngine() { + for (Map option : rdsService.describeOrderableDbInstanceOptions(null, null, null)) { + assertEquals(1, rdsService.describeDbEngineVersions(option.get("engine"), option.get("engineVersion"), + null, false, Map.of(), null, null).versions().stream() + .filter(v -> v.version().equals(option.get("engineVersion"))).count()); + } + Map defaults = RdsEngineCatalog.VERSIONS.stream() + .filter(RdsEngineCatalog.EngineVersion::isDefault) + .collect(Collectors.groupingBy(RdsEngineCatalog.EngineVersion::engine, Collectors.counting())); + RdsEngineCatalog.VERSIONS.forEach(v -> assertEquals(1L, defaults.get(v.engine()), v.engine())); + } + + @Test + void engineVersionsSortNumericallyForUpgradeTargets() { + RdsEngineCatalog.EngineVersion pg163 = RdsEngineCatalog.VERSIONS.stream() + .filter(v -> v.engine().equals("postgres") && v.version().equals("16.3")).findFirst().orElseThrow(); + assertEquals(List.of("16.14", "17.4", "18.1", "18.4"), + RdsEngineCatalog.upgradeTargets(pg163).stream().map(RdsEngineCatalog.EngineVersion::version).toList()); + } + @Test void describeOrderableDbInstanceOptionsFiltersByEngineVersionAndClass() { List> result = rdsService.describeOrderableDbInstanceOptions(