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:
Andrew Selden 2014-04-09 19:02:41 -07:00
parent 1f7f72135a
commit 3121ad20dd
2 changed files with 19 additions and 20 deletions

View File

@ -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;
} }

View File

@ -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);
} }
}); });