From 6f968cd58b8ed8139d012672a72c0fa856ba1ec4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 3 May 2023 21:11:57 +0000 Subject: [PATCH] Fixing issues when deserializing response for tasks API (#463) * Fix failure when deserializing response for tasks API Signed-off-by: Vacha Shah * Add changelog Signed-off-by: Vacha Shah * Marking the fields Nullable Signed-off-by: Vacha Shah --------- Signed-off-by: Vacha Shah (cherry picked from commit 4b9bcbc75ce4816cc762975222a33d65a111f8f2) Signed-off-by: github-actions[bot] --- CHANGELOG.md | 1 + .../client/opensearch/_types/BaseNode.java | 37 +++++++++++-------- .../opensearch/integTest/AbstractNodesIT.java | 9 +++++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27c01e60ed..bd880a8cd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fix missing Highlight and SourceConfig in the MultisearchBody ([#442](https://github.com/opensearch-project/opensearch-java/pull/442)) - Fix search failure with missing required property HitsMetadata.total when trackTotalHits is disabled ([#372](https://github.com/opensearch-project/opensearch-java/pull/372)) +- Fix failure when deserialing response for tasks API ([#463](https://github.com/opensearch-project/opensearch-java/pull/463)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/BaseNode.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/BaseNode.java index ccf876ba38..534dcab79c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/BaseNode.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/BaseNode.java @@ -67,38 +67,38 @@ public abstract class BaseNode implements JsonpSerializable { protected BaseNode(AbstractBuilder builder) { - this.attributes = ApiTypeHelper.unmodifiableRequired(builder.attributes, this, "attributes"); - this.host = ApiTypeHelper.requireNonNull(builder.host, this, "host"); - this.ip = ApiTypeHelper.requireNonNull(builder.ip, this, "ip"); - this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); + this.attributes = ApiTypeHelper.unmodifiable(builder.attributes); + this.host = builder.host; + this.ip = builder.ip; + this.name = builder.name; this.roles = ApiTypeHelper.unmodifiable(builder.roles); - this.transportAddress = ApiTypeHelper.requireNonNull(builder.transportAddress, this, "transportAddress"); + this.transportAddress = builder.transportAddress; } /** - * Required - API name: {@code attributes} + * API name: {@code attributes} */ public final Map attributes() { return this.attributes; } /** - * Required - API name: {@code host} + * API name: {@code host} */ public final String host() { return this.host; } /** - * Required - API name: {@code ip} + * API name: {@code ip} */ public final String ip() { return this.ip; } /** - * Required - API name: {@code name} + * API name: {@code name} */ public final String name() { return this.name; @@ -112,7 +112,7 @@ public final List roles() { } /** - * Required - API name: {@code transport_address} + * API name: {@code transport_address} */ public final String transportAddress() { return this.transportAddress; @@ -166,21 +166,26 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { protected abstract static class AbstractBuilder> extends ObjectBuilderBase { + @Nullable private Map attributes; + @Nullable private String host; + @Nullable private String ip; + @Nullable private String name; @Nullable private List roles; + @Nullable private String transportAddress; /** - * Required - API name: {@code attributes} + * API name: {@code attributes} *

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

* Adds an entry to attributes. */ @@ -200,7 +205,7 @@ public final BuilderT attributes(String key, String value) { } /** - * Required - API name: {@code host} + * API name: {@code host} */ public final BuilderT host(String value) { this.host = value; @@ -208,7 +213,7 @@ public final BuilderT host(String value) { } /** - * Required - API name: {@code ip} + * API name: {@code ip} */ public final BuilderT ip(String value) { this.ip = value; @@ -216,7 +221,7 @@ public final BuilderT ip(String value) { } /** - * Required - API name: {@code name} + * API name: {@code name} */ public final BuilderT name(String value) { this.name = value; @@ -244,7 +249,7 @@ public final BuilderT roles(NodeRole value, NodeRole... values) { } /** - * Required - API name: {@code transport_address} + * API name: {@code transport_address} */ public final BuilderT transportAddress(String value) { this.transportAddress = value; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractNodesIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractNodesIT.java index 6a00a76ac3..3cb83a6793 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractNodesIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractNodesIT.java @@ -13,8 +13,11 @@ import static org.hamcrest.Matchers.anEmptyMap; import java.io.IOException; +import java.util.Arrays; import org.opensearch.client.opensearch.nodes.NodesStatsResponse; +import org.opensearch.client.opensearch.tasks.ListRequest; +import org.opensearch.client.opensearch.tasks.ListResponse; public abstract class AbstractNodesIT extends OpenSearchJavaClientTestCase { public void testNodesStats() throws IOException { @@ -22,4 +25,10 @@ public void testNodesStats() throws IOException { assertThat(response.clusterName(), not(nullValue())); assertThat(response.nodes(), not(anEmptyMap())); } + + public void testNodesList() throws IOException { + ListRequest listRequest = new ListRequest.Builder().actions(Arrays.asList("*reindex")).build(); + ListResponse listResponse = javaClient().tasks().list(); + assertThat(listResponse.nodes(), not(anEmptyMap())); + } }