mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
1 parent
3701d4d041
commit
6e3bdaf9ef
4 files changed
+59
-2
No files matched your search
@@ -92,6 +92,11 @@ class OpenSearchTest {
|
||||
|
||||
assertThat(response.domainStatus().domainName()).isEqualTo(DOMAIN_NAME);
|
||||
domainEndpoint = response.domainStatus().endpoint();
|
||||
assertThat(domainEndpoint).doesNotStartWith("http://").doesNotStartWith("https://");
|
||||
DescribeDomainsResponse bulk = opensearch.describeDomains(DescribeDomainsRequest.builder()
|
||||
.domainNames(DOMAIN_NAME).build());
|
||||
assertThat(bulk.domainStatusList()).singleElement()
|
||||
.satisfies(status -> assertThat(status.endpoint()).isEqualTo(domainEndpoint));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +161,7 @@ class OpenSearchTest {
|
||||
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection)
|
||||
URI.create(domainEndpoint + "/_cluster/health").toURL().openConnection();
|
||||
URI.create("http://" + domainEndpoint + "/_cluster/health").toURL().openConnection();
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
int code = conn.getResponseCode();
|
||||
|
||||
@@ -16,6 +16,8 @@ Domain metadata is stored in-process. No Docker containers are started. Domains
|
||||
|
||||
Floci starts an **OpenSearch** Docker container per domain, choosing the image based on the requested `EngineVersion` (e.g. `OpenSearch_3.6` → `opensearchproject/opensearch:3.6.0`, `Elasticsearch_7.10` → `docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2`). The container is exposed on a host port from the configured range (`9400–9499`). Once `/_cluster/health` returns `green` or `yellow`, the domain transitions to `Created: true` and the `Endpoint` field is populated with the container's address.
|
||||
|
||||
The returned `Endpoint` contains the host and port without a scheme. Use `http://` when connecting to the local data plane.
|
||||
|
||||
OpenSearch 2.12+ requires an initial admin password even when the security plugin is disabled; Floci sets `OPENSEARCH_INITIAL_ADMIN_PASSWORD=FlociAdmin1!` automatically for those versions. The security plugin itself stays disabled.
|
||||
|
||||
!!! note "Docker socket required"
|
||||
|
||||
@@ -636,7 +636,8 @@ public class OpenSearchController {
|
||||
node.put("Created", !domain.isProcessing());
|
||||
node.put("Processing", domain.isProcessing());
|
||||
node.put("Deleted", domain.isDeleted());
|
||||
String endpoint = domain.getEndpoint() != null ? domain.getEndpoint() : "";
|
||||
String endpoint = domain.getEndpoint() != null
|
||||
? domain.getEndpoint().replaceFirst("(?i)^https?://", "") : "";
|
||||
if (domain.getVpcOptions() == null) {
|
||||
node.put("Endpoint", endpoint);
|
||||
} else if (!endpoint.isEmpty()) {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.floci.aws.services.opensearch;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.services.opensearch.model.Domain;
|
||||
import io.floci.aws.services.opensearch.model.VpcOptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class OpenSearchEndpointTest {
|
||||
@Test
|
||||
void allDomainResponsesReturnAnEndpointWithoutItsScheme() {
|
||||
OpenSearchService service = mock(OpenSearchService.class);
|
||||
RegionResolver resolver = mock(RegionResolver.class);
|
||||
when(resolver.resolveRegion(any())).thenReturn("us-east-1");
|
||||
Domain domain = new Domain();
|
||||
when(service.createDomain(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(domain);
|
||||
when(service.describeDomain(anyString(), anyString())).thenReturn(domain);
|
||||
when(service.describeDomains(anyList(), anyString())).thenReturn(List.of(domain));
|
||||
when(service.deleteDomain(anyString(), anyString())).thenReturn(domain);
|
||||
OpenSearchController controller = new OpenSearchController(service, resolver, new ObjectMapper());
|
||||
|
||||
String[][] cases = {{"http://host:9200", "host:9200"}, {"HTTPS://host:443", "host:443"},
|
||||
{"host", "host"}, {"http://[::1]:9200", "[::1]:9200"}, {null, ""}, {"", ""}};
|
||||
for (String[] testCase : cases) {
|
||||
domain.setEndpoint(testCase[0]);
|
||||
JsonNode create = (JsonNode) controller.createDomain(null, "{\"DomainName\":\"test\"}").getEntity();
|
||||
JsonNode describe = (JsonNode) controller.describeDomain(null, "test").getEntity();
|
||||
JsonNode bulk = (JsonNode) controller.describeDomains(null, "{\"DomainNames\":[\"test\"]}").getEntity();
|
||||
JsonNode delete = (JsonNode) controller.deleteDomain(null, "test").getEntity();
|
||||
assertEquals(testCase[1], create.path("DomainStatus").path("Endpoint").asText());
|
||||
assertEquals(testCase[1], describe.path("DomainStatus").path("Endpoint").asText());
|
||||
assertEquals(testCase[1], bulk.path("DomainStatusList").get(0).path("Endpoint").asText());
|
||||
assertEquals(testCase[1], delete.path("DomainStatus").path("Endpoint").asText());
|
||||
assertEquals(testCase[0], domain.getEndpoint());
|
||||
domain.setVpcOptions(new VpcOptions());
|
||||
JsonNode vpc = (JsonNode) controller.describeDomain(null, "test").getEntity();
|
||||
assertEquals(testCase[1], vpc.path("DomainStatus").path("Endpoints").path("vpc").asText());
|
||||
assertEquals(testCase[0], domain.getEndpoint());
|
||||
domain.setVpcOptions(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user