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 #10352
Closes #10412
  • Loading branch information
Leonardo Menezes authored and javanna committed Apr 8, 2015
1 parent 5585175 commit 5fd9aee
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 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 @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/elasticsearch/cluster/ClusterState.java
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -33,7 +32,6 @@
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;
Expand Down Expand Up @@ -261,6 +259,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 @@ -465,7 +464,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 5fd9aee

Please sign in to comment.