diff --git a/docs/services/opensearch.md b/docs/services/opensearch.md index 5bfdfc4a30..e26c1e11ae 100644 --- a/docs/services/opensearch.md +++ b/docs/services/opensearch.md @@ -70,7 +70,7 @@ OpenSearch Service-managed VPC endpoints, which Terraform's `aws_opensearch_vpc_ ### 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`. +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`, for `InstanceType` and `DedicatedMasterType` (`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 | |---|---| @@ -155,6 +155,8 @@ services: - **Elasticsearch 7.1, 7.4 and 7.7 images:** published for amd64 only, so on arm64 hosts Docker runs them under emulation (slower; emulation must be enabled). - **Version validation:** `CreateDomain`, `UpdateDomainConfig`, and `UpgradeDomain` reject unknown engine versions with `ValidationException`. `UpgradeDomain` also rejects targets that aren't reachable from the current version per AWS's documented upgrade matrix. - **Cluster defaults:** `m5.large.search`, 1 instance, EBS enabled with 10 GiB `gp2` volume. +- **Stored settings:** `CreateDomain` and `UpdateDomainConfig` keep, and `DescribeDomain` and `DescribeDomainConfig` report, `ClusterConfig.ZoneAwarenessConfig`, `DedicatedMasterType` and `DedicatedMasterCount`, EBS `Iops` and `Throughput`, `AdvancedOptions`, `IPAddressType`, `OffPeakWindowOptions` and `SoftwareUpdateOptions`. An update changes only the members it gives; `AdvancedOptions` replaces the whole map. None of them changes how the domain's container runs. +- **Defaults for those settings:** a domain created without them reports `IPAddressType` `ipv4`, an empty `AdvancedOptions`, automatic software updates off, and an enabled off-peak window starting at 22:00, as AWS does for a new domain. AWS reads 10:00 P.M. in the Region's local time; Floci keeps no time zone per Region and reports 22:00 UTC. A window enabled without a start time gets the same default. - **Instance type families:** `t3.*` / `m5/m6g/m7g.*` / `r5/r6g/r7g.*` / `c5/c6g/c7g.*` are EBS-backed (3584 GiB max). `i3.*` are local-NVMe instance-store. `or1.*` are S3-backed and surface a much larger volume ceiling on `DescribeInstanceTypeLimits` (8–36 TiB depending on size). Floci still boots one Docker container per domain regardless of family — the metadata fidelity matters for SDK clients that introspect, not for runtime data placement. - **Container identity:** containers are named `floci-aws-opensearch---`, or `floci-aws--opensearch---` when `FLOCI_DOCKER_RESOURCE_NAMESPACE` is set. Account and Region come from the domain's stored ARN and are also recorded in its container labels. Restarts remove older containers by their persisted container ID and preserve the stored volume name. Legacy names that omit account and Region are never removed solely by name, because another domain may own them. - **Container storage:** each domain gets a named Docker volume (`floci-aws-opensearch-{volumeId}`) created automatically. In memory mode the volume is removed on domain delete; in persistent modes it is retained unless `FLOCI_STORAGE_PRUNE_VOLUMES_ON_DELETE=true`. Set `FLOCI_SERVICES_OPENSEARCH_DATA_VOLUME` to choose the storage yourself: an absolute path bind-mounts `///` (a directory on the Docker daemon's host), and any other value is a Docker volume name the domain gets its own `---` volume of. When `FLOCI_DOCKER_RESOURCE_NAMESPACE` is set, the namespace is inserted into both forms, so two namespaced deployments sharing a Docker daemon never converge on one data directory through the same configured base. Linux daemon paths starting with `/` retain Linux path syntax when Floci runs on Windows; native Windows absolute paths retain their native handling. Before a configured bind directory is mounted, a temporary root container using the selected OpenSearch image copies ownership from the image's data directory and grants the owner write access. Only the directory itself is adjusted; existing files retain their ownership and permissions. Preparation failures abort domain startup. Storage named that way is never removed on domain delete, and a volume created when absent carries no Floci label, so neither a floci-scoped volume prune nor a testcontainers run's labelled-children sweep collects it: the operator named it, so its lifecycle is theirs. Legacy host-path mode (`FLOCI_STORAGE_HOST_PERSISTENT_PATH` set to an absolute path) gives each domain its own `/[/]opensearch/floci-aws[-]-opensearch---` directory, so two domains sharing a name across Regions or accounts never share one data directory; a domain whose record predates regional scoping keeps the bare `` directory while it still exists, since that is where its data lives. 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 index 08fa6aa11e..23b8299d6d 100644 --- a/src/main/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchController.java +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/ElasticsearchController.java @@ -20,6 +20,7 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import java.io.IOException; +import java.util.List; /** * Legacy Amazon Elasticsearch Service API ({@code 2015-01-01}), still used by @@ -182,10 +183,12 @@ public class ElasticsearchController { * 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); + // The store keeps no WarmType to respell. + for (String member : List.of("InstanceType", "DedicatedMasterType")) { + String type = cluster.path(member).asText(""); + if (cluster instanceof ObjectNode node && type.endsWith(from)) { + node.put(member, type.substring(0, type.length() - from.length()) + to); + } } } 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.java index 984fc6dd63..02ad9fbbd8 100644 --- a/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchController.java +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchController.java @@ -13,7 +13,9 @@ import io.github.hectorvent.floci.services.opensearch.model.DomainEndpointOption import io.github.hectorvent.floci.services.opensearch.model.EbsOptions; import io.github.hectorvent.floci.services.opensearch.model.EncryptionAtRestOptions; import io.github.hectorvent.floci.services.opensearch.model.NodeToNodeEncryptionOptions; +import io.github.hectorvent.floci.services.opensearch.model.OffPeakWindowOptions; import io.github.hectorvent.floci.services.opensearch.model.OpenSearchVpcEndpoint; +import io.github.hectorvent.floci.services.opensearch.model.SoftwareUpdateOptions; import io.github.hectorvent.floci.services.opensearch.model.VpcOptions; import jakarta.inject.Inject; import jakarta.ws.rs.*; @@ -26,8 +28,10 @@ import org.jboss.logging.Logger; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.UUID; @Path("/2021-01-01") @@ -74,7 +78,11 @@ public class OpenSearchController { parseAdvancedSecurityOptions(req.path("AdvancedSecurityOptions")), parseEncryptionAtRestOptions(req.path("EncryptionAtRestOptions")), parseNodeToNodeEncryptionOptions(req.path("NodeToNodeEncryptionOptions")), - parseDomainEndpointOptions(req.path("DomainEndpointOptions"))); + parseDomainEndpointOptions(req.path("DomainEndpointOptions")), + parseAdvancedOptions(req.path("AdvancedOptions")), + req.path("IPAddressType").asText(null), + parseOffPeakWindowOptions(req.path("OffPeakWindowOptions")), + parseSoftwareUpdateOptions(req.path("SoftwareUpdateOptions"))); Domain domain = service.createDomain(domainName, engineVersion, clusterConfig, ebsOptions, tags, accessPolicies, options, region); @@ -180,7 +188,11 @@ public class OpenSearchController { parseAdvancedSecurityOptions(req.path("AdvancedSecurityOptions")), parseEncryptionAtRestOptions(req.path("EncryptionAtRestOptions")), parseNodeToNodeEncryptionOptions(req.path("NodeToNodeEncryptionOptions")), - parseDomainEndpointOptions(req.path("DomainEndpointOptions"))); + parseDomainEndpointOptions(req.path("DomainEndpointOptions")), + parseAdvancedOptions(req.path("AdvancedOptions")), + req.path("IPAddressType").asText(null), + parseOffPeakWindowOptions(req.path("OffPeakWindowOptions")), + parseSoftwareUpdateOptions(req.path("SoftwareUpdateOptions"))); Domain domain = service.updateDomainConfig(domainName, engineVersion, clusterConfig, ebsOptions, accessPolicies, options, regionResolver.resolveRegion(headers)); @@ -651,6 +663,14 @@ public class OpenSearchController { if (domain.getDomainEndpointOptions() != null) { node.set("DomainEndpointOptions", toDomainEndpointOptionsNode(domain.getDomainEndpointOptions())); } + node.set("AdvancedOptions", toAdvancedOptionsNode(domain)); + node.put("IPAddressType", ipAddressTypeOf(domain)); + if (domain.getOffPeakWindowOptions() != null) { + node.set("OffPeakWindowOptions", toOffPeakWindowNode(domain.getOffPeakWindowOptions())); + } + if (domain.getSoftwareUpdateOptions() != null) { + node.set("SoftwareUpdateOptions", toSoftwareUpdateNode(domain.getSoftwareUpdateOptions())); + } return node; } @@ -691,6 +711,51 @@ public class OpenSearchController { section.set("Options", toDomainEndpointOptionsNode(domain.getDomainEndpointOptions())); section.set("Status", configStatusNode(epochSeconds)); } + ObjectNode advanced = domainConfig.putObject("AdvancedOptions"); + advanced.set("Options", toAdvancedOptionsNode(domain)); + advanced.set("Status", configStatusNode(epochSeconds)); + ObjectNode ipAddressType = domainConfig.putObject("IPAddressType"); + ipAddressType.put("Options", ipAddressTypeOf(domain)); + ipAddressType.set("Status", configStatusNode(epochSeconds)); + if (domain.getOffPeakWindowOptions() != null) { + ObjectNode section = domainConfig.putObject("OffPeakWindowOptions"); + section.set("Options", toOffPeakWindowNode(domain.getOffPeakWindowOptions())); + section.set("Status", configStatusNode(epochSeconds)); + } + if (domain.getSoftwareUpdateOptions() != null) { + ObjectNode section = domainConfig.putObject("SoftwareUpdateOptions"); + section.set("Options", toSoftwareUpdateNode(domain.getSoftwareUpdateOptions())); + section.set("Status", configStatusNode(epochSeconds)); + } + } + + private ObjectNode toAdvancedOptionsNode(Domain domain) { + ObjectNode node = objectMapper.createObjectNode(); + new TreeMap<>(domain.getAdvancedOptions()).forEach(node::put); + return node; + } + + /** Records written before the address type was stored are reported as {@code ipv4}. */ + private static String ipAddressTypeOf(Domain domain) { + return domain.getIpAddressType() != null + ? domain.getIpAddressType() : OpenSearchService.DEFAULT_IP_ADDRESS_TYPE; + } + + private ObjectNode toOffPeakWindowNode(OffPeakWindowOptions offPeak) { + ObjectNode node = objectMapper.createObjectNode(); + node.put("Enabled", Boolean.TRUE.equals(offPeak.getEnabled())); + if (offPeak.getStartHours() != null) { + ObjectNode start = node.putObject("OffPeakWindow").putObject("WindowStartTime"); + start.put("Hours", offPeak.getStartHours()); + start.put("Minutes", offPeak.getStartMinutes() != null ? offPeak.getStartMinutes() : 0L); + } + return node; + } + + private ObjectNode toSoftwareUpdateNode(SoftwareUpdateOptions software) { + ObjectNode node = objectMapper.createObjectNode(); + node.put("AutoSoftwareUpdateEnabled", Boolean.TRUE.equals(software.getAutoSoftwareUpdateEnabled())); + return node; } private ObjectNode toVpcOptionsNode(VpcOptions vpc) { @@ -769,6 +834,15 @@ public class OpenSearchController { node.put("InstanceCount", cc.getInstanceCount()); node.put("DedicatedMasterEnabled", cc.isDedicatedMasterEnabled()); node.put("ZoneAwarenessEnabled", cc.isZoneAwarenessEnabled()); + if (cc.getAvailabilityZoneCount() != null) { + node.putObject("ZoneAwarenessConfig").put("AvailabilityZoneCount", cc.getAvailabilityZoneCount()); + } + if (cc.getDedicatedMasterType() != null) { + node.put("DedicatedMasterType", cc.getDedicatedMasterType()); + } + if (cc.getDedicatedMasterCount() != null) { + node.put("DedicatedMasterCount", cc.getDedicatedMasterCount()); + } } return node; } @@ -783,6 +857,12 @@ public class OpenSearchController { node.put("EBSEnabled", ebs.isEbsEnabled()); node.put("VolumeType", ebs.getVolumeType()); node.put("VolumeSize", ebs.getVolumeSize()); + if (ebs.getIops() != null) { + node.put("Iops", ebs.getIops()); + } + if (ebs.getThroughput() != null) { + node.put("Throughput", ebs.getThroughput()); + } } return node; } @@ -807,6 +887,10 @@ public class OpenSearchController { ? node.get("DedicatedMasterEnabled").asBoolean() : null); cc.setZoneAwarenessEnabled(node.has("ZoneAwarenessEnabled") ? node.get("ZoneAwarenessEnabled").asBoolean() : null); + JsonNode azCount = node.path("ZoneAwarenessConfig").path("AvailabilityZoneCount"); + cc.setAvailabilityZoneCount(azCount.isNumber() ? azCount.asInt() : null); + cc.setDedicatedMasterType(node.has("DedicatedMasterType") ? node.get("DedicatedMasterType").asText() : null); + cc.setDedicatedMasterCount(node.has("DedicatedMasterCount") ? node.get("DedicatedMasterCount").asInt() : null); return cc; } @@ -819,9 +903,40 @@ public class OpenSearchController { ebs.setEbsEnabled(node.has("EBSEnabled") ? node.get("EBSEnabled").asBoolean() : null); ebs.setVolumeType(node.has("VolumeType") ? node.get("VolumeType").asText() : null); ebs.setVolumeSize(node.has("VolumeSize") ? node.get("VolumeSize").asInt() : null); + ebs.setIops(node.has("Iops") ? node.get("Iops").asInt() : null); + ebs.setThroughput(node.has("Throughput") ? node.get("Throughput").asInt() : null); return ebs; } + /** {@code AdvancedOptions} as given; null when the request leaves it out. */ + private static Map parseAdvancedOptions(JsonNode node) { + if (node == null || !node.isObject()) { + return null; + } + Map options = new LinkedHashMap<>(); + node.properties().forEach(entry -> options.put(entry.getKey(), entry.getValue().asText())); + return options; + } + + private static OffPeakWindowOptions parseOffPeakWindowOptions(JsonNode node) { + if (node == null || !node.isObject()) { + return null; + } + JsonNode start = node.path("OffPeakWindow").path("WindowStartTime"); + return new OffPeakWindowOptions( + node.has("Enabled") ? node.get("Enabled").asBoolean() : null, + start.path("Hours").isNumber() ? start.get("Hours").asLong() : null, + start.path("Minutes").isNumber() ? start.get("Minutes").asLong() : null); + } + + private static SoftwareUpdateOptions parseSoftwareUpdateOptions(JsonNode node) { + if (node == null || !node.isObject()) { + return null; + } + return new SoftwareUpdateOptions(node.has("AutoSoftwareUpdateEnabled") + ? node.get("AutoSoftwareUpdateEnabled").asBoolean() : null); + } + private VpcOptions parseVpcOptions(JsonNode node) { if (node == null || node.isMissingNode() || node.isNull()) { return null; 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.java index af87acf18c..7ff8e90e1a 100644 --- a/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java @@ -19,6 +19,8 @@ import io.github.hectorvent.floci.services.opensearch.model.DomainEndpointOption import io.github.hectorvent.floci.services.opensearch.model.EbsOptions; import io.github.hectorvent.floci.services.opensearch.model.EncryptionAtRestOptions; import io.github.hectorvent.floci.services.opensearch.model.NodeToNodeEncryptionOptions; +import io.github.hectorvent.floci.services.opensearch.model.OffPeakWindowOptions; +import io.github.hectorvent.floci.services.opensearch.model.SoftwareUpdateOptions; import io.github.hectorvent.floci.services.opensearch.model.VolumeOwnership; import io.github.hectorvent.floci.services.opensearch.model.VpcOptions; import jakarta.annotation.PostConstruct; @@ -30,6 +32,7 @@ import org.jboss.logging.Logger; import java.security.SecureRandom; import java.time.Instant; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -110,11 +113,31 @@ public class OpenSearchService implements ResourceProvider { AdvancedSecurityOptions advancedSecurityOptions, EncryptionAtRestOptions encryptionAtRestOptions, NodeToNodeEncryptionOptions nodeToNodeEncryptionOptions, - DomainEndpointOptions domainEndpointOptions) { + DomainEndpointOptions domainEndpointOptions, + Map advancedOptions, + String ipAddressType, + OffPeakWindowOptions offPeakWindowOptions, + SoftwareUpdateOptions softwareUpdateOptions) { public static final DomainOptions EMPTY = new DomainOptions(null, null, null, null, null); + + public DomainOptions(VpcOptions vpcOptions, AdvancedSecurityOptions advancedSecurityOptions, + EncryptionAtRestOptions encryptionAtRestOptions, + NodeToNodeEncryptionOptions nodeToNodeEncryptionOptions, + DomainEndpointOptions domainEndpointOptions) { + this(vpcOptions, advancedSecurityOptions, encryptionAtRestOptions, nodeToNodeEncryptionOptions, + domainEndpointOptions, null, null, null, null); + } } + /** AWS's address type for a domain whose request names none. */ + static final String DEFAULT_IP_ADDRESS_TYPE = "ipv4"; + /** + * The start AWS gives an off-peak window the request leaves unset: 10:00 P.M., which AWS + * reads as the Region's local time. Floci keeps no time zone per Region and reports it in UTC. + */ + static final long DEFAULT_OFF_PEAK_START_HOURS = 22; + public Domain createDomain(String domainName, String engineVersion, ClusterConfig clusterConfig, EbsOptions ebsOptions, Map tags, String region) { return createDomain(domainName, engineVersion, clusterConfig, ebsOptions, tags, null, @@ -157,6 +180,7 @@ public class OpenSearchService implements ResourceProvider { domain.setTags(tags); } applyDomainOptions(domain, options); + applyCreateDefaults(domain); String creatingKey = accountId + "/" + storageKey(region, domainName); if (!creating.add(creatingKey)) { @@ -284,6 +308,15 @@ public class OpenSearchService implements ResourceProvider { if (supplied.isZoneAwarenessEnabled() != null) { existing.setZoneAwarenessEnabled(supplied.isZoneAwarenessEnabled()); } + if (supplied.getAvailabilityZoneCount() != null) { + existing.setAvailabilityZoneCount(supplied.getAvailabilityZoneCount()); + } + if (supplied.getDedicatedMasterType() != null) { + existing.setDedicatedMasterType(supplied.getDedicatedMasterType()); + } + if (supplied.getDedicatedMasterCount() != null) { + existing.setDedicatedMasterCount(supplied.getDedicatedMasterCount()); + } } /** Copies only the fields the request supplied (non-null) onto {@code existing}. */ @@ -300,6 +333,12 @@ public class OpenSearchService implements ResourceProvider { if (supplied.getVolumeSize() != null && supplied.getVolumeSize() > 0) { existing.setVolumeSize(supplied.getVolumeSize()); } + if (supplied.getIops() != null) { + existing.setIops(supplied.getIops()); + } + if (supplied.getThroughput() != null) { + existing.setThroughput(supplied.getThroughput()); + } } public Domain deleteDomain(String domainName, String region) { @@ -484,6 +523,55 @@ public class OpenSearchService implements ResourceProvider { if (options.domainEndpointOptions() != null) { domain.setDomainEndpointOptions(options.domainEndpointOptions()); } + if (options.advancedOptions() != null) { + domain.setAdvancedOptions(new HashMap<>(options.advancedOptions())); + } + if (options.ipAddressType() != null) { + domain.setIpAddressType(options.ipAddressType()); + } + if (options.offPeakWindowOptions() != null) { + OffPeakWindowOptions supplied = options.offPeakWindowOptions(); + OffPeakWindowOptions current = domain.getOffPeakWindowOptions() != null + ? domain.getOffPeakWindowOptions() : new OffPeakWindowOptions(); + if (supplied.getEnabled() != null) { + current.setEnabled(supplied.getEnabled()); + } + if (supplied.getStartHours() != null) { + current.setStartHours(supplied.getStartHours()); + current.setStartMinutes(supplied.getStartMinutes() != null ? supplied.getStartMinutes() : 0L); + } + domain.setOffPeakWindowOptions(current); + } + if (options.softwareUpdateOptions() != null + && options.softwareUpdateOptions().getAutoSoftwareUpdateEnabled() != null) { + domain.setSoftwareUpdateOptions(options.softwareUpdateOptions()); + } + } + + /** + * The settings a new domain reports when its request leaves them out, as AWS fills them: an + * {@code ipv4} address type, an enabled off-peak window starting at 10:00 P.M., and automatic + * software updates off. + */ + private static void applyCreateDefaults(Domain domain) { + if (domain.getIpAddressType() == null) { + domain.setIpAddressType(DEFAULT_IP_ADDRESS_TYPE); + } + OffPeakWindowOptions offPeak = domain.getOffPeakWindowOptions(); + if (offPeak == null) { + offPeak = new OffPeakWindowOptions(true, null, null); + domain.setOffPeakWindowOptions(offPeak); + } + if (offPeak.getEnabled() == null) { + offPeak.setEnabled(true); + } + if (offPeak.getStartHours() == null) { + offPeak.setStartHours(DEFAULT_OFF_PEAK_START_HOURS); + offPeak.setStartMinutes(0L); + } + if (domain.getSoftwareUpdateOptions() == null) { + domain.setSoftwareUpdateOptions(new SoftwareUpdateOptions(false)); + } } private boolean matchesEngineType(String engineVersion, String engineType) { 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.java index 45a7211850..f5d4cf9e09 100644 --- 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.java @@ -20,6 +20,16 @@ public class ClusterConfig { @JsonProperty("ZoneAwarenessEnabled") private Boolean zoneAwarenessEnabled = false; + /** {@code ZoneAwarenessConfig.AvailabilityZoneCount}; null when the domain was given none. */ + @JsonProperty("AvailabilityZoneCount") + private Integer availabilityZoneCount; + + @JsonProperty("DedicatedMasterType") + private String dedicatedMasterType; + + @JsonProperty("DedicatedMasterCount") + private Integer dedicatedMasterCount; + public ClusterConfig() {} public String getInstanceType() { @@ -46,6 +56,30 @@ public class ClusterConfig { this.dedicatedMasterEnabled = dedicatedMasterEnabled; } + public Integer getAvailabilityZoneCount() { + return availabilityZoneCount; + } + + public void setAvailabilityZoneCount(Integer availabilityZoneCount) { + this.availabilityZoneCount = availabilityZoneCount; + } + + public String getDedicatedMasterType() { + return dedicatedMasterType; + } + + public void setDedicatedMasterType(String dedicatedMasterType) { + this.dedicatedMasterType = dedicatedMasterType; + } + + public Integer getDedicatedMasterCount() { + return dedicatedMasterCount; + } + + public void setDedicatedMasterCount(Integer dedicatedMasterCount) { + this.dedicatedMasterCount = dedicatedMasterCount; + } + public Boolean isZoneAwarenessEnabled() { return 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.java index 302cc9faa2..98fcd6a23e 100644 --- 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.java @@ -64,6 +64,19 @@ public class Domain { @JsonProperty("DomainEndpointOptions") private DomainEndpointOptions domainEndpointOptions; + @JsonProperty("AdvancedOptions") + private Map advancedOptions = new HashMap<>(); + + /** Null on records written before this field existed; reported as {@code ipv4}. */ + @JsonProperty("IPAddressType") + private String ipAddressType; + + @JsonProperty("OffPeakWindowOptions") + private OffPeakWindowOptions offPeakWindowOptions; + + @JsonProperty("SoftwareUpdateOptions") + private SoftwareUpdateOptions softwareUpdateOptions; + @JsonProperty("Endpoint") private String endpoint = ""; @@ -103,6 +116,38 @@ public class Domain { public Domain() {} + public Map getAdvancedOptions() { + return advancedOptions; + } + + public void setAdvancedOptions(Map advancedOptions) { + this.advancedOptions = advancedOptions != null ? advancedOptions : new HashMap<>(); + } + + public String getIpAddressType() { + return ipAddressType; + } + + public void setIpAddressType(String ipAddressType) { + this.ipAddressType = ipAddressType; + } + + public OffPeakWindowOptions getOffPeakWindowOptions() { + return offPeakWindowOptions; + } + + public void setOffPeakWindowOptions(OffPeakWindowOptions offPeakWindowOptions) { + this.offPeakWindowOptions = offPeakWindowOptions; + } + + public SoftwareUpdateOptions getSoftwareUpdateOptions() { + return softwareUpdateOptions; + } + + public void setSoftwareUpdateOptions(SoftwareUpdateOptions softwareUpdateOptions) { + this.softwareUpdateOptions = softwareUpdateOptions; + } + public String getDomainName() { return domainName; } 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.java index 9650f70941..39f4c939cb 100644 --- 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.java @@ -17,6 +17,12 @@ public class EbsOptions { @JsonProperty("VolumeSize") private Integer volumeSize = 10; + @JsonProperty("Iops") + private Integer iops; + + @JsonProperty("Throughput") + private Integer throughput; + public EbsOptions() {} public Boolean isEbsEnabled() { @@ -35,6 +41,22 @@ public class EbsOptions { this.volumeType = volumeType; } + public Integer getIops() { + return iops; + } + + public void setIops(Integer iops) { + this.iops = iops; + } + + public Integer getThroughput() { + return throughput; + } + + public void setThroughput(Integer throughput) { + this.throughput = throughput; + } + public Integer getVolumeSize() { return volumeSize; } diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/model/OffPeakWindowOptions.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/OffPeakWindowOptions.java new file mode 100644 index 0000000000..2bd38fa839 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/OffPeakWindowOptions.java @@ -0,0 +1,41 @@ +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; + +/** + * A domain's off-peak window: whether it is on, and the UTC time its daily ten-hour window starts. + * The API nests the start as {@code OffPeakWindow.WindowStartTime.Hours/Minutes}; the store keeps + * the two numbers flat. + */ +@RegisterForReflection +@JsonIgnoreProperties(ignoreUnknown = true) +public class OffPeakWindowOptions { + + @JsonProperty("Enabled") + private Boolean enabled; + + @JsonProperty("StartHours") + private Long startHours; + + @JsonProperty("StartMinutes") + private Long startMinutes; + + public OffPeakWindowOptions() {} + + public OffPeakWindowOptions(Boolean enabled, Long startHours, Long startMinutes) { + this.enabled = enabled; + this.startHours = startHours; + this.startMinutes = startMinutes; + } + + public Boolean getEnabled() { return enabled; } + public void setEnabled(Boolean enabled) { this.enabled = enabled; } + + public Long getStartHours() { return startHours; } + public void setStartHours(Long startHours) { this.startHours = startHours; } + + public Long getStartMinutes() { return startMinutes; } + public void setStartMinutes(Long startMinutes) { this.startMinutes = startMinutes; } +} diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/model/SoftwareUpdateOptions.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/SoftwareUpdateOptions.java new file mode 100644 index 0000000000..4a8d776732 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/model/SoftwareUpdateOptions.java @@ -0,0 +1,23 @@ +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; + +/** Whether the domain takes service software updates on its own. */ +@RegisterForReflection +@JsonIgnoreProperties(ignoreUnknown = true) +public class SoftwareUpdateOptions { + + @JsonProperty("AutoSoftwareUpdateEnabled") + private Boolean autoSoftwareUpdateEnabled; + + public SoftwareUpdateOptions() {} + + public SoftwareUpdateOptions(Boolean autoSoftwareUpdateEnabled) { + this.autoSoftwareUpdateEnabled = autoSoftwareUpdateEnabled; + } + + public Boolean getAutoSoftwareUpdateEnabled() { return autoSoftwareUpdateEnabled; } + public void setAutoSoftwareUpdateEnabled(Boolean enabled) { this.autoSoftwareUpdateEnabled = enabled; } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/opensearch/OpenSearchDomainConfigRoundTripIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/opensearch/OpenSearchDomainConfigRoundTripIntegrationTest.java new file mode 100644 index 0000000000..232aedb004 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/opensearch/OpenSearchDomainConfigRoundTripIntegrationTest.java @@ -0,0 +1,105 @@ +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.anEmptyMap; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; + +/** + * The domain settings {@code terraform-aws-modules/opensearch} sets beyond the cluster basics + * survive CreateDomain and UpdateDomainConfig: the zone awareness count, the dedicated master + * type and count, EBS IOPS and throughput, advanced options, the address type, the off-peak + * window and automatic software updates. A domain created without them reports AWS's defaults. + */ +@QuarkusTest +class OpenSearchDomainConfigRoundTripIntegrationTest { + + private static final String AUTH = + "AWS4-HMAC-SHA256 Credential=AKID/20261103/us-east-1/es/aws4_request"; + private static final String DOMAINS = "/2021-01-01/opensearch/domain"; + + @AfterEach + void cleanup() { + for (String name : new String[]{"cfg-full", "cfg-bare"}) { + given().header("Authorization", AUTH).when().delete(DOMAINS + "/" + name); + } + } + + @Test + void theSettingsGivenOnCreateAreReported() { + given().contentType("application/json").header("Authorization", AUTH).body(""" + {"DomainName": "cfg-full", "EngineVersion": "OpenSearch_2.19", + "ClusterConfig": {"InstanceType": "r7g.medium.search", "InstanceCount": 2, + "DedicatedMasterEnabled": false, "DedicatedMasterType": "c7g.large.search", + "DedicatedMasterCount": 3, "ZoneAwarenessEnabled": true, + "ZoneAwarenessConfig": {"AvailabilityZoneCount": 2}}, + "EBSOptions": {"EBSEnabled": true, "VolumeType": "gp3", "VolumeSize": 20, + "Iops": 3000, "Throughput": 250}, + "AdvancedOptions": {"rest.action.multi.allow_explicit_index": "true"}, + "IPAddressType": "ipv4", + "OffPeakWindowOptions": {"Enabled": true}, + "SoftwareUpdateOptions": {"AutoSoftwareUpdateEnabled": true}} + """).when().post(DOMAINS).then().statusCode(200); + + String status = "DomainStatus."; + given().header("Authorization", AUTH).when().get(DOMAINS + "/cfg-full").then().statusCode(200) + .body(status + "ClusterConfig.ZoneAwarenessConfig.AvailabilityZoneCount", equalTo(2)) + .body(status + "ClusterConfig.DedicatedMasterType", equalTo("c7g.large.search")) + .body(status + "ClusterConfig.DedicatedMasterCount", equalTo(3)) + .body(status + "EBSOptions.Iops", equalTo(3000)) + .body(status + "EBSOptions.Throughput", equalTo(250)) + .body(status + "AdvancedOptions.'rest.action.multi.allow_explicit_index'", equalTo("true")) + .body(status + "IPAddressType", equalTo("ipv4")) + .body(status + "OffPeakWindowOptions.Enabled", equalTo(true)) + // A window the request leaves unset starts at 10:00 P.M. + .body(status + "OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Hours", equalTo(22)) + .body(status + "OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Minutes", equalTo(0)) + .body(status + "SoftwareUpdateOptions.AutoSoftwareUpdateEnabled", equalTo(true)); + + String config = "DomainConfig."; + given().header("Authorization", AUTH).when().get(DOMAINS + "/cfg-full/config").then().statusCode(200) + .body(config + "ClusterConfig.Options.ZoneAwarenessConfig.AvailabilityZoneCount", equalTo(2)) + .body(config + "EBSOptions.Options.Throughput", equalTo(250)) + .body(config + "AdvancedOptions.Options.'rest.action.multi.allow_explicit_index'", equalTo("true")) + .body(config + "IPAddressType.Options", equalTo("ipv4")) + .body(config + "OffPeakWindowOptions.Options.Enabled", equalTo(true)) + .body(config + "SoftwareUpdateOptions.Options.AutoSoftwareUpdateEnabled", equalTo(true)) + .body(config + "SoftwareUpdateOptions.Status.State", equalTo("Active")); + } + + @Test + void aDomainCreatedWithoutThemReportsTheDefaultsAndUpdatesChangeThem() { + given().contentType("application/json").header("Authorization", AUTH) + .body("{\"DomainName\": \"cfg-bare\", \"EngineVersion\": \"OpenSearch_2.19\"}") + .when().post(DOMAINS).then().statusCode(200) + .body("DomainStatus.IPAddressType", equalTo("ipv4")) + .body("DomainStatus.AdvancedOptions", anEmptyMap()) + .body("DomainStatus.OffPeakWindowOptions.Enabled", equalTo(true)) + .body("DomainStatus.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Hours", equalTo(22)) + .body("DomainStatus.SoftwareUpdateOptions.AutoSoftwareUpdateEnabled", equalTo(false)) + .body("DomainStatus.ClusterConfig.ZoneAwarenessConfig", nullValue()) + .body("DomainStatus.ClusterConfig.DedicatedMasterType", nullValue()) + .body("DomainStatus.EBSOptions.Iops", nullValue()); + + given().contentType("application/json").header("Authorization", AUTH).body(""" + {"ClusterConfig": {"ZoneAwarenessEnabled": true, "ZoneAwarenessConfig": {"AvailabilityZoneCount": 3}}, + "EBSOptions": {"VolumeType": "gp3", "Iops": 4000}, + "AdvancedOptions": {"indices.query.bool.max_clause_count": "2048"}, + "OffPeakWindowOptions": {"OffPeakWindow": {"WindowStartTime": {"Hours": 3, "Minutes": 30}}}, + "SoftwareUpdateOptions": {"AutoSoftwareUpdateEnabled": true}} + """).when().post(DOMAINS + "/cfg-bare/config").then().statusCode(200); + + given().header("Authorization", AUTH).when().get(DOMAINS + "/cfg-bare").then().statusCode(200) + .body("DomainStatus.ClusterConfig.ZoneAwarenessConfig.AvailabilityZoneCount", equalTo(3)) + .body("DomainStatus.EBSOptions.Iops", equalTo(4000)) + .body("DomainStatus.AdvancedOptions.'indices.query.bool.max_clause_count'", equalTo("2048")) + .body("DomainStatus.OffPeakWindowOptions.Enabled", equalTo(true)) + .body("DomainStatus.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Hours", equalTo(3)) + .body("DomainStatus.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Minutes", equalTo(30)) + .body("DomainStatus.SoftwareUpdateOptions.AutoSoftwareUpdateEnabled", equalTo(true)); + } +}