Search in sources :

Example 1 with ShardOperationFailedException

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();
}
Also used : ShardOperationFailedException(org.opensearch.action.ShardOperationFailedException)

Example 2 with ShardOperationFailedException

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]);
}
Also used : ArrayList(java.util.ArrayList) OpenSearchException(org.opensearch.OpenSearchException) ShardOperationFailedException(org.opensearch.action.ShardOperationFailedException)

Example 3 with ShardOperationFailedException

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++]));
    }
}
Also used : ShardOperationFailedException(org.opensearch.action.ShardOperationFailedException)

Example 4 with ShardOperationFailedException

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));
}
Also used : ParsingException(org.opensearch.common.ParsingException) ShardOperationFailedException(org.opensearch.action.ShardOperationFailedException) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure)

Example 5 with ShardOperationFailedException

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++]));
    }
}
Also used : ShardOperationFailedException(org.opensearch.action.ShardOperationFailedException)

Aggregations

ShardOperationFailedException (org.opensearch.action.ShardOperationFailedException)9 ArrayList (java.util.ArrayList)3 OpenSearchException (org.opensearch.OpenSearchException)2 ArrayDeque (java.util.ArrayDeque)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executor (java.util.concurrent.Executor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiFunction (java.util.function.BiFunction)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.logging.log4j.Logger)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 SetOnce (org.apache.lucene.util.SetOnce)1 ExceptionsHelper (org.opensearch.ExceptionsHelper)1 Version (org.opensearch.Version)1