Search in sources :

Example 76 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class CloseIndexResponseTests method createServerTestInstance.

@Override
protected org.opensearch.action.admin.indices.close.CloseIndexResponse createServerTestInstance(XContentType xContentType) {
    boolean acknowledged = true;
    final String[] indicesNames = generateRandomStringArray(10, 10, false, true);
    final List<org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult> indexResults = new ArrayList<>();
    for (String indexName : indicesNames) {
        final Index index = new Index(indexName, randomAlphaOfLength(5));
        if (randomBoolean()) {
            indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index));
        } else {
            if (randomBoolean()) {
                acknowledged = false;
                Exception exception = randomFrom(new IndexNotFoundException(index), new ActionNotFoundTransportException("test"));
                indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index, exception));
            } else {
                final int nbShards = randomIntBetween(1, 5);
                org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult[] shards = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult[nbShards];
                for (int i = 0; i < nbShards; i++) {
                    org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure[] failures = null;
                    if (randomBoolean()) {
                        acknowledged = false;
                        int nbFailures = randomIntBetween(1, 3);
                        failures = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure[nbFailures];
                        for (int j = 0; j < failures.length; j++) {
                            String nodeId = null;
                            if (frequently()) {
                                nodeId = randomAlphaOfLength(5);
                            }
                            failures[j] = newFailure(indexName, i, nodeId);
                        }
                    }
                    shards[i] = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult(i, failures);
                }
                indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index, shards));
            }
        }
    }
    final boolean shardsAcknowledged = acknowledged ? randomBoolean() : false;
    return new org.opensearch.action.admin.indices.close.CloseIndexResponse(acknowledged, shardsAcknowledged, indexResults);
}
Also used : ArrayList(java.util.ArrayList) Index(org.opensearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException) IOException(java.io.IOException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException)

Example 77 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class TypesExistsIT method testSimple.

public void testSimple() throws Exception {
    Client client = client();
    CreateIndexResponse response1 = client.admin().indices().prepareCreate("test1").addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject()).execute().actionGet();
    CreateIndexResponse response2 = client.admin().indices().prepareCreate("test2").addMapping("type2", jsonBuilder().startObject().startObject("type2").endObject().endObject()).execute().actionGet();
    client.admin().indices().prepareAliases().addAlias("test1", "alias1").execute().actionGet();
    assertAcked(response1);
    assertAcked(response2);
    TypesExistsResponse response = client.admin().indices().prepareTypesExists("test1").setTypes("type1").execute().actionGet();
    assertThat(response.isExists(), equalTo(true));
    response = client.admin().indices().prepareTypesExists("test1").setTypes("type2").execute().actionGet();
    assertThat(response.isExists(), equalTo(false));
    try {
        client.admin().indices().prepareTypesExists("notExist").setTypes("type1").execute().actionGet();
        fail("Exception should have been thrown");
    } catch (IndexNotFoundException e) {
    }
    try {
        client.admin().indices().prepareTypesExists("notExist").setTypes("type0").execute().actionGet();
        fail("Exception should have been thrown");
    } catch (IndexNotFoundException e) {
    }
    response = client.admin().indices().prepareTypesExists("alias1").setTypes("type1").execute().actionGet();
    assertThat(response.isExists(), equalTo(true));
    response = client.admin().indices().prepareTypesExists("*").setTypes("type1").execute().actionGet();
    assertThat(response.isExists(), equalTo(false));
    response = client.admin().indices().prepareTypesExists("test1", "test2").setTypes("type1").execute().actionGet();
    assertThat(response.isExists(), equalTo(false));
    response = client.admin().indices().prepareTypesExists("test1", "test2").setTypes("type2").execute().actionGet();
    assertThat(response.isExists(), equalTo(false));
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) TypesExistsResponse(org.opensearch.action.admin.indices.exists.types.TypesExistsResponse) Client(org.opensearch.client.Client) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse)

Example 78 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class TransportValidateQueryAction method doExecute.

@Override
protected void doExecute(Task task, ValidateQueryRequest request, ActionListener<ValidateQueryResponse> listener) {
    request.nowInMillis = System.currentTimeMillis();
    LongSupplier timeProvider = () -> request.nowInMillis;
    ActionListener<org.opensearch.index.query.QueryBuilder> rewriteListener = ActionListener.wrap(rewrittenQuery -> {
        request.query(rewrittenQuery);
        super.doExecute(task, request, listener);
    }, ex -> {
        if (ex instanceof IndexNotFoundException || ex instanceof IndexClosedException) {
            listener.onFailure(ex);
            return;
        }
        List<QueryExplanation> explanations = new ArrayList<>();
        explanations.add(new QueryExplanation(null, QueryExplanation.RANDOM_SHARD, false, null, ex.getMessage()));
        listener.onResponse(new ValidateQueryResponse(false, explanations, // which is 0 since the failure is happening on the coordinating node.
        0, 0, 0, null));
    });
    if (request.query() == null) {
        rewriteListener.onResponse(request.query());
    } else {
        Rewriteable.rewriteAndFetch(request.query(), searchService.getRewriteContext(timeProvider), rewriteListener);
    }
}
Also used : IndexClosedException(org.opensearch.indices.IndexClosedException) ArrayList(java.util.ArrayList) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) LongSupplier(java.util.function.LongSupplier)

Example 79 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class CreateIndexIT method testCreateAndDeleteIndexConcurrently.

public void testCreateAndDeleteIndexConcurrently() throws InterruptedException {
    createIndex("test");
    final AtomicInteger indexVersion = new AtomicInteger(0);
    final Object indexVersionLock = new Object();
    final CountDownLatch latch = new CountDownLatch(1);
    int numDocs = randomIntBetween(1, 10);
    for (int i = 0; i < numDocs; i++) {
        client().prepareIndex("test").setSource("index_version", indexVersion.get()).get();
    }
    synchronized (indexVersionLock) {
        // not necessarily needed here but for completeness we lock here too
        indexVersion.incrementAndGet();
    }
    client().admin().indices().prepareDelete("test").execute(new // this happens async!!!
    ActionListener<AcknowledgedResponse>() {

        @Override
        public void onResponse(AcknowledgedResponse deleteIndexResponse) {
            Thread thread = new Thread() {

                @Override
                public void run() {
                    try {
                        // recreate that index
                        client().prepareIndex("test").setSource("index_version", indexVersion.get()).get();
                        synchronized (indexVersionLock) {
                            // we sync here since we have to ensure that all indexing operations below for a given ID are done before
                            // we increment the index version otherwise a doc that is in-flight could make it into an index that it
                            // was supposed to be deleted for and our assertion fail...
                            indexVersion.incrementAndGet();
                        }
                        // from here on all docs with index_version == 0|1 must be gone!!!! only 2 are ok;
                        assertAcked(client().admin().indices().prepareDelete("test").get());
                    } finally {
                        latch.countDown();
                    }
                }
            };
            thread.start();
        }

        @Override
        public void onFailure(Exception e) {
            throw new RuntimeException(e);
        }
    });
    numDocs = randomIntBetween(100, 200);
    for (int i = 0; i < numDocs; i++) {
        try {
            synchronized (indexVersionLock) {
                client().prepareIndex("test").setSource("index_version", indexVersion.get()).setTimeout(TimeValue.timeValueSeconds(10)).get();
            }
        } catch (IndexNotFoundException inf) {
        // fine
        } catch (UnavailableShardsException ex) {
            assertEquals(ex.getCause().getClass(), IndexNotFoundException.class);
        // fine we run into a delete index while retrying
        }
    }
    latch.await();
    refresh();
    // we only really assert that we never reuse segments of old indices or anything like this here and that nothing fails with
    // crazy exceptions
    SearchResponse expected = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).setQuery(new RangeQueryBuilder("index_version").from(indexVersion.get(), true)).get();
    SearchResponse all = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get();
    assertEquals(expected + " vs. " + all, expected.getHits().getTotalHits().value, all.getHits().getTotalHits().value);
    logger.info("total: {}", expected.getHits().getTotalHits().value);
}
Also used : AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) CountDownLatch(java.util.concurrent.CountDownLatch) RangeQueryBuilder(org.opensearch.index.query.RangeQueryBuilder) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) SearchResponse(org.opensearch.action.search.SearchResponse) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 80 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class CloseIndexIT method testCloseMissingIndex.

public void testCloseMissingIndex() {
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test").get());
    assertThat(e.getMessage(), is("no such index [test]"));
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Aggregations

IndexNotFoundException (org.opensearch.index.IndexNotFoundException)107 ActionListener (org.opensearch.action.ActionListener)32 ClusterState (org.opensearch.cluster.ClusterState)26 IOException (java.io.IOException)25 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)25 Map (java.util.Map)23 Client (org.opensearch.client.Client)23 ArrayList (java.util.ArrayList)21 Settings (org.opensearch.common.settings.Settings)21 Logger (org.apache.logging.log4j.Logger)20 List (java.util.List)19 LogManager (org.apache.logging.log4j.LogManager)19 SearchResponse (org.opensearch.action.search.SearchResponse)19 HashMap (java.util.HashMap)18 GetRequest (org.opensearch.action.get.GetRequest)18 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)18 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)18 ClusterService (org.opensearch.cluster.service.ClusterService)17 XContentParser (org.opensearch.common.xcontent.XContentParser)17 DeleteResponse (org.opensearch.action.delete.DeleteResponse)16