use of org.opensearch.action.ShardOperationFailedException in project OpenSearch by opensearch-project.
the class RestActions method buildBroadcastShardsHeader.
public static void buildBroadcastShardsHeader(XContentBuilder builder, Params params, int total, int successful, int skipped, int failed, ShardOperationFailedException[] shardFailures) throws IOException {
builder.startObject(_SHARDS_FIELD.getPreferredName());
builder.field(TOTAL_FIELD.getPreferredName(), total);
builder.field(SUCCESSFUL_FIELD.getPreferredName(), successful);
if (skipped >= 0) {
builder.field(SKIPPED_FIELD.getPreferredName(), skipped);
}
builder.field(FAILED_FIELD.getPreferredName(), failed);
if (CollectionUtils.isEmpty(shardFailures) == false) {
builder.startArray(FAILURES_FIELD.getPreferredName());
for (ShardOperationFailedException shardFailure : ExceptionsHelper.groupBy(shardFailures)) {
shardFailure.toXContent(builder, params);
}
builder.endArray();
}
builder.endObject();
}
use of org.opensearch.action.ShardOperationFailedException in project OpenSearch by opensearch-project.
the class SearchPhaseExecutionException method guessRootCauses.
@Override
public OpenSearchException[] guessRootCauses() {
ShardOperationFailedException[] failures = ExceptionsHelper.groupBy(shardFailures);
List<OpenSearchException> rootCauses = new ArrayList<>(failures.length);
for (ShardOperationFailedException failure : failures) {
OpenSearchException[] guessRootCauses = OpenSearchException.guessRootCauses(failure.getCause());
rootCauses.addAll(Arrays.asList(guessRootCauses));
}
return rootCauses.toArray(new OpenSearchException[0]);
}
use of org.opensearch.action.ShardOperationFailedException in project OpenSearch by opensearch-project.
the class ExceptionsHelperTests method testGroupBy.
public void testGroupBy() {
ShardOperationFailedException[] failures = new ShardOperationFailedException[] { createShardFailureParsingException("error", "node0", "index", 0, null), createShardFailureParsingException("error", "node1", "index", 1, null), createShardFailureParsingException("error", "node2", "index2", 2, null), createShardFailureParsingException("error", "node0", "index", 0, "cluster1"), createShardFailureParsingException("error", "node1", "index", 1, "cluster1"), createShardFailureParsingException("error", "node2", "index", 2, "cluster1"), createShardFailureParsingException("error", "node0", "index", 0, "cluster2"), createShardFailureParsingException("error", "node1", "index", 1, "cluster2"), createShardFailureParsingException("error", "node2", "index", 2, "cluster2"), createShardFailureParsingException("another error", "node2", "index", 2, "cluster2") };
ShardOperationFailedException[] groupBy = ExceptionsHelper.groupBy(failures);
assertThat(groupBy.length, equalTo(5));
String[] expectedIndices = new String[] { "index", "index2", "cluster1:index", "cluster2:index", "cluster2:index" };
String[] expectedErrors = new String[] { "error", "error", "error", "error", "another error" };
int i = 0;
for (ShardOperationFailedException shardOperationFailedException : groupBy) {
assertThat(shardOperationFailedException.getCause().getMessage(), equalTo(expectedErrors[i]));
assertThat(shardOperationFailedException.index(), equalTo(expectedIndices[i++]));
}
}
use of org.opensearch.action.ShardOperationFailedException in project OpenSearch by opensearch-project.
the class ExceptionsHelperTests method testGroupByNullIndex.
public void testGroupByNullIndex() {
ShardOperationFailedException[] failures = new ShardOperationFailedException[] { new ShardSearchFailure(new IllegalArgumentException("error")), new ShardSearchFailure(new ParsingException(0, 0, "error", null)) };
ShardOperationFailedException[] groupBy = ExceptionsHelper.groupBy(failures);
assertThat(groupBy.length, equalTo(2));
}
use of org.opensearch.action.ShardOperationFailedException in project OpenSearch by opensearch-project.
the class ExceptionsHelperTests method testGroupByNullTarget.
public void testGroupByNullTarget() {
ShardOperationFailedException[] failures = new ShardOperationFailedException[] { createShardFailureQueryShardException("error", "index", null), createShardFailureQueryShardException("error", "index", null), createShardFailureQueryShardException("error", "index", null), createShardFailureQueryShardException("error", "index", "cluster1"), createShardFailureQueryShardException("error", "index", "cluster1"), createShardFailureQueryShardException("error", "index", "cluster1"), createShardFailureQueryShardException("error", "index", "cluster2"), createShardFailureQueryShardException("error", "index", "cluster2"), createShardFailureQueryShardException("error", "index2", null), createShardFailureQueryShardException("another error", "index2", null) };
ShardOperationFailedException[] groupBy = ExceptionsHelper.groupBy(failures);
assertThat(groupBy.length, equalTo(5));
String[] expectedIndices = new String[] { "index", "cluster1:index", "cluster2:index", "index2", "index2" };
String[] expectedErrors = new String[] { "error", "error", "error", "error", "another error" };
int i = 0;
for (ShardOperationFailedException shardOperationFailedException : groupBy) {
assertThat(shardOperationFailedException.index(), nullValue());
assertThat(shardOperationFailedException.getCause(), instanceOf(OpenSearchException.class));
OpenSearchException openSearchException = (OpenSearchException) shardOperationFailedException.getCause();
assertThat(openSearchException.getMessage(), equalTo(expectedErrors[i]));
assertThat(openSearchException.getIndex().getName(), equalTo(expectedIndices[i++]));
}
}
Aggregations