mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(opensearch): report an endpoint for a domain with no container behind it (#4284)
* fix(opensearch): report an endpoint for a domain with no container behind it A domain reports Processing false as soon as it is created, but Endpoint stays blank whenever there is no container: the service is mocked, or the container could not be started. SDK waiters poll DescribeDomain until the domain is active and names an endpoint, so neither exit is ever reached and a create hangs until the caller's own deadline instead of failing. Both paths now synthesize an AWS-shaped endpoint, search-<domain>-<suffix>.<region>.es.amazonaws.com, with the suffix derived from the domain name so it survives a restart. The container path is unchanged. * docs(opensearch): say which cases the synthesized endpoint covers The javadoc claimed SDK waiters poll DescribeDomain until the domain names an endpoint. botocore ships no waiters for opensearch or es, and Terraform's create wait only checks that Endpoint is non-nil, which "" already satisfies. It also claimed the fallback covers a container that could not be started. tryStartDomain rethrows whenever Docker is reachable, so it returns false only when no daemon is reachable at all. Both now say what they actually cover: mock mode and an unreachable Docker daemon, reporting an AWS-shaped endpoint in place of a blank one. The test's class comment carried the same two claims. * fix(opensearch): take the synthesized endpoint's DNS suffix from the partition The endpoint hardcoded .es.amazonaws.com, so a cn or gov region reported a commercial hostname. AwsRegions.dnsSuffixFor resolves it from the region, which is what the partition-literals gate asks for. theEndpointTakesItsDnsSuffixFromThePartition creates a domain in cn-north-1 and asserts the endpoint ends in .amazonaws.com.cn.
This commit is contained in:
1 parent
ec40bcf5f4
commit
db07c56704
2 files changed
+111
No files matched your search
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
@@ -149,10 +150,12 @@ public class OpenSearchService implements ResourceProvider {
|
||||
|
||||
if (config.services().opensearch().mock()) {
|
||||
domain.setProcessing(false);
|
||||
domain.setEndpoint(synthesizedEndpoint(domainName, region));
|
||||
} else {
|
||||
domain.setProcessing(true);
|
||||
if (!domainManager.tryStartDomain(domain)) {
|
||||
domain.setProcessing(false);
|
||||
domain.setEndpoint(synthesizedEndpoint(domainName, region));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +164,24 @@ public class OpenSearchService implements ResourceProvider {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* The endpoint reported for a domain with no container behind it. Two cases reach this: the
|
||||
* service is mocked, and no Docker daemon is reachable, which is the only condition under which
|
||||
* {@link OpenSearchDomainManager#tryStartDomain} returns false rather than rethrowing.
|
||||
*
|
||||
* <p>It reports an AWS-shaped endpoint in place of a blank one,
|
||||
* {@code search-<domain>-<suffix>.<region>.es.<dnsSuffix>}, taking the DNS suffix from the
|
||||
* region's partition rather than assuming the commercial one, with the name suffix derived from the
|
||||
* domain name so it survives a restart. A domain reporting {@code Processing false} alongside
|
||||
* {@code Endpoint ""} describes a state AWS never returns, and a client that reads the endpoint
|
||||
* to address the domain gets an empty string to connect to.
|
||||
*/
|
||||
private static String synthesizedEndpoint(String domainName, String region) {
|
||||
String suffix = Integer.toHexString(domainName.hashCode() & 0x7fffffff);
|
||||
return "search-" + domainName + "-" + suffix + "." + region + ".es."
|
||||
+ AwsRegions.dnsSuffixFor(region);
|
||||
}
|
||||
|
||||
public Domain describeDomain(String domainName) {
|
||||
return domainStore.get(domainName)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package io.github.hectorvent.floci.services.opensearch;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.emptyString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* A domain that reports itself no longer processing also reports an endpoint.
|
||||
*
|
||||
* <p>Covers the two cases with no container behind the domain: the service is mocked, and no Docker
|
||||
* daemon is reachable. Both once reported {@code Processing false} alongside {@code Endpoint ""},
|
||||
* which AWS never returns, leaving a client that reads the endpoint with an empty string to address.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class OpenSearchDomainEndpointIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/es/aws4_request";
|
||||
private static final String DOMAIN = "endpoint-probe";
|
||||
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.when().delete("/2021-01-01/opensearch/domain/" + DOMAIN);
|
||||
}
|
||||
|
||||
/** The DNS suffix comes from the region's partition, so a China region must not report .com. */
|
||||
@Test
|
||||
void theEndpointTakesItsDnsSuffixFromThePartition() {
|
||||
String domain = "endpoint-cn-probe";
|
||||
try {
|
||||
given()
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/cn-north-1/es/aws4_request")
|
||||
.contentType("application/json")
|
||||
.body("{\"DomainName\":\"" + domain + "\",\"EngineVersion\":\"OpenSearch_2.11\"}")
|
||||
.when()
|
||||
.post("/2021-01-01/opensearch/domain")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DomainStatus.Endpoint", endsWith(".cn-north-1.es.amazonaws.com.cn"));
|
||||
} finally {
|
||||
given().header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/cn-north-1/es/aws4_request")
|
||||
.when().delete("/2021-01-01/opensearch/domain/" + domain);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndDescribeReportAnEndpointBesideProcessingFalse() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body("{\"DomainName\":\"" + DOMAIN + "\",\"EngineVersion\":\"OpenSearch_2.11\"}")
|
||||
.when()
|
||||
.post("/2021-01-01/opensearch/domain")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DomainStatus.Processing", is(false))
|
||||
.body("DomainStatus.Endpoint", not(emptyString()))
|
||||
.body("DomainStatus.Endpoint", startsWith("search-" + DOMAIN + "-"))
|
||||
.body("DomainStatus.Endpoint", endsWith(".us-east-1.es.amazonaws.com"));
|
||||
|
||||
String first = given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/2021-01-01/opensearch/domain/" + DOMAIN)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DomainStatus.Processing", is(false))
|
||||
.body("DomainStatus.Endpoint", not(emptyString()))
|
||||
.extract().path("DomainStatus.Endpoint");
|
||||
|
||||
// The waiter polls, so the value has to be the same every time.
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/2021-01-01/opensearch/domain/" + DOMAIN)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DomainStatus.Endpoint", is(first));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user