Skip to content

Commit

Permalink
Cluster state REST api: routing_nodes as an independent metric option
Browse files Browse the repository at this point in the history
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 elastic#10352
Closes elastic#10412
  • Loading branch information
Leonardo Menezes authored and javanna committed Apr 8, 2015
1 parent 3ff8c90 commit 84d17c7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rest-api-spec/api/cluster.state.json
Expand Up @@ -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"
}
},
Expand Down
12 changes: 12 additions & 0 deletions rest-api-spec/test/cluster.state/20_filtering.yaml
Expand Up @@ -88,6 +88,18 @@ setup:
- is_true: routing_nodes
- is_true: allocations

---
"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:
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/elasticsearch/cluster/ClusterState.java
Expand Up @@ -269,6 +269,7 @@ public enum Metric {
NODES("nodes"),
METADATA("metadata"),
ROUTING_TABLE("routing_table"),
ROUTING_NODES("routing_nodes"),
CUSTOMS("customs");

private static Map<String, Metric> valueToEnum;
Expand Down Expand Up @@ -479,7 +480,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

// 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()) {
Expand Down
Expand Up @@ -72,7 +72,8 @@ public void handleRequest(final RestRequest request, final RestChannel channel,
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));
}
Expand Down

0 comments on commit 84d17c7

Please sign in to comment.