Search in sources :

Example 1 with RoutingTableGenerator

use of org.elasticsearch.cluster.routing.RoutingTableGenerator in project elasticsearch by elastic.

the class ClusterIndexHealthTests method testClusterIndexHealth.

public void testClusterIndexHealth() {
    RoutingTableGenerator routingTableGenerator = new RoutingTableGenerator();
    int numberOfShards = randomInt(3) + 1;
    int numberOfReplicas = randomInt(4);
    IndexMetaData indexMetaData = IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas).build();
    RoutingTableGenerator.ShardCounter counter = new RoutingTableGenerator.ShardCounter();
    IndexRoutingTable indexRoutingTable = routingTableGenerator.genIndexRoutingTable(indexMetaData, counter);
    ClusterIndexHealth indexHealth = new ClusterIndexHealth(indexMetaData, indexRoutingTable);
    logger.info("index status: {}, expected {}", indexHealth.getStatus(), counter.status());
    assertIndexHealth(indexHealth, counter, indexMetaData);
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTableGenerator(org.elasticsearch.cluster.routing.RoutingTableGenerator) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 2 with RoutingTableGenerator

use of org.elasticsearch.cluster.routing.RoutingTableGenerator in project elasticsearch by elastic.

the class ClusterStateHealthTests method testClusterHealth.

public void testClusterHealth() throws IOException {
    RoutingTableGenerator routingTableGenerator = new RoutingTableGenerator();
    RoutingTableGenerator.ShardCounter counter = new RoutingTableGenerator.ShardCounter();
    RoutingTable.Builder routingTable = RoutingTable.builder();
    MetaData.Builder metaData = MetaData.builder();
    for (int i = randomInt(4); i >= 0; i--) {
        int numberOfShards = randomInt(3) + 1;
        int numberOfReplicas = randomInt(4);
        IndexMetaData indexMetaData = IndexMetaData.builder("test_" + Integer.toString(i)).settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas).build();
        IndexRoutingTable indexRoutingTable = routingTableGenerator.genIndexRoutingTable(indexMetaData, counter);
        metaData.put(indexMetaData, true);
        routingTable.add(indexRoutingTable);
    }
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable.build()).build();
    String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), (String[]) null);
    ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState, concreteIndices);
    logger.info("cluster status: {}, expected {}", clusterStateHealth.getStatus(), counter.status());
    clusterStateHealth = maybeSerialize(clusterStateHealth);
    assertClusterHealth(clusterStateHealth, counter);
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) ClusterState(org.elasticsearch.cluster.ClusterState) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) 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) RoutingTableGenerator(org.elasticsearch.cluster.routing.RoutingTableGenerator)

Aggregations

IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)2 RoutingTableGenerator (org.elasticsearch.cluster.routing.RoutingTableGenerator)2 ClusterState (org.elasticsearch.cluster.ClusterState)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)1 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)1