Skip to content
This repository was archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Scan bulk response for errors and log them
Browse files Browse the repository at this point in the history
  • Loading branch information
bleskes committed Mar 4, 2014
1 parent 5d9840a commit 54efca5
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,30 @@ private void addXContentRendererToConnection(HttpURLConnection conn,
}
}

@SuppressWarnings("unchecked")
private void sendCloseExportingConnection(HttpURLConnection conn) throws IOException {
logger.trace("sending content");
OutputStream os = conn.getOutputStream();
os.close();

InputStream inputStream = conn.getInputStream();
while (inputStream.read() != -1) ;
inputStream.close();

if (conn.getResponseCode() != 200) {
logConnectionError("remote target didn't respond with 200 OK", conn);
return;
}

InputStream inputStream = conn.getInputStream();
XContentParser parser = XContentType.SMILE.xContent().createParser(inputStream);
Map<String, Object> response = parser.mapAndClose();
if (response.get("items") != null) {
ArrayList<Object> list = (ArrayList<Object>) response.get("items");
for (Object itemObject : list) {
Map<String, Object> actions = (Map<String, Object>) itemObject;
for (String actionKey : actions.keySet()) {
Map<String, Object> action = (Map<String, Object>) actions.get(actionKey);
if (action.get("error") != null) {
logger.error("{} failure (index:[{}] type: [{}]): {}", actionKey, action.get("_index"), action.get("_type"), action.get("error"));
}
}
}
}
}

Expand Down Expand Up @@ -502,7 +515,6 @@ private void addNodeInfo(XContentBuilder builder, String fieldname) throws IOExc
builder.endObject();
}


class NodeStatsRenderer implements MultiXContentRenderer {

NodeStats stats;
Expand Down

0 comments on commit 54efca5

Please sign in to comment.