From 38e6649a7e364ec728ed4b953e3b5ba575f1f6ae Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 21 Aug 2010 16:03:29 +0300 Subject: [PATCH] Cluster Health API: Add `initializing_shards` and `unassigned_shards` to the response, closes #330. --- .../cluster/health/ClusterHealthResponse.java | 24 +++++++++++++++++++ .../cluster/health/ClusterIndexHealth.java | 24 +++++++++++++++++++ .../cluster/health/ClusterShardHealth.java | 24 +++++++++++++++++++ .../health/TransportClusterHealthAction.java | 8 +++++++ .../health/RestClusterHealthAction.java | 6 +++++ 5 files changed, 86 insertions(+) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java index 199f5c7dd1c..88251fb15a5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java @@ -48,6 +48,10 @@ public class ClusterHealthResponse implements ActionResponse, Iterable, Streama int relocatingShards = 0; + int initializingShards = 0; + + int unassignedShards = 0; + int activePrimaryShards = 0; ClusterHealthStatus status = ClusterHealthStatus.RED; @@ -121,6 +125,22 @@ public class ClusterIndexHealth implements Iterable, Streama return activePrimaryShards(); } + public int initializingShards() { + return initializingShards; + } + + public int getInitializingShards() { + return initializingShards(); + } + + public int unassignedShards() { + return unassignedShards; + } + + public int getUnassignedShards() { + return unassignedShards(); + } + public ClusterHealthStatus status() { return status; } @@ -154,6 +174,8 @@ public class ClusterIndexHealth implements Iterable, Streama activePrimaryShards = in.readVInt(); activeShards = in.readVInt(); relocatingShards = in.readVInt(); + initializingShards = in.readVInt(); + unassignedShards = in.readVInt(); status = ClusterHealthStatus.fromValue(in.readByte()); int size = in.readVInt(); @@ -178,6 +200,8 @@ public class ClusterIndexHealth implements Iterable, Streama out.writeVInt(activePrimaryShards); out.writeVInt(activeShards); out.writeVInt(relocatingShards); + out.writeVInt(initializingShards); + out.writeVInt(unassignedShards); out.writeByte(status.value()); out.writeVInt(shards.size()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterShardHealth.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterShardHealth.java index 6f32c885712..371326e0f70 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterShardHealth.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterShardHealth.java @@ -38,6 +38,10 @@ public class ClusterShardHealth implements Streamable { int relocatingShards = 0; + int initializingShards = 0; + + int unassignedShards = 0; + boolean primaryActive = false; private ClusterShardHealth() { @@ -88,6 +92,22 @@ public class ClusterShardHealth implements Streamable { return primaryActive(); } + public int initializingShards() { + return initializingShards; + } + + public int getInitializingShards() { + return initializingShards(); + } + + public int unassignedShards() { + return unassignedShards; + } + + public int getUnassignedShards() { + return unassignedShards(); + } + static ClusterShardHealth readClusterShardHealth(StreamInput in) throws IOException { ClusterShardHealth ret = new ClusterShardHealth(); ret.readFrom(in); @@ -99,6 +119,8 @@ public class ClusterShardHealth implements Streamable { status = ClusterHealthStatus.fromValue(in.readByte()); activeShards = in.readVInt(); relocatingShards = in.readVInt(); + initializingShards = in.readVInt(); + unassignedShards = in.readVInt(); primaryActive = in.readBoolean(); } @@ -107,6 +129,8 @@ public class ClusterShardHealth implements Streamable { out.writeByte(status.value()); out.writeVInt(activeShards); out.writeVInt(relocatingShards); + out.writeVInt(initializingShards); + out.writeVInt(unassignedShards); out.writeBoolean(primaryActive); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index 905a1f8b345..f86eba13b2c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -187,6 +187,10 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc if (shardRouting.primary()) { shardHealth.primaryActive = true; } + } else if (shardRouting.initializing()) { + shardHealth.initializingShards++; + } else if (shardRouting.unassigned()) { + shardHealth.unassignedShards++; } } if (shardHealth.primaryActive) { @@ -207,6 +211,8 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc } indexHealth.activeShards += shardHealth.activeShards; indexHealth.relocatingShards += shardHealth.relocatingShards; + indexHealth.initializingShards += shardHealth.initializingShards; + indexHealth.unassignedShards += shardHealth.unassignedShards; } // update the index status indexHealth.status = ClusterHealthStatus.GREEN; @@ -231,6 +237,8 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc response.activePrimaryShards += indexHealth.activePrimaryShards; response.activeShards += indexHealth.activeShards; response.relocatingShards += indexHealth.relocatingShards; + response.initializingShards += indexHealth.initializingShards; + response.unassignedShards += indexHealth.unassignedShards; } response.status = ClusterHealthStatus.GREEN; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java index 6a60e8c2a0b..c1735fc0117 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java @@ -90,6 +90,8 @@ public class RestClusterHealthAction extends BaseRestHandler { builder.field("active_primary_shards", response.activePrimaryShards()); builder.field("active_shards", response.activeShards()); builder.field("relocating_shards", response.relocatingShards()); + builder.field("initializing_shards", response.initializingShards()); + builder.field("unassigned_shards", response.unassignedShards()); if (!response.validationFailures().isEmpty()) { builder.startArray("validation_failures"); @@ -127,6 +129,8 @@ public class RestClusterHealthAction extends BaseRestHandler { builder.field("active_primary_shards", indexHealth.activePrimaryShards()); builder.field("active_shards", indexHealth.activeShards()); builder.field("relocating_shards", indexHealth.relocatingShards()); + builder.field("initializing_shards", indexHealth.initializingShards()); + builder.field("unassigned_shards", indexHealth.unassignedShards()); if (!indexHealth.validationFailures().isEmpty()) { builder.startArray("validation_failures"); @@ -146,6 +150,8 @@ public class RestClusterHealthAction extends BaseRestHandler { builder.field("primary_active", shardHealth.primaryActive()); builder.field("active_shards", shardHealth.activeShards()); builder.field("relocating_shards", shardHealth.relocatingShards()); + builder.field("initializing_shards", shardHealth.initializingShards()); + builder.field("unassigned_shards", shardHealth.unassignedShards()); builder.endObject(); }