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();
}
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();
}
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();
}
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));
}
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));
}
Aggregations