Skip to content

Commit

Permalink
Fixing issues when deserializing response for tasks API (#463)
Browse files Browse the repository at this point in the history
* Fix failure when deserializing response for tasks API

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Add changelog

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Marking the fields Nullable

Signed-off-by: Vacha Shah <vachshah@amazon.com>

---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed May 3, 2023
1 parent 81ed75c commit 4b9bcbc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased 2.x]

### Added
- Add workflow to publish snapshots via GHA ([#454](https://github.com/opensearch-project/opensearch-java/pull/454))

### Dependencies

Expand All @@ -41,6 +42,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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;
Expand All @@ -112,7 +112,7 @@ public final List<NodeRole> roles() {
}

/**
* Required - API name: {@code transport_address}
* API name: {@code transport_address}
*/
public final String transportAddress() {
return this.transportAddress;
Expand Down Expand Up @@ -166,21 +166,26 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder<BuilderT>>
extends
ObjectBuilderBase {
@Nullable
private Map<String, String> attributes;

@Nullable
private String host;

@Nullable
private String ip;

@Nullable
private String name;

@Nullable
private List<NodeRole> roles;

@Nullable
private String transportAddress;

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

/**
* Required - API name: {@code attributes}
* API name: {@code attributes}
* <p>
* Adds an entry to <code>attributes</code>.
*/
Expand All @@ -200,23 +205,23 @@ 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;
return self();
}

/**
* Required - API name: {@code ip}
* API name: {@code ip}
*/
public final BuilderT ip(String value) {
this.ip = value;
return self();
}

/**
* Required - API name: {@code name}
* API name: {@code name}
*/
public final BuilderT name(String value) {
this.name = value;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
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 {
final NodesStatsResponse response = javaClient().nodes().stats();
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()));
}
}

0 comments on commit 4b9bcbc

Please sign in to comment.