From 4afa7d8e9f5c716c4bf16af2eb0291f495ebc708 Mon Sep 17 00:00:00 2001 From: Allen Sanborn Date: Mon, 12 Oct 2026 22:50:09 -0500 Subject: [PATCH] feat(opensearch): serve the legacy Elasticsearch Service 2015-01-01 API (#5357) * feat(opensearch): serve the legacy Elasticsearch Service 2015-01-01 API `aws es` and Terraform's aws_elasticsearch_domain call the 2015-01-01 API, which Floci did not route, so every call got UnknownOperationException. ElasticsearchController serves the domain lifecycle, ListDomainNames and the tag operations on that path by delegating to OpenSearchController, renaming only the members the legacy model spells differently: ElasticsearchVersion (bare "7.10", stored as "Elasticsearch_7.10") and ElasticsearchClusterConfig. A legacy create without a version gets Elasticsearch 7.10 rather than the OpenSearch default. * fix(opensearch): reject blank legacy ElasticsearchVersion, report legacy instance types ElasticsearchVersionString's pattern matches no blank or non-string value, so CreateElasticsearchDomain now returns ValidationException instead of storing an empty engine version. ESPartitionInstanceType lists only *.elasticsearch types, so the legacy responses rewrite the store's *.search spelling (including the m5.large.search default). The legacy test methods get distinct @Order values. * fix(opensearch): store legacy .elasticsearch instance types as .search, accept OS_X.Y The legacy API now respells ElasticsearchClusterConfig.InstanceType from *.elasticsearch to *.search on create and update, so the 2021 API reports t3.small.search and the legacy API maps it back. ElasticsearchVersion's OS_X.Y form is stored as OpenSearch_X.Y instead of Elasticsearch_OS_X.Y. Replaces the jakarta.ws.rs wildcard import with explicit imports. --- docs/services/opensearch.md | 15 + .../core/common/ResolvedServiceCatalog.java | 4 +- .../opensearch/ElasticsearchController.java | 216 +++++++++++ .../ElasticsearchIntegrationTest.java | 348 ++++++++++++++++++ 4 files changed, 582 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchController.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchIntegrationTest.java diff --git a/docs/services/opensearch.md b/docs/services/opensearch.md index 76afcab424..497a98d378 100644 --- a/docs/services/opensearch.md +++ b/docs/services/opensearch.md @@ -55,6 +55,21 @@ services: | `ListTags` | `GET /2021-01-01/tags/?arn=` | List tags for a domain | | `RemoveTags` | `POST /2021-01-01/tags-removal` | Remove tag keys from a domain | +### Legacy Elasticsearch Service API + +The `2015-01-01` API used by `aws es` and Terraform's `aws_elasticsearch_domain` is served over the same domains. It differs only in spelling: `ElasticsearchVersion` (bare, e.g. `7.10`, stored as `Elasticsearch_7.10`; `OS_2.11` and `OpenSearch_2.11` both store and report as `OpenSearch_2.11`) for `EngineVersion`, `ElasticsearchClusterConfig` for `ClusterConfig`, and instance types ending in `.elasticsearch` (`t3.small.elasticsearch` is stored, and reported by the 2021 API, as `t3.small.search`). A domain created without `ElasticsearchVersion` gets `7.10`. + +| Operation | Method + Path | +|---|---| +| `CreateElasticsearchDomain` | `POST /2015-01-01/es/domain` | +| `DescribeElasticsearchDomain` | `GET /2015-01-01/es/domain/{name}` | +| `DescribeElasticsearchDomains` | `POST /2015-01-01/es/domain-info` | +| `DescribeElasticsearchDomainConfig` | `GET /2015-01-01/es/domain/{name}/config` | +| `UpdateElasticsearchDomainConfig` | `POST /2015-01-01/es/domain/{name}/config` | +| `DeleteElasticsearchDomain` | `DELETE /2015-01-01/es/domain/{name}` | +| `ListDomainNames` | `GET /2015-01-01/domain` | +| `AddTags` / `ListTags` / `RemoveTags` | `POST /2015-01-01/tags`, `GET /2015-01-01/tags/?arn=`, `POST /2015-01-01/tags-removal` | + ### Versions & Instance Types | Operation | Method + Path | Description | diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java index d6965e6def..ee055c75d1 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java @@ -52,6 +52,7 @@ import io.github.hectorvent.floci.services.marketplace.MarketplaceDiscoveryContr import io.github.hectorvent.floci.services.marketplace.MarketplaceReportingController; import io.github.hectorvent.floci.services.mwaa.MwaaController; import io.github.hectorvent.floci.services.oam.OamController; +import io.github.hectorvent.floci.services.opensearch.ElasticsearchController; import io.github.hectorvent.floci.services.opensearch.OpenSearchController; import io.github.hectorvent.floci.services.pipes.PipesController; import io.github.hectorvent.floci.services.rdsdata.RdsDataController; @@ -331,7 +332,8 @@ public class ResolvedServiceCatalog { "opensearch", storageMode(config.storage().services().opensearch().mode(), config.storage().mode()), config.storage().services().opensearch().flushIntervalMs(), null, ServiceProtocol.REST_JSON, protocols(ServiceProtocol.REST_JSON), - Set.of(), Set.of("es"), Set.of(), Set.of(OpenSearchController.class)), + Set.of(), Set.of("es"), Set.of(), + Set.of(OpenSearchController.class, ElasticsearchController.class)), descriptor("ec2", "ec2", config.services().ec2().enabled(), true, "ec2", storageMode(config.storage().services().ec2().mode(), config.storage().mode()), 5000L, AwsNamespaces.EC2, ServiceProtocol.QUERY, diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchController.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchController.java new file mode 100644 index 0000000000..08fa6aa11e --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchController.java @@ -0,0 +1,216 @@ +package io.github.hectorvent.floci.services.opensearch; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.RegionResolver; +import jakarta.inject.Inject; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +import java.io.IOException; + +/** + * Legacy Amazon Elasticsearch Service API ({@code 2015-01-01}), still used by + * {@code aws es} and Terraform's {@code aws_elasticsearch_domain}. It addresses + * the same domains as the OpenSearch API, so every operation delegates to + * {@link OpenSearchController} and only renames the members the legacy model + * spells differently: {@code ElasticsearchVersion} / {@code EngineVersion} and + * {@code ElasticsearchClusterConfig} / {@code ClusterConfig}. The legacy version + * is bare ({@code 7.10}) where the store holds {@code Elasticsearch_7.10}, and + * legacy instance types end in {@code .elasticsearch} where the store holds {@code .search}. + */ +@Path("/2015-01-01") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class ElasticsearchController { + + private static final String ES_PREFIX = "Elasticsearch_"; + private static final String OS_PREFIX = "OpenSearch_"; + private static final String LEGACY_SUFFIX = ".elasticsearch"; + private static final String SEARCH_SUFFIX = ".search"; + /** The legacy API always creates an Elasticsearch domain; 7.10 is the newest Floci serves. */ + private static final String DEFAULT_VERSION = ES_PREFIX + "7.10"; + + private final OpenSearchController delegate; + private final ObjectMapper objectMapper; + + @Inject + public ElasticsearchController(OpenSearchService service, RegionResolver regionResolver, + ObjectMapper objectMapper) { + this.delegate = new OpenSearchController(service, regionResolver, objectMapper); + this.objectMapper = objectMapper; + } + + @POST + @Path("/es/domain") + public Response createElasticsearchDomain(@Context HttpHeaders headers, String body) { + return toLegacy(delegate.createDomain(headers, toOpenSearch(body, true))); + } + + @GET + @Path("/es/domain/{domainName}") + public Response describeElasticsearchDomain(@Context HttpHeaders headers, + @PathParam("domainName") String domainName) { + return toLegacy(delegate.describeDomain(headers, domainName)); + } + + @POST + @Path("/es/domain-info") + public Response describeElasticsearchDomains(@Context HttpHeaders headers, String body) { + return toLegacy(delegate.describeDomains(headers, body)); + } + + @GET + @Path("/domain") + public Response listDomainNames(@Context HttpHeaders headers, + @QueryParam("engineType") String engineType) { + return delegate.listDomainNames(headers, engineType); + } + + @GET + @Path("/es/domain/{domainName}/config") + public Response describeElasticsearchDomainConfig(@Context HttpHeaders headers, + @PathParam("domainName") String domainName) { + return toLegacy(delegate.describeDomainConfig(headers, domainName)); + } + + @POST + @Path("/es/domain/{domainName}/config") + public Response updateElasticsearchDomainConfig(@Context HttpHeaders headers, + @PathParam("domainName") String domainName, + String body) { + return toLegacy(delegate.updateDomainConfig(headers, domainName, toOpenSearch(body, false))); + } + + @DELETE + @Path("/es/domain/{domainName}") + public Response deleteElasticsearchDomain(@Context HttpHeaders headers, + @PathParam("domainName") String domainName) { + return toLegacy(delegate.deleteDomain(headers, domainName)); + } + + @POST + @Path("/tags") + public Response addTags(@Context HttpHeaders headers, String body) { + return delegate.addTags(headers, body); + } + + @GET + @Path("/tags/") + public Response listTags(@Context HttpHeaders headers, @QueryParam("arn") String arn) { + return delegate.listTags(headers, arn); + } + + @POST + @Path("/tags-removal") + public Response removeTags(@Context HttpHeaders headers, String body) { + return delegate.removeTags(headers, body); + } + + // ── Member translation ─────────────────────────────────────────────────── + + private String toOpenSearch(String body, boolean create) { + JsonNode tree; + try { + tree = objectMapper.readTree(body); + } catch (IOException e) { + throw new AwsException("ValidationException", e.getMessage(), 400); + } + if (!(tree instanceof ObjectNode req)) { + return body; + } + rename(req, "ElasticsearchClusterConfig", "ClusterConfig"); + swapInstanceTypeSuffix(req.path("ClusterConfig"), LEGACY_SUFFIX, SEARCH_SUFFIX); + JsonNode version = req.remove("ElasticsearchVersion"); + if (version != null && !version.isNull()) { + // ElasticsearchVersionString is a pattern no blank or non-string value matches. + if (!version.isTextual() || version.asText().isBlank()) { + throw new AwsException("ValidationException", + "ElasticsearchVersion must be a version string such as 7.10.", 400); + } + req.put("EngineVersion", toEngineVersion(version.asText())); + } else if (create) { + req.put("EngineVersion", DEFAULT_VERSION); + } + return req.toString(); + } + + private static Response toLegacy(Response response) { + if (!(response.getEntity() instanceof ObjectNode body)) { + return response; + } + if (body.get("DomainStatus") instanceof ObjectNode status) { + toLegacyStatus(status); + } + body.path("DomainStatusList").forEach(s -> toLegacyStatus((ObjectNode) s)); + if (body.get("DomainConfig") instanceof ObjectNode config) { + rename(config, "ClusterConfig", "ElasticsearchClusterConfig"); + swapInstanceTypeSuffix(config.path("ElasticsearchClusterConfig").path("Options"), + SEARCH_SUFFIX, LEGACY_SUFFIX); + if (config.remove("EngineVersion") instanceof ObjectNode version) { + version.put("Options", toLegacyVersion(version.path("Options").asText(null))); + config.set("ElasticsearchVersion", version); + } + } + return response; + } + + private static void toLegacyStatus(ObjectNode status) { + rename(status, "ClusterConfig", "ElasticsearchClusterConfig"); + swapInstanceTypeSuffix(status.path("ElasticsearchClusterConfig"), SEARCH_SUFFIX, LEGACY_SUFFIX); + JsonNode version = status.remove("EngineVersion"); + if (version != null) { + status.put("ElasticsearchVersion", toLegacyVersion(version.asText(null))); + } + } + + /** + * ESPartitionInstanceType lists only {@code *.elasticsearch} types while the store + * (and the 2021 API) uses {@code *.search}, so instance types are respelled on the + * way in and out. + */ + private static void swapInstanceTypeSuffix(JsonNode cluster, String from, String to) { + // Only InstanceType: the store keeps no DedicatedMasterType or WarmType to respell. + String type = cluster.path("InstanceType").asText(""); + if (cluster instanceof ObjectNode node && type.endsWith(from)) { + node.put("InstanceType", type.substring(0, type.length() - from.length()) + to); + } + } + + private static void rename(ObjectNode node, String from, String to) { + JsonNode value = node.remove(from); + if (value != null) { + node.set(to, value); + } + } + + static String toEngineVersion(String legacy) { + if (legacy == null || legacy.isBlank() + || legacy.startsWith(ES_PREFIX) || legacy.startsWith(OS_PREFIX)) { + return legacy; + } + // ElasticsearchVersionString also accepts the short OS_X.Y spelling of OpenSearch_X.Y. + if (legacy.startsWith("OS_")) { + return OS_PREFIX + legacy.substring("OS_".length()); + } + return ES_PREFIX + legacy; + } + + static String toLegacyVersion(String engineVersion) { + return engineVersion != null && engineVersion.startsWith(ES_PREFIX) + ? engineVersion.substring(ES_PREFIX.length()) + : engineVersion; + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchIntegrationTest.java new file mode 100644 index 0000000000..4ec47f1dca --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchIntegrationTest.java @@ -0,0 +1,348 @@ +package io.github.hectorvent.floci.services.opensearch; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.*; + +/** The legacy Elasticsearch Service API ({@code 2015-01-01}) over the shared OpenSearch store. */ +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class ElasticsearchIntegrationTest { + + private static final String DOMAIN_NAME = "legacy-es-domain"; + private static final String AUTH_HEADER = "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/es/aws4_request"; + + private static String arn; + + @Test + @Order(1) + void createElasticsearchDomain() { + arn = given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"DomainName\":\"" + DOMAIN_NAME + "\",\"ElasticsearchVersion\":\"7.10\"," + + "\"ElasticsearchClusterConfig\":{\"InstanceType\":\"t3.small.elasticsearch\",\"InstanceCount\":2}," + + "\"EBSOptions\":{\"EBSEnabled\":true,\"VolumeType\":\"gp2\",\"VolumeSize\":20}}") + .when() + .post("/2015-01-01/es/domain") + .then() + .statusCode(200) + .body("DomainStatus.DomainName", equalTo(DOMAIN_NAME)) + .body("DomainStatus.ElasticsearchVersion", equalTo("7.10")) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceType", equalTo("t3.small.elasticsearch")) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceCount", equalTo(2)) + .body("DomainStatus", not(hasKey("EngineVersion"))) + .body("DomainStatus", not(hasKey("ClusterConfig"))) + .body("DomainStatus.ARN", containsString(":domain/" + DOMAIN_NAME)) + .extract().path("DomainStatus.ARN"); + } + + @Test + @Order(2) + void storedAsElasticsearchEngineVersion() { + // Read back through the OpenSearch API: the legacy version must be stored prefixed. + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME) + .then() + .statusCode(200) + .body("DomainStatus.EngineVersion", equalTo("Elasticsearch_7.10")) + .body("DomainStatus.ClusterConfig.InstanceType", equalTo("t3.small.search")) + .body("DomainStatus.ClusterConfig.InstanceCount", equalTo(2)); + } + + @Test + @Order(3) + void describeElasticsearchDomain() { + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/" + DOMAIN_NAME) + .then() + .statusCode(200) + .body("DomainStatus.ElasticsearchVersion", equalTo("7.10")) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceType", equalTo("t3.small.elasticsearch")) + .body("DomainStatus.EBSOptions.VolumeSize", equalTo(20)); + } + + @Test + @Order(4) + void describeElasticsearchDomains() { + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"DomainNames\":[\"" + DOMAIN_NAME + "\"]}") + .when() + .post("/2015-01-01/es/domain-info") + .then() + .statusCode(200) + .body("DomainStatusList", hasSize(1)) + .body("DomainStatusList[0].ElasticsearchVersion", equalTo("7.10")) + .body("DomainStatusList[0].ElasticsearchClusterConfig.InstanceCount", equalTo(2)); + } + + @Test + @Order(5) + void listDomainNames() { + given() + .header("Authorization", AUTH_HEADER) + .queryParam("engineType", "Elasticsearch") + .when() + .get("/2015-01-01/domain") + .then() + .statusCode(200) + .body("DomainNames.DomainName", hasItem(DOMAIN_NAME)) + .body("DomainNames.find { it.DomainName == '" + DOMAIN_NAME + "' }.EngineType", + equalTo("Elasticsearch")); + } + + @Test + @Order(6) + void describeElasticsearchDomainConfig() { + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/" + DOMAIN_NAME + "/config") + .then() + .statusCode(200) + .body("DomainConfig.ElasticsearchVersion.Options", equalTo("7.10")) + .body("DomainConfig.ElasticsearchVersion.Status.State", equalTo("Active")) + .body("DomainConfig.ElasticsearchClusterConfig.Options.InstanceCount", equalTo(2)) + .body("DomainConfig", not(hasKey("EngineVersion"))) + .body("DomainConfig", not(hasKey("ClusterConfig"))); + } + + @Test + @Order(7) + void updateElasticsearchDomainConfig() { + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"ElasticsearchClusterConfig\":{\"InstanceType\":\"m5.large.elasticsearch\",\"InstanceCount\":3}}") + .when() + .post("/2015-01-01/es/domain/" + DOMAIN_NAME + "/config") + .then() + .statusCode(200) + .body("DomainConfig.ElasticsearchClusterConfig.Options.InstanceCount", equalTo(3)); + + // The update must reach the store, not just the response. + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/" + DOMAIN_NAME) + .then() + .statusCode(200) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceType", equalTo("m5.large.elasticsearch")) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceCount", equalTo(3)) + .body("DomainStatus.ElasticsearchVersion", equalTo("7.10")); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME) + .then() + .statusCode(200) + .body("DomainStatus.ClusterConfig.InstanceType", equalTo("m5.large.search")); + } + + @Test + @Order(8) + void addListRemoveTags() { + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"ARN\":\"" + arn + "\",\"TagList\":[{\"Key\":\"env\",\"Value\":\"test\"},{\"Key\":\"owner\",\"Value\":\"team\"}]}") + .when() + .post("/2015-01-01/tags") + .then() + .statusCode(200); + + given() + .header("Authorization", AUTH_HEADER) + .queryParam("arn", arn) + .when() + .get("/2015-01-01/tags/") + .then() + .statusCode(200) + .body("TagList.Key", containsInAnyOrder("env", "owner")); + + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"ARN\":\"" + arn + "\",\"TagKeys\":[\"owner\"]}") + .when() + .post("/2015-01-01/tags-removal") + .then() + .statusCode(200); + + given() + .header("Authorization", AUTH_HEADER) + .queryParam("arn", arn) + .when() + .get("/2015-01-01/tags/") + .then() + .statusCode(200) + .body("TagList.Key", contains("env")); + } + + @Test + @Order(9) + void createWithoutVersionIsElasticsearch() { + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"DomainName\":\"legacy-es-default\"}") + .when() + .post("/2015-01-01/es/domain") + .then() + .statusCode(200) + .body("DomainStatus.ElasticsearchVersion", equalTo("7.10")) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceType", equalTo("m5.large.elasticsearch")); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/legacy-es-default/config") + .then() + .statusCode(200) + .body("DomainConfig.ElasticsearchClusterConfig.Options.InstanceType", equalTo("m5.large.elasticsearch")); + + // A domain created with no cluster or EBS block accepts a first update of either. + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"ElasticsearchClusterConfig\":{\"InstanceCount\":2},\"EBSOptions\":{\"EBSEnabled\":true,\"VolumeSize\":30}}") + .when() + .post("/2015-01-01/es/domain/legacy-es-default/config") + .then() + .statusCode(200); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/legacy-es-default") + .then() + .statusCode(200) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceCount", equalTo(2)) + .body("DomainStatus.EBSOptions.VolumeSize", equalTo(30)); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .delete("/2015-01-01/es/domain/legacy-es-default") + .then() + .statusCode(200); + } + + @Test + @Order(10) + void shortOpenSearchVersion() { + // ElasticsearchVersionString accepts ^OS_[0-9]{1,2}\.[0-9]{1,2}$ alongside OpenSearch_X.Y. + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"DomainName\":\"legacy-es-os\",\"ElasticsearchVersion\":\"OS_2.11\"," + + "\"ElasticsearchClusterConfig\":{\"InstanceType\":\"r6g.large.elasticsearch\"}}") + .when() + .post("/2015-01-01/es/domain") + .then() + .statusCode(200) + .body("DomainStatus.ElasticsearchVersion", equalTo("OpenSearch_2.11")) + .body("DomainStatus.ElasticsearchClusterConfig.InstanceType", equalTo("r6g.large.elasticsearch")); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2021-01-01/opensearch/domain/legacy-es-os") + .then() + .statusCode(200) + .body("DomainStatus.EngineVersion", equalTo("OpenSearch_2.11")) + .body("DomainStatus.ClusterConfig.InstanceType", equalTo("r6g.large.search")); + + given() + .header("Authorization", AUTH_HEADER) + .queryParam("engineType", "OpenSearch") + .when() + .get("/2015-01-01/domain") + .then() + .statusCode(200) + .body("DomainNames.DomainName", hasItem("legacy-es-os")); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .delete("/2015-01-01/es/domain/legacy-es-os") + .then() + .statusCode(200); + } + + @Test + @Order(11) + void blankVersionIsRejected() { + // ElasticsearchVersionString: ^[0-9]{1}\\.[0-9]{1,2}$|^OpenSearch_...$|^OS_...$ -- "" matches none. + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("{\"DomainName\":\"legacy-es-blank\",\"ElasticsearchVersion\":\"\"}") + .when() + .post("/2015-01-01/es/domain") + .then() + .statusCode(400) + .body("__type", containsString("ValidationException")); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/legacy-es-blank") + .then() + .statusCode(409); + } + + @Test + @Order(12) + void emptyBodiesAreValidationErrors() { + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("") + .when() + .post("/2015-01-01/es/domain") + .then() + .statusCode(400); + + given() + .contentType("application/json") + .header("Authorization", AUTH_HEADER) + .body("") + .when() + .post("/2015-01-01/es/domain/" + DOMAIN_NAME + "/config") + .then() + .statusCode(lessThan(500)); + } + + @Test + @Order(13) + void deleteElasticsearchDomain() { + given() + .header("Authorization", AUTH_HEADER) + .when() + .delete("/2015-01-01/es/domain/" + DOMAIN_NAME) + .then() + .statusCode(200) + .body("DomainStatus.Deleted", equalTo(true)) + .body("DomainStatus.ElasticsearchVersion", equalTo("7.10")); + + given() + .header("Authorization", AUTH_HEADER) + .when() + .get("/2015-01-01/es/domain/" + DOMAIN_NAME) + .then() + .statusCode(409); + } +}