Search in sources :

Example 96 with IndexNotFoundException

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

the class IndexNameExpressionResolverTests method testConcreteIndicesIgnoreIndicesAllMissing.

public void testConcreteIndicesIgnoreIndicesAllMissing() {
    Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("testXXX")).put(indexBuilder("kuku"));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false);
    IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy"));
    assertThat(infe.getMessage(), is("no such index [testMo]"));
}
Also used : ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 97 with IndexNotFoundException

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

the class IndexNameExpressionResolverTests method testIndicesAliasesRequestIgnoresAliases.

public void testIndicesAliasesRequestIgnoresAliases() {
    Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias"))).put(indexBuilder("index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias2")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-alias");
        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
        assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-a*");
        IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
        assertEquals("test-a*", infe.getIndex().getName());
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-index");
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-*");
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-alias");
        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
        assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-a*");
        IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
        assertEquals("test-a*", infe.getIndex().getName());
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-index");
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-*");
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-alias");
        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
        assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-a*");
        IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
        assertEquals("test-a*", infe.getIndex().getName());
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-index");
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
    {
        IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-*");
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 98 with IndexNotFoundException

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

the class IndexNameExpressionResolverTests method testDeleteIndexIgnoresAliases.

public void testDeleteIndexIgnoresAliases() {
    Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias"))).put(indexBuilder("index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias2")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
    {
        IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("does_not_exist")));
        assertEquals("does_not_exist", infe.getIndex().getName());
        assertEquals("no such index [does_not_exist]", infe.getMessage());
    }
    {
        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-alias")));
        assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
    }
    {
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("test-alias");
        deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(true, true, true, true, false, false, true, false));
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, deleteIndexRequest);
        assertEquals(0, indices.length);
    }
    {
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("test-a*");
        deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, true, false, false, true, false));
        IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, deleteIndexRequest));
        assertEquals(infe.getIndex().getName(), "test-a*");
    }
    {
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-a*"));
        assertEquals(0, indices.length);
    }
    {
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-index"));
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
    {
        String[] indices = indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-*"));
        assertEquals(1, indices.length);
        assertEquals("test-index", indices[0]);
    }
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest)

Example 99 with IndexNotFoundException

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

the class IndexNameExpressionResolverTests method testConcreteIndicesNoIndicesErrorMessage.

public void testConcreteIndicesNoIndicesErrorMessage() {
    Metadata.Builder mdBuilder = Metadata.builder();
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(false, false, true, true), false);
    IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[] {}));
    assertThat(infe.getMessage(), is("no such index [null] and no indices exist"));
}
Also used : ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 100 with IndexNotFoundException

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

the class IndexNameExpressionResolverTests method testIndexOptionsNoExpandWildcards.

public void testIndexOptionsNoExpandWildcards() {
    Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("foo").putAlias(AliasMetadata.builder("foofoobar"))).put(indexBuilder("foobar").putAlias(AliasMetadata.builder("foofoobar"))).put(indexBuilder("foofoo-closed").state(IndexMetadata.State.CLOSE)).put(indexBuilder("foofoo").putAlias(AliasMetadata.builder("barbaz")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
    // ignore unavailable and allow no indices
    {
        IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false, randomBoolean());
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient, false);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
        results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
        assertEquals(0, results.length);
        results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
        assertEquals(0, results.length);
    }
    // ignore unavailable but don't allow no indices
    {
        IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false, randomBoolean());
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty, false);
        {
            IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*"));
            assertThat(infe.getIndex().getName(), equalTo("baz*"));
        }
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
        {
            // unavailable indices are ignored but no indices are disallowed
            expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "bar", "baz"));
        }
    }
    // error on unavailable but allow no indices
    {
        IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false, randomBoolean());
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable, false);
        {
            String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            assertThat(results, emptyArray());
        }
        {
            IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"));
            assertThat(infe.getIndex().getName(), equalTo("baz*"));
        }
        {
            // unavailable indices are not ignored, hence the error on the first unavailable indices encountered
            IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "bar", "baz"));
            assertThat(infe.getIndex().getName(), equalTo("bar"));
        }
        {
            String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
            assertEquals(2, results.length);
            assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
        }
    }
    // error on both unavailable and no indices
    {
        IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false, randomBoolean());
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict, false);
        IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*"));
        assertThat(infe.getIndex().getName(), equalTo("baz*"));
        IndexNotFoundException infe2 = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"));
        assertThat(infe2.getIndex().getName(), equalTo("baz*"));
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
}
Also used : ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.opensearch.action.support.IndicesOptions)

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