diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java index aa75487649e..f9f45fa05ed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -74,6 +74,7 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct } if (!request.filterRoutingTable()) { builder.routingTable(currentState.routingTable()); + builder.allocationExplanation(currentState.allocationExplanation()); } if (!request.filterBlocks()) { builder.blocks(currentState.blocks()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java index 9a90601ce82..9320fef37ee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java @@ -32,6 +32,7 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.allocation.AllocationExplanation; import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.inject.Inject; @@ -40,11 +41,13 @@ import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; import java.io.IOException; +import java.util.List; import java.util.Map; /** @@ -207,6 +210,29 @@ public class RestClusterStateAction extends BaseRestHandler { builder.endObject(); } + if (!clusterStateRequest.filterRoutingTable()) { + builder.startArray("allocations"); + for (Map.Entry> entry : state.allocationExplanation().explanations().entrySet()) { + builder.startObject(); + builder.field("index", entry.getKey().index().name()); + builder.field("shard", entry.getKey().id()); + builder.startArray("explanations"); + for (AllocationExplanation.NodeExplanation nodeExplanation : entry.getValue()) { + builder.field("desc", nodeExplanation.description()); + if (nodeExplanation.node() != null) { + builder.startObject("node"); + builder.field("id", nodeExplanation.node().id()); + builder.field("name", nodeExplanation.node().name()); + builder.endObject(); + } + } + builder.endArray(); + builder.endObject(); + } + builder.endObject(); + } + + builder.endObject(); channel.sendResponse(new XContentRestResponse(request, RestResponse.Status.OK, builder)); } catch (Exception e) {