Search in sources :

Example 86 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testConcreteIndicesIgnoreIndicesEmptyRequest.

public void testConcreteIndicesIgnoreIndicesEmptyRequest() {
    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.lenientExpandOpen());
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, new String[] {})), equalTo(newHashSet("kuku", "testXXX")));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName)

Example 87 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

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);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient);
        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);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.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"));
    }
    //error on unavailable but allow no indices
    {
        IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        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);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
}
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 88 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsEmptyCluster.

public void testIndexOptionsEmptyCluster() {
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(MetaData.builder().build()).build();
    IndicesOptions options = IndicesOptions.strictExpandOpen();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertThat(results, emptyArray());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("foo"));
    }
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertThat(results, emptyArray());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("bar"));
    }
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
    assertThat(results, emptyArray());
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false));
    try {
        indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    } catch (IndexNotFoundException e) {
        assertThat(e.getResourceId().toString(), equalTo("[_all]"));
    }
}
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 89 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testConcreteIndicesWildcardWithNegation.

public void testConcreteIndicesWildcardWithNegation() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("testXXX").state(State.OPEN)).put(indexBuilder("testXXY").state(State.OPEN)).put(indexBuilder("testXYY").state(State.OPEN)).put(indexBuilder("-testXYZ").state(State.OPEN)).put(indexBuilder("-testXZZ").state(State.OPEN)).put(indexBuilder("-testYYY").state(State.OPEN)).put(indexBuilder("testYYY").state(State.OPEN)).put(indexBuilder("testYYX").state(State.OPEN));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "test*", "-testX*")), equalTo(newHashSet("testYYY", "testYYX")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "-testX*")), equalTo(newHashSet("-testXYZ", "-testXZZ")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testXXY", "-testX*")), equalTo(newHashSet("testXXY", "-testXYZ", "-testXZZ")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "*", "--testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY", "testYYX", "testYYY", "-testYYY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "-testXXX", "test*")), equalTo(newHashSet("testYYX", "testXXX", "testXYY", "testYYY", "testXXY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "test*", "-testXXX")), equalTo(newHashSet("testYYX", "testXYY", "testYYY", "testXXY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "+testXXX", "+testXXY", "+testYYY", "-testYYY")), equalTo(newHashSet("testXXX", "testXXY", "testYYY", "-testYYY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testYYY", "testYYX", "testX*", "-testXXX")), equalTo(newHashSet("testYYY", "testYYX", "testXXY", "testXYY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "-testXXX", "*testY*", "-testYYY")), equalTo(newHashSet("testYYX", "testYYY", "-testYYY")));
    String[] indexNames = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), "-doesnotexist");
    assertEquals(0, indexNames.length);
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), "-*")), equalTo(newHashSet("-testXYZ", "-testXZZ", "-testYYY")));
    assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), "+testXXX", "+testXXY", "+testXYY", "-testXXY")), equalTo(newHashSet("testXXX", "testXYY", "testXXY")));
    indexNames = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), "*", "-*");
    assertEquals(0, indexNames.length);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 90 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class WildcardExpressionResolverTests method testConvertWildcardsOpenClosedIndicesTests.

public void testConvertWildcardsOpenClosedIndicesTests() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("testXXX").state(IndexMetaData.State.OPEN)).put(indexBuilder("testXXY").state(IndexMetaData.State.OPEN)).put(indexBuilder("testXYY").state(IndexMetaData.State.CLOSE)).put(indexBuilder("testYYY").state(IndexMetaData.State.OPEN)).put(indexBuilder("testYYX").state(IndexMetaData.State.CLOSE)).put(indexBuilder("kuku").state(IndexMetaData.State.OPEN));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true));
    assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*"))), equalTo(newHashSet("testXXX", "testXXY", "testXYY")));
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true));
    assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*"))), equalTo(newHashSet("testXYY")));
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false));
    assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*"))), equalTo(newHashSet("testXXX", "testXXY")));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)95 ClusterState (org.elasticsearch.cluster.ClusterState)76 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)22 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)20 Settings (org.elasticsearch.common.settings.Settings)20 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Version (org.elasticsearch.Version)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)12 ArrayList (java.util.ArrayList)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)10 List (java.util.List)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 ESTestCase (org.elasticsearch.test.ESTestCase)8