Skip to content

Commit fbaee9d

Browse files
committed
fix GetTasksResponse failures mapping
Signed-off-by: bfindlay <[email protected]> update changelog Signed-off-by: bfindlay <[email protected]> revert Info change Signed-off-by: bfindlay <[email protected]> change response to JsonData type Signed-off-by: bfindlay <[email protected]> fix spottless check Signed-off-by: bfindlay <[email protected]> Update status to JsonData Signed-off-by: bfindlay <[email protected]> apply spotless check Signed-off-by: bfindlay <[email protected]> add itest for JsonData deserialization Signed-off-by: bfindlay <[email protected]> update itest Signed-off-by: bfindlay <[email protected]> update itest Signed-off-by: bfindlay <[email protected]> fix itest Signed-off-by: bfindlay <[email protected]> fix pipeline failure Signed-off-by: bfindlay <[email protected]> exclude system indices from cat itest Signed-off-by: bfindlay <[email protected]>
1 parent a4dc4f0 commit fbaee9d

File tree

11 files changed

+518
-35
lines changed

11 files changed

+518
-35
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ This section is for maintaining a changelog for all breaking changes for the cli
4343

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

4749
### Security
4850

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client.opensearch._types;
10+
11+
// typedef: _types.TaskFailure
12+
13+
import jakarta.json.stream.JsonGenerator;
14+
import java.util.function.Function;
15+
import javax.annotation.Nullable;
16+
import org.opensearch.client.json.*;
17+
import org.opensearch.client.util.ApiTypeHelper;
18+
import org.opensearch.client.util.ObjectBuilder;
19+
import org.opensearch.client.util.ObjectBuilderBase;
20+
21+
@JsonpDeserializable
22+
public class TaskFailure implements JsonpSerializable {
23+
24+
private final ErrorCause cause;
25+
26+
@Nullable
27+
private final String id;
28+
29+
@Nullable
30+
private final String index;
31+
32+
@Nullable
33+
private final Integer status;
34+
35+
@Nullable
36+
private final String type;
37+
38+
// ---------------------------------------------------------------------------------------------
39+
40+
private TaskFailure(Builder builder) {
41+
42+
this.index = builder.index;
43+
this.id = builder.id;
44+
this.cause = ApiTypeHelper.requireNonNull(builder.cause, this, "cause");
45+
this.status = builder.status;
46+
this.type = builder.type;
47+
48+
}
49+
50+
public static TaskFailure of(Function<Builder, ObjectBuilder<TaskFailure>> fn) {
51+
return fn.apply(new Builder()).build();
52+
}
53+
54+
/**
55+
* API name: {@code index}
56+
*/
57+
@Nullable
58+
public final String index() {
59+
return this.index;
60+
}
61+
62+
/**
63+
* API name: {@code id}
64+
*/
65+
@Nullable
66+
public final String id() {
67+
return this.id;
68+
}
69+
70+
/**
71+
* Required - API name: {@code cause}
72+
*/
73+
public final ErrorCause cause() {
74+
return this.cause;
75+
}
76+
77+
/**
78+
* API name: {@code status}
79+
*/
80+
@Nullable
81+
public final Integer status() {
82+
return this.status;
83+
}
84+
85+
/**
86+
* API name: {@code type}
87+
*/
88+
@Nullable
89+
public final String type() {
90+
return this.type;
91+
}
92+
93+
/**
94+
* Serialize this object to JSON.
95+
*/
96+
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
97+
generator.writeStartObject();
98+
serializeInternal(generator, mapper);
99+
generator.writeEnd();
100+
}
101+
102+
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
103+
104+
if (this.index != null) {
105+
generator.writeKey("index");
106+
generator.write(this.index);
107+
108+
}
109+
if (this.id != null) {
110+
generator.writeKey("id");
111+
generator.write(this.id);
112+
}
113+
114+
generator.writeKey("cause");
115+
this.cause.serialize(generator, mapper);
116+
117+
if (this.status != null) {
118+
generator.writeKey("status");
119+
generator.write(this.status);
120+
}
121+
if (this.type != null) {
122+
generator.writeKey("type");
123+
generator.write(this.type);
124+
}
125+
126+
}
127+
128+
// ---------------------------------------------------------------------------------------------
129+
130+
/**
131+
* Builder for {@link TaskFailure}.
132+
*/
133+
134+
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<TaskFailure> {
135+
@Nullable
136+
private String index;
137+
138+
@Nullable
139+
private String id;
140+
141+
private ErrorCause cause;
142+
143+
@Nullable
144+
private Integer status;
145+
146+
@Nullable
147+
private String type;
148+
149+
/**
150+
* API name: {@code index}
151+
*/
152+
public final Builder index(@Nullable String value) {
153+
this.index = value;
154+
return this;
155+
}
156+
157+
/**
158+
* API name: {@code id}
159+
*/
160+
public final Builder id(@Nullable String value) {
161+
this.id = value;
162+
return this;
163+
}
164+
165+
/**
166+
* Required - API name: {@code cause}
167+
*/
168+
public final Builder cause(ErrorCause value) {
169+
this.cause = value;
170+
return this;
171+
}
172+
173+
/**
174+
* Required - API name: {@code cause}
175+
*/
176+
public final Builder cause(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
177+
return this.cause(fn.apply(new ErrorCause.Builder()).build());
178+
}
179+
180+
/**
181+
* API name: {@code status}
182+
*/
183+
public final Builder status(@Nullable Integer value) {
184+
this.status = value;
185+
return this;
186+
}
187+
188+
/**
189+
* API name: {@code type}
190+
*/
191+
public final Builder type(@Nullable String value) {
192+
this.type = value;
193+
return this;
194+
}
195+
196+
/**
197+
* Builds a {@link TaskFailure}.
198+
*
199+
* @throws NullPointerException
200+
* if some of the required fields are null.
201+
*/
202+
public TaskFailure build() {
203+
_checkSingleUse();
204+
205+
return new TaskFailure(this);
206+
}
207+
}
208+
209+
// ---------------------------------------------------------------------------------------------
210+
211+
/**
212+
* Json deserializer for {@link TaskFailure}
213+
*/
214+
public static final JsonpDeserializer<TaskFailure> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
215+
Builder::new,
216+
TaskFailure::setupTaskFailureDeserializer
217+
);
218+
219+
protected static void setupTaskFailureDeserializer(ObjectDeserializer<Builder> op) {
220+
221+
op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index");
222+
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
223+
op.add(Builder::cause, ErrorCause._DESERIALIZER, "cause");
224+
op.add(Builder::status, JsonpDeserializer.integerDeserializer(), "status");
225+
op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type");
226+
227+
}
228+
229+
}

java-client/src/main/java/org/opensearch/client/opensearch/tasks/GetTasksResponse.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import jakarta.json.stream.JsonGenerator;
3636
import java.util.function.Function;
3737
import javax.annotation.Nullable;
38+
import org.opensearch.client.json.JsonData;
3839
import org.opensearch.client.json.JsonpDeserializable;
3940
import org.opensearch.client.json.JsonpDeserializer;
4041
import org.opensearch.client.json.JsonpMapper;
@@ -55,7 +56,7 @@ public class GetTasksResponse implements JsonpSerializable {
5556
private final Info task;
5657

5758
@Nullable
58-
private final Status response;
59+
private final JsonData response;
5960

6061
@Nullable
6162
private final ErrorCause error;
@@ -93,7 +94,7 @@ public final Info task() {
9394
* API name: {@code response}
9495
*/
9596
@Nullable
96-
public final Status response() {
97+
public final JsonData response() {
9798
return this.response;
9899
}
99100

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

149150
@Nullable
150-
private Status response;
151+
private JsonData response;
151152

152153
@Nullable
153154
private ErrorCause error;
@@ -178,18 +179,11 @@ public final Builder task(Function<Info.Builder, ObjectBuilder<Info>> fn) {
178179
/**
179180
* API name: {@code response}
180181
*/
181-
public final Builder response(@Nullable Status value) {
182+
public final Builder response(@Nullable JsonData value) {
182183
this.response = value;
183184
return this;
184185
}
185186

186-
/**
187-
* API name: {@code response}
188-
*/
189-
public final Builder response(Function<Status.Builder, ObjectBuilder<Status>> fn) {
190-
return this.response(fn.apply(new Status.Builder()).build());
191-
}
192-
193187
/**
194188
* API name: {@code error}
195189
*/
@@ -232,7 +226,7 @@ protected static void setupGetTasksResponseDeserializer(ObjectDeserializer<GetTa
232226

233227
op.add(Builder::completed, JsonpDeserializer.booleanDeserializer(), "completed");
234228
op.add(Builder::task, Info._DESERIALIZER, "task");
235-
op.add(Builder::response, Status._DESERIALIZER, "response");
229+
op.add(Builder::response, JsonData._DESERIALIZER, "response");
236230
op.add(Builder::error, ErrorCause._DESERIALIZER, "error");
237231

238232
}

java-client/src/main/java/org/opensearch/client/opensearch/tasks/Info.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Map;
3838
import java.util.function.Function;
3939
import javax.annotation.Nullable;
40+
import org.opensearch.client.json.JsonData;
4041
import org.opensearch.client.json.JsonpDeserializable;
4142
import org.opensearch.client.json.JsonpDeserializer;
4243
import org.opensearch.client.json.JsonpMapper;
@@ -71,7 +72,7 @@ public class Info implements JsonpSerializable {
7172
private final long startTimeInMillis;
7273

7374
@Nullable
74-
private final Status status;
75+
private final JsonData status;
7576

7677
private final String type;
7778

@@ -169,7 +170,7 @@ public final long startTimeInMillis() {
169170
* API name: {@code status}
170171
*/
171172
@Nullable
172-
public final Status status() {
173+
public final JsonData status() {
173174
return this.status;
174175
}
175176

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

296297
@Nullable
297-
private Status status;
298+
private JsonData status;
298299

299300
private String type;
300301

@@ -409,18 +410,11 @@ public final Builder startTimeInMillis(long value) {
409410
/**
410411
* API name: {@code status}
411412
*/
412-
public final Builder status(@Nullable Status value) {
413+
public final Builder status(@Nullable JsonData value) {
413414
this.status = value;
414415
return this;
415416
}
416417

417-
/**
418-
* API name: {@code status}
419-
*/
420-
public final Builder status(Function<Status.Builder, ObjectBuilder<Status>> fn) {
421-
return this.status(fn.apply(new Status.Builder()).build());
422-
}
423-
424418
/**
425419
* Required - API name: {@code type}
426420
*/
@@ -472,7 +466,7 @@ protected static void setupInfoDeserializer(ObjectDeserializer<Info.Builder> op)
472466
op.add(Builder::node, JsonpDeserializer.stringDeserializer(), "node");
473467
op.add(Builder::runningTimeInNanos, JsonpDeserializer.longDeserializer(), "running_time_in_nanos");
474468
op.add(Builder::startTimeInMillis, JsonpDeserializer.longDeserializer(), "start_time_in_millis");
475-
op.add(Builder::status, Status._DESERIALIZER, "status");
469+
op.add(Builder::status, JsonData._DESERIALIZER, "status");
476470
op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type");
477471
op.add(Builder::parentTaskId, JsonpDeserializer.stringDeserializer(), "parent_task_id");
478472

0 commit comments

Comments
 (0)