Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetTasksResponse TaskFailure deserialization #727

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Fixed
- Fix partial success results for msearch_template ([#709](https://github.com/opensearch-project/opensearch-java/pull/709))
- Fix deserialization of failures in GetTasksResponse ([#727](https://github.com/opensearch-project/opensearch-java/pull/727))


### Security

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* 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._types;

// typedef: _types.TaskFailure

import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.*;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

@JsonpDeserializable
public class TaskFailure implements JsonpSerializable {

private final ErrorCause cause;

@Nullable
private final String id;

@Nullable
private final String index;

@Nullable
private final Integer status;

@Nullable
private final String type;

// ---------------------------------------------------------------------------------------------

private TaskFailure(Builder builder) {

this.index = builder.index;
this.id = builder.id;
this.cause = ApiTypeHelper.requireNonNull(builder.cause, this, "cause");
this.status = builder.status;
this.type = builder.type;

}

public static TaskFailure of(Function<Builder, ObjectBuilder<TaskFailure>> fn) {
return fn.apply(new Builder()).build();
}

/**
* API name: {@code index}
*/
@Nullable
public final String index() {
return this.index;
}

/**
* API name: {@code id}
*/
@Nullable
public final String id() {
return this.id;
}

/**
* Required - API name: {@code cause}
*/
public final ErrorCause cause() {
return this.cause;
}

/**
* API name: {@code status}
*/
@Nullable
public final Integer status() {
return this.status;
}

/**
* API name: {@code type}
*/
@Nullable
public final String type() {
return this.type;
}

/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

if (this.index != null) {
generator.writeKey("index");
generator.write(this.index);

}
if (this.id != null) {
generator.writeKey("id");
generator.write(this.id);
}

generator.writeKey("cause");
this.cause.serialize(generator, mapper);

if (this.status != null) {
generator.writeKey("status");
generator.write(this.status);
}
if (this.type != null) {
generator.writeKey("type");
generator.write(this.type);
}

}

// ---------------------------------------------------------------------------------------------

/**
* Builder for {@link TaskFailure}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<TaskFailure> {
@Nullable
private String index;

@Nullable
private String id;

private ErrorCause cause;

@Nullable
private Integer status;

@Nullable
private String type;

/**
* API name: {@code index}
*/
public final Builder index(@Nullable String value) {
this.index = value;
return this;
}

/**
* API name: {@code id}
*/
public final Builder id(@Nullable String value) {
this.id = value;
return this;
}

/**
* Required - API name: {@code cause}
*/
public final Builder cause(ErrorCause value) {
this.cause = value;
return this;
}

/**
* Required - API name: {@code cause}
*/
public final Builder cause(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
return this.cause(fn.apply(new ErrorCause.Builder()).build());
}

/**
* API name: {@code status}
*/
public final Builder status(@Nullable Integer value) {
this.status = value;
return this;
}

/**
* API name: {@code type}
*/
public final Builder type(@Nullable String value) {
this.type = value;
return this;
}

/**
* Builds a {@link TaskFailure}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public TaskFailure build() {
_checkSingleUse();

return new TaskFailure(this);
}
}

// ---------------------------------------------------------------------------------------------

/**
* Json deserializer for {@link TaskFailure}
*/
public static final JsonpDeserializer<TaskFailure> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
TaskFailure::setupTaskFailureDeserializer
);

protected static void setupTaskFailureDeserializer(ObjectDeserializer<Builder> op) {

op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index");
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
op.add(Builder::cause, ErrorCause._DESERIALIZER, "cause");
op.add(Builder::status, JsonpDeserializer.integerDeserializer(), "status");
op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
Expand All @@ -55,7 +56,7 @@ public class GetTasksResponse implements JsonpSerializable {
private final Info task;

@Nullable
private final Status response;
private final JsonData response;

@Nullable
private final ErrorCause error;
Expand Down Expand Up @@ -93,7 +94,7 @@ public final Info task() {
* API name: {@code response}
*/
@Nullable
public final Status response() {
public final JsonData response() {
return this.response;
}

Expand Down Expand Up @@ -147,7 +148,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<G
private Info task;

@Nullable
private Status response;
private JsonData response;

@Nullable
private ErrorCause error;
Expand Down Expand Up @@ -178,18 +179,11 @@ public final Builder task(Function<Info.Builder, ObjectBuilder<Info>> fn) {
/**
* API name: {@code response}
*/
public final Builder response(@Nullable Status value) {
public final Builder response(@Nullable JsonData value) {
this.response = value;
return this;
}

/**
* API name: {@code response}
*/
public final Builder response(Function<Status.Builder, ObjectBuilder<Status>> fn) {
return this.response(fn.apply(new Status.Builder()).build());
}

/**
* API name: {@code error}
*/
Expand Down Expand Up @@ -232,7 +226,7 @@ protected static void setupGetTasksResponseDeserializer(ObjectDeserializer<GetTa

op.add(Builder::completed, JsonpDeserializer.booleanDeserializer(), "completed");
op.add(Builder::task, Info._DESERIALIZER, "task");
op.add(Builder::response, Status._DESERIALIZER, "response");
op.add(Builder::response, JsonData._DESERIALIZER, "response");
op.add(Builder::error, ErrorCause._DESERIALIZER, "error");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
Expand Down Expand Up @@ -71,7 +72,7 @@ public class Info implements JsonpSerializable {
private final long startTimeInMillis;

@Nullable
private final Status status;
private final JsonData status;

private final String type;

Expand Down Expand Up @@ -169,7 +170,7 @@ public final long startTimeInMillis() {
* API name: {@code status}
*/
@Nullable
public final Status status() {
public final JsonData status() {
return this.status;
}

Expand Down Expand Up @@ -294,7 +295,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<I
private Long startTimeInMillis;

@Nullable
private Status status;
private JsonData status;

private String type;

Expand Down Expand Up @@ -409,18 +410,11 @@ public final Builder startTimeInMillis(long value) {
/**
* API name: {@code status}
*/
public final Builder status(@Nullable Status value) {
public final Builder status(@Nullable JsonData value) {
this.status = value;
return this;
}

/**
* API name: {@code status}
*/
public final Builder status(Function<Status.Builder, ObjectBuilder<Status>> fn) {
return this.status(fn.apply(new Status.Builder()).build());
}

/**
* Required - API name: {@code type}
*/
Expand Down Expand Up @@ -472,7 +466,7 @@ protected static void setupInfoDeserializer(ObjectDeserializer<Info.Builder> op)
op.add(Builder::node, JsonpDeserializer.stringDeserializer(), "node");
op.add(Builder::runningTimeInNanos, JsonpDeserializer.longDeserializer(), "running_time_in_nanos");
op.add(Builder::startTimeInMillis, JsonpDeserializer.longDeserializer(), "start_time_in_millis");
op.add(Builder::status, Status._DESERIALIZER, "status");
op.add(Builder::status, JsonData._DESERIALIZER, "status");
op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type");
op.add(Builder::parentTaskId, JsonpDeserializer.stringDeserializer(), "parent_task_id");

Expand Down
Loading
Loading