Search in sources :

Example 11 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class SimpleClusterStateIT method testIndicesIgnoreUnavailableFalse.

public void testIndicesIgnoreUnavailableFalse() throws Exception {
    // ignore_unavailable set to false throws exception when allowNoIndices is turned off
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false);
    try {
        client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("fzzbzz").setIndicesOptions(allowNoIndices).get();
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index"));
    }
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 12 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class MetaDataDeleteIndexServiceTests method testDeleteMissing.

public void testDeleteMissing() {
    Index index = new Index("missing", "doesn't matter");
    ClusterState state = ClusterState.builder(ClusterName.DEFAULT).build();
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.deleteIndices(state, singleton(index)));
    assertEquals(index, e.getIndex());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Index(org.elasticsearch.index.Index)

Example 13 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class MetaDataIndexAliasesServiceTests method testAddAliasToRemovedIndex.

public void testAddAliasToRemovedIndex() {
    // Create "test"
    ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), "test");
    // Attempt to add an alias to "test" at the same time as we remove it
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.innerExecute(before, Arrays.asList(new AliasAction.Add("test", "alias", null, null, null), new AliasAction.RemoveIndex("test"))));
    assertEquals("test", e.getIndex().getName());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 14 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsWildcardExpansion.

public void testIndexOptionsWildcardExpansion() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo").state(IndexMetaData.State.CLOSE)).put(indexBuilder("bar")).put(indexBuilder("foobar").putAlias(AliasMetaData.builder("barbaz")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    // Only closed
    IndicesOptions options = IndicesOptions.fromOptions(false, true, false, true);
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(1, results.length);
    assertEquals("foo", results[0]);
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertEquals(1, results.length);
    assertEquals("foo", results[0]);
    // no wildcards, so wildcard expansion don't apply
    results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
    assertEquals(1, results.length);
    assertEquals("bar", results[0]);
    // Only open
    options = IndicesOptions.fromOptions(false, true, true, false);
    context = new IndexNameExpressionResolver.Context(state, options);
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(2, results.length);
    assertThat(results, arrayContainingInAnyOrder("bar", "foobar"));
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertEquals(1, results.length);
    assertEquals("foobar", results[0]);
    results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
    assertEquals(1, results.length);
    assertEquals("bar", results[0]);
    // Open and closed
    options = IndicesOptions.fromOptions(false, true, true, true);
    context = new IndexNameExpressionResolver.Context(state, options);
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(3, results.length);
    assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo"));
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertEquals(2, results.length);
    assertThat(results, arrayContainingInAnyOrder("foobar", "foo"));
    results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
    assertEquals(1, results.length);
    assertEquals("bar", results[0]);
    results = indexNameExpressionResolver.concreteIndexNames(context, "*", "-foo*");
    assertEquals(1, results.length);
    assertEquals("bar", results[0]);
    results = indexNameExpressionResolver.concreteIndexNames(context, "-*");
    assertEquals(0, results.length);
    options = IndicesOptions.fromOptions(false, false, true, true);
    context = new IndexNameExpressionResolver.Context(state, options);
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "-*");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getResourceId().toString(), equalTo("[-*]"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 15 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testConcreteIndicesWildcardNoMatch.

/**
     * test resolving wildcard pattern that matches no index of alias for random IndicesOptions
     */
public void testConcreteIndicesWildcardNoMatch() {
    for (int i = 0; i < 10; i++) {
        IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
        MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("aaa").state(State.OPEN).putAlias(AliasMetaData.builder("aaa_alias1"))).put(indexBuilder("bbb").state(State.OPEN).putAlias(AliasMetaData.builder("bbb_alias1"))).put(indexBuilder("ccc").state(State.CLOSE).putAlias(AliasMetaData.builder("ccc_alias1")));
        ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions);
        // asking for non existing wildcard pattern should return empty list or exception
        if (indicesOptions.allowNoIndices()) {
            String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, "Foo*");
            assertThat(concreteIndices, notNullValue());
            assertThat(concreteIndices.length, equalTo(0));
        } else {
            try {
                indexNameExpressionResolver.concreteIndexNames(context, "Foo*");
                fail("expecting exception when result empty and allowNoIndicec=false");
            } catch (IndexNotFoundException e) {
            // expected exception
            }
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Aggregations

IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)92 ClusterState (org.elasticsearch.cluster.ClusterState)22 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)21 ShardId (org.elasticsearch.index.shard.ShardId)19 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)16 Index (org.elasticsearch.index.Index)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)12 List (java.util.List)11 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)11 ClusterName (org.elasticsearch.cluster.ClusterName)9 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 Settings (org.elasticsearch.common.settings.Settings)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 HashMap (java.util.HashMap)8 Nullable (javax.annotation.Nullable)8 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)8