diff --git a/CHANGELOG.md b/CHANGELOG.md index 82b9452222..a17640ea09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Make ChildrenAggregate as a SingleBucketAggregate ([#306](https://github.com/opensearch-project/opensearch-java/pull/306)) +- Fix /_nodes/stats, /_nodes/info throwing serialization error ([#315](https://github.com/opensearch-project/opensearch-java/pull/315)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/PluginStats.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/PluginStats.java index 0aca1805c0..9f9cbdc20c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/PluginStats.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/PluginStats.java @@ -69,10 +69,6 @@ public class PluginStats implements JsonpSerializable { private final String version; - private final boolean licensed; - - private final String type; - // --------------------------------------------------------------------------------------------- private PluginStats(Builder builder) { @@ -87,8 +83,6 @@ private PluginStats(Builder builder) { this.javaVersion = ApiTypeHelper.requireNonNull(builder.javaVersion, this, "javaVersion"); this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); this.version = ApiTypeHelper.requireNonNull(builder.version, this, "version"); - this.licensed = ApiTypeHelper.requireNonNull(builder.licensed, this, "licensed"); - this.type = ApiTypeHelper.requireNonNull(builder.type, this, "type"); } @@ -152,20 +146,6 @@ public final String version() { return this.version; } - /** - * Required - API name: {@code licensed} - */ - public final boolean licensed() { - return this.licensed; - } - - /** - * Required - API name: {@code type} - */ - public final String type() { - return this.type; - } - /** * Serialize this object to JSON. */ @@ -207,13 +187,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("version"); generator.write(this.version); - - generator.writeKey("licensed"); - generator.write(this.licensed); - - generator.writeKey("type"); - generator.write(this.type); - } // --------------------------------------------------------------------------------------------- @@ -239,10 +212,6 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder

{ private Long avgQueueSize; - private Long avgResponseTime; - private Long avgResponseTimeNs; - private String avgServiceTime; - private Long avgServiceTimeNs; private Long outgoingSearches; @@ -197,14 +167,6 @@ public final Builder avgQueueSize(long value) { return this; } - /** - * Required - API name: {@code avg_response_time} - */ - public final Builder avgResponseTime(long value) { - this.avgResponseTime = value; - return this; - } - /** * Required - API name: {@code avg_response_time_ns} */ @@ -213,14 +175,6 @@ public final Builder avgResponseTimeNs(long value) { return this; } - /** - * Required - API name: {@code avg_service_time} - */ - public final Builder avgServiceTime(String value) { - this.avgServiceTime = value; - return this; - } - /** * Required - API name: {@code avg_service_time_ns} */ @@ -269,9 +223,7 @@ public AdaptiveSelection build() { protected static void setupAdaptiveSelectionDeserializer(ObjectDeserializer op) { op.add(Builder::avgQueueSize, JsonpDeserializer.longDeserializer(), "avg_queue_size"); - op.add(Builder::avgResponseTime, JsonpDeserializer.longDeserializer(), "avg_response_time"); op.add(Builder::avgResponseTimeNs, JsonpDeserializer.longDeserializer(), "avg_response_time_ns"); - op.add(Builder::avgServiceTime, JsonpDeserializer.stringDeserializer(), "avg_service_time"); op.add(Builder::avgServiceTimeNs, JsonpDeserializer.longDeserializer(), "avg_service_time_ns"); op.add(Builder::outgoingSearches, JsonpDeserializer.longDeserializer(), "outgoing_searches"); op.add(Builder::rank, JsonpDeserializer.stringDeserializer(), "rank"); diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/DataPathStats.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/DataPathStats.java index 928113fc36..6e24932d03 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/DataPathStats.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/DataPathStats.java @@ -53,34 +53,14 @@ @JsonpDeserializable public class DataPathStats implements JsonpSerializable { - private final String available; - private final long availableInBytes; - private final String diskQueue; - - private final long diskReads; - - private final String diskReadSize; - - private final long diskReadSizeInBytes; - - private final long diskWrites; - - private final String diskWriteSize; - - private final long diskWriteSizeInBytes; - - private final String free; - private final long freeInBytes; private final String mount; private final String path; - private final String total; - private final long totalInBytes; private final String type; @@ -89,22 +69,10 @@ public class DataPathStats implements JsonpSerializable { private DataPathStats(Builder builder) { - this.available = ApiTypeHelper.requireNonNull(builder.available, this, "available"); this.availableInBytes = ApiTypeHelper.requireNonNull(builder.availableInBytes, this, "availableInBytes"); - this.diskQueue = ApiTypeHelper.requireNonNull(builder.diskQueue, this, "diskQueue"); - this.diskReads = ApiTypeHelper.requireNonNull(builder.diskReads, this, "diskReads"); - this.diskReadSize = ApiTypeHelper.requireNonNull(builder.diskReadSize, this, "diskReadSize"); - this.diskReadSizeInBytes = ApiTypeHelper.requireNonNull(builder.diskReadSizeInBytes, this, - "diskReadSizeInBytes"); - this.diskWrites = ApiTypeHelper.requireNonNull(builder.diskWrites, this, "diskWrites"); - this.diskWriteSize = ApiTypeHelper.requireNonNull(builder.diskWriteSize, this, "diskWriteSize"); - this.diskWriteSizeInBytes = ApiTypeHelper.requireNonNull(builder.diskWriteSizeInBytes, this, - "diskWriteSizeInBytes"); - this.free = ApiTypeHelper.requireNonNull(builder.free, this, "free"); this.freeInBytes = ApiTypeHelper.requireNonNull(builder.freeInBytes, this, "freeInBytes"); this.mount = ApiTypeHelper.requireNonNull(builder.mount, this, "mount"); this.path = ApiTypeHelper.requireNonNull(builder.path, this, "path"); - this.total = ApiTypeHelper.requireNonNull(builder.total, this, "total"); this.totalInBytes = ApiTypeHelper.requireNonNull(builder.totalInBytes, this, "totalInBytes"); this.type = ApiTypeHelper.requireNonNull(builder.type, this, "type"); @@ -114,13 +82,6 @@ public static DataPathStats of(Function> f return fn.apply(new Builder()).build(); } - /** - * Required - API name: {@code available} - */ - public final String available() { - return this.available; - } - /** * Required - API name: {@code available_in_bytes} */ @@ -128,62 +89,6 @@ public final long availableInBytes() { return this.availableInBytes; } - /** - * Required - API name: {@code disk_queue} - */ - public final String diskQueue() { - return this.diskQueue; - } - - /** - * Required - API name: {@code disk_reads} - */ - public final long diskReads() { - return this.diskReads; - } - - /** - * Required - API name: {@code disk_read_size} - */ - public final String diskReadSize() { - return this.diskReadSize; - } - - /** - * Required - API name: {@code disk_read_size_in_bytes} - */ - public final long diskReadSizeInBytes() { - return this.diskReadSizeInBytes; - } - - /** - * Required - API name: {@code disk_writes} - */ - public final long diskWrites() { - return this.diskWrites; - } - - /** - * Required - API name: {@code disk_write_size} - */ - public final String diskWriteSize() { - return this.diskWriteSize; - } - - /** - * Required - API name: {@code disk_write_size_in_bytes} - */ - public final long diskWriteSizeInBytes() { - return this.diskWriteSizeInBytes; - } - - /** - * Required - API name: {@code free} - */ - public final String free() { - return this.free; - } - /** * Required - API name: {@code free_in_bytes} */ @@ -205,13 +110,6 @@ public final String path() { return this.path; } - /** - * Required - API name: {@code total} - */ - public final String total() { - return this.total; - } - /** * Required - API name: {@code total_in_bytes} */ @@ -237,36 +135,9 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - generator.writeKey("available"); - generator.write(this.available); - generator.writeKey("available_in_bytes"); generator.write(this.availableInBytes); - generator.writeKey("disk_queue"); - generator.write(this.diskQueue); - - generator.writeKey("disk_reads"); - generator.write(this.diskReads); - - generator.writeKey("disk_read_size"); - generator.write(this.diskReadSize); - - generator.writeKey("disk_read_size_in_bytes"); - generator.write(this.diskReadSizeInBytes); - - generator.writeKey("disk_writes"); - generator.write(this.diskWrites); - - generator.writeKey("disk_write_size"); - generator.write(this.diskWriteSize); - - generator.writeKey("disk_write_size_in_bytes"); - generator.write(this.diskWriteSizeInBytes); - - generator.writeKey("free"); - generator.write(this.free); - generator.writeKey("free_in_bytes"); generator.write(this.freeInBytes); @@ -276,9 +147,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("path"); generator.write(this.path); - generator.writeKey("total"); - generator.write(this.total); - generator.writeKey("total_in_bytes"); generator.write(this.totalInBytes); @@ -294,46 +162,19 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { */ public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - private String available; private Long availableInBytes; - private String diskQueue; - - private Long diskReads; - - private String diskReadSize; - - private Long diskReadSizeInBytes; - - private Long diskWrites; - - private String diskWriteSize; - - private Long diskWriteSizeInBytes; - - private String free; - private Long freeInBytes; private String mount; private String path; - private String total; - private Long totalInBytes; private String type; - /** - * Required - API name: {@code available} - */ - public final Builder available(String value) { - this.available = value; - return this; - } - /** * Required - API name: {@code available_in_bytes} */ @@ -342,70 +183,6 @@ public final Builder availableInBytes(long value) { return this; } - /** - * Required - API name: {@code disk_queue} - */ - public final Builder diskQueue(String value) { - this.diskQueue = value; - return this; - } - - /** - * Required - API name: {@code disk_reads} - */ - public final Builder diskReads(long value) { - this.diskReads = value; - return this; - } - - /** - * Required - API name: {@code disk_read_size} - */ - public final Builder diskReadSize(String value) { - this.diskReadSize = value; - return this; - } - - /** - * Required - API name: {@code disk_read_size_in_bytes} - */ - public final Builder diskReadSizeInBytes(long value) { - this.diskReadSizeInBytes = value; - return this; - } - - /** - * Required - API name: {@code disk_writes} - */ - public final Builder diskWrites(long value) { - this.diskWrites = value; - return this; - } - - /** - * Required - API name: {@code disk_write_size} - */ - public final Builder diskWriteSize(String value) { - this.diskWriteSize = value; - return this; - } - - /** - * Required - API name: {@code disk_write_size_in_bytes} - */ - public final Builder diskWriteSizeInBytes(long value) { - this.diskWriteSizeInBytes = value; - return this; - } - - /** - * Required - API name: {@code free} - */ - public final Builder free(String value) { - this.free = value; - return this; - } - /** * Required - API name: {@code free_in_bytes} */ @@ -430,14 +207,6 @@ public final Builder path(String value) { return this; } - /** - * Required - API name: {@code total} - */ - public final Builder total(String value) { - this.total = value; - return this; - } - /** * Required - API name: {@code total_in_bytes} */ @@ -477,20 +246,10 @@ public DataPathStats build() { protected static void setupDataPathStatsDeserializer(ObjectDeserializer op) { - op.add(Builder::available, JsonpDeserializer.stringDeserializer(), "available"); op.add(Builder::availableInBytes, JsonpDeserializer.longDeserializer(), "available_in_bytes"); - op.add(Builder::diskQueue, JsonpDeserializer.stringDeserializer(), "disk_queue"); - op.add(Builder::diskReads, JsonpDeserializer.longDeserializer(), "disk_reads"); - op.add(Builder::diskReadSize, JsonpDeserializer.stringDeserializer(), "disk_read_size"); - op.add(Builder::diskReadSizeInBytes, JsonpDeserializer.longDeserializer(), "disk_read_size_in_bytes"); - op.add(Builder::diskWrites, JsonpDeserializer.longDeserializer(), "disk_writes"); - op.add(Builder::diskWriteSize, JsonpDeserializer.stringDeserializer(), "disk_write_size"); - op.add(Builder::diskWriteSizeInBytes, JsonpDeserializer.longDeserializer(), "disk_write_size_in_bytes"); - op.add(Builder::free, JsonpDeserializer.stringDeserializer(), "free"); op.add(Builder::freeInBytes, JsonpDeserializer.longDeserializer(), "free_in_bytes"); op.add(Builder::mount, JsonpDeserializer.stringDeserializer(), "mount"); op.add(Builder::path, JsonpDeserializer.stringDeserializer(), "path"); - op.add(Builder::total, JsonpDeserializer.stringDeserializer(), "total"); op.add(Builder::totalInBytes, JsonpDeserializer.longDeserializer(), "total_in_bytes"); op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type"); diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/FileSystemTotal.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/FileSystemTotal.java index 64727d5498..0916e4604b 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/FileSystemTotal.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/FileSystemTotal.java @@ -53,27 +53,18 @@ @JsonpDeserializable public class FileSystemTotal implements JsonpSerializable { - private final String available; - private final long availableInBytes; - private final String free; - private final long freeInBytes; - private final String total; - private final long totalInBytes; // --------------------------------------------------------------------------------------------- private FileSystemTotal(Builder builder) { - this.available = ApiTypeHelper.requireNonNull(builder.available, this, "available"); this.availableInBytes = ApiTypeHelper.requireNonNull(builder.availableInBytes, this, "availableInBytes"); - this.free = ApiTypeHelper.requireNonNull(builder.free, this, "free"); this.freeInBytes = ApiTypeHelper.requireNonNull(builder.freeInBytes, this, "freeInBytes"); - this.total = ApiTypeHelper.requireNonNull(builder.total, this, "total"); this.totalInBytes = ApiTypeHelper.requireNonNull(builder.totalInBytes, this, "totalInBytes"); } @@ -82,13 +73,6 @@ public static FileSystemTotal of(Function { - private String available; private Long availableInBytes; - private String free; - private Long freeInBytes; - private String total; - private Long totalInBytes; - /** - * Required - API name: {@code available} - */ - public final Builder available(String value) { - this.available = value; - return this; - } - /** * Required - API name: {@code available_in_bytes} */ @@ -190,13 +139,6 @@ public final Builder availableInBytes(long value) { return this; } - /** - * Required - API name: {@code free} - */ - public final Builder free(String value) { - this.free = value; - return this; - } /** * Required - API name: {@code free_in_bytes} @@ -206,14 +148,6 @@ public final Builder freeInBytes(long value) { return this; } - /** - * Required - API name: {@code total} - */ - public final Builder total(String value) { - this.total = value; - return this; - } - /** * Required - API name: {@code total_in_bytes} */ @@ -245,11 +179,8 @@ public FileSystemTotal build() { protected static void setupFileSystemTotalDeserializer(ObjectDeserializer op) { - op.add(Builder::available, JsonpDeserializer.stringDeserializer(), "available"); op.add(Builder::availableInBytes, JsonpDeserializer.longDeserializer(), "available_in_bytes"); - op.add(Builder::free, JsonpDeserializer.stringDeserializer(), "free"); op.add(Builder::freeInBytes, JsonpDeserializer.longDeserializer(), "free_in_bytes"); - op.add(Builder::total, JsonpDeserializer.stringDeserializer(), "total"); op.add(Builder::totalInBytes, JsonpDeserializer.longDeserializer(), "total_in_bytes"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/GarbageCollectorTotal.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/GarbageCollectorTotal.java index 2d5abaf5b2..248ef171ca 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/GarbageCollectorTotal.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/GarbageCollectorTotal.java @@ -55,8 +55,6 @@ public class GarbageCollectorTotal implements JsonpSerializable { private final long collectionCount; - private final String collectionTime; - private final long collectionTimeInMillis; // --------------------------------------------------------------------------------------------- @@ -64,7 +62,6 @@ public class GarbageCollectorTotal implements JsonpSerializable { private GarbageCollectorTotal(Builder builder) { this.collectionCount = ApiTypeHelper.requireNonNull(builder.collectionCount, this, "collectionCount"); - this.collectionTime = ApiTypeHelper.requireNonNull(builder.collectionTime, this, "collectionTime"); this.collectionTimeInMillis = ApiTypeHelper.requireNonNull(builder.collectionTimeInMillis, this, "collectionTimeInMillis"); @@ -81,13 +78,6 @@ public final long collectionCount() { return this.collectionCount; } - /** - * Required - API name: {@code collection_time} - */ - public final String collectionTime() { - return this.collectionTime; - } - /** * Required - API name: {@code collection_time_in_millis} */ @@ -109,9 +99,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("collection_count"); generator.write(this.collectionCount); - generator.writeKey("collection_time"); - generator.write(this.collectionTime); - generator.writeKey("collection_time_in_millis"); generator.write(this.collectionTimeInMillis); @@ -126,8 +113,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Long collectionCount; - private String collectionTime; - private Long collectionTimeInMillis; /** @@ -138,14 +123,6 @@ public final Builder collectionCount(long value) { return this; } - /** - * Required - API name: {@code collection_time} - */ - public final Builder collectionTime(String value) { - this.collectionTime = value; - return this; - } - /** * Required - API name: {@code collection_time_in_millis} */ @@ -178,7 +155,6 @@ public GarbageCollectorTotal build() { protected static void setupGarbageCollectorTotalDeserializer(ObjectDeserializer op) { op.add(Builder::collectionCount, JsonpDeserializer.longDeserializer(), "collection_count"); - op.add(Builder::collectionTime, JsonpDeserializer.stringDeserializer(), "collection_time"); op.add(Builder::collectionTimeInMillis, JsonpDeserializer.longDeserializer(), "collection_time_in_millis"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/IngestTotal.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/IngestTotal.java index 4dc2054e50..88ba7f108c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/IngestTotal.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/IngestTotal.java @@ -59,8 +59,6 @@ public class IngestTotal implements JsonpSerializable { private final long failed; - private final List processors; - private final long timeInMillis; // --------------------------------------------------------------------------------------------- @@ -70,7 +68,6 @@ private IngestTotal(Builder builder) { this.count = ApiTypeHelper.requireNonNull(builder.count, this, "count"); this.current = ApiTypeHelper.requireNonNull(builder.current, this, "current"); this.failed = ApiTypeHelper.requireNonNull(builder.failed, this, "failed"); - this.processors = ApiTypeHelper.unmodifiableRequired(builder.processors, this, "processors"); this.timeInMillis = ApiTypeHelper.requireNonNull(builder.timeInMillis, this, "timeInMillis"); } @@ -100,13 +97,6 @@ public final long failed() { return this.failed; } - /** - * Required - API name: {@code processors} - */ - public final List processors() { - return this.processors; - } - /** * Required - API name: {@code time_in_millis} */ @@ -134,16 +124,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("failed"); generator.write(this.failed); - if (ApiTypeHelper.isDefined(this.processors)) { - generator.writeKey("processors"); - generator.writeStartArray(); - for (KeyedProcessor item0 : this.processors) { - item0.serialize(generator, mapper); - - } - generator.writeEnd(); - - } generator.writeKey("time_in_millis"); generator.write(this.timeInMillis); @@ -162,8 +142,6 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder processors; - private Long timeInMillis; /** @@ -190,35 +168,6 @@ public final Builder failed(long value) { return this; } - /** - * Required - API name: {@code processors} - *

- * Adds all elements of list to processors. - */ - public final Builder processors(List list) { - this.processors = _listAddAll(this.processors, list); - return this; - } - - /** - * Required - API name: {@code processors} - *

- * Adds one or more values to processors. - */ - public final Builder processors(KeyedProcessor value, KeyedProcessor... values) { - this.processors = _listAdd(this.processors, value, values); - return this; - } - - /** - * Required - API name: {@code processors} - *

- * Adds a value to processors using a builder lambda. - */ - public final Builder processors(Function> fn) { - return processors(fn.apply(new KeyedProcessor.Builder()).build()); - } - /** * Required - API name: {@code time_in_millis} */ @@ -253,7 +202,6 @@ protected static void setupIngestTotalDeserializer(ObjectDeserializer op) { op.add(Builder::mem, MemoryStats._DESERIALIZER, "mem"); op.add(Builder::threads, JvmThreads._DESERIALIZER, "threads"); op.add(Builder::timestamp, JsonpDeserializer.longDeserializer(), "timestamp"); - op.add(Builder::uptime, JsonpDeserializer.stringDeserializer(), "uptime"); op.add(Builder::uptimeInMillis, JsonpDeserializer.longDeserializer(), "uptime_in_millis"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/MemoryStats.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/MemoryStats.java index 0251e052c4..4153706bc6 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/MemoryStats.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/MemoryStats.java @@ -42,7 +42,6 @@ import org.opensearch.client.json.JsonpSerializable; import org.opensearch.client.json.ObjectBuilderDeserializer; import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; import org.opensearch.client.util.ObjectBuilderBase; import jakarta.json.stream.JsonGenerator; @@ -72,11 +71,14 @@ public class MemoryStats implements JsonpSerializable { @Nullable private final Long totalVirtualInBytes; - private final long totalInBytes; + @Nullable + private final Long totalInBytes; - private final long freeInBytes; + @Nullable + private final Long freeInBytes; - private final long usedInBytes; + @Nullable + private final Long usedInBytes; // --------------------------------------------------------------------------------------------- @@ -88,9 +90,9 @@ protected MemoryStats(AbstractBuilder builder) { this.shareInBytes = builder.shareInBytes; this.totalVirtual = builder.totalVirtual; this.totalVirtualInBytes = builder.totalVirtualInBytes; - this.totalInBytes = ApiTypeHelper.requireNonNull(builder.totalInBytes, this, "totalInBytes"); - this.freeInBytes = ApiTypeHelper.requireNonNull(builder.freeInBytes, this, "freeInBytes"); - this.usedInBytes = ApiTypeHelper.requireNonNull(builder.usedInBytes, this, "usedInBytes"); + this.totalInBytes = builder.totalInBytes; + this.freeInBytes = builder.freeInBytes; + this.usedInBytes = builder.usedInBytes; } @@ -147,21 +149,21 @@ public final Long totalVirtualInBytes() { } /** - * Required - API name: {@code total_in_bytes} + * API name: {@code total_in_bytes} */ public final long totalInBytes() { return this.totalInBytes; } /** - * Required - API name: {@code free_in_bytes} + * API name: {@code free_in_bytes} */ public final long freeInBytes() { return this.freeInBytes; } /** - * Required - API name: {@code used_in_bytes} + * API name: {@code used_in_bytes} */ public final long usedInBytes() { return this.usedInBytes; @@ -208,15 +210,21 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.write(this.totalVirtualInBytes); } - generator.writeKey("total_in_bytes"); - generator.write(this.totalInBytes); - - generator.writeKey("free_in_bytes"); - generator.write(this.freeInBytes); + + if (this.totalInBytes != null) { + generator.writeKey("total_in_bytes"); + generator.write(this.totalInBytes); + } - generator.writeKey("used_in_bytes"); - generator.write(this.usedInBytes); + if (this.freeInBytes != null) { + generator.writeKey("free_in_bytes"); + generator.write(this.freeInBytes); + } + if (this.usedInBytes != null) { + generator.writeKey("used_in_bytes"); + generator.write(this.usedInBytes); + } } // --------------------------------------------------------------------------------------------- @@ -320,7 +328,7 @@ public final BuilderT totalVirtualInBytes(@Nullable Long value) { } /** - * Required - API name: {@code total_in_bytes} + * API name: {@code total_in_bytes} */ public final BuilderT totalInBytes(long value) { this.totalInBytes = value; @@ -328,7 +336,7 @@ public final BuilderT totalInBytes(long value) { } /** - * Required - API name: {@code free_in_bytes} + * API name: {@code free_in_bytes} */ public final BuilderT freeInBytes(long value) { this.freeInBytes = value; @@ -336,7 +344,7 @@ public final BuilderT freeInBytes(long value) { } /** - * Required - API name: {@code used_in_bytes} + * API name: {@code used_in_bytes} */ public final BuilderT usedInBytes(long value) { this.usedInBytes = value; diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/NodeBufferPool.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/NodeBufferPool.java index 063d48603d..c9998ad65e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/NodeBufferPool.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/NodeBufferPool.java @@ -55,12 +55,8 @@ public class NodeBufferPool implements JsonpSerializable { private final long count; - private final String totalCapacity; - private final long totalCapacityInBytes; - private final String used; - private final long usedInBytes; // --------------------------------------------------------------------------------------------- @@ -68,10 +64,8 @@ public class NodeBufferPool implements JsonpSerializable { private NodeBufferPool(Builder builder) { this.count = ApiTypeHelper.requireNonNull(builder.count, this, "count"); - this.totalCapacity = ApiTypeHelper.requireNonNull(builder.totalCapacity, this, "totalCapacity"); this.totalCapacityInBytes = ApiTypeHelper.requireNonNull(builder.totalCapacityInBytes, this, "totalCapacityInBytes"); - this.used = ApiTypeHelper.requireNonNull(builder.used, this, "used"); this.usedInBytes = ApiTypeHelper.requireNonNull(builder.usedInBytes, this, "usedInBytes"); } @@ -87,13 +81,6 @@ public final long count() { return this.count; } - /** - * Required - API name: {@code total_capacity} - */ - public final String totalCapacity() { - return this.totalCapacity; - } - /** * Required - API name: {@code total_capacity_in_bytes} */ @@ -101,13 +88,6 @@ public final long totalCapacityInBytes() { return this.totalCapacityInBytes; } - /** - * Required - API name: {@code used} - */ - public final String used() { - return this.used; - } - /** * Required - API name: {@code used_in_bytes} */ @@ -129,15 +109,9 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("count"); generator.write(this.count); - generator.writeKey("total_capacity"); - generator.write(this.totalCapacity); - generator.writeKey("total_capacity_in_bytes"); generator.write(this.totalCapacityInBytes); - generator.writeKey("used"); - generator.write(this.used); - generator.writeKey("used_in_bytes"); generator.write(this.usedInBytes); @@ -152,12 +126,8 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Long count; - private String totalCapacity; - private Long totalCapacityInBytes; - private String used; - private Long usedInBytes; /** @@ -168,14 +138,6 @@ public final Builder count(long value) { return this; } - /** - * Required - API name: {@code total_capacity} - */ - public final Builder totalCapacity(String value) { - this.totalCapacity = value; - return this; - } - /** * Required - API name: {@code total_capacity_in_bytes} */ @@ -184,14 +146,6 @@ public final Builder totalCapacityInBytes(long value) { return this; } - /** - * Required - API name: {@code used} - */ - public final Builder used(String value) { - this.used = value; - return this; - } - /** * Required - API name: {@code used_in_bytes} */ @@ -224,9 +178,7 @@ public NodeBufferPool build() { protected static void setupNodeBufferPoolDeserializer(ObjectDeserializer op) { op.add(Builder::count, JsonpDeserializer.longDeserializer(), "count"); - op.add(Builder::totalCapacity, JsonpDeserializer.stringDeserializer(), "total_capacity"); op.add(Builder::totalCapacityInBytes, JsonpDeserializer.longDeserializer(), "total_capacity_in_bytes"); - op.add(Builder::used, JsonpDeserializer.stringDeserializer(), "used"); op.add(Builder::usedInBytes, JsonpDeserializer.longDeserializer(), "used_in_bytes"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/Transport.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/Transport.java index cd9b9ddb10..7488a71ea5 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/Transport.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/Transport.java @@ -55,16 +55,12 @@ public class Transport implements JsonpSerializable { private final long rxCount; - private final String rxSize; - private final long rxSizeInBytes; private final int serverOpen; private final long txCount; - private final String txSize; - private final long txSizeInBytes; // --------------------------------------------------------------------------------------------- @@ -72,11 +68,9 @@ public class Transport implements JsonpSerializable { private Transport(Builder builder) { this.rxCount = ApiTypeHelper.requireNonNull(builder.rxCount, this, "rxCount"); - this.rxSize = ApiTypeHelper.requireNonNull(builder.rxSize, this, "rxSize"); this.rxSizeInBytes = ApiTypeHelper.requireNonNull(builder.rxSizeInBytes, this, "rxSizeInBytes"); this.serverOpen = ApiTypeHelper.requireNonNull(builder.serverOpen, this, "serverOpen"); this.txCount = ApiTypeHelper.requireNonNull(builder.txCount, this, "txCount"); - this.txSize = ApiTypeHelper.requireNonNull(builder.txSize, this, "txSize"); this.txSizeInBytes = ApiTypeHelper.requireNonNull(builder.txSizeInBytes, this, "txSizeInBytes"); } @@ -92,13 +86,6 @@ public final long rxCount() { return this.rxCount; } - /** - * Required - API name: {@code rx_size} - */ - public final String rxSize() { - return this.rxSize; - } - /** * Required - API name: {@code rx_size_in_bytes} */ @@ -120,13 +107,6 @@ public final long txCount() { return this.txCount; } - /** - * Required - API name: {@code tx_size} - */ - public final String txSize() { - return this.txSize; - } - /** * Required - API name: {@code tx_size_in_bytes} */ @@ -148,9 +128,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("rx_count"); generator.write(this.rxCount); - generator.writeKey("rx_size"); - generator.write(this.rxSize); - generator.writeKey("rx_size_in_bytes"); generator.write(this.rxSizeInBytes); @@ -160,9 +137,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("tx_count"); generator.write(this.txCount); - generator.writeKey("tx_size"); - generator.write(this.txSize); - generator.writeKey("tx_size_in_bytes"); generator.write(this.txSizeInBytes); @@ -177,16 +151,12 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Long rxCount; - private String rxSize; - private Long rxSizeInBytes; private Integer serverOpen; private Long txCount; - private String txSize; - private Long txSizeInBytes; /** @@ -197,14 +167,6 @@ public final Builder rxCount(long value) { return this; } - /** - * Required - API name: {@code rx_size} - */ - public final Builder rxSize(String value) { - this.rxSize = value; - return this; - } - /** * Required - API name: {@code rx_size_in_bytes} */ @@ -229,14 +191,6 @@ public final Builder txCount(long value) { return this; } - /** - * Required - API name: {@code tx_size} - */ - public final Builder txSize(String value) { - this.txSize = value; - return this; - } - /** * Required - API name: {@code tx_size_in_bytes} */ @@ -269,11 +223,9 @@ public Transport build() { protected static void setupTransportDeserializer(ObjectDeserializer op) { op.add(Builder::rxCount, JsonpDeserializer.longDeserializer(), "rx_count"); - op.add(Builder::rxSize, JsonpDeserializer.stringDeserializer(), "rx_size"); op.add(Builder::rxSizeInBytes, JsonpDeserializer.longDeserializer(), "rx_size_in_bytes"); op.add(Builder::serverOpen, JsonpDeserializer.integerDeserializer(), "server_open"); op.add(Builder::txCount, JsonpDeserializer.longDeserializer(), "tx_count"); - op.add(Builder::txSize, JsonpDeserializer.stringDeserializer(), "tx_size"); op.add(Builder::txSizeInBytes, JsonpDeserializer.longDeserializer(), "tx_size_in_bytes"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfo.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfo.java index 684b25ea3f..471dd96aaa 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfo.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfo.java @@ -57,9 +57,8 @@ @JsonpDeserializable public class NodeInfo implements JsonpSerializable { - private final Map attributes; - - private final String buildFlavor; + @Nullable + private final Map attributes; private final String buildHash; @@ -119,8 +118,7 @@ public class NodeInfo implements JsonpSerializable { private NodeInfo(Builder builder) { - this.attributes = ApiTypeHelper.unmodifiableRequired(builder.attributes, this, "attributes"); - this.buildFlavor = ApiTypeHelper.requireNonNull(builder.buildFlavor, this, "buildFlavor"); + this.attributes = ApiTypeHelper.unmodifiable(builder.attributes); this.buildHash = ApiTypeHelper.requireNonNull(builder.buildHash, this, "buildHash"); this.buildType = ApiTypeHelper.requireNonNull(builder.buildType, this, "buildType"); this.host = ApiTypeHelper.requireNonNull(builder.host, this, "host"); @@ -151,19 +149,13 @@ public static NodeInfo of(Function> fn) { } /** - * Required - API name: {@code attributes} + * API name: {@code attributes} */ + @Nullable public final Map attributes() { return this.attributes; } - /** - * Required - API name: {@code build_flavor} - */ - public final String buildFlavor() { - return this.buildFlavor; - } - /** * Required - Short hash of the last git commit in this release. *

@@ -368,8 +360,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeEnd(); } - generator.writeKey("build_flavor"); - generator.write(this.buildFlavor); generator.writeKey("build_hash"); generator.write(this.buildHash); @@ -503,10 +493,9 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { */ public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable private Map attributes; - private String buildFlavor; - private String buildHash; private String buildType; @@ -566,7 +555,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder aggregations; /** - * Required - API name: {@code attributes} + * API name: {@code attributes} *

* Adds all entries of map to attributes. */ @@ -576,7 +565,7 @@ public final Builder attributes(Map map) { } /** - * Required - API name: {@code attributes} + * API name: {@code attributes} *

* Adds an entry to attributes. */ @@ -585,14 +574,6 @@ public final Builder attributes(String key, String value) { return this; } - /** - * Required - API name: {@code build_flavor} - */ - public final Builder buildFlavor(String value) { - this.buildFlavor = value; - return this; - } - /** * Required - Short hash of the last git commit in this release. *

@@ -966,7 +947,6 @@ protected static void setupNodeInfoDeserializer(ObjectDeserializer seedHosts; // --------------------------------------------------------------------------------------------- private NodeInfoDiscover(Builder builder) { - this.seedHosts = ApiTypeHelper.requireNonNull(builder.seedHosts, this, "seedHosts"); + this.seedHosts = builder.seedHosts; } @@ -69,8 +74,8 @@ public static NodeInfoDiscover of(Function seedHosts() { + return Collections.unmodifiableList(this.seedHosts); } /** @@ -83,10 +88,11 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - - generator.writeKey("seed_hosts"); - generator.write(this.seedHosts); - + if (this.seedHosts != null) { + generator.writeStartArray("seed_hosts"); + this.seedHosts.forEach(generator::write); + generator.writeEnd(); + } } // --------------------------------------------------------------------------------------------- @@ -96,13 +102,14 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { */ public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - private String seedHosts; + @Nullable + private List seedHosts; /** - * Required - API name: {@code seed_hosts} + * API name: {@code seed_hosts} */ - public final Builder seedHosts(String value) { - this.seedHosts = value; + public final Builder seedHosts(List values) { + this.seedHosts = values; return this; } @@ -129,7 +136,7 @@ public NodeInfoDiscover build() { protected static void setupNodeInfoDiscoverDeserializer(ObjectDeserializer op) { - op.add(Builder::seedHosts, JsonpDeserializer.stringDeserializer(), "seed_hosts"); + op.add(Builder::seedHosts, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "seed_hosts"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoPath.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoPath.java index 7cab089347..124e47d13b 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoPath.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoPath.java @@ -58,6 +58,7 @@ public class NodeInfoPath implements JsonpSerializable { private final String home; + @Nullable private final List repo; private final List data; @@ -68,7 +69,7 @@ private NodeInfoPath(Builder builder) { this.logs = ApiTypeHelper.requireNonNull(builder.logs, this, "logs"); this.home = ApiTypeHelper.requireNonNull(builder.home, this, "home"); - this.repo = ApiTypeHelper.unmodifiableRequired(builder.repo, this, "repo"); + this.repo = ApiTypeHelper.unmodifiable(builder.repo); this.data = ApiTypeHelper.unmodifiable(builder.data); } @@ -92,7 +93,7 @@ public final String home() { } /** - * Required - API name: {@code repo} + * API name: {@code repo} */ public final List repo() { return this.repo; @@ -178,7 +179,7 @@ public final Builder home(String value) { } /** - * Required - API name: {@code repo} + * API name: {@code repo} *

* Adds all elements of list to repo. */ diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoScript.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoScript.java index f552e9a009..4cc74372cd 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoScript.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoScript.java @@ -48,10 +48,13 @@ import jakarta.json.stream.JsonGenerator; import java.util.function.Function; +import javax.annotation.Nullable; + // typedef: nodes.info.NodeInfoScript @JsonpDeserializable public class NodeInfoScript implements JsonpSerializable { + @Nullable private final String allowedTypes; private final String disableMaxCompilationsRate; @@ -60,7 +63,7 @@ public class NodeInfoScript implements JsonpSerializable { private NodeInfoScript(Builder builder) { - this.allowedTypes = ApiTypeHelper.requireNonNull(builder.allowedTypes, this, "allowedTypes"); + this.allowedTypes = builder.allowedTypes; this.disableMaxCompilationsRate = ApiTypeHelper.requireNonNull(builder.disableMaxCompilationsRate, this, "disableMaxCompilationsRate"); @@ -71,8 +74,9 @@ public static NodeInfoScript of(Function> } /** - * Required - API name: {@code allowed_types} + * API name: {@code allowed_types} */ + @Nullable public final String allowedTypes() { return this.allowedTypes; } @@ -94,9 +98,10 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - - generator.writeKey("allowed_types"); - generator.write(this.allowedTypes); + if (this.allowedTypes != null) { + generator.writeKey("allowed_types"); + generator.write(this.allowedTypes); + } generator.writeKey("disable_max_compilations_rate"); generator.write(this.disableMaxCompilationsRate); @@ -110,12 +115,13 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { */ public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - private String allowedTypes; + @Nullable + private String allowedTypes; private String disableMaxCompilationsRate; /** - * Required - API name: {@code allowed_types} + * API name: {@code allowed_types} */ public final Builder allowedTypes(String value) { this.allowedTypes = value; diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsCluster.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsCluster.java index db773cd0ad..9b1d17baa2 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsCluster.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsCluster.java @@ -47,6 +47,8 @@ import org.opensearch.client.util.ObjectBuilder; import org.opensearch.client.util.ObjectBuilderBase; import jakarta.json.stream.JsonGenerator; + +import java.util.List; import java.util.function.Function; import javax.annotation.Nullable; @@ -59,14 +61,15 @@ public class NodeInfoSettingsCluster implements JsonpSerializable { @Nullable private final IndexRouting routing; + @Nullable private final NodeInfoSettingsClusterElection election; @Deprecated @Nullable - private final String initialMasterNodes; + private final List initialMasterNodes; @Nullable - private final String initialClusterManagerNodes; + private final List initialClusterManagerNodes; // --------------------------------------------------------------------------------------------- @@ -74,7 +77,7 @@ private NodeInfoSettingsCluster(Builder builder) { this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); this.routing = builder.routing; - this.election = ApiTypeHelper.requireNonNull(builder.election, this, "election"); + this.election = builder.election; this.initialMasterNodes = builder.initialMasterNodes; this.initialClusterManagerNodes = builder.initialClusterManagerNodes; @@ -100,8 +103,9 @@ public final IndexRouting routing() { } /** - * Required - API name: {@code election} + * API name: {@code election} */ + @Nullable public final NodeInfoSettingsClusterElection election() { return this.election; } @@ -111,7 +115,7 @@ public final NodeInfoSettingsClusterElection election() { */ @Deprecated @Nullable - public final String initialMasterNodes() { + public final List initialMasterNodes() { return this.initialMasterNodes; } @@ -119,7 +123,7 @@ public final String initialMasterNodes() { * API name: {@code initial_cluster_manager_nodes} */ @Nullable - public final String initialClusterManagerNodes() { + public final List initialClusterManagerNodes() { return this.initialClusterManagerNodes; } @@ -146,15 +150,15 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { this.election.serialize(generator, mapper); if (this.initialMasterNodes != null) { - generator.writeKey("initial_master_nodes"); - generator.write(this.initialMasterNodes); - + generator.writeStartArray("initial_master_nodes"); + this.initialMasterNodes.forEach(generator::write); + generator.writeEnd(); } if (this.initialClusterManagerNodes != null) { - generator.writeKey("initial_cluster_manager_nodes"); - generator.write(this.initialClusterManagerNodes); - + generator.writeStartArray("initial_cluster_manager_nodes"); + this.initialClusterManagerNodes.forEach(generator::write); + generator.writeEnd(); } } @@ -171,14 +175,15 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder initialMasterNodes; @Nullable - private String initialClusterManagerNodes; + private List initialClusterManagerNodes; /** * Required - API name: {@code name} @@ -204,7 +209,7 @@ public final Builder routing(Function> fn) { @@ -223,7 +228,7 @@ public final Builder election( * API name: {@code initial_master_nodes} */ @Deprecated - public final Builder initialMasterNodes(@Nullable String value) { + public final Builder initialMasterNodes(@Nullable List value) { this.initialMasterNodes = value; return this; } @@ -231,7 +236,7 @@ public final Builder initialMasterNodes(@Nullable String value) { /** * API name: {@code initial_cluster_manager_nodes} */ - public final Builder initialClusterManagerNodes(@Nullable String value) { + public final Builder initialClusterManagerNodes(@Nullable List value) { this.initialClusterManagerNodes = value; return this; } @@ -263,8 +268,8 @@ protected static void setupNodeInfoSettingsClusterDeserializer( op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); op.add(Builder::routing, IndexRouting._DESERIALIZER, "routing"); op.add(Builder::election, NodeInfoSettingsClusterElection._DESERIALIZER, "election"); - op.add(Builder::initialMasterNodes, JsonpDeserializer.stringDeserializer(), "initial_master_nodes"); - op.add(Builder::initialClusterManagerNodes, JsonpDeserializer.stringDeserializer(), "initial_cluster_manager_nodes"); + op.add(Builder::initialMasterNodes, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "initial_master_nodes"); + op.add(Builder::initialClusterManagerNodes, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "initial_cluster_manager_nodes"); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsNode.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsNode.java index 92a51be897..bd73a74e9e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsNode.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/info/NodeInfoSettingsNode.java @@ -57,6 +57,7 @@ public class NodeInfoSettingsNode implements JsonpSerializable { private final String name; + @Nullable private final Map attr; @Nullable @@ -67,7 +68,7 @@ public class NodeInfoSettingsNode implements JsonpSerializable { private NodeInfoSettingsNode(Builder builder) { this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); - this.attr = ApiTypeHelper.unmodifiableRequired(builder.attr, this, "attr"); + this.attr = ApiTypeHelper.unmodifiable(builder.attr); this.maxLocalStorageNodes = builder.maxLocalStorageNodes; } @@ -84,8 +85,9 @@ public final String name() { } /** - * Required - API name: {@code attr} + * API name: {@code attr} */ + @Nullable public final Map attr() { return this.attr; } @@ -140,6 +142,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private String name; + @Nullable private Map attr; @Nullable @@ -164,7 +167,7 @@ public final Builder attr(Map map) { } /** - * Required - API name: {@code attr} + * API name: {@code attr} *

* Adds an entry to attr. */ diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/CrudIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/CrudIT.java index 1fee8b7a77..2af3bf5867 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/CrudIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/CrudIT.java @@ -36,17 +36,17 @@ import java.util.Collections; import java.util.List; -public class CrudIT extends OpenSearchRestHighLevelClientTestCase { +public class CrudIT extends OpenSearchJavaClientTestCase { public void testDelete() throws IOException { { // Testing index deletion String index1 = "my-index"; - CreateIndexResponse createIndexResponse = highLevelClient().indices().create(b -> b.index(index1)); + CreateIndexResponse createIndexResponse = client().indices().create(b -> b.index(index1)); assertEquals(index1, createIndexResponse.index()); assertTrue(createIndexResponse.acknowledged()); assertTrue(createIndexResponse.shardsAcknowledged()); - DeleteIndexResponse deleteIndexResponse = highLevelClient().indices().delete(b -> b.index(index1)); + DeleteIndexResponse deleteIndexResponse = client().indices().delete(b -> b.index(index1)); assertTrue(deleteIndexResponse.acknowledged()); } @@ -54,22 +54,22 @@ public void testDelete() throws IOException { // Testing doc deletion after data ingestion String docId = "id"; String index = "my-index1"; - highLevelClient().indices().create(b -> b.index(index)); + client().indices().create(b -> b.index(index)); - String id = highLevelClient().index(b -> b + String id = client().index(b -> b .index(index) .id(docId) .document(Collections.singletonMap("foo", "bar"))) .id(); assertEquals(id, docId); - DeleteResponse deleteResponse = highLevelClient().delete(d -> d.id(docId).index(index)); + DeleteResponse deleteResponse = client().delete(d -> d.id(docId).index(index)); assertEquals(deleteResponse.index(), index); assertEquals(deleteResponse.id(), docId); assertEquals(deleteResponse.result(), Result.Deleted); String docIdTemp = "does_not_exist"; - DeleteResponse deleteResponseDocNotExist = highLevelClient().delete(d -> d.id(docIdTemp).index(index)); + DeleteResponse deleteResponseDocNotExist = client().delete(d -> d.id(docIdTemp).index(index)); assertEquals(deleteResponseDocNotExist.index(), index); assertEquals(deleteResponseDocNotExist.id(), docIdTemp); assertEquals(deleteResponseDocNotExist.result(), Result.NotFound); @@ -78,26 +78,26 @@ public void testDelete() throws IOException { } public void testExists() throws IOException { - assertFalse(highLevelClient().indices().exists(b -> b.index("index")).value()); + assertFalse(client().indices().exists(b -> b.index("index")).value()); String index = "ingest-test"; // Create an index - CreateIndexResponse createIndexResponse = highLevelClient().indices().create(b -> b + CreateIndexResponse createIndexResponse = client().indices().create(b -> b .index(index) ); assertEquals(index, createIndexResponse.index()); // Check that it actually exists. Example of a boolean response - assertTrue(highLevelClient().indices().exists(b -> b.index(index)).value()); + assertTrue(client().indices().exists(b -> b.index(index)).value()); - highLevelClient().index(b -> b + client().index(b -> b .index(index) .id("id") .document(Collections.singletonMap("foo", "bar")) .refresh(Refresh.True)); - assertTrue(highLevelClient().exists(b -> b.index(index).id("id")).value()); - assertFalse(highLevelClient().exists(b -> b.index(index).id("random_id")).value()); - assertFalse(highLevelClient().exists(b -> b.index(index).id("random_id").version(1L)).value()); + assertTrue(client().exists(b -> b.index(index).id("id")).value()); + assertFalse(client().exists(b -> b.index(index).id("random_id")).value()); + assertFalse(client().exists(b -> b.index(index).id("random_id").version(1L)).value()); } public void testSourceExists() throws IOException { @@ -110,10 +110,10 @@ public void testSourceExists() throws IOException { .index("index") .id("id") .build(); - BooleanResponse response = highLevelClient().existsSource(request); + BooleanResponse response = client().existsSource(request); assertFalse(response.value()); } - highLevelClient().index(b -> b + client().index(b -> b .index("index") .id("id") .refresh(Refresh.True) @@ -123,7 +123,7 @@ public void testSourceExists() throws IOException { .index("index") .id("id") .build(); - BooleanResponse response = highLevelClient().existsSource(request); + BooleanResponse response = client().existsSource(request); assertTrue(response.value()); } { @@ -131,7 +131,7 @@ public void testSourceExists() throws IOException { .index("index") .id("does_not_exist") .build(); - BooleanResponse response = highLevelClient().existsSource(request); + BooleanResponse response = client().existsSource(request); assertFalse(response.value()); } } @@ -141,7 +141,7 @@ public void testGet() throws IOException { { OpenSearchException exception = expectThrows( OpenSearchException.class, - () -> highLevelClient().get(new GetRequest.Builder().index("index").id("id").build(), String.class) + () -> client().get(new GetRequest.Builder().index("index").id("id").build(), String.class) ); assertEquals(404, exception.status()); assertEquals("Request failed: [index_not_found_exception] no such index [index]", @@ -152,10 +152,10 @@ public void testGet() throws IOException { appData.setIntValue(1337); appData.setMsg("foo"); - highLevelClient().index(b -> b.index("index").id("id").document(appData).refresh(Refresh.True)); + client().index(b -> b.index("index").id("id").document(appData).refresh(Refresh.True)); { - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index("index") .id("id") .version(1L) @@ -169,7 +169,7 @@ public void testGet() throws IOException { assertEquals(appData.getMsg(), getResponse.source().getMsg()); } { - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index("index") .id("does_not_exist") , AppData.class @@ -187,13 +187,13 @@ public void testGetWithTypes() throws IOException { appData.setIntValue(1337); appData.setMsg("foo"); - highLevelClient().index(b -> b + client().index(b -> b .index("index") .id("id") .document(appData) .refresh(Refresh.True)); - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index("index") .id("id") , AppData.class @@ -216,7 +216,7 @@ public void testMultiGet() throws IOException { List ids = new ArrayList<>(); ids.add("id1"); ids.add("id2"); - MgetResponse response = highLevelClient().mget(b -> b + MgetResponse response = client().mget(b -> b .index("index") .ids(ids) , AppData.class @@ -256,7 +256,7 @@ public void testUpdate() throws Exception { .doc(appData) .build(); try { - highLevelClient().update(updateRequest, AppData.class); + client().update(updateRequest, AppData.class); } catch (OpenSearchException e) { // 1.x: [document_missing_exception] [_doc][does_not_exist]: document missing // 2.x: [document_missing_exception] [does_not_exist]: document missing @@ -271,7 +271,7 @@ public void testUpdate() throws Exception { .id("id") .document(appData) .build(); - IndexResponse indexResponse = highLevelClient().index(indexRequest); + IndexResponse indexResponse = client().index(indexRequest); assertEquals(Result.Created, indexResponse.result()); long lastUpdateSeqNo; @@ -282,7 +282,7 @@ public void testUpdate() throws Exception { .id("id") .doc(updatedAppData) .build(); - UpdateResponse updateResponse = highLevelClient().update(updateRequest, AppData.class); + UpdateResponse updateResponse = client().update(updateRequest, AppData.class); assertEquals(Result.Updated, updateResponse.result()); assertEquals(indexResponse.version() + 1, updateResponse.version()); lastUpdateSeqNo = updateResponse.seqNo(); @@ -309,14 +309,14 @@ public void testUpdateWithTypes() throws IOException { .id("id") .document(appData) .build(); - IndexResponse indexResponse = highLevelClient().index(indexRequest); + IndexResponse indexResponse = client().index(indexRequest); UpdateRequest updateRequest = new UpdateRequest.Builder() .index("index") .id("id") .doc(updatedAppData) .build(); - UpdateResponse updateResponse = highLevelClient().update(updateRequest, AppData.class); + UpdateResponse updateResponse = client().update(updateRequest, AppData.class); assertEquals(Result.Updated, updateResponse.result()); assertEquals(indexResponse.version() + 1, updateResponse.version()); @@ -341,7 +341,7 @@ public void testBulk() throws IOException { if (!erroneous) { assertEquals( Result.Created, - highLevelClient().index(b -> b.index("index").id(id).document(appData)).result() + client().index(b -> b.index("index").id(id).document(appData)).result() ); } BulkOperation op = new BulkOperation.Builder().delete(d -> d.index("index").id(id)).build(); @@ -367,7 +367,7 @@ public void testBulk() throws IOException { opsList.add(op); if (erroneous) { - assertEquals(Result.Created, highLevelClient().index(b -> b. + assertEquals(Result.Created, client().index(b -> b. index("index").id(id).document(appData)).result()); } @@ -381,7 +381,7 @@ public void testBulk() throws IOException { if (!erroneous) { assertEquals( Result.Created, - highLevelClient().index(b -> b.index("index").id(id).document(appData)).result() + client().index(b -> b.index("index").id(id).document(appData)).result() ); } } @@ -389,7 +389,7 @@ public void testBulk() throws IOException { } BulkRequest bulkRequest = new BulkRequest.Builder().operations(opsList).build(); - BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest); + BulkResponse bulkResponse = client().bulk(bulkRequest); assertTrue(bulkResponse.took() > 0); assertEquals(nbItems, bulkResponse.items().size()); @@ -424,12 +424,12 @@ public void testUrlEncode() throws IOException { appData.setIntValue(1337); appData.setMsg("foo"); { - IndexResponse response = highLevelClient().index(b -> b.index(indexPattern).id("id#1").document(appData)); + IndexResponse response = client().index(b -> b.index(indexPattern).id("id#1").document(appData)); assertEquals(expectedIndex, response.index()); assertEquals("id#1", response.id()); } { - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index(indexPattern).id("id#1"), AppData.class); assertTrue(getResponse.found()); assertEquals(expectedIndex, getResponse.index()); @@ -438,19 +438,19 @@ public void testUrlEncode() throws IOException { String docId = "this/is/the/id"; { - IndexResponse indexResponse = highLevelClient().index(b -> b.index("index").id(docId).document(appData)); + IndexResponse indexResponse = client().index(b -> b.index("index").id(docId).document(appData)); assertEquals("index", indexResponse.index()); assertEquals(docId, indexResponse.id()); } { - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index("index").id(docId), AppData.class); assertTrue(getResponse.found()); assertEquals("index", getResponse.index()); assertEquals(docId, getResponse.id()); } - assertTrue(highLevelClient().indices().exists(b -> b.index(indexPattern, "index")).value()); + assertTrue(client().indices().exists(b -> b.index(indexPattern, "index")).value()); } public void testParamsEncode() throws IOException { @@ -460,12 +460,12 @@ public void testParamsEncode() throws IOException { AppData appData = new AppData(); appData.setIntValue(1337); appData.setMsg("foo"); - IndexResponse response = highLevelClient().index(b -> b.index("index").id(id).document(appData).routing(routing)); + IndexResponse response = client().index(b -> b.index("index").id(id).document(appData).routing(routing)); assertEquals("index", response.index()); assertEquals(id, response.id()); } { - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index("index").id("id").routing(routing), AppData.class); assertTrue(getResponse.found()); assertEquals("index", getResponse.index()); @@ -481,13 +481,13 @@ public void testGetIdWithPlusSign() throws Exception { appData.setMsg("foo"); { - IndexResponse indexResponse = highLevelClient().index(b -> b + IndexResponse indexResponse = client().index(b -> b .index("index").id(id).document(appData)); assertEquals("index", indexResponse.index()); assertEquals(id, indexResponse.id()); } { - GetResponse getResponse = highLevelClient().get(b -> b + GetResponse getResponse = client().get(b -> b .index("index").id(id), AppData.class); assertTrue(getResponse.found()); assertEquals("index", getResponse.index()); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java index 89c17043e4..72f32de045 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java @@ -15,25 +15,23 @@ import org.opensearch.client.opensearch.indices.GetIndexResponse; import org.opensearch.client.opensearch.indices.GetIndicesSettingsRequest; import org.opensearch.client.opensearch.indices.IndexState; -import org.opensearch.common.settings.Settings; - import java.io.IOException; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -public class IndicesClientIT extends OpenSearchRestHighLevelClientTestCase { +public class IndicesClientIT extends OpenSearchJavaClientTestCase { public void testIndicesExists() throws IOException { // Index present { String indexName = "test_index_exists_index_present"; - highLevelClient().indices().create(_1 -> _1.index(indexName)); + client().indices().create(_1 -> _1.index(indexName)); GetIndexRequest request = new GetIndexRequest.Builder().index(indexName).build(); - GetIndexResponse response = highLevelClient().indices().get(request); + GetIndexResponse response = client().indices().get(request); assertNotNull(response.result()); assertEquals(response.result().size(), 1); @@ -45,7 +43,7 @@ public void testIndicesExists() throws IOException { GetIndexRequest request = new GetIndexRequest.Builder().index(indexName).build(); try { - highLevelClient().indices().get(request); + client().indices().get(request); fail(); // should never execute } catch (OpenSearchException ex) { assertNotNull(ex); @@ -59,14 +57,14 @@ public void testIndicesExists() throws IOException { // One index exists, one doesn't { String existingIndex = "apples"; - createIndex(existingIndex, Settings.EMPTY); + createIndex(existingIndex, EMPTY); String nonExistentIndex = "oranges"; GetIndexRequest request = new GetIndexRequest.Builder().index(existingIndex, nonExistentIndex).build(); try { - highLevelClient().indices().get(request); + client().indices().get(request); fail(); // should never execute } catch (OpenSearchException ex) { assertNotNull(ex); @@ -75,8 +73,8 @@ public void testIndicesExists() throws IOException { } public void testCreateIndex() throws Exception { - OpenSearchAsyncClient asyncClient = new OpenSearchAsyncClient(highLevelClient()._transport()); - CreateIndexResponse createResponse = highLevelClient().indices().create(b -> b.index("my-index")); + OpenSearchAsyncClient asyncClient = new OpenSearchAsyncClient(client()._transport()); + CreateIndexResponse createResponse = client().indices().create(b -> b.index("my-index")); assertTrue(createResponse.acknowledged()); assertTrue(createResponse.shardsAcknowledged()); @@ -98,7 +96,7 @@ public void testGetSettingsNonExistentIndex() throws IOException { .index(nonExistentIndex).build(); try { - highLevelClient().indices().getSettings(getIndicesSettingsRequest); + client().indices().getSettings(getIndicesSettingsRequest); fail(); } catch (OpenSearchException ex) { assertNotNull(ex); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/NodesIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/NodesIT.java new file mode 100644 index 0000000000..9272de6bbf --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/NodesIT.java @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.integTest; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.anEmptyMap; + +import java.io.IOException; + +import org.opensearch.client.opensearch.nodes.NodesStatsResponse; + +public class NodesIT extends OpenSearchJavaClientTestCase { + public void testNodesStats() throws IOException { + final NodesStatsResponse response = client().nodes().stats(); + assertThat(response.clusterName(), not(nullValue())); + assertThat(response.nodes(), not(anEmptyMap())); + } +} \ No newline at end of file diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java new file mode 100644 index 0000000000..9ad8ac10c7 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java @@ -0,0 +1,251 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.integTest; + + +import org.apache.hc.client5.http.auth.AuthScope; +import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; +import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; +import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager; +import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; +import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder; +import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; +import org.apache.hc.core5.function.Factory; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.nio.ssl.TlsStrategy; +import org.apache.hc.core5.reactor.ssl.TlsDetails; +import org.apache.hc.core5.ssl.SSLContextBuilder; +import org.junit.After; +import org.opensearch.Version; +import org.opensearch.client.RestClient; +import org.opensearch.client.RestClientBuilder; +import org.opensearch.client.json.jackson.JacksonJsonpMapper; +import org.opensearch.client.opensearch.OpenSearchClient; +import org.opensearch.client.opensearch._types.ExpandWildcard; +import org.opensearch.client.opensearch._types.mapping.TypeMapping; +import org.opensearch.client.opensearch.cat.IndicesResponse; +import org.opensearch.client.opensearch.cat.indices.IndicesRecord; +import org.opensearch.client.opensearch.indices.Alias; +import org.opensearch.client.opensearch.indices.CreateIndexRequest; +import org.opensearch.client.opensearch.indices.DeleteIndexRequest; +import org.opensearch.client.opensearch.indices.IndexSettings; +import org.opensearch.client.opensearch.nodes.NodesInfoResponse; +import org.opensearch.client.opensearch.nodes.info.NodeInfo; +import org.junit.AfterClass; +import org.junit.Before; +import org.opensearch.client.transport.rest_client.RestClientTransport; +import org.opensearch.common.settings.Settings; +import org.opensearch.core.internal.io.IOUtils; +import org.opensearch.test.OpenSearchTestCase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.TreeSet; + +import javax.net.ssl.SSLEngine; + +public abstract class OpenSearchJavaClientTestCase extends OpenSearchTestCase { + public static final String TRUSTSTORE_PATH = "truststore.path"; + public static final String TRUSTSTORE_PASSWORD = "truststore.password"; + public static final String CLIENT_SOCKET_TIMEOUT = "client.socket.timeout"; + public static final String CLIENT_PATH_PREFIX = "client.path.prefix"; + + protected static final IndexSettings EMPTY = new IndexSettings.Builder().build(); + + private static OpenSearchClient client; + private static OpenSearchClient adminClient; + + private static TreeSet nodeVersions; + private static List clusterHosts; + + @Before + public void initHighLevelClient() throws IOException { + if (client == null) { + String cluster = getTestRestCluster(); + String[] stringUrls = cluster.split(","); + List hosts = new ArrayList<>(stringUrls.length); + for (String stringUrl : stringUrls) { + int portSeparator = stringUrl.lastIndexOf(':'); + if (portSeparator < 0) { + throw new IllegalArgumentException("Illegal cluster url [" + stringUrl + "]"); + } + String host = stringUrl.substring(0, portSeparator); + int port = Integer.valueOf(stringUrl.substring(portSeparator + 1)); + hosts.add(new HttpHost(getProtocol(), host, port)); + } + clusterHosts = Collections.unmodifiableList(hosts); + logger.info("initializing REST clients against {}", clusterHosts); + + client = buildClient(clientSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()])); + adminClient = buildClient(adminSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()])); + + nodeVersions = new TreeSet<>(); + final NodesInfoResponse response = adminClient.nodes().info(); + for (final NodeInfo node : response.nodes().values()) { + nodeVersions.add(Version.fromString(node.version())); + } + } + } + + private boolean isHttps() { + return Optional.ofNullable(System.getProperty("https")) + .map("true"::equalsIgnoreCase) + .orElse(false); + } + + protected String getProtocol() { + return isHttps() ? "https" : "http"; + } + + /** + * Used to obtain settings for the REST client that is used to send REST requests. + */ + protected Settings clientSettings() { + Settings.Builder builder = Settings.builder(); + if (System.getProperty("tests.rest.client_path_prefix") != null) { + builder.put(CLIENT_PATH_PREFIX, System.getProperty("tests.rest.client_path_prefix")); + } + return builder.build(); + } + + /** + * Returns the REST client settings used for admin actions like cleaning up after the test has completed. + */ + protected Settings adminSettings() { + return clientSettings(); // default to the same client settings + } + + protected OpenSearchClient buildClient(Settings settings, HttpHost[] hosts) throws IOException { + final RestClientBuilder builder = RestClient.builder(hosts); + + builder.setStrictDeprecationMode(true); + if (isHttps()) { + configureHttpsClient(builder, hosts); + } + + return new OpenSearchClient(new RestClientTransport(builder.build(), new JacksonJsonpMapper())); + } + + protected static OpenSearchClient client() { + return client; + } + + protected static OpenSearchClient adminClient() { + return adminClient; + } + + private void configureHttpsClient(RestClientBuilder builder, HttpHost[] hosts) { + builder.setHttpClientConfigCallback(httpClientBuilder -> { + String userName = Optional.ofNullable(System.getProperty("user")).orElse("admin"); + String password = Optional.ofNullable(System.getProperty("password")).orElse("admin"); + + final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + for (final HttpHost host: hosts) { + credentialsProvider.setCredentials(new AuthScope(host), new UsernamePasswordCredentials(userName, password.toCharArray())); + } + + try { + final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder + .create() + .setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build()) + // disable the certificate since our testing cluster just uses the default security configuration + .setHostnameVerifier(NoopHostnameVerifier.INSTANCE) + // See please https://issues.apache.org/jira/browse/HTTPCLIENT-2219 + .setTlsDetailsFactory(new Factory() { + @Override + public TlsDetails create(final SSLEngine sslEngine) { + return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol()); + } + }) + .build(); + + final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder.create() + .setTlsStrategy(tlsStrategy) + .build(); + + return httpClientBuilder + .setDefaultCredentialsProvider(credentialsProvider) + .setConnectionManager(connectionManager); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + protected String getTestRestCluster() { + String cluster = System.getProperty("tests.rest.cluster"); + if (cluster == null) { + cluster = "localhost:9200"; + } + return cluster; + } + + @AfterClass + public static void cleanupClient() throws IOException { + try { + if (client != null) { + IOUtils.close(client._transport()); + } + + if (adminClient != null) { + IOUtils.close(adminClient._transport()); + } + } finally { + clusterHosts = null; + client = null; + adminClient = null; + nodeVersions = null; + } + } + + @After + protected void wipeAllOSIndices() throws IOException { + final IndicesResponse response = adminClient + .cat() + .indices(r -> r.expandWildcards(ExpandWildcard.All)); + + for (IndicesRecord index : response.valueBody()) { + if (index.index() != null && !".opendistro_security".equals(index.index())) { + adminClient().indices().delete(new DeleteIndexRequest.Builder().index(index.index()).build()); + } + } + } + + /** + * wipeAllIndices won't work since it cannot delete security index. Use wipeAllOSIndices instead. + */ + protected boolean preserveIndicesUponCompletion() { + return true; + } + + protected static void createIndex(String name, IndexSettings settings) throws IOException { + createIndex(name, settings, null); + } + + protected static void createIndex(String name, IndexSettings settings, TypeMapping mapping, String ... aliases) throws IOException { + final CreateIndexRequest.Builder builder = new CreateIndexRequest.Builder(); + builder.index(name); + builder.settings(settings); + + if (mapping != null) { + builder.mappings(mapping); + } + if (aliases != null) { + Arrays + .stream(aliases) + .forEach(a -> builder.aliases(a, new Alias.Builder().build())); + } + + client().indices().create(builder.build()); + } +} \ No newline at end of file diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/RequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/RequestTest.java index 4196884453..b91d276274 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/RequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/RequestTest.java @@ -72,25 +72,25 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -public class RequestTest extends OpenSearchRestHighLevelClientTestCase { +public class RequestTest extends OpenSearchJavaClientTestCase { @Test public void testCount() throws Exception { // Tests that a no-parameter method exists for endpoints that only have optional properties - assertTrue(highLevelClient().count().count() >= 0); + assertTrue(client().count().count() >= 0); } @Test public void testIndexCreation() throws Exception { - OpenSearchAsyncClient asyncClient = new OpenSearchAsyncClient(highLevelClient()._transport()); + OpenSearchAsyncClient asyncClient = new OpenSearchAsyncClient(client()._transport()); // Ping the server - assertTrue(highLevelClient().ping().value()); + assertTrue(client().ping().value()); // Create an index... - final CreateIndexResponse createResponse = highLevelClient().indices().create(b -> b.index("my-index")); + final CreateIndexResponse createResponse = client().indices().create(b -> b.index("my-index")); assertTrue(createResponse.acknowledged()); assertTrue(createResponse.shardsAcknowledged()); @@ -110,14 +110,14 @@ public void testDataIngestion() throws Exception { String index = "ingest-test"; // Create an index - CreateIndexResponse createIndexResponse = highLevelClient().indices().create(b -> b + CreateIndexResponse createIndexResponse = client().indices().create(b -> b .index(index) ); assertEquals(index, createIndexResponse.index()); // Check that it actually exists. Example of a boolean response - BooleanResponse existsResponse = highLevelClient().indices().exists(b -> b.index(index)); + BooleanResponse existsResponse = client().indices().exists(b -> b.index(index)); assertTrue(existsResponse.value()); // Ingest some data @@ -125,7 +125,7 @@ public void testDataIngestion() throws Exception { appData.setIntValue(1337); appData.setMsg("foo"); - String docId = highLevelClient().index(b -> b + String docId = client().index(b -> b .index(index) .id("my/Id") // test with url-unsafe string .document(appData) @@ -135,14 +135,14 @@ public void testDataIngestion() throws Exception { assertEquals("my/Id", docId); // Check auto-created mapping - GetMappingResponse mapping = highLevelClient().indices().getMapping(b -> b.index(index)); + GetMappingResponse mapping = client().indices().getMapping(b -> b.index(index)); assertEquals( Property.Kind.Long, mapping.get("ingest-test").mappings().properties().get("intValue")._kind() ); // Query by id - AppData esData = highLevelClient().get(b -> b + AppData esData = client().get(b -> b .index(index) .id(docId) , AppData.class @@ -152,7 +152,7 @@ public void testDataIngestion() throws Exception { assertEquals("foo", esData.getMsg()); // Query by id a non-existing document - final GetResponse notExists = highLevelClient().get(b -> b + final GetResponse notExists = client().get(b -> b .index(index) .id("some-random-id") , AppData.class @@ -162,7 +162,7 @@ public void testDataIngestion() throws Exception { assertNull(notExists.source()); // Search - SearchResponse search = highLevelClient().search(b -> b + SearchResponse search = client().search(b -> b .index(index) , AppData.class ); @@ -180,7 +180,7 @@ public void testDataIngestion() throws Exception { ); // MSearch: 1st search on an existing index, 2nd one on a non-existing index - final MsearchResponse msearch = highLevelClient().msearch(_0 -> _0 + final MsearchResponse msearch = client().msearch(_0 -> _0 .searches(_1 -> _1 .header(_3 -> _3.index(index)) .body(_3 -> _3.query(_4 -> _4.matchAll(_5 -> _5))) @@ -200,10 +200,10 @@ public void testDataIngestion() throws Exception { @Test public void testCatRequest() throws IOException { // Cat requests should have the "format=json" added by the transport - NodesResponse nodes = highLevelClient().cat().nodes(_0 -> _0); - System.out.println(ModelTestCase.toJson(nodes, highLevelClient()._transport().jsonpMapper())); + NodesResponse nodes = client().cat().nodes(_0 -> _0); + System.out.println(ModelTestCase.toJson(nodes, client()._transport().jsonpMapper())); - InfoResponse info = highLevelClient().info(); + InfoResponse info = client().info(); String version = info.version().number(); if (version.contains("SNAPSHOT")) { version = version.split("-")[0]; @@ -223,7 +223,7 @@ public void testBulkRequest() throws IOException { appData.setIntValue(42); appData.setMsg("Some message"); - BulkResponse bulk = highLevelClient().bulk(_0 -> _0 + BulkResponse bulk = client().bulk(_0 -> _0 .operations(_1 -> _1 .create(_2 -> _2 .index("foo") @@ -245,7 +245,7 @@ public void testBulkRequest() throws IOException { assertEquals(1L, bulk.items().get(0).version().longValue()); assertEquals("foo", bulk.items().get(1).index()); assertEquals(1L, bulk.items().get(1).version().longValue()); - assertEquals(42, highLevelClient().get(b -> b.index("foo").id("abc"), AppData.class).source().getIntValue()); + assertEquals(42, client().get(b -> b.index("foo").id("abc"), AppData.class).source().getIntValue()); } @Test @@ -254,7 +254,7 @@ public void testRefresh() throws IOException { appData.setIntValue(42); appData.setMsg("Some message"); - IndexResponse ir = highLevelClient().index(_0 -> _0 + IndexResponse ir = client().index(_0 -> _0 .index("test") .id("1") .document(appData) @@ -265,11 +265,11 @@ public void testRefresh() throws IOException { } @Test public void errorResponse() throws Exception { - BooleanResponse exists = highLevelClient().exists(_0 -> _0.index("doesnotexist").id("reallynot")); + BooleanResponse exists = client().exists(_0 -> _0.index("doesnotexist").id("reallynot")); assertFalse(exists.value()); OpenSearchException ex = assertThrows(OpenSearchException.class, () -> { - GetResponse response = highLevelClient().get( + GetResponse response = client().get( _0 -> _0.index("doesnotexist").id("reallynot"), String.class ); }); @@ -280,7 +280,7 @@ public void testRefresh() throws IOException { ExecutionException ee = assertThrows(ExecutionException.class, () -> { - OpenSearchAsyncClient aClient = new OpenSearchAsyncClient(highLevelClient()._transport()); + OpenSearchAsyncClient aClient = new OpenSearchAsyncClient(client()._transport()); GetResponse response = aClient.get( _0 -> _0.index("doesnotexist").id("reallynot"), String.class ).get(); @@ -297,7 +297,7 @@ public void testErrorStatusCodeWithValidResponse() throws IOException { // Transports should first try to decode an error, and if they fail because of missing properties for // the error type, then try to decode the regular request. - final ClearScrollResponse clearResponse = highLevelClient().clearScroll(b -> b.scrollId( + final ClearScrollResponse clearResponse = client().clearScroll(b -> b.scrollId( "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ==") ); assertEquals(0, clearResponse.numFreed()); @@ -306,11 +306,11 @@ public void testErrorStatusCodeWithValidResponse() throws IOException { @Test public void testSearchAggregation() throws IOException { - highLevelClient().create(_1 -> _1.index("products").id("A").document(new Product(5)).refresh(Refresh.True)); - highLevelClient().create(_1 -> _1.index("products").id("B").document(new Product(15)).refresh(Refresh.True)); - highLevelClient().create(_1 -> _1.index("products").id("C").document(new Product(25)).refresh(Refresh.True)); + client().create(_1 -> _1.index("products").id("A").document(new Product(5)).refresh(Refresh.True)); + client().create(_1 -> _1.index("products").id("B").document(new Product(15)).refresh(Refresh.True)); + client().create(_1 -> _1.index("products").id("C").document(new Product(25)).refresh(Refresh.True)); - SearchResponse searchResponse = highLevelClient().search(_1 -> _1 + SearchResponse searchResponse = client().search(_1 -> _1 .index("products") .size(0) .aggregations( @@ -339,9 +339,9 @@ public void testSearchAggregation() throws IOException { @Test public void testSubAggregation() throws IOException { - highLevelClient().create(_1 -> _1.index("products").id("A").document(new Product(5, "Blue")).refresh(Refresh.True)); - highLevelClient().create(_1 -> _1.index("products").id("B").document(new Product(10, "Blue")).refresh(Refresh.True)); - highLevelClient().create(_1 -> _1.index("products").id("C").document(new Product(15, "Black")).refresh(Refresh.True)); + client().create(_1 -> _1.index("products").id("A").document(new Product(5, "Blue")).refresh(Refresh.True)); + client().create(_1 -> _1.index("products").id("B").document(new Product(10, "Blue")).refresh(Refresh.True)); + client().create(_1 -> _1.index("products").id("C").document(new Product(15, "Black")).refresh(Refresh.True)); List fieldValues = List.of(FieldValue.of("Blue")); @@ -362,7 +362,7 @@ public void testSubAggregation() throws IOException { ._toQuery() ) )); - SearchResponse searchResponse = highLevelClient().search(searchRequest, Product.class); + SearchResponse searchResponse = client().search(searchRequest, Product.class); Aggregate prices = searchResponse.aggregations().get("price")._get()._toAggregate(); assertEquals(2, searchResponse.aggregations().get("price").filter().docCount()); @@ -381,16 +381,16 @@ public void testChildAggregation() throws IOException { String question = "question"; String answer = "answer"; - highLevelClient().indices().create(c -> c.index(index).mappings(m -> m.properties("join", p -> p + client().indices().create(c -> c.index(index).mappings(m -> m.properties("join", p -> p .join(j -> j.relations(Collections.singletonMap(question, Collections.singletonList(answer))))))); - highLevelClient().index(i -> i.index(index).id("1").document(new Question("exists")).refresh(Refresh.True)); - highLevelClient().index(i -> i.index(index).id("2").routing("1").document(new Answer("true", "1")).refresh(Refresh.True)); - highLevelClient().index(i -> i.index(index).id("3").routing("1").document(new Answer("false", "1")).refresh(Refresh.True)); + client().index(i -> i.index(index).id("1").document(new Question("exists")).refresh(Refresh.True)); + client().index(i -> i.index(index).id("2").routing("1").document(new Answer("true", "1")).refresh(Refresh.True)); + client().index(i -> i.index(index).id("3").routing("1").document(new Answer("false", "1")).refresh(Refresh.True)); SearchRequest searchRequest = SearchRequest.of(r -> r.index(index).size(0) .aggregations(answer, a -> a.children(c -> c.type(answer)))); - SearchResponse searchResponse = highLevelClient().search(searchRequest, Void.class); + SearchResponse searchResponse = client().search(searchRequest, Void.class); assertEquals(2, searchResponse.aggregations().get(answer).children().docCount()); } @@ -403,7 +403,7 @@ public void testGetMapping() throws Exception { Map fields = Collections.singletonMap("keyword", Property.of(p -> p.keyword(k -> k.ignoreAbove(256)))); Property text = Property.of(p -> p.text(t -> t.fields(fields))); - highLevelClient().indices().create(c -> c + client().indices().create(c -> c .index(index) .mappings(m -> m .properties("id", text) @@ -416,7 +416,7 @@ public void testGetMapping() throws Exception { ) ); - GetMappingResponse mr = highLevelClient().indices().getMapping(mrb -> mrb.index(index)); + GetMappingResponse mr = client().indices().getMapping(mrb -> mrb.index(index)); assertNotNull(mr.result().get(index)); assertNotNull(mr.result().get(index).mappings().properties().get("name").object()); @@ -426,13 +426,13 @@ public void testGetMapping() throws Exception { public void testDefaultIndexSettings() throws IOException { String index = "index-settings"; - highLevelClient().index(_1 -> _1.index(index).document(new Product(5)).refresh(Refresh.True)); + client().index(_1 -> _1.index(index).document(new Product(5)).refresh(Refresh.True)); GetIndicesSettingsResponse settings; - settings = highLevelClient().indices().getSettings(b -> b.index(index).includeDefaults(true)); + settings = client().indices().getSettings(b -> b.index(index).includeDefaults(true)); assertNotNull(settings.get(index).defaults()); - settings = highLevelClient().indices().getSettings(b -> b.index(index)); + settings = client().indices().getSettings(b -> b.index(index)); assertNull(settings.get(index).defaults()); }