From a82bf74c1ce0b03f552467acaa2a33cefc74efc2 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 29 Jun 2010 01:00:07 +0300 Subject: [PATCH] expose blocks in the cluster state rest api --- .../state/TransportClusterStateAction.java | 1 + .../cluster/block/ClusterBlocks.java | 32 ++++++++++++++ .../cluster/state/RestClusterStateAction.java | 42 +++++++++++++++++++ 3 files changed, 75 insertions(+) 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 1c975aa04ab..d2199454099 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 @@ -87,6 +87,7 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct builder.metaData(currentState.metaData()); } } + builder.blocks(currentState.blocks()); return new ClusterStateResponse(clusterName, builder.build()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java index 040cdfc9a46..27636578bb5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java @@ -49,6 +49,38 @@ public class ClusterBlocks { return levelHolders[level.id()].global(); } + public boolean globalBlocked() { + for (ClusterBlockLevel level : ClusterBlockLevel.values()) { + if (!levelHolders[level.id()].global().isEmpty()) { + return true; + } + } + return false; + } + + public ImmutableSet indicesBlocked() { + Set indices = Sets.newHashSet(); + for (ClusterBlockLevel level : ClusterBlockLevel.values()) { + for (String index : indices(level).keySet()) { + ImmutableSet indexBlocks = indices(level).get(index); + if (indexBlocks != null && !indexBlocks.isEmpty()) { + indices.add(index); + } + } + } + return ImmutableSet.copyOf(indices); + } + + public ImmutableMap> indexBlocks(String index) { + ImmutableMap.Builder> builder = ImmutableMap.builder(); + for (ClusterBlockLevel level : ClusterBlockLevel.values()) { + if (indices(level).containsKey(index) && !indices(level).get(index).isEmpty()) { + builder.put(level, indices(level).get(index)); + } + } + return builder.build(); + } + public ImmutableMap> indices(ClusterBlockLevel level) { return levelHolders[level.id()].indices(); } 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 b4a4c505172..d5d60ae965b 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 @@ -25,12 +25,15 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlock; +import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; 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.common.collect.ImmutableSet; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; @@ -76,6 +79,45 @@ public class RestClusterStateAction extends BaseRestHandler { builder.field("master_node", state.nodes().masterNodeId()); + // blocks + builder.startObject("blocks"); + + if (state.blocks().globalBlocked()) { + builder.startObject("global"); + for (ClusterBlockLevel level : ClusterBlockLevel.values()) { + if (!state.blocks().global(level).isEmpty()) { + builder.startObject(level.name().toLowerCase()); + for (ClusterBlock block : state.blocks().global(level)) { + builder.startObject(Integer.toString(block.id())); + builder.field("description", block.description()); + builder.endObject(); + } + builder.endObject(); + } + } + builder.endObject(); + } + + if (!state.blocks().indicesBlocked().isEmpty()) { + builder.startObject("indices"); + for (String index : state.blocks().indicesBlocked()) { + builder.startObject(index); + for (Map.Entry> entry : state.blocks().indexBlocks(index).entrySet()) { + ClusterBlockLevel level = entry.getKey(); + builder.startObject(level.name().toLowerCase()); + for (ClusterBlock block : entry.getValue()) { + builder.startObject(Integer.toString(block.id())); + builder.field("description", block.description()); + builder.endObject(); + } + } + builder.endObject(); + } + builder.endObject(); + } + + builder.endObject(); + // nodes builder.startObject("nodes"); for (DiscoveryNode node : state.nodes()) {