Light, fluffy, and always free - The AWS Local Emulator alternative
feat: add opensearch service emulation (#85) (#132)
Hector Ventura68b8ed883a45
diff --git a/README.md b/README.mdindex 19d7aeb513..f7f6194ff3 100644--- a/README.md+++ b/README.md@@ -52,7 +52,7 @@| KMS (sign, verify, re-encrypt) | ✅ | ⚠️ Partial || Native binary | ✅ ~40 MB | ❌ |-**24 services. 408/408 SDK tests passing. Free forever.**+**25 services. 408/408 SDK tests passing. Free forever.**## Architecture Overview@@ -64,7 +64,7 @@ flowchart LRRouter["HTTP Router\n(JAX-RS / Vert.x)"]subgraph Stateless ["Stateless Services"]- A["SSM · SQS · SNS\nIAM · STS · KMS\nSecrets Manager · SES\nCognito · Kinesis\nEventBridge · CloudWatch\nStep Functions · CloudFormation\nACM · API Gateway"]+ A["SSM · SQS · SNS\nIAM · STS · KMS\nSecrets Manager · SES\nCognito · Kinesis · OpenSearch\nEventBridge · CloudWatch\nStep Functions · CloudFormation\nACM · API Gateway"]endsubgraph Stateful ["Stateful Services"]@@ -114,6 +114,7 @@ flowchart LR| **RDS** | 14 | **Real Docker containers** | PostgreSQL & MySQL, IAM auth, JDBC-compatible || **ACM** | 8 | In-process | Certificate issuance, validation lifecycle || **SES** | 14 | In-process | Send email / raw email, identity verification, DKIM attributes |+| **OpenSearch** | 24 | In-process | Domain CRUD, tags, versions, instance types, upgrade stubs |> **Lambda, ElastiCache, and RDS** spin up real Docker containers and support IAM authentication and SigV4 request signing — the same auth flow as production AWS.diff --git a/docs/configuration/application-yml.md b/docs/configuration/application-yml.mdindex e4256d5ff2..62bf4ca997 100644--- a/docs/configuration/application-yml.md+++ b/docs/configuration/application-yml.md@@ -40,6 +40,8 @@ floci:flush-interval-ms: 5000secretsmanager:flush-interval-ms: 5000+ opensearch:+ flush-interval-ms: 5000 # inherits global storage modeservices:ssm:@@ -121,6 +123,20 @@ floci:cloudformation:enabled: true++ acm:+ enabled: true+ validation-wait-seconds: 0 # Seconds before transitioning PENDING_VALIDATION → ISSUED++ ses:+ enabled: true++ opensearch:+ enabled: true+ mode: mock # mock | real+ default-image: "opensearchproject/opensearch:2"+ proxy-base-port: 9400+ proxy-max-port: 9499```## Service Limitsdiff --git a/docs/configuration/storage.md b/docs/configuration/storage.mdindex 8b9a54c8f4..044c0738ac 100644--- a/docs/configuration/storage.md+++ b/docs/configuration/storage.md@@ -62,6 +62,8 @@ Override the global mode for individual services via environment variables. When| `FLOCI_STORAGE_SERVICES_SECRETSMANAGER_FLUSH_INTERVAL_MS` | `5000` | Secrets Manager flush interval (ms) || `FLOCI_STORAGE_SERVICES_ACM_MODE` | global default | ACM storage mode || `FLOCI_STORAGE_SERVICES_ACM_FLUSH_INTERVAL_MS` | `5000` | ACM flush interval (ms) |+| `FLOCI_STORAGE_SERVICES_OPENSEARCH_MODE` | global default | OpenSearch storage mode |+| `FLOCI_STORAGE_SERVICES_OPENSEARCH_FLUSH_INTERVAL_MS` | `5000` | OpenSearch flush interval (ms) |## Environment Variable Overridediff --git a/docs/services/index.md b/docs/services/index.mdindex abaa1f1147..4db52f435a 100644--- a/docs/services/index.md+++ b/docs/services/index.md@@ -1,6 +1,6 @@# Services Overview-Floci emulates 21+ AWS services on a single port (`4566`). All services use the real AWS wire protocol — your existing AWS CLI commands and SDK clients work without modification.+Floci emulates 25 AWS services on a single port (`4566`). All services use the real AWS wire protocol — your existing AWS CLI commands and SDK clients work without modification.## Service Matrix@@ -29,6 +29,8 @@ Floci emulates 21+ AWS services on a single port (`4566`). All services use the| [CloudWatch Logs](cloudwatch.md) | `POST /` + `X-Amz-Target: Logs.*` | JSON 1.1 | 14 || [CloudWatch Metrics](cloudwatch.md#metrics) | `POST /` with `Action=` or JSON 1.1 | Query / JSON | 8 || [ACM](acm.md) | `POST /` + `X-Amz-Target: CertificateManager.*` | JSON 1.1 | 12 |+| [SES](ses.md) | `POST /` with `Action=` param | Query | 14 |+| [OpenSearch](opensearch.md) | `/2021-01-01/opensearch/...` | REST JSON | 24 |## Common Setupdiff --git a/docs/services/opensearch.md b/docs/services/opensearch.mdnew file mode 100644index 0000000000..8d33aca819--- /dev/null+++ b/docs/services/opensearch.md@@ -0,0 +1,215 @@+# OpenSearch Service++**Protocol:** REST JSON+**Endpoint:** `http://localhost:4566/2021-01-01/...`+**Credential scope:** `es`++## Implementation Mode++OpenSearch supports two implementation modes controlled by `FLOCI_SERVICES_OPENSEARCH_MODE`:++| Mode | Behaviour |+|---|---|+| `mock` *(default)* | Management API only. Domains are stored in the configured StorageBackend and appear `ACTIVE` immediately. No real search capability. |+| `real` | *(v2, coming soon)* Spins up a real OpenSearch Docker container per domain and proxies data-plane requests to it. |++## Supported Operations++### Domain Lifecycle++| Operation | Method + Path | Description |+|---|---|---|+| `CreateDomain` | `POST /2021-01-01/opensearch/domain` | Create a new domain |+| `DescribeDomain` | `GET /2021-01-01/opensearch/domain/{name}` | Get domain details |+| `DescribeDomains` | `POST /2021-01-01/opensearch/domain-info` | Batch describe domains |+| `DescribeDomainConfig` | `GET /2021-01-01/opensearch/domain/{name}/config` | Get domain configuration |+| `UpdateDomainConfig` | `POST /2021-01-01/opensearch/domain/{name}/config` | Update cluster config, EBS options, engine version |+| `DeleteDomain` | `DELETE /2021-01-01/opensearch/domain/{name}` | Delete a domain |+| `ListDomainNames` | `GET /2021-01-01/domain` | List all domains (supports `?engineType=` filter) |++### Tags++| Operation | Method + Path | Description |+|---|---|---|+| `AddTags` | `POST /2021-01-01/tags` | Add tags to a domain by ARN |+| `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 |++### Versions & Instance Types++| Operation | Method + Path | Description |+|---|---|---|+| `ListVersions` | `GET /2021-01-01/opensearch/versions` | List supported engine versions |+| `GetCompatibleVersions` | `GET /2021-01-01/opensearch/compatibleVersions` | List valid upgrade paths |+| `ListInstanceTypeDetails` | `GET /2021-01-01/opensearch/instanceTypeDetails/{version}` | List available instance types |+| `DescribeInstanceTypeLimits` | `GET /2021-01-01/opensearch/instanceTypeLimits/{version}/{type}` | Get limits for an instance type |++### Stubs (SDK-compatible, no-op responses)++| Operation | Notes |+|---|---|+| `DescribeDomainChangeProgress` | Returns empty `ChangeProgressStatus` |+| `DescribeDomainAutoTunes` | Returns empty `AutoTunes` list |+| `DescribeDryRunProgress` | Returns empty `DryRunProgressStatus` |+| `DescribeDomainHealth` | Returns `ClusterHealth: Green` |+| `GetUpgradeHistory` | Returns empty list |+| `GetUpgradeStatus` | Returns `StepStatus: SUCCEEDED` |+| `UpgradeDomain` | Stores new engine version, returns immediately |+| `CancelDomainConfigChange` | Returns empty `CancelledChangeIds` |+| `StartServiceSoftwareUpdate` | Returns no-op `ServiceSoftwareOptions` |+| `CancelServiceSoftwareUpdate` | Returns no-op `ServiceSoftwareOptions` |++## Configuration++```yaml title="application.yml"+floci:+ services:+ opensearch:+ enabled: true+ mode: mock # mock | real (real is v2, not yet available)+ default-image: "opensearchproject/opensearch:2" # used only when mode=real+ proxy-base-port: 9400 # port range for real-mode containers+ proxy-max-port: 9499++ storage:+ services:+ opensearch:+ flush-interval-ms: 5000 # flush interval when using hybrid/wal storage+```++### Environment Variables++| Variable | Default | Description |+|---|---|---|+| `FLOCI_SERVICES_OPENSEARCH_ENABLED` | `true` | Enable/disable the service |+| `FLOCI_SERVICES_OPENSEARCH_MODE` | `mock` | `mock` or `real` |+| `FLOCI_SERVICES_OPENSEARCH_DEFAULT_IMAGE` | `opensearchproject/opensearch:2` | Docker image for `real` mode |+| `FLOCI_SERVICES_OPENSEARCH_PROXY_BASE_PORT` | `9400` | Port range start for `real` mode |+| `FLOCI_SERVICES_OPENSEARCH_PROXY_MAX_PORT` | `9499` | Port range end for `real` mode |+| `FLOCI_STORAGE_SERVICES_OPENSEARCH_MODE` | *(global default)* | Storage mode override |+| `FLOCI_STORAGE_SERVICES_OPENSEARCH_FLUSH_INTERVAL_MS` | `5000` | Flush interval (ms) |++## Emulation Behaviour++- **Domain name validation:** 3–28 characters, must start with a lowercase letter, only lowercase letters, digits, and hyphens.+- **ARN format:** `arn:aws:es:{region}:{accountId}:domain/{domainName}`+- **Domain ID format:** `{accountId}/{domainName}`+- **Processing:** Always `false` in `mock` mode — domains are `ACTIVE` immediately.+- **Engine version default:** `OpenSearch_2.11`+- **Cluster defaults:** `m5.large.search`, 1 instance, EBS enabled with 10 GiB `gp2` volume.++## Examples++```bash+export AWS_ENDPOINT_URL=http://localhost:4566+export AWS_DEFAULT_REGION=us-east-1+export AWS_ACCESS_KEY_ID=test+export AWS_SECRET_ACCESS_KEY=test++# Create a domain+aws opensearch create-domain \+ --domain-name my-search \+ --engine-version "OpenSearch_2.11" \+ --cluster-config InstanceType=m5.large.search,InstanceCount=1 \+ --ebs-options EBSEnabled=true,VolumeType=gp2,VolumeSize=10++# Describe the domain+aws opensearch describe-domain --domain-name my-search++# List all domains+aws opensearch list-domain-names++# Update cluster config+aws opensearch update-domain-config \+ --domain-name my-search \+ --cluster-config InstanceCount=3++# Add tags+aws opensearch add-tags \+ --arn arn:aws:es:us-east-1:000000000000:domain/my-search \+ --tag-list Key=env,Value=dev++# List tags+aws opensearch list-tags \+ --arn arn:aws:es:us-east-1:000000000000:domain/my-search++# Delete domain+aws opensearch delete-domain --domain-name my-search+```++## SDK Example (Java)++```java+OpenSearchClient os = OpenSearchClient.builder()+ .endpointOverride(URI.create("http://localhost:4566"))+ .region(Region.US_EAST_1)+ .credentialsProvider(StaticCredentialsProvider.create(+ AwsBasicCredentials.create("test", "test")))+ .build();++// Create a domain+CreateDomainResponse created = os.createDomain(req -> req+ .domainName("my-search")+ .engineVersion("OpenSearch_2.11")+ .clusterConfig(c -> c+ .instanceType(OpenSearchPartitionInstanceType.M5_LARGE_SEARCH)+ .instanceCount(1))+ .ebsOptions(e -> e+ .ebsEnabled(true)+ .volumeType(VolumeType.GP2)+ .volumeSize(10)));++System.out.println("ARN: " + created.domainStatus().arn());++// Describe the domain+DescribeDomainResponse desc = os.describeDomain(req -> req+ .domainName("my-search"));++System.out.println("Version: " + desc.domainStatus().engineVersion());++// List domains+os.listDomainNames(req -> req.build())+ .domainNames()+ .forEach(d -> System.out.println(d.domainName()));++// Delete+os.deleteDomain(req -> req.domainName("my-search"));+```++## SDK Example (Python)++```python+import boto3++os_client = boto3.client(+ "opensearch",+ endpoint_url="http://localhost:4566",+ region_name="us-east-1",+ aws_access_key_id="test",+ aws_secret_access_key="test"+)++# Create a domain+response = os_client.create_domain(+ DomainName="my-search",+ EngineVersion="OpenSearch_2.11",+ ClusterConfig={"InstanceType": "m5.large.search", "InstanceCount": 1},+ EBSOptions={"EBSEnabled": True, "VolumeType": "gp2", "VolumeSize": 10}+)+print(response["DomainStatus"]["ARN"])++# List domains+domains = os_client.list_domain_names()+for d in domains["DomainNames"]:+ print(d["DomainName"])++# Delete+os_client.delete_domain(DomainName="my-search")+```++## Limitations (v1)++- No real search capability in `mock` mode — data-plane endpoints (`/_search`, `/_index`, etc.) are not proxied.+- No Elasticsearch-compatible endpoints (`/2015-01-01/es/domain/...`).+- VPC options, fine-grained access control, encryption-at-rest, and cross-cluster connections are accepted in the request but silently ignored.+- All 41 "not applicable" operations (VPC endpoints, reserved instances, packages, applications, data sources) return `UnsupportedOperationException`.diff --git a/mkdocs.yml b/mkdocs.ymlindex 1cbc49f9d7..e4b6a9b08f 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -85,4 +85,6 @@ nav:- RDS: services/rds.md- EventBridge: services/eventbridge.md- CloudWatch: services/cloudwatch.md+ - ACM: services/acm.md+ - OpenSearch: services/opensearch.md- Contributing: contributing.md\ No newline at end of filediff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex 9fa01285ca..f3e8de4e42 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -72,6 +72,7 @@ public interface EmulatorConfig {CloudWatchMetricsStorageConfig cloudwatchmetrics();SecretsManagerStorageConfig secretsmanager();AcmStorageConfig acm();+ OpenSearchStorageConfig opensearch();}interface SsmStorageConfig {@@ -138,6 +139,13 @@ public interface EmulatorConfig {long flushIntervalMs();}+ interface OpenSearchStorageConfig {+ Optional<String> mode();++ @WithDefault("5000")+ long flushIntervalMs();+ }+interface WalConfig {@WithDefault("30000")long compactionIntervalMs();@@ -178,6 +186,7 @@ public interface EmulatorConfig {CloudFormationServiceConfig cloudformation();AcmServiceConfig acm();SesServiceConfig ses();+ OpenSearchServiceConfig opensearch();}interface SsmServiceConfig {@@ -337,6 +346,25 @@ public interface EmulatorConfig {boolean enabled();}+ interface OpenSearchServiceConfig {+ @WithDefault("true")+ boolean enabled();++ @WithDefault("mock")+ String mode();++ @WithDefault("opensearchproject/opensearch:2")+ String defaultImage();++ @WithDefault("9400")+ int proxyBasePort();++ @WithDefault("9499")+ int proxyMaxPort();++ Optional<String> dockerNetwork();+ }+interface LambdaServiceConfig {@WithDefault("true")boolean enabled();diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ServiceRegistry.java b/src/main/java/io/github/hectorvent/floci/core/common/ServiceRegistry.javaindex 9fd075f94a..5da4e28fe8 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/ServiceRegistry.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/ServiceRegistry.java@@ -47,6 +47,7 @@ public class ServiceRegistry {case "cloudformation" -> config.services().cloudformation().enabled();case "acm" -> config.services().acm().enabled();case "email" -> config.services().ses().enabled();+ case "es" -> config.services().opensearch().enabled();default -> true;};}@@ -75,6 +76,7 @@ public class ServiceRegistry {if (config.services().cloudformation().enabled()) enabled.add("cloudformation");if (config.services().acm().enabled()) enabled.add("acm");if (config.services().ses().enabled()) enabled.add("email");+ if (config.services().opensearch().enabled()) enabled.add("es");return enabled;}diff --git a/src/main/java/io/github/hectorvent/floci/core/storage/StorageFactory.java b/src/main/java/io/github/hectorvent/floci/core/storage/StorageFactory.javaindex c245e3eb01..151f6b513f 100644--- a/src/main/java/io/github/hectorvent/floci/core/storage/StorageFactory.java+++ b/src/main/java/io/github/hectorvent/floci/core/storage/StorageFactory.java@@ -109,6 +109,7 @@ public class StorageFactory {case "cloudwatchlogs" -> config.storage().services().cloudwatchlogs().mode().orElse(globalMode);case "cloudwatchmetrics" -> config.storage().services().cloudwatchmetrics().mode().orElse(globalMode);case "secretsmanager" -> config.storage().services().secretsmanager().mode().orElse(globalMode);+ case "opensearch" -> config.storage().services().opensearch().mode().orElse(globalMode);default -> globalMode;};}@@ -122,6 +123,7 @@ public class StorageFactory {case "cloudwatchlogs" -> config.storage().services().cloudwatchlogs().flushIntervalMs();case "cloudwatchmetrics" -> config.storage().services().cloudwatchmetrics().flushIntervalMs();case "secretsmanager" -> config.storage().services().secretsmanager().flushIntervalMs();+ case "opensearch" -> config.storage().services().opensearch().flushIntervalMs();default -> 5000L;};}diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchController.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchController.javanew file mode 100644index 0000000000..153abc23de--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchController.java@@ -0,0 +1,556 @@+package io.github.hectorvent.floci.services.opensearch;++import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.common.RegionResolver;+import io.github.hectorvent.floci.services.opensearch.model.ClusterConfig;+import io.github.hectorvent.floci.services.opensearch.model.Domain;+import io.github.hectorvent.floci.services.opensearch.model.EbsOptions;+import com.fasterxml.jackson.databind.JsonNode;+import com.fasterxml.jackson.databind.ObjectMapper;+import com.fasterxml.jackson.databind.node.ArrayNode;+import com.fasterxml.jackson.databind.node.ObjectNode;+import jakarta.inject.Inject;+import jakarta.ws.rs.*;+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 org.jboss.logging.Logger;++import java.io.IOException;+import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++@Path("/2021-01-01")+@Produces(MediaType.APPLICATION_JSON)+@Consumes(MediaType.APPLICATION_JSON)+public class OpenSearchController {++ private static final Logger LOG = Logger.getLogger(OpenSearchController.class);++ private static final List<String> SUPPORTED_VERSIONS = List.of(+ "OpenSearch_2.13", "OpenSearch_2.11", "OpenSearch_2.9", "OpenSearch_2.7",+ "OpenSearch_2.5", "OpenSearch_2.3", "OpenSearch_1.3", "OpenSearch_1.2",+ "Elasticsearch_7.10", "Elasticsearch_7.9", "Elasticsearch_7.8"+ );++ private static final List<String> INSTANCE_TYPES = List.of(+ "t3.small.search", "t3.medium.search",+ "m5.large.search", "m5.xlarge.search", "m5.2xlarge.search",+ "r5.large.search", "r5.xlarge.search", "r5.2xlarge.search",+ "c5.large.search", "c5.xlarge.search", "c5.2xlarge.search"+ );++ private final OpenSearchService service;+ private final RegionResolver regionResolver;+ private final ObjectMapper objectMapper;++ @Inject+ public OpenSearchController(OpenSearchService service, RegionResolver regionResolver,+ ObjectMapper objectMapper) {+ this.service = service;+ this.regionResolver = regionResolver;+ this.objectMapper = objectMapper;+ }++ @POST+ @Path("/opensearch/domain")+ public Response createDomain(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode req = objectMapper.readTree(body);+ String domainName = req.path("DomainName").asText(null);+ String engineVersion = req.path("EngineVersion").asText(null);+ ClusterConfig clusterConfig = parseClusterConfig(req.path("ClusterConfig"));+ EbsOptions ebsOptions = parseEbsOptions(req.path("EBSOptions"));+ Map<String, String> tags = parseTags(req.path("TagList"));++ Domain domain = service.createDomain(domainName, engineVersion, clusterConfig,+ ebsOptions, tags, region);++ ObjectNode response = objectMapper.createObjectNode();+ response.set("DomainStatus", toDomainStatusNode(domain));+ return Response.ok(response).build();+ } catch (AwsException e) {+ throw e;+ } catch (IOException e) {+ throw new AwsException("ValidationException", e.getMessage(), 400);+ }+ }++ @GET+ @Path("/opensearch/domain/{domainName}")+ public Response describeDomain(@Context HttpHeaders headers,+ @PathParam("domainName") String domainName) {+ Domain domain = service.describeDomain(domainName);+ ObjectNode response = objectMapper.createObjectNode();+ response.set("DomainStatus", toDomainStatusNode(domain));+ return Response.ok(response).build();+ }++ @POST+ @Path("/opensearch/domain-info")+ public Response describeDomains(@Context HttpHeaders headers, String body) {+ try {+ JsonNode req = objectMapper.readTree(body);+ List<String> names = new ArrayList<>();+ req.path("DomainNames").forEach(n -> names.add(n.asText()));+ List<Domain> domains = service.describeDomains(names);++ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode list = response.putArray("DomainStatusList");+ domains.forEach(d -> list.add(toDomainStatusNode(d)));+ return Response.ok(response).build();+ } catch (AwsException e) {+ throw e;+ } catch (IOException e) {+ throw new AwsException("ValidationException", e.getMessage(), 400);+ }+ }++ @GET+ @Path("/domain")+ public Response listDomainNames(@Context HttpHeaders headers,+ @QueryParam("engineType") String engineType) {+ List<Domain> domains = service.listDomainNames(engineType);+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode list = response.putArray("DomainNames");+ for (Domain d : domains) {+ ObjectNode entry = objectMapper.createObjectNode();+ entry.put("DomainName", d.getDomainName());+ String ev = d.getEngineVersion();+ entry.put("EngineType", (ev != null && ev.startsWith("Elasticsearch")) ? "Elasticsearch" : "OpenSearch");+ list.add(entry);+ }+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/domain/{domainName}/config")+ public Response describeDomainConfig(@Context HttpHeaders headers,+ @PathParam("domainName") String domainName) {+ Domain domain = service.describeDomain(domainName);+ long epochSeconds = domain.getCreatedAt() != null ? domain.getCreatedAt().getEpochSecond() : 0;++ ObjectNode response = objectMapper.createObjectNode();+ ObjectNode domainConfig = response.putObject("DomainConfig");++ ObjectNode clusterSection = domainConfig.putObject("ClusterConfig");+ clusterSection.set("Options", toClusterConfigNode(domain.getClusterConfig()));+ clusterSection.set("Status", configStatusNode(epochSeconds));++ ObjectNode ebsSection = domainConfig.putObject("EBSOptions");+ ebsSection.set("Options", toEbsOptionsNode(domain.getEbsOptions()));+ ebsSection.set("Status", configStatusNode(epochSeconds));++ ObjectNode versionSection = domainConfig.putObject("EngineVersion");+ versionSection.put("Options", domain.getEngineVersion());+ versionSection.set("Status", configStatusNode(epochSeconds));++ return Response.ok(response).build();+ }++ @POST+ @Path("/opensearch/domain/{domainName}/config")+ public Response updateDomainConfig(@Context HttpHeaders headers,+ @PathParam("domainName") String domainName,+ String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode req = objectMapper.readTree(body);+ String engineVersion = req.path("EngineVersion").asText(null);+ ClusterConfig clusterConfig = parseClusterConfig(req.path("ClusterConfig"));+ EbsOptions ebsOptions = parseEbsOptions(req.path("EBSOptions"));++ Domain domain = service.updateDomainConfig(domainName, engineVersion, clusterConfig,+ ebsOptions, region);++ long epochSeconds = domain.getCreatedAt() != null ? domain.getCreatedAt().getEpochSecond() : 0;+ ObjectNode response = objectMapper.createObjectNode();+ ObjectNode domainConfig = response.putObject("DomainConfig");++ ObjectNode clusterSection = domainConfig.putObject("ClusterConfig");+ clusterSection.set("Options", toClusterConfigNode(domain.getClusterConfig()));+ clusterSection.set("Status", configStatusNode(epochSeconds));++ ObjectNode ebsSection = domainConfig.putObject("EBSOptions");+ ebsSection.set("Options", toEbsOptionsNode(domain.getEbsOptions()));+ ebsSection.set("Status", configStatusNode(epochSeconds));++ ObjectNode versionSection = domainConfig.putObject("EngineVersion");+ versionSection.put("Options", domain.getEngineVersion());+ versionSection.set("Status", configStatusNode(epochSeconds));++ return Response.ok(response).build();+ } catch (AwsException e) {+ throw e;+ } catch (IOException e) {+ throw new AwsException("ValidationException", e.getMessage(), 400);+ }+ }++ @DELETE+ @Path("/opensearch/domain/{domainName}")+ public Response deleteDomain(@Context HttpHeaders headers,+ @PathParam("domainName") String domainName) {+ Domain domain = service.deleteDomain(domainName);+ ObjectNode response = objectMapper.createObjectNode();+ response.set("DomainStatus", toDomainStatusNode(domain));+ return Response.ok(response).build();+ }++ // ── Tags ─────────────────────────────────────────────────────────────────++ @POST+ @Path("/tags")+ public Response addTags(@Context HttpHeaders headers, String body) {+ try {+ JsonNode req = objectMapper.readTree(body);+ String arn = req.path("ARN").asText(null);+ if (arn == null || arn.isBlank()) {+ throw new AwsException("ValidationException", "ARN is required.", 400);+ }+ Map<String, String> tags = parseTags(req.path("TagList"));+ service.addTags(arn, tags);+ return Response.ok("{}").build();+ } catch (AwsException e) {+ throw e;+ } catch (IOException e) {+ throw new AwsException("ValidationException", e.getMessage(), 400);+ }+ }++ @GET+ @Path("/tags/")+ public Response listTags(@Context HttpHeaders headers, @QueryParam("arn") String arn) {+ if (arn == null || arn.isBlank()) {+ throw new AwsException("ValidationException", "ARN query parameter is required.", 400);+ }+ Map<String, String> tags = service.listTags(arn);+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode tagList = response.putArray("TagList");+ tags.forEach((k, v) -> {+ ObjectNode tag = objectMapper.createObjectNode();+ tag.put("Key", k);+ tag.put("Value", v);+ tagList.add(tag);+ });+ return Response.ok(response).build();+ }++ @POST+ @Path("/tags-removal")+ public Response removeTags(@Context HttpHeaders headers, String body) {+ try {+ JsonNode req = objectMapper.readTree(body);+ String arn = req.path("ARN").asText(null);+ if (arn == null || arn.isBlank()) {+ throw new AwsException("ValidationException", "ARN is required.", 400);+ }+ List<String> tagKeys = new ArrayList<>();+ req.path("TagKeys").forEach(n -> tagKeys.add(n.asText()));+ service.removeTags(arn, tagKeys);+ return Response.ok("{}").build();+ } catch (AwsException e) {+ throw e;+ } catch (IOException e) {+ throw new AwsException("ValidationException", e.getMessage(), 400);+ }+ }++ @GET+ @Path("/opensearch/versions")+ public Response listVersions(@Context HttpHeaders headers) {+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode versions = response.putArray("Versions");+ SUPPORTED_VERSIONS.forEach(versions::add);+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/compatibleVersions")+ public Response getCompatibleVersions(@Context HttpHeaders headers,+ @QueryParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode compatibleVersions = response.putArray("CompatibleVersions");++ ObjectNode entry = objectMapper.createObjectNode();+ entry.put("SourceVersion", "OpenSearch_2.9");+ ArrayNode targets = entry.putArray("TargetVersions");+ targets.add("OpenSearch_2.11");+ targets.add("OpenSearch_2.13");+ compatibleVersions.add(entry);++ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/instanceTypeDetails/{engineVersion}")+ public Response listInstanceTypeDetails(@Context HttpHeaders headers,+ @PathParam("engineVersion") String engineVersion) {+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode details = response.putArray("InstanceTypeDetails");+ for (String instanceType : INSTANCE_TYPES) {+ ObjectNode detail = objectMapper.createObjectNode();+ detail.put("InstanceType", instanceType);+ detail.put("EncryptionEnabled", true);+ detail.put("CognitoEnabled", false);+ detail.put("AppLogsEnabled", true);+ detail.put("AdvancedSecurityEnabled", false);+ ArrayNode roles = detail.putArray("InstanceRole");+ roles.add("Data");+ details.add(detail);+ }+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/instanceTypeLimits/{engineVersion}/{instanceType}")+ public Response describeInstanceTypeLimits(@Context HttpHeaders headers,+ @PathParam("engineVersion") String engineVersion,+ @PathParam("instanceType") String instanceType) {+ ObjectNode response = objectMapper.createObjectNode();+ ObjectNode limitsByRole = response.putObject("LimitsByRole");+ ObjectNode dataRole = limitsByRole.putObject("data");++ ArrayNode storageTypes = dataRole.putArray("StorageTypes");+ ObjectNode storageType = objectMapper.createObjectNode();+ storageType.put("StorageTypeName", "ebs");+ storageType.put("StorageSubTypeName", "standard");+ ArrayNode storageTypeLimits = storageType.putArray("StorageTypeLimits");+ ObjectNode minLimit = objectMapper.createObjectNode();+ minLimit.put("LimitName", "MinimumVolumeSize");+ minLimit.putArray("LimitValues").add("10");+ storageTypeLimits.add(minLimit);+ ObjectNode maxLimit = objectMapper.createObjectNode();+ maxLimit.put("LimitName", "MaximumVolumeSize");+ maxLimit.putArray("LimitValues").add("3584");+ storageTypeLimits.add(maxLimit);+ storageTypes.add(storageType);++ ObjectNode instanceLimits = dataRole.putObject("InstanceLimits");+ ObjectNode instanceCountLimits = instanceLimits.putObject("InstanceCountLimits");+ instanceCountLimits.put("MinimumInstanceCount", 1);+ instanceCountLimits.put("MaximumInstanceCount", 20);++ dataRole.putArray("AdditionalLimits");++ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/domain/{domainName}/progress")+ public Response describeDomainChangeProgress(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.putObject("ChangeProgressStatus");+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/domain/{domainName}/autoTunes")+ public Response describeDomainAutoTunes(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.putArray("AutoTunes");+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/domain/{domainName}/dryRun")+ public Response describeDryRunProgress(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.putObject("DryRunProgressStatus");+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/domain/{domainName}/health")+ public Response describeDomainHealth(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.put("ClusterHealth", "Green");+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/upgradeDomain/{domainName}/history")+ public Response getUpgradeHistory(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.putArray("UpgradeHistories");+ return Response.ok(response).build();+ }++ @GET+ @Path("/opensearch/upgradeDomain/{domainName}/status")+ public Response getUpgradeStatus(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.put("UpgradeStep", "UPGRADE");+ response.put("StepStatus", "SUCCEEDED");+ response.put("UpgradeName", "");+ return Response.ok(response).build();+ }++ @POST+ @Path("/opensearch/upgradeDomain")+ public Response upgradeDomain(String body) {+ try {+ JsonNode req = objectMapper.readTree(body);+ String domainName = req.path("DomainName").asText(null);+ String targetVersion = req.path("TargetVersion").asText(null);+ Domain domain = service.upgradeDomain(domainName, targetVersion);++ ObjectNode response = objectMapper.createObjectNode();+ response.put("DomainName", domain.getDomainName());+ response.put("TargetVersion", domain.getEngineVersion());+ response.put("PerformCheckOnly", false);+ return Response.ok(response).build();+ } catch (AwsException e) {+ throw e;+ } catch (IOException e) {+ throw new AwsException("ValidationException", e.getMessage(), 400);+ }+ }++ @POST+ @Path("/opensearch/domain/{domainName}/config/cancel")+ public Response cancelDomainConfigChange(@PathParam("domainName") String domainName) {+ ObjectNode response = objectMapper.createObjectNode();+ response.put("DryRun", false);+ response.putArray("CancelledChangeIds");+ return Response.ok(response).build();+ }++ @POST+ @Path("/opensearch/serviceSoftwareUpdate/start")+ public Response startServiceSoftwareUpdate(String body) {+ ObjectNode response = objectMapper.createObjectNode();+ ObjectNode options = response.putObject("ServiceSoftwareOptions");+ options.put("UpdateAvailable", false);+ options.put("Cancellable", false);+ options.put("UpdateStatus", "COMPLETED");+ options.put("Description", "There is no software update available for this domain.");+ options.put("AutomatedUpdateDate", 0);+ options.put("OptionalDeployment", false);+ return Response.ok(response).build();+ }++ @POST+ @Path("/opensearch/serviceSoftwareUpdate/cancel")+ public Response cancelServiceSoftwareUpdate(String body) {+ ObjectNode response = objectMapper.createObjectNode();+ ObjectNode options = response.putObject("ServiceSoftwareOptions");+ options.put("UpdateAvailable", false);+ options.put("Cancellable", false);+ options.put("UpdateStatus", "COMPLETED");+ options.put("Description", "There is no software update available for this domain.");+ options.put("AutomatedUpdateDate", 0);+ options.put("OptionalDeployment", false);+ return Response.ok(response).build();+ }++ // ── Helpers ───────────────────────────────────────────────────────────────++ private ObjectNode toDomainStatusNode(Domain domain) {+ ObjectNode node = objectMapper.createObjectNode();+ node.put("ARN", domain.getArn());+ node.put("DomainId", domain.getDomainId());+ node.put("DomainName", domain.getDomainName());+ node.put("EngineVersion", domain.getEngineVersion());+ node.put("Processing", domain.isProcessing());+ node.put("Deleted", domain.isDeleted());+ node.put("Endpoint", domain.getEndpoint() != null ? domain.getEndpoint() : "");+ node.set("ClusterConfig", toClusterConfigNode(domain.getClusterConfig()));+ node.set("EBSOptions", toEbsOptionsNode(domain.getEbsOptions()));+ return node;+ }++ private ObjectNode toClusterConfigNode(ClusterConfig cc) {+ ObjectNode node = objectMapper.createObjectNode();+ if (cc == null) {+ node.put("InstanceType", "m5.large.search");+ node.put("InstanceCount", 1);+ node.put("DedicatedMasterEnabled", false);+ node.put("ZoneAwarenessEnabled", false);+ } else {+ node.put("InstanceType", cc.getInstanceType());+ node.put("InstanceCount", cc.getInstanceCount());+ node.put("DedicatedMasterEnabled", cc.isDedicatedMasterEnabled());+ node.put("ZoneAwarenessEnabled", cc.isZoneAwarenessEnabled());+ }+ return node;+ }++ private ObjectNode toEbsOptionsNode(EbsOptions ebs) {+ ObjectNode node = objectMapper.createObjectNode();+ if (ebs == null) {+ node.put("EBSEnabled", true);+ node.put("VolumeType", "gp2");+ node.put("VolumeSize", 10);+ } else {+ node.put("EBSEnabled", ebs.isEbsEnabled());+ node.put("VolumeType", ebs.getVolumeType());+ node.put("VolumeSize", ebs.getVolumeSize());+ }+ return node;+ }++ private ObjectNode configStatusNode(long epochSeconds) {+ ObjectNode status = objectMapper.createObjectNode();+ status.put("CreationDate", epochSeconds);+ status.put("UpdateDate", epochSeconds);+ status.put("State", "Active");+ return status;+ }++ private ClusterConfig parseClusterConfig(JsonNode node) {+ if (node == null || node.isMissingNode() || node.isNull()) {+ return null;+ }+ ClusterConfig cc = new ClusterConfig();+ if (node.has("InstanceType")) {+ cc.setInstanceType(node.get("InstanceType").asText());+ }+ if (node.has("InstanceCount")) {+ cc.setInstanceCount(node.get("InstanceCount").asInt());+ }+ if (node.has("DedicatedMasterEnabled")) {+ cc.setDedicatedMasterEnabled(node.get("DedicatedMasterEnabled").asBoolean());+ }+ if (node.has("ZoneAwarenessEnabled")) {+ cc.setZoneAwarenessEnabled(node.get("ZoneAwarenessEnabled").asBoolean());+ }+ return cc;+ }++ private EbsOptions parseEbsOptions(JsonNode node) {+ if (node == null || node.isMissingNode() || node.isNull()) {+ return null;+ }+ EbsOptions ebs = new EbsOptions();+ if (node.has("EBSEnabled")) {+ ebs.setEbsEnabled(node.get("EBSEnabled").asBoolean());+ }+ if (node.has("VolumeType")) {+ ebs.setVolumeType(node.get("VolumeType").asText());+ }+ if (node.has("VolumeSize")) {+ ebs.setVolumeSize(node.get("VolumeSize").asInt());+ }+ return ebs;+ }++ private Map<String, String> parseTags(JsonNode node) {+ Map<String, String> tags = new HashMap<>();+ if (node == null || node.isMissingNode() || node.isNull()) {+ return tags;+ }+ node.forEach(tag -> {+ String key = tag.path("Key").asText(null);+ String value = tag.path("Value").asText(null);+ if (key != null && value != null) {+ tags.put(key, value);+ }+ });+ return tags;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.javanew file mode 100644index 0000000000..6755784494--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java@@ -0,0 +1,190 @@+package io.github.hectorvent.floci.services.opensearch;++import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.storage.StorageBackend;+import io.github.hectorvent.floci.core.storage.StorageFactory;+import io.github.hectorvent.floci.services.opensearch.model.ClusterConfig;+import io.github.hectorvent.floci.services.opensearch.model.Domain;+import io.github.hectorvent.floci.services.opensearch.model.EbsOptions;+import com.fasterxml.jackson.core.type.TypeReference;+import jakarta.enterprise.context.ApplicationScoped;+import jakarta.inject.Inject;+import org.jboss.logging.Logger;++import java.time.Instant;+import java.util.List;+import java.util.Map;++@ApplicationScoped+public class OpenSearchService {++ private static final Logger LOG = Logger.getLogger(OpenSearchService.class);++ private static final String DEFAULT_ENGINE_VERSION = "OpenSearch_2.11";++ private final StorageBackend<String, Domain> domainStore;+ private final EmulatorConfig config;++ @Inject+ public OpenSearchService(StorageFactory storageFactory, EmulatorConfig config) {+ this.domainStore = storageFactory.create("opensearch", "opensearch-domains.json",+ new TypeReference<Map<String, Domain>>() {});+ this.config = config;+ }++ OpenSearchService(StorageBackend<String, Domain> domainStore, EmulatorConfig config) {+ this.domainStore = domainStore;+ this.config = config;+ }++ public Domain createDomain(String domainName, String engineVersion, ClusterConfig clusterConfig,+ EbsOptions ebsOptions, Map<String, String> tags, String region) {+ validateDomainName(domainName);++ if (domainStore.get(domainName).isPresent()) {+ throw new AwsException("ResourceAlreadyExistsException",+ "Domain with name " + domainName + " already exists.", 409);+ }++ String accountId = config.defaultAccountId();+ Domain domain = new Domain();+ domain.setDomainName(domainName);+ domain.setDomainId(accountId + "/" + domainName);+ domain.setArn("arn:aws:es:" + region + ":" + accountId + ":domain/" + domainName);+ domain.setEngineVersion(engineVersion != null ? engineVersion : DEFAULT_ENGINE_VERSION);+ domain.setProcessing(false);+ domain.setDeleted(false);+ domain.setEndpoint("");+ domain.setCreatedAt(Instant.now());++ if (clusterConfig != null) {+ domain.setClusterConfig(clusterConfig);+ }+ if (ebsOptions != null) {+ domain.setEbsOptions(ebsOptions);+ }+ if (tags != null) {+ domain.setTags(tags);+ }++ domainStore.put(domainName, domain);+ LOG.infov("Created OpenSearch domain: {0}", domainName);+ return domain;+ }++ public Domain describeDomain(String domainName) {+ return domainStore.get(domainName)+ .orElseThrow(() -> new AwsException("ResourceNotFoundException",+ "Domain not found: " + domainName, 409));+ }++ public List<Domain> describeDomains(List<String> domainNames) {+ return domainNames.stream()+ .map(name -> domainStore.get(name)+ .orElseThrow(() -> new AwsException("ResourceNotFoundException",+ "Domain not found: " + name, 409)))+ .toList();+ }++ public List<Domain> listDomainNames(String engineType) {+ return domainStore.scan(k -> true).stream()+ .filter(d -> !d.isDeleted())+ .filter(d -> engineType == null || engineType.isBlank()+ || matchesEngineType(d.getEngineVersion(), engineType))+ .toList();+ }++ public Domain updateDomainConfig(String domainName, String engineVersion,+ ClusterConfig clusterConfig, EbsOptions ebsOptions,+ String region) {+ Domain domain = describeDomain(domainName);++ if (engineVersion != null && !engineVersion.isBlank()) {+ domain.setEngineVersion(engineVersion);+ }+ if (clusterConfig != null) {+ ClusterConfig existing = domain.getClusterConfig();+ if (clusterConfig.getInstanceType() != null) {+ existing.setInstanceType(clusterConfig.getInstanceType());+ }+ if (clusterConfig.getInstanceCount() > 0) {+ existing.setInstanceCount(clusterConfig.getInstanceCount());+ }+ existing.setDedicatedMasterEnabled(clusterConfig.isDedicatedMasterEnabled());+ existing.setZoneAwarenessEnabled(clusterConfig.isZoneAwarenessEnabled());+ }+ if (ebsOptions != null) {+ EbsOptions existing = domain.getEbsOptions();+ existing.setEbsEnabled(ebsOptions.isEbsEnabled());+ if (ebsOptions.getVolumeType() != null) {+ existing.setVolumeType(ebsOptions.getVolumeType());+ }+ if (ebsOptions.getVolumeSize() > 0) {+ existing.setVolumeSize(ebsOptions.getVolumeSize());+ }+ }++ domainStore.put(domainName, domain);+ return domain;+ }++ public Domain deleteDomain(String domainName) {+ Domain domain = describeDomain(domainName);+ domain.setDeleted(true);+ domainStore.delete(domainName);+ LOG.infov("Deleted OpenSearch domain: {0}", domainName);+ return domain;+ }++ public void addTags(String arn, Map<String, String> tags) {+ Domain domain = findByArn(arn);+ domain.getTags().putAll(tags);+ domainStore.put(domain.getDomainName(), domain);+ }++ public Map<String, String> listTags(String arn) {+ return findByArn(arn).getTags();+ }++ public void removeTags(String arn, List<String> tagKeys) {+ Domain domain = findByArn(arn);+ tagKeys.forEach(domain.getTags()::remove);+ domainStore.put(domain.getDomainName(), domain);+ }++ public Domain upgradeDomain(String domainName, String targetVersion) {+ Domain domain = describeDomain(domainName);+ if (targetVersion != null && !targetVersion.isBlank()) {+ domain.setEngineVersion(targetVersion);+ domainStore.put(domainName, domain);+ }+ return domain;+ }++ private Domain findByArn(String arn) {+ return domainStore.scan(k -> true).stream()+ .filter(d -> arn.equals(d.getArn()))+ .findFirst()+ .orElseThrow(() -> new AwsException("ResourceNotFoundException",+ "Domain not found for ARN: " + arn, 409));+ }++ private void validateDomainName(String name) {+ if (name == null || name.length() < 3 || name.length() > 28) {+ throw new AwsException("ValidationException",+ "Domain name must be between 3 and 28 characters.", 400);+ }+ if (!name.matches("[a-z][a-z0-9\\-]*")) {+ throw new AwsException("ValidationException",+ "Domain name must start with a lowercase letter and contain only lowercase letters, numbers, and hyphens.", 400);+ }+ }++ private boolean matchesEngineType(String engineVersion, String engineType) {+ if ("Elasticsearch".equalsIgnoreCase(engineType)) {+ return engineVersion != null && engineVersion.startsWith("Elasticsearch");+ }+ return engineVersion == null || engineVersion.startsWith("OpenSearch");+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/model/ClusterConfig.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/ClusterConfig.javanew file mode 100644index 0000000000..9ba6fb71c1--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/ClusterConfig.java@@ -0,0 +1,56 @@+package io.github.hectorvent.floci.services.opensearch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonProperty;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+public class ClusterConfig {++ @JsonProperty("InstanceType")+ private String instanceType = "m5.large.search";++ @JsonProperty("InstanceCount")+ private int instanceCount = 1;++ @JsonProperty("DedicatedMasterEnabled")+ private boolean dedicatedMasterEnabled = false;++ @JsonProperty("ZoneAwarenessEnabled")+ private boolean zoneAwarenessEnabled = false;++ public ClusterConfig() {}++ public String getInstanceType() {+ return instanceType;+ }++ public void setInstanceType(String instanceType) {+ this.instanceType = instanceType;+ }++ public int getInstanceCount() {+ return instanceCount;+ }++ public void setInstanceCount(int instanceCount) {+ this.instanceCount = instanceCount;+ }++ public boolean isDedicatedMasterEnabled() {+ return dedicatedMasterEnabled;+ }++ public void setDedicatedMasterEnabled(boolean dedicatedMasterEnabled) {+ this.dedicatedMasterEnabled = dedicatedMasterEnabled;+ }++ public boolean isZoneAwarenessEnabled() {+ return zoneAwarenessEnabled;+ }++ public void setZoneAwarenessEnabled(boolean zoneAwarenessEnabled) {+ this.zoneAwarenessEnabled = zoneAwarenessEnabled;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/model/Domain.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/Domain.javanew file mode 100644index 0000000000..e3ffba6497--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/Domain.java@@ -0,0 +1,137 @@+package io.github.hectorvent.floci.services.opensearch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonProperty;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.time.Instant;+import java.util.HashMap;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+public class Domain {++ @JsonProperty("DomainName")+ private String domainName;++ @JsonProperty("DomainId")+ private String domainId;++ @JsonProperty("ARN")+ private String arn;++ @JsonProperty("EngineVersion")+ private String engineVersion = "OpenSearch_2.11";++ @JsonProperty("Processing")+ private boolean processing = false;++ @JsonProperty("Deleted")+ private boolean deleted = false;++ @JsonProperty("ClusterConfig")+ private ClusterConfig clusterConfig = new ClusterConfig();++ @JsonProperty("EBSOptions")+ private EbsOptions ebsOptions = new EbsOptions();++ @JsonProperty("Endpoint")+ private String endpoint = "";++ @JsonProperty("Tags")+ private Map<String, String> tags = new HashMap<>();++ @JsonProperty("CreatedAt")+ private Instant createdAt;++ public Domain() {}++ public String getDomainName() {+ return domainName;+ }++ public void setDomainName(String domainName) {+ this.domainName = domainName;+ }++ public String getDomainId() {+ return domainId;+ }++ public void setDomainId(String domainId) {+ this.domainId = domainId;+ }++ public String getArn() {+ return arn;+ }++ public void setArn(String arn) {+ this.arn = arn;+ }++ public String getEngineVersion() {+ return engineVersion;+ }++ public void setEngineVersion(String engineVersion) {+ this.engineVersion = engineVersion;+ }++ public boolean isProcessing() {+ return processing;+ }++ public void setProcessing(boolean processing) {+ this.processing = processing;+ }++ public boolean isDeleted() {+ return deleted;+ }++ public void setDeleted(boolean deleted) {+ this.deleted = deleted;+ }++ public ClusterConfig getClusterConfig() {+ return clusterConfig;+ }++ public void setClusterConfig(ClusterConfig clusterConfig) {+ this.clusterConfig = clusterConfig;+ }++ public EbsOptions getEbsOptions() {+ return ebsOptions;+ }++ public void setEbsOptions(EbsOptions ebsOptions) {+ this.ebsOptions = ebsOptions;+ }++ public String getEndpoint() {+ return endpoint;+ }++ public void setEndpoint(String endpoint) {+ this.endpoint = endpoint;+ }++ public Map<String, String> getTags() {+ return tags;+ }++ public void setTags(Map<String, String> tags) {+ this.tags = tags != null ? new HashMap<>(tags) : new HashMap<>();+ }++ public Instant getCreatedAt() {+ return createdAt;+ }++ public void setCreatedAt(Instant createdAt) {+ this.createdAt = createdAt;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/model/EbsOptions.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/EbsOptions.javanew file mode 100644index 0000000000..0725b09b08--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/EbsOptions.java@@ -0,0 +1,45 @@+package io.github.hectorvent.floci.services.opensearch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonProperty;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+public class EbsOptions {++ @JsonProperty("EBSEnabled")+ private boolean ebsEnabled = true;++ @JsonProperty("VolumeType")+ private String volumeType = "gp2";++ @JsonProperty("VolumeSize")+ private int volumeSize = 10;++ public EbsOptions() {}++ public boolean isEbsEnabled() {+ return ebsEnabled;+ }++ public void setEbsEnabled(boolean ebsEnabled) {+ this.ebsEnabled = ebsEnabled;+ }++ public String getVolumeType() {+ return volumeType;+ }++ public void setVolumeType(String volumeType) {+ this.volumeType = volumeType;+ }++ public int getVolumeSize() {+ return volumeSize;+ }++ public void setVolumeSize(int volumeSize) {+ this.volumeSize = volumeSize;+ }+}diff --git a/src/main/resources/application.yml b/src/main/resources/application.ymlindex c1d72ca3c3..81f3796472 100644--- a/src/main/resources/application.yml+++ b/src/main/resources/application.yml@@ -45,6 +45,8 @@ floci:flush-interval-ms: 5000acm:flush-interval-ms: 5000+ opensearch:+ flush-interval-ms: 5000auth:validate-signatures: false@@ -117,3 +119,9 @@ floci:validation-wait-seconds: 0ses:enabled: true+ opensearch:+ enabled: true+ mode: mock+ default-image: "opensearchproject/opensearch:2"+ proxy-base-port: 9400+ proxy-max-port: 9499diff --git a/src/test/java/io/github/hectorvent/floci/services/opensearch/OpenSearchIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/opensearch/OpenSearchIntegrationTest.javanew file mode 100644index 0000000000..a59b3fbe3a--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/opensearch/OpenSearchIntegrationTest.java@@ -0,0 +1,413 @@+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.*;++@QuarkusTest+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class OpenSearchIntegrationTest {++ private static final String DOMAIN_NAME = "test-domain";+ private static final String AUTH_HEADER = "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/es/aws4_request";++ // ── Domain CRUD ──────────────────────────────────────────────────────────++ @Test+ @Order(1)+ void createDomain() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"DomainName\":\"" + DOMAIN_NAME + "\",\"EngineVersion\":\"OpenSearch_2.11\"}")+ .when()+ .post("/2021-01-01/opensearch/domain")+ .then()+ .statusCode(200)+ .body("DomainStatus.DomainName", equalTo(DOMAIN_NAME))+ .body("DomainStatus.EngineVersion", equalTo("OpenSearch_2.11"))+ .body("DomainStatus.Processing", equalTo(false))+ .body("DomainStatus.Deleted", equalTo(false))+ .body("DomainStatus.ARN", containsString("arn:aws:es:"))+ .body("DomainStatus.ARN", containsString(DOMAIN_NAME));+ }++ @Test+ @Order(2)+ void createDuplicateDomainFails() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"DomainName\":\"" + DOMAIN_NAME + "\"}")+ .when()+ .post("/2021-01-01/opensearch/domain")+ .then()+ .statusCode(409);+ }++ @Test+ @Order(3)+ void describeDomain() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME)+ .then()+ .statusCode(200)+ .body("DomainStatus.DomainName", equalTo(DOMAIN_NAME))+ .body("DomainStatus.EngineVersion", equalTo("OpenSearch_2.11"))+ .body("DomainStatus.ClusterConfig.InstanceType", equalTo("m5.large.search"))+ .body("DomainStatus.ClusterConfig.InstanceCount", equalTo(1))+ .body("DomainStatus.EBSOptions.EBSEnabled", equalTo(true));+ }++ @Test+ @Order(4)+ void describeDomains() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"DomainNames\":[\"" + DOMAIN_NAME + "\"]}")+ .when()+ .post("/2021-01-01/opensearch/domain-info")+ .then()+ .statusCode(200)+ .body("DomainStatusList", hasSize(1))+ .body("DomainStatusList[0].DomainName", equalTo(DOMAIN_NAME));+ }++ @Test+ @Order(5)+ void listDomainNames() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/domain")+ .then()+ .statusCode(200)+ .body("DomainNames", hasSize(greaterThanOrEqualTo(1)))+ .body("DomainNames.DomainName", hasItem(DOMAIN_NAME));+ }++ @Test+ @Order(6)+ void listDomainNamesFilteredByEngineType() {+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("engineType", "OpenSearch")+ .when()+ .get("/2021-01-01/domain")+ .then()+ .statusCode(200)+ .body("DomainNames.DomainName", hasItem(DOMAIN_NAME));+ }++ @Test+ @Order(7)+ void describeDomainConfig() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/config")+ .then()+ .statusCode(200)+ .body("DomainConfig.ClusterConfig.Options.InstanceType", equalTo("m5.large.search"))+ .body("DomainConfig.ClusterConfig.Status.State", equalTo("Active"))+ .body("DomainConfig.EBSOptions.Options.EBSEnabled", equalTo(true))+ .body("DomainConfig.EngineVersion.Options", equalTo("OpenSearch_2.11"));+ }++ @Test+ @Order(8)+ void updateDomainConfig() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"ClusterConfig\":{\"InstanceCount\":3}}")+ .when()+ .post("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/config")+ .then()+ .statusCode(200)+ .body("DomainConfig.ClusterConfig.Options.InstanceCount", equalTo(3));+ }++ @Test+ @Order(9)+ void describeNonExistentDomain() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/nonexistent-domain")+ .then()+ .statusCode(409);+ }++ // ── Tags ─────────────────────────────────────────────────────────────────++ @Test+ @Order(10)+ void addTags() {+ String arn = "arn:aws:es:us-east-1:000000000000:domain/" + DOMAIN_NAME;+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"ARN\":\"" + arn + "\",\"TagList\":[{\"Key\":\"env\",\"Value\":\"test\"},{\"Key\":\"owner\",\"Value\":\"team\"}]}")+ .when()+ .post("/2021-01-01/tags")+ .then()+ .statusCode(200);+ }++ @Test+ @Order(11)+ void listTags() {+ String arn = "arn:aws:es:us-east-1:000000000000:domain/" + DOMAIN_NAME;+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("arn", arn)+ .when()+ .get("/2021-01-01/tags/")+ .then()+ .statusCode(200)+ .body("TagList.Key", hasItem("env"))+ .body("TagList.Key", hasItem("owner"));+ }++ @Test+ @Order(12)+ void removeTags() {+ String arn = "arn:aws:es:us-east-1:000000000000:domain/" + DOMAIN_NAME;+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"ARN\":\"" + arn + "\",\"TagKeys\":[\"owner\"]}")+ .when()+ .post("/2021-01-01/tags-removal")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("arn", arn)+ .when()+ .get("/2021-01-01/tags/")+ .then()+ .statusCode(200)+ .body("TagList.Key", not(hasItem("owner")))+ .body("TagList.Key", hasItem("env"));+ }++ // ── Versions & Instance Types ─────────────────────────────────────────────++ @Test+ @Order(13)+ void listVersions() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/versions")+ .then()+ .statusCode(200)+ .body("Versions", not(empty()))+ .body("Versions", hasItem("OpenSearch_2.11"));+ }++ @Test+ @Order(14)+ void getCompatibleVersions() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/compatibleVersions")+ .then()+ .statusCode(200)+ .body("CompatibleVersions", not(empty()));+ }++ @Test+ @Order(15)+ void listInstanceTypeDetails() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/instanceTypeDetails/OpenSearch_2.11")+ .then()+ .statusCode(200)+ .body("InstanceTypeDetails", not(empty()));+ }++ @Test+ @Order(16)+ void describeInstanceTypeLimits() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/instanceTypeLimits/OpenSearch_2.11/m5.large.search")+ .then()+ .statusCode(200)+ .body("LimitsByRole", notNullValue());+ }++ // ── Stubs ─────────────────────────────────────────────────────────────────++ @Test+ @Order(17)+ void describeDomainChangeProgress() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/progress")+ .then()+ .statusCode(200)+ .body("ChangeProgressStatus", notNullValue());+ }++ @Test+ @Order(18)+ void describeDomainAutoTunes() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/autoTunes")+ .then()+ .statusCode(200)+ .body("AutoTunes", empty());+ }++ @Test+ @Order(19)+ void describeDryRunProgress() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/dryRun")+ .then()+ .statusCode(200)+ .body("DryRunProgressStatus", notNullValue());+ }++ @Test+ @Order(20)+ void describeDomainHealth() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/health")+ .then()+ .statusCode(200)+ .body("ClusterHealth", equalTo("Green"));+ }++ @Test+ @Order(21)+ void getUpgradeHistory() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/upgradeDomain/" + DOMAIN_NAME + "/history")+ .then()+ .statusCode(200)+ .body("UpgradeHistories", empty());+ }++ @Test+ @Order(22)+ void getUpgradeStatus() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/2021-01-01/opensearch/upgradeDomain/" + DOMAIN_NAME + "/status")+ .then()+ .statusCode(200)+ .body("UpgradeStep", equalTo("UPGRADE"))+ .body("StepStatus", equalTo("SUCCEEDED"));+ }++ @Test+ @Order(23)+ void upgradeDomain() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"DomainName\":\"" + DOMAIN_NAME + "\",\"TargetVersion\":\"OpenSearch_2.13\"}")+ .when()+ .post("/2021-01-01/opensearch/upgradeDomain")+ .then()+ .statusCode(200)+ .body("DomainName", equalTo(DOMAIN_NAME))+ .body("TargetVersion", equalTo("OpenSearch_2.13"));+ }++ @Test+ @Order(24)+ void cancelDomainConfigChange() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{}")+ .when()+ .post("/2021-01-01/opensearch/domain/" + DOMAIN_NAME + "/config/cancel")+ .then()+ .statusCode(200)+ .body("CancelledChangeIds", empty());+ }++ @Test+ @Order(25)+ void startServiceSoftwareUpdate() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"DomainName\":\"" + DOMAIN_NAME + "\"}")+ .when()+ .post("/2021-01-01/opensearch/serviceSoftwareUpdate/start")+ .then()+ .statusCode(200)+ .body("ServiceSoftwareOptions.UpdateStatus", equalTo("COMPLETED"));+ }++ @Test+ @Order(26)+ void cancelServiceSoftwareUpdate() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("{\"DomainName\":\"" + DOMAIN_NAME + "\"}")+ .when()+ .post("/2021-01-01/opensearch/serviceSoftwareUpdate/cancel")+ .then()+ .statusCode(200)+ .body("ServiceSoftwareOptions.UpdateStatus", equalTo("COMPLETED"));+ }++ // ── Cleanup ───────────────────────────────────────────────────────────────++ @Test+ @Order(30)+ void deleteDomain() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .delete("/2021-01-01/opensearch/domain/" + DOMAIN_NAME)+ .then()+ .statusCode(200)+ .body("DomainStatus.DomainName", equalTo(DOMAIN_NAME))+ .body("DomainStatus.Deleted", equalTo(true));+ }++ @Test+ @Order(31)+ void deleteNonExistentDomain() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .delete("/2021-01-01/opensearch/domain/" + DOMAIN_NAME)+ .then()+ .statusCode(409);+ }+}diff --git a/src/test/resources/application.yml b/src/test/resources/application.ymlindex 04f74b11f0..da8aa02549 100644--- a/src/test/resources/application.yml+++ b/src/test/resources/application.yml@@ -29,6 +29,8 @@ floci:flush-interval-ms: 60000secretsmanager:flush-interval-ms: 60000+ opensearch:+ flush-interval-ms: 60000auth:validate-signatures: false@@ -92,3 +94,6 @@ floci:enabled: truecloudformation:enabled: true+ opensearch:+ enabled: true+ mode: mock\ No newline at end of file