Search in sources :

Example 16 with ShardSearchFailure

use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.

the class ExceptionSerializationTests method testSearchPhaseExecutionException.

public void testSearchPhaseExecutionException() throws IOException {
    ShardSearchFailure[] empty = new ShardSearchFailure[0];
    SearchPhaseExecutionException ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), empty));
    assertEquals("boom", ex.getPhaseName());
    assertEquals("baam", ex.getMessage());
    assertTrue(ex.getCause() instanceof NullPointerException);
    assertEquals(empty.length, ex.shardFailures().length);
    ShardSearchFailure[] one = new ShardSearchFailure[] { new ShardSearchFailure(new IllegalArgumentException("nono!")) };
    ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), one));
    assertEquals("boom", ex.getPhaseName());
    assertEquals("baam", ex.getMessage());
    assertTrue(ex.getCause() instanceof NullPointerException);
    assertEquals(one.length, ex.shardFailures().length);
    assertTrue(ex.shardFailures()[0].getCause() instanceof IllegalArgumentException);
}
Also used : SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure)

Example 17 with ShardSearchFailure

use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.

the class OpenSearchExceptionTests method randomExceptions.

public static Tuple<Throwable, OpenSearchException> randomExceptions() {
    Throwable actual;
    OpenSearchException expected;
    int type = randomIntBetween(0, 5);
    switch(type) {
        case 0:
            actual = new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES));
            expected = new OpenSearchException("OpenSearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]");
            break;
        case // Simple opensearch exception with headers (other metadata of type number are not parsed)
        1:
            actual = new ParsingException(3, 2, "Unknown identifier", null);
            expected = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=Unknown identifier]");
            break;
        case 2:
            actual = new SearchParseException(SHARD_TARGET, "Parse failure", new XContentLocation(12, 98));
            expected = new OpenSearchException("OpenSearch exception [type=search_parse_exception, reason=Parse failure]");
            break;
        case 3:
            actual = new IllegalArgumentException("Closed resource", new RuntimeException("Resource"));
            expected = new OpenSearchException("OpenSearch exception [type=illegal_argument_exception, reason=Closed resource]", new OpenSearchException("OpenSearch exception [type=runtime_exception, reason=Resource]"));
            break;
        case 4:
            actual = new SearchPhaseExecutionException("search", "all shards failed", new ShardSearchFailure[] { new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new ShardId("foo", "_na_", 1), null, OriginalIndices.NONE)) });
            expected = new OpenSearchException("OpenSearch exception [type=search_phase_execution_exception, " + "reason=all shards failed]");
            expected.addMetadata("opensearch.phase", "search");
            break;
        case 5:
            actual = new OpenSearchException("Parsing failed", new ParsingException(9, 42, "Wrong state", new NullPointerException("Unexpected null value")));
            OpenSearchException expectedCause = new OpenSearchException("OpenSearch exception [type=parsing_exception, " + "reason=Wrong state]", new OpenSearchException("OpenSearch exception [type=null_pointer_exception, " + "reason=Unexpected null value]"));
            expected = new OpenSearchException("OpenSearch exception [type=exception, reason=Parsing failed]", expectedCause);
            break;
        default:
            throw new UnsupportedOperationException("No randomized exceptions generated for type [" + type + "]");
    }
    if (actual instanceof OpenSearchException) {
        OpenSearchException actualException = (OpenSearchException) actual;
        if (randomBoolean()) {
            int nbHeaders = randomIntBetween(1, 5);
            Map<String, List<String>> randomHeaders = new HashMap<>(nbHeaders);
            for (int i = 0; i < nbHeaders; i++) {
                List<String> values = new ArrayList<>();
                int nbValues = randomIntBetween(1, 3);
                for (int j = 0; j < nbValues; j++) {
                    values.add(frequently() ? randomAlphaOfLength(5) : "");
                }
                randomHeaders.put("header_" + i, values);
            }
            for (Map.Entry<String, List<String>> entry : randomHeaders.entrySet()) {
                actualException.addHeader(entry.getKey(), entry.getValue());
                expected.addHeader(entry.getKey(), entry.getValue());
            }
            if (rarely()) {
                // Empty or null headers are not printed out by the toXContent method
                actualException.addHeader("ignored", randomBoolean() ? emptyList() : null);
            }
        }
        if (randomBoolean()) {
            int nbMetadata = randomIntBetween(1, 5);
            Map<String, List<String>> randomMetadata = new HashMap<>(nbMetadata);
            for (int i = 0; i < nbMetadata; i++) {
                List<String> values = new ArrayList<>();
                int nbValues = randomIntBetween(1, 3);
                for (int j = 0; j < nbValues; j++) {
                    values.add(frequently() ? randomAlphaOfLength(5) : "");
                }
                randomMetadata.put("opensearch.metadata_" + i, values);
            }
            for (Map.Entry<String, List<String>> entry : randomMetadata.entrySet()) {
                actualException.addMetadata(entry.getKey(), entry.getValue());
                expected.addMetadata(entry.getKey(), entry.getValue());
            }
            if (rarely()) {
                // Empty or null metadata are not printed out by the toXContent method
                actualException.addMetadata("opensearch.ignored", randomBoolean() ? emptyList() : null);
            }
        }
        if (randomBoolean()) {
            int nbResources = randomIntBetween(1, 5);
            for (int i = 0; i < nbResources; i++) {
                String resourceType = "type_" + i;
                String[] resourceIds = new String[randomIntBetween(1, 3)];
                for (int j = 0; j < resourceIds.length; j++) {
                    resourceIds[j] = frequently() ? randomAlphaOfLength(5) : "";
                }
                actualException.setResources(resourceType, resourceIds);
                expected.setResources(resourceType, resourceIds);
            }
        }
    }
    return new Tuple<>(actual, expected);
}
Also used : HashMap(java.util.HashMap) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) ArrayList(java.util.ArrayList) ShardId(org.opensearch.index.shard.ShardId) ParsingException(org.opensearch.common.ParsingException) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) XContentLocation(org.opensearch.common.xcontent.XContentLocation) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) SearchParseException(org.opensearch.search.SearchParseException) SearchShardTarget(org.opensearch.search.SearchShardTarget) Map(java.util.Map) HashMap(java.util.HashMap) Tuple(org.opensearch.common.collect.Tuple)

Example 18 with ShardSearchFailure

use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.

the class ExceptionsHelperTests method createShardFailureParsingException.

private static ShardSearchFailure createShardFailureParsingException(String error, String nodeId, String index, int shardId, String clusterAlias) {
    ParsingException ex = new ParsingException(0, 0, error, new IllegalArgumentException("some bad argument"));
    ex.setIndex(index);
    return new ShardSearchFailure(ex, createSearchShardTarget(nodeId, shardId, index, clusterAlias));
}
Also used : ParsingException(org.opensearch.common.ParsingException) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure)

Example 19 with ShardSearchFailure

use of org.opensearch.action.search.ShardSearchFailure 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 20 with ShardSearchFailure

use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.

the class ExceptionsHelperTests method createShardFailureQueryShardException.

private static ShardSearchFailure createShardFailureQueryShardException(String error, String indexName, String clusterAlias) {
    Index index = new Index(RemoteClusterAware.buildRemoteIndexName(clusterAlias, indexName), "uuid");
    QueryShardException queryShardException = new QueryShardException(index, error, new IllegalArgumentException("parse error"));
    return new ShardSearchFailure(queryShardException, null);
}
Also used : QueryShardException(org.opensearch.index.query.QueryShardException) Index(org.opensearch.index.Index) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure)

Aggregations

ShardSearchFailure (org.opensearch.action.search.ShardSearchFailure)23 SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)8 SearchResponse (org.opensearch.action.search.SearchResponse)7 ParsingException (org.opensearch.common.ParsingException)7 IOException (java.io.IOException)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ShardId (org.opensearch.index.shard.ShardId)4 SearchShardTarget (org.opensearch.search.SearchShardTarget)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)3 Index (org.opensearch.index.Index)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ActionListener (org.opensearch.action.ActionListener)2 LatchedActionListener (org.opensearch.action.LatchedActionListener)2 MultiSearchResponse (org.opensearch.action.search.MultiSearchResponse)2 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)2 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)2