Search in sources :

Example 26 with ClusterName

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

the class VerifyRepositoryResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    clusterName = new ClusterName(in);
    nodes = new DiscoveryNode[in.readVInt()];
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = new DiscoveryNode(in);
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterName(org.elasticsearch.cluster.ClusterName)

Example 27 with ClusterName

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

the class MainActionTests method testMainActionClusterAvailable.

public void testMainActionClusterAvailable() {
    final ClusterService clusterService = mock(ClusterService.class);
    final ClusterName clusterName = new ClusterName("elasticsearch");
    final Settings settings = Settings.builder().put("node.name", "my-node").build();
    final boolean available = randomBoolean();
    ClusterBlocks blocks;
    if (available) {
        if (randomBoolean()) {
            blocks = ClusterBlocks.EMPTY_CLUSTER_BLOCK;
        } else {
            blocks = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(randomIntBetween(1, 16), "test global block 400", randomBoolean(), randomBoolean(), RestStatus.BAD_REQUEST, ClusterBlockLevel.ALL)).build();
        }
    } else {
        blocks = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(randomIntBetween(1, 16), "test global block 503", randomBoolean(), randomBoolean(), RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL)).build();
    }
    ClusterState state = ClusterState.builder(clusterName).blocks(blocks).build();
    when(clusterService.state()).thenReturn(state);
    TransportService transportService = new TransportService(Settings.EMPTY, null, null, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    TransportMainAction action = new TransportMainAction(settings, mock(ThreadPool.class), transportService, mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), clusterService);
    AtomicReference<MainResponse> responseRef = new AtomicReference<>();
    action.doExecute(new MainRequest(), new ActionListener<MainResponse>() {

        @Override
        public void onResponse(MainResponse mainResponse) {
            responseRef.set(mainResponse);
        }

        @Override
        public void onFailure(Exception e) {
            logger.error("unexpected error", e);
        }
    });
    assertNotNull(responseRef.get());
    assertEquals(available, responseRef.get().isAvailable());
    verify(clusterService, times(1)).state();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ThreadPool(org.elasticsearch.threadpool.ThreadPool) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionFilters(org.elasticsearch.action.support.ActionFilters) IOException(java.io.IOException) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterService(org.elasticsearch.cluster.service.ClusterService) TransportService(org.elasticsearch.transport.TransportService) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.elasticsearch.common.settings.Settings)

Example 28 with ClusterName

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

the class AutoCreateIndexTests method testAutoCreationPatternDisabled.

public void testAutoCreationPatternDisabled() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "-index*").build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).metaData(MetaData.builder()).build();
    expectForbidden(clusterState, autoCreateIndex, "index" + randomAsciiOfLengthBetween(1, 5), "-index*");
    /* When patterns are specified, even if the are all negative, the default is can't create. So a pure negative pattern is the same
         * as false, really. */
    expectNotMatch(clusterState, autoCreateIndex, "does_not_match" + randomAsciiOfLengthBetween(1, 5));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 29 with ClusterName

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

the class AutoCreateIndexTests method testAutoCreationMultiplePatternsNoWildcards.

public void testAutoCreationMultiplePatternsNoWildcards() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "+test1,-index1").build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).metaData(MetaData.builder()).build();
    assertThat(autoCreateIndex.shouldAutoCreate("test1", clusterState), equalTo(true));
    expectNotMatch(clusterState, autoCreateIndex, "index" + randomAsciiOfLengthBetween(1, 5));
    expectNotMatch(clusterState, autoCreateIndex, "test" + randomAsciiOfLengthBetween(2, 5));
    expectNotMatch(clusterState, autoCreateIndex, "does_not_match" + randomAsciiOfLengthBetween(1, 5));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 30 with ClusterName

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

the class IndexNameExpressionResolverTests method testIndexOptionsFailClosedIndicesAndAliases.

public void testIndexOptionsFailClosedIndicesAndAliases() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo1-closed").state(IndexMetaData.State.CLOSE).putAlias(AliasMetaData.builder("foobar1-closed")).putAlias(AliasMetaData.builder("foobar2-closed"))).put(indexBuilder("foo2-closed").state(IndexMetaData.State.CLOSE).putAlias(AliasMetaData.builder("foobar2-closed"))).put(indexBuilder("foo3").putAlias(AliasMetaData.builder("foobar2-closed")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed");
        fail("foo1-closed should be closed, but it is open");
    } catch (IndexClosedException e) {
    // expected
    }
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed");
        fail("foo1-closed should be closed, but it is open");
    } catch (IndexClosedException e) {
    // expected
    }
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), context.getOptions().expandWildcardsClosed(), context.getOptions()));
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed");
    assertThat(results, emptyArray());
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed");
    assertThat(results, arrayWithSize(1));
    assertThat(results, arrayContaining("foo1-closed"));
    results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed");
    assertThat(results, arrayWithSize(1));
    assertThat(results, arrayContaining("foo1-closed"));
    // testing an alias pointing to three indices:
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed");
        fail("foo2-closed should be closed, but it is open");
    } catch (IndexClosedException e) {
    // expected
    }
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), context.getOptions().expandWildcardsClosed(), context.getOptions()));
    results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed");
    assertThat(results, arrayWithSize(1));
    assertThat(results, arrayContaining("foo3"));
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed");
    assertThat(results, arrayWithSize(3));
    assertThat(results, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexClosedException(org.elasticsearch.indices.IndexClosedException) ClusterName(org.elasticsearch.cluster.ClusterName) Matchers.containsString(org.hamcrest.Matchers.containsString)

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