Skip to content

Commit

Permalink
[7.7] Handle exceptions when building _cat/indices response (#57147)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann committed May 26, 2020
1 parent dd9be9c commit 03a0dc7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,22 @@
open \s+ foo\n
open \s+ baz\n
$/
---
"Test cat indices with invalid health parameter":
- skip:
version: " - 7.7.1"
reason: "fixed in 7.7.1+"

- do:
indices.create:
index: foo
body:
settings:
number_of_shards: "1"
number_of_replicas: "0"

- do:
catch: bad_request
cat.indices:
health: "invalid-health-value"
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,27 @@ private GroupedActionListener<ActionResponse> createGroupedListener(final RestRe
return new GroupedActionListener<>(new ActionListener<Collection<ActionResponse>>() {
@Override
public void onResponse(final Collection<ActionResponse> responses) {
GetSettingsResponse settingsResponse = extractResponse(responses, GetSettingsResponse.class);
Map<String, Settings> indicesSettings = StreamSupport.stream(settingsResponse.getIndexToSettings().spliterator(), false)
.collect(Collectors.toMap(cursor -> cursor.key, cursor -> cursor.value));

ClusterStateResponse stateResponse = extractResponse(responses, ClusterStateResponse.class);
Map<String, IndexMetaData> indicesStates = StreamSupport.stream(stateResponse.getState().getMetaData().spliterator(), false)
.collect(Collectors.toMap(indexMetaData -> indexMetaData.getIndex().getName(), Function.identity()));

ClusterHealthResponse healthResponse = extractResponse(responses, ClusterHealthResponse.class);
Map<String, ClusterIndexHealth> indicesHealths = healthResponse.getIndices();

IndicesStatsResponse statsResponse = extractResponse(responses, IndicesStatsResponse.class);
Map<String, IndexStats> indicesStats = statsResponse.getIndices();

listener.onResponse(buildTable(request, indicesSettings, indicesHealths, indicesStats, indicesStates));
try {
GetSettingsResponse settingsResponse = extractResponse(responses, GetSettingsResponse.class);
Map<String, Settings> indicesSettings = StreamSupport.stream(settingsResponse.getIndexToSettings().spliterator(), false)
.collect(Collectors.toMap(cursor -> cursor.key, cursor -> cursor.value));

ClusterStateResponse stateResponse = extractResponse(responses, ClusterStateResponse.class);
Map<String, IndexMetaData> indicesStates =
StreamSupport.stream(stateResponse.getState().getMetaData().spliterator(), false)
.collect(Collectors.toMap(indexMetadata -> indexMetadata.getIndex().getName(), Function.identity()));

ClusterHealthResponse healthResponse = extractResponse(responses, ClusterHealthResponse.class);
Map<String, ClusterIndexHealth> indicesHealths = healthResponse.getIndices();

IndicesStatsResponse statsResponse = extractResponse(responses, IndicesStatsResponse.class);
Map<String, IndexStats> indicesStats = statsResponse.getIndices();

Table responseTable = buildTable(request, indicesSettings, indicesHealths, indicesStats, indicesStates);
listener.onResponse(responseTable);
} catch (Exception e) {
onFailure(e);
}
}

@Override
Expand Down

0 comments on commit 03a0dc7

Please sign in to comment.