Search in sources :

Example 1 with DefaultShardOperationFailedException

use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.

the class IndicesClientDocumentationIT method testValidateQuery.

@SuppressWarnings("unused")
public void testValidateQuery() throws IOException, InterruptedException {
    RestHighLevelClient client = highLevelClient();
    String index = "some_index";
    createIndex(index, Settings.EMPTY);
    // tag::indices-validate-query-request
    // <1>
    ValidateQueryRequest request = new ValidateQueryRequest(index);
    // end::indices-validate-query-request
    // tag::indices-validate-query-request-query
    QueryBuilder builder = QueryBuilders.boolQuery().must(QueryBuilders.queryStringQuery("*:*")).filter(QueryBuilders.termQuery("user", "foobar"));
    // <2>
    request.query(builder);
    // end::indices-validate-query-request-query
    // tag::indices-validate-query-request-explain
    // <1>
    request.explain(true);
    // end::indices-validate-query-request-explain
    // tag::indices-validate-query-request-allShards
    // <1>
    request.allShards(true);
    // end::indices-validate-query-request-allShards
    // tag::indices-validate-query-request-rewrite
    // <1>
    request.rewrite(true);
    // end::indices-validate-query-request-rewrite
    // tag::indices-validate-query-execute
    // <1>
    ValidateQueryResponse response = client.indices().validateQuery(request, RequestOptions.DEFAULT);
    // end::indices-validate-query-execute
    // tag::indices-validate-query-response
    // <1>
    boolean isValid = response.isValid();
    // <2>
    int totalShards = response.getTotalShards();
    // <3>
    int successfulShards = response.getSuccessfulShards();
    // <4>
    int failedShards = response.getFailedShards();
    if (failedShards > 0) {
        for (DefaultShardOperationFailedException failure : response.getShardFailures()) {
            // <5>
            // <6>
            String failedIndex = failure.index();
            // <7>
            int shardId = failure.shardId();
            // <8>
            String reason = failure.reason();
        }
    }
    for (QueryExplanation explanation : response.getQueryExplanation()) {
        // <9>
        // <10>
        String explanationIndex = explanation.getIndex();
        // <11>
        int shardId = explanation.getShard();
        // <12>
        String explanationString = explanation.getExplanation();
    }
    // end::indices-validate-query-response
    // tag::indices-validate-query-execute-listener
    ActionListener<ValidateQueryResponse> listener = new ActionListener<ValidateQueryResponse>() {

        @Override
        public void onResponse(ValidateQueryResponse validateQueryResponse) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::indices-validate-query-execute-listener
    // Replace the empty listener by a blocking listener in test
    final CountDownLatch latch = new CountDownLatch(1);
    listener = new LatchedActionListener<>(listener, latch);
    // tag::indices-validate-query-execute-async
    // <1>
    client.indices().validateQueryAsync(request, RequestOptions.DEFAULT, listener);
    // end::indices-validate-query-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : ValidateQueryResponse(org.opensearch.action.admin.indices.validate.query.ValidateQueryResponse) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) QueryBuilder(org.opensearch.index.query.QueryBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) IOException(java.io.IOException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException) QueryExplanation(org.opensearch.action.admin.indices.validate.query.QueryExplanation) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener)

Example 2 with DefaultShardOperationFailedException

use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.

the class BroadcastResponseTests method assertInstances.

@Override
protected void assertInstances(org.opensearch.action.support.broadcast.BroadcastResponse serverTestInstance, BroadcastResponse clientInstance) {
    assertThat(clientInstance.shards().total(), equalTo(serverTestInstance.getTotalShards()));
    assertThat(clientInstance.shards().successful(), equalTo(serverTestInstance.getSuccessfulShards()));
    assertThat(clientInstance.shards().skipped(), equalTo(0));
    assertThat(clientInstance.shards().failed(), equalTo(serverTestInstance.getFailedShards()));
    // failures are grouped
    assertThat(clientInstance.shards().failures(), hasSize(clientInstance.shards().failed() == 0 ? 0 : 1));
    if (clientInstance.shards().failed() > 0) {
        final DefaultShardOperationFailedException groupedFailure = clientInstance.shards().failures().iterator().next();
        assertThat(groupedFailure.index(), equalTo(index));
        assertThat(groupedFailure.shardId(), in(shardIds));
        assertThat(groupedFailure.reason(), containsString("reason=retention lease with ID [" + id + "] not found"));
    }
}
Also used : DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException)

Example 3 with DefaultShardOperationFailedException

use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.

the class BroadcastResponseTests method createServerTestInstance.

@Override
protected org.opensearch.action.support.broadcast.BroadcastResponse createServerTestInstance(XContentType xContentType) {
    index = randomAlphaOfLength(8);
    id = randomAlphaOfLength(8);
    final int total = randomIntBetween(1, 16);
    final int successful = total - scaledRandomIntBetween(0, total);
    final int failed = scaledRandomIntBetween(0, total - successful);
    final List<DefaultShardOperationFailedException> failures = new ArrayList<>();
    shardIds = new HashSet<>();
    for (int i = 0; i < failed; i++) {
        final DefaultShardOperationFailedException failure = new DefaultShardOperationFailedException(index, randomValueOtherThanMany(shardIds::contains, () -> randomIntBetween(0, total - 1)), new RetentionLeaseNotFoundException(id));
        failures.add(failure);
        shardIds.add(failure.shardId());
    }
    return new org.opensearch.action.support.broadcast.BroadcastResponse(total, successful, failed, failures);
}
Also used : RetentionLeaseNotFoundException(org.opensearch.index.seqno.RetentionLeaseNotFoundException) ArrayList(java.util.ArrayList) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException)

Example 4 with DefaultShardOperationFailedException

use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.

the class DataStreamsStatsResponseTests method createServerTestInstance.

@Override
protected DataStreamsStatsAction.Response createServerTestInstance(XContentType xContentType) {
    int dataStreamCount = randomInt(10);
    int backingIndicesTotal = 0;
    long totalStoreSize = 0L;
    ArrayList<DataStreamsStatsAction.DataStreamStats> dataStreamStats = new ArrayList<>();
    for (int i = 0; i < dataStreamCount; i++) {
        String dataStreamName = randomAlphaOfLength(8).toLowerCase(Locale.getDefault());
        int backingIndices = randomInt(5);
        backingIndicesTotal += backingIndices;
        long storeSize = randomLongBetween(250, 1000000000);
        totalStoreSize += storeSize;
        long maximumTimestamp = randomRecentTimestamp();
        dataStreamStats.add(new DataStreamsStatsAction.DataStreamStats(dataStreamName, backingIndices, new ByteSizeValue(storeSize), maximumTimestamp));
    }
    int totalShards = randomIntBetween(backingIndicesTotal, backingIndicesTotal * 3);
    int successfulShards = randomInt(totalShards);
    int failedShards = totalShards - successfulShards;
    List<DefaultShardOperationFailedException> exceptions = new ArrayList<>();
    for (int i = 0; i < failedShards; i++) {
        exceptions.add(new DefaultShardOperationFailedException(randomAlphaOfLength(8).toLowerCase(Locale.getDefault()), randomInt(totalShards), new OpenSearchException("boom")));
    }
    return new DataStreamsStatsAction.Response(totalShards, successfulShards, failedShards, exceptions, dataStreamCount, backingIndicesTotal, new ByteSizeValue(totalStoreSize), dataStreamStats.toArray(new DataStreamsStatsAction.DataStreamStats[0]));
}
Also used : DataStreamsStatsAction(org.opensearch.action.admin.indices.datastream.DataStreamsStatsAction) ArrayList(java.util.ArrayList) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException)

Example 5 with DefaultShardOperationFailedException

use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.

the class BroadcastResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(totalShards);
    out.writeVInt(successfulShards);
    out.writeVInt(failedShards);
    out.writeVInt(shardFailures.length);
    for (DefaultShardOperationFailedException exp : shardFailures) {
        exp.writeTo(out);
    }
}
Also used : DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException)

Aggregations

DefaultShardOperationFailedException (org.opensearch.action.support.DefaultShardOperationFailedException)19 ArrayList (java.util.ArrayList)9 OpenSearchException (org.opensearch.OpenSearchException)6 IOException (java.io.IOException)3 Index (org.opensearch.index.Index)3 ShardId (org.opensearch.index.shard.ShardId)3 HashMap (java.util.HashMap)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 FlushResponse (org.opensearch.action.admin.indices.flush.FlushResponse)2 BroadcastShardOperationFailedException (org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException)2 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)2 BytesReference (org.opensearch.common.bytes.BytesReference)2 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1