expose blocks in the cluster state rest api

This commit is contained in:
kimchy 2010-06-29 01:00:07 +03:00
parent 5f538b1ba3
commit a82bf74c1c
3 changed files with 75 additions and 0 deletions

View File

@ -87,6 +87,7 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
builder.metaData(currentState.metaData());
}
}
builder.blocks(currentState.blocks());
return new ClusterStateResponse(clusterName, builder.build());
}
}

View File

@ -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<String> indicesBlocked() {
Set<String> indices = Sets.newHashSet();
for (ClusterBlockLevel level : ClusterBlockLevel.values()) {
for (String index : indices(level).keySet()) {
ImmutableSet<ClusterBlock> indexBlocks = indices(level).get(index);
if (indexBlocks != null && !indexBlocks.isEmpty()) {
indices.add(index);
}
}
}
return ImmutableSet.copyOf(indices);
}
public ImmutableMap<ClusterBlockLevel, ImmutableSet<ClusterBlock>> indexBlocks(String index) {
ImmutableMap.Builder<ClusterBlockLevel, ImmutableSet<ClusterBlock>> 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<String, ImmutableSet<ClusterBlock>> indices(ClusterBlockLevel level) {
return levelHolders[level.id()].indices();
}

View File

@ -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<ClusterBlockLevel, ImmutableSet<ClusterBlock>> 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()) {