Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.7] Handle exceptions when building _cat/indices response #57147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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