Cluster state REST api: routing_nodes as an independent metric option

Cluster state api returns both routing_table and routing_nodes sections whenever routing_table is requested. That is pretty much the same info, just grouped differently. This commit allows to differentiate between the two. Yet, routing_table still returns both for bw comp reasons.

Closes #10352
Closes #10412
This commit is contained in:
Leonardo Menezes 2015-04-03 12:35:09 +02:00 committed by Luca Cavanna
parent 5585175173
commit 5fd9aee16e
4 changed files with 18 additions and 5 deletions

View File

@ -16,7 +16,7 @@
},
"metric" : {
"type" : "list",
"options" : ["_all", "blocks", "metadata", "nodes", "routing_table", "master_node", "version"],
"options" : ["_all", "blocks", "metadata", "nodes", "routing_table", "routing_nodes", "master_node", "version"],
"description" : "Limit the information returned to the specified metrics"
}
},

View File

@ -83,6 +83,18 @@ setup:
- is_true: routing_table
- is_true: routing_nodes
---
"Filtering the cluster state by routing nodes only should work":
- do:
cluster.state:
metric: [ routing_nodes ]
- is_false: blocks
- is_false: nodes
- is_false: metadata
- is_false: routing_table
- is_true: routing_nodes
---
"Filtering the cluster state by indices should work in routing table and metadata":
- do:

View File

@ -23,7 +23,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -33,7 +32,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.*;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
@ -261,6 +259,7 @@ public class ClusterState implements ToXContent {
NODES("nodes"),
METADATA("metadata"),
ROUTING_TABLE("routing_table"),
ROUTING_NODES("routing_nodes"),
CUSTOMS("customs");
private static Map<String, Metric> valueToEnum;
@ -465,7 +464,8 @@ public class ClusterState implements ToXContent {
}
// routing nodes
if (metrics.contains(Metric.ROUTING_TABLE)) {
// gets printed out even if only routing_table was requested for bw comp reasons
if (metrics.contains(Metric.ROUTING_TABLE) || metrics.contains(Metric.ROUTING_NODES)) {
builder.startObject("routing_nodes");
builder.startArray("unassigned");
for (ShardRouting shardRouting : readOnlyRoutingNodes().unassigned()) {

View File

@ -72,7 +72,8 @@ public class RestClusterStateAction extends BaseRestHandler {
EnumSet<ClusterState.Metric> metrics = ClusterState.Metric.parseString(request.param("metric"), true);
// do not ask for what we do not need.
clusterStateRequest.nodes(metrics.contains(ClusterState.Metric.NODES) || metrics.contains(ClusterState.Metric.MASTER_NODE));
clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE));
//there is no distinction in Java api between routing_table and routing_nodes, it's the same info set over the wire, one single flag to ask for it
clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE) || metrics.contains(ClusterState.Metric.ROUTING_NODES));
clusterStateRequest.metaData(metrics.contains(ClusterState.Metric.METADATA));
clusterStateRequest.blocks(metrics.contains(ClusterState.Metric.BLOCKS));
}