Search in sources :

Example 61 with ClusterName

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

the class ActiveShardCountTests method initializeWithNewIndex.

private ClusterState initializeWithNewIndex(final String indexName, final int numShards, final int numReplicas) {
    // initial index creation and new routing table info
    final IndexMetaData indexMetaData = IndexMetaData.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())).numberOfShards(numShards).numberOfReplicas(numReplicas).build();
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).build();
    final RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build();
    return ClusterState.builder(new ClusterName("test_cluster")).metaData(metaData).routingTable(routingTable).build();
}
Also used : IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 62 with ClusterName

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

the class ClusterStateCreationUtils method stateWithAssignedPrimariesAndOneReplica.

/**
     * Creates cluster state with several shards and one replica and all shards STARTED.
     */
public static ClusterState stateWithAssignedPrimariesAndOneReplica(String index, int numberOfShards) {
    // we need a non-local master to test shard failures
    int numberOfNodes = 2;
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    for (int i = 0; i < numberOfNodes + 1; i++) {
        final DiscoveryNode node = newNode(i);
        discoBuilder = discoBuilder.add(node);
    }
    discoBuilder.localNodeId(newNode(0).getId());
    // we need a non-local master to test shard failures
    discoBuilder.masterNodeId(newNode(1).getId());
    IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(Settings.builder().put(SETTING_VERSION_CREATED, Version.CURRENT).put(SETTING_NUMBER_OF_SHARDS, numberOfShards).put(SETTING_NUMBER_OF_REPLICAS, 1).put(SETTING_CREATION_DATE, System.currentTimeMillis())).build();
    ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
    state.nodes(discoBuilder);
    state.metaData(MetaData.builder().put(indexMetaData, false).generateClusterUuidIfNeeded());
    IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(indexMetaData.getIndex());
    for (int i = 0; i < numberOfShards; i++) {
        RoutingTable.Builder routing = new RoutingTable.Builder();
        routing.addAsNew(indexMetaData);
        final ShardId shardId = new ShardId(index, "_na_", i);
        IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId);
        indexShardRoutingBuilder.addShard(TestShardRouting.newShardRouting(index, i, newNode(0).getId(), null, true, ShardRoutingState.STARTED));
        indexShardRoutingBuilder.addShard(TestShardRouting.newShardRouting(index, i, newNode(1).getId(), null, false, ShardRoutingState.STARTED));
        indexRoutingTableBuilder.addIndexShard(indexShardRoutingBuilder.build());
    }
    state.routingTable(RoutingTable.builder().add(indexRoutingTableBuilder.build()).build());
    return state.build();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardId(org.elasticsearch.index.shard.ShardId) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 63 with ClusterName

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

the class ClusterStateCreationUtils method state.

/**
     * Creates a cluster state where local node and master node can be specified
     *
     * @param localNode  node in allNodes that is the local node
     * @param masterNode node in allNodes that is the master node. Can be null if no master exists
     * @param allNodes   all nodes in the cluster
     * @return cluster state
     */
public static ClusterState state(DiscoveryNode localNode, DiscoveryNode masterNode, DiscoveryNode... allNodes) {
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    for (DiscoveryNode node : allNodes) {
        discoBuilder.add(node);
    }
    if (masterNode != null) {
        discoBuilder.masterNodeId(masterNode.getId());
    }
    discoBuilder.localNodeId(localNode.getId());
    ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
    state.nodes(discoBuilder);
    state.metaData(MetaData.builder().generateClusterUuidIfNeeded());
    return state.build();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 64 with ClusterName

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

the class AutoCreateIndexTests method testAutoCreationPatternEnabled.

public void testAutoCreationPatternEnabled() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom("+index*", "index*")).build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).metaData(MetaData.builder()).build();
    assertThat(autoCreateIndex.shouldAutoCreate("index" + randomAsciiOfLengthBetween(1, 5), clusterState), equalTo(true));
    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 65 with ClusterName

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

the class AutoCreateIndexTests method testAutoCreationMultipleIndexNames.

public void testAutoCreationMultipleIndexNames() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "test1,test2").build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).metaData(MetaData.builder()).build();
    assertThat(autoCreateIndex.shouldAutoCreate("test1", clusterState), equalTo(true));
    assertThat(autoCreateIndex.shouldAutoCreate("test2", clusterState), equalTo(true));
    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)

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