Return valid empty JSON response when no recovery information
This is a fix to send back to the client a valid empty JSON response in the case when we have no recovery information. Closes #5743
This commit is contained in:
parent
1f7f72135a
commit
3121ad20dd
|
@ -89,22 +89,23 @@ public class RecoveryResponse extends BroadcastOperationResponse implements ToXC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
if (hasRecoveries()) {
|
||||||
for (String index : shardResponses.keySet()) {
|
for (String index : shardResponses.keySet()) {
|
||||||
List<ShardRecoveryResponse> responses = shardResponses.get(index);
|
List<ShardRecoveryResponse> responses = shardResponses.get(index);
|
||||||
if (responses == null || responses.size() == 0) {
|
if (responses == null || responses.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
builder.startObject(index);
|
builder.startObject(index);
|
||||||
builder.startArray("shards");
|
builder.startArray("shards");
|
||||||
for (ShardRecoveryResponse recoveryResponse : responses) {
|
for (ShardRecoveryResponse recoveryResponse : responses) {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
recoveryResponse.detailed(this.detailed);
|
recoveryResponse.detailed(this.detailed);
|
||||||
recoveryResponse.toXContent(builder, params);
|
recoveryResponse.toXContent(builder, params);
|
||||||
|
builder.endObject();
|
||||||
|
}
|
||||||
|
builder.endArray();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
builder.endArray();
|
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,12 +57,10 @@ public class RestRecoveryAction extends BaseRestHandler {
|
||||||
client.admin().indices().recoveries(recoveryRequest, new RestBuilderListener<RecoveryResponse>(channel) {
|
client.admin().indices().recoveries(recoveryRequest, new RestBuilderListener<RecoveryResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(RecoveryResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(RecoveryResponse response, XContentBuilder builder) throws Exception {
|
||||||
if (response.hasRecoveries()) {
|
response.detailed(recoveryRequest.detailed());
|
||||||
response.detailed(recoveryRequest.detailed());
|
builder.startObject();
|
||||||
builder.startObject();
|
response.toXContent(builder, request);
|
||||||
response.toXContent(builder, request);
|
builder.endObject();
|
||||||
builder.endObject();
|
|
||||||
}
|
|
||||||
return new BytesRestResponse(OK, builder);
|
return new BytesRestResponse(OK, builder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue