Cluster Health API: Add initializing_shards and unassigned_shards to the response, closes #330.

This commit is contained in:
kimchy 2010-08-21 16:03:29 +03:00
parent 113ea1bb1b
commit 38e6649a7e
5 changed files with 86 additions and 0 deletions

View File

@ -48,6 +48,10 @@ public class ClusterHealthResponse implements ActionResponse, Iterable<ClusterIn
int activePrimaryShards = 0; int activePrimaryShards = 0;
int initializingShards = 0;
int unassignedShards = 0;
boolean timedOut = false; boolean timedOut = false;
ClusterHealthStatus status = ClusterHealthStatus.RED; ClusterHealthStatus status = ClusterHealthStatus.RED;
@ -129,6 +133,22 @@ public class ClusterHealthResponse implements ActionResponse, Iterable<ClusterIn
return activePrimaryShards(); return activePrimaryShards();
} }
public int initializingShards() {
return initializingShards;
}
public int getInitializingShards() {
return initializingShards();
}
public int unassignedShards() {
return unassignedShards;
}
public int getUnassignedShards() {
return unassignedShards();
}
public int numberOfNodes() { public int numberOfNodes() {
return this.numberOfNodes; return this.numberOfNodes;
} }
@ -173,6 +193,8 @@ public class ClusterHealthResponse implements ActionResponse, Iterable<ClusterIn
activePrimaryShards = in.readVInt(); activePrimaryShards = in.readVInt();
activeShards = in.readVInt(); activeShards = in.readVInt();
relocatingShards = in.readVInt(); relocatingShards = in.readVInt();
initializingShards = in.readVInt();
unassignedShards = in.readVInt();
numberOfNodes = in.readVInt(); numberOfNodes = in.readVInt();
status = ClusterHealthStatus.fromValue(in.readByte()); status = ClusterHealthStatus.fromValue(in.readByte());
int size = in.readVInt(); int size = in.readVInt();
@ -196,6 +218,8 @@ public class ClusterHealthResponse implements ActionResponse, Iterable<ClusterIn
out.writeVInt(activePrimaryShards); out.writeVInt(activePrimaryShards);
out.writeVInt(activeShards); out.writeVInt(activeShards);
out.writeVInt(relocatingShards); out.writeVInt(relocatingShards);
out.writeVInt(initializingShards);
out.writeVInt(unassignedShards);
out.writeVInt(numberOfNodes); out.writeVInt(numberOfNodes);
out.writeByte(status.value()); out.writeByte(status.value());
out.writeVInt(indices.size()); out.writeVInt(indices.size());

View File

@ -47,6 +47,10 @@ public class ClusterIndexHealth implements Iterable<ClusterShardHealth>, Streama
int relocatingShards = 0; int relocatingShards = 0;
int initializingShards = 0;
int unassignedShards = 0;
int activePrimaryShards = 0; int activePrimaryShards = 0;
ClusterHealthStatus status = ClusterHealthStatus.RED; ClusterHealthStatus status = ClusterHealthStatus.RED;
@ -121,6 +125,22 @@ public class ClusterIndexHealth implements Iterable<ClusterShardHealth>, Streama
return activePrimaryShards(); 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() { public ClusterHealthStatus status() {
return status; return status;
} }
@ -154,6 +174,8 @@ public class ClusterIndexHealth implements Iterable<ClusterShardHealth>, Streama
activePrimaryShards = in.readVInt(); activePrimaryShards = in.readVInt();
activeShards = in.readVInt(); activeShards = in.readVInt();
relocatingShards = in.readVInt(); relocatingShards = in.readVInt();
initializingShards = in.readVInt();
unassignedShards = in.readVInt();
status = ClusterHealthStatus.fromValue(in.readByte()); status = ClusterHealthStatus.fromValue(in.readByte());
int size = in.readVInt(); int size = in.readVInt();
@ -178,6 +200,8 @@ public class ClusterIndexHealth implements Iterable<ClusterShardHealth>, Streama
out.writeVInt(activePrimaryShards); out.writeVInt(activePrimaryShards);
out.writeVInt(activeShards); out.writeVInt(activeShards);
out.writeVInt(relocatingShards); out.writeVInt(relocatingShards);
out.writeVInt(initializingShards);
out.writeVInt(unassignedShards);
out.writeByte(status.value()); out.writeByte(status.value());
out.writeVInt(shards.size()); out.writeVInt(shards.size());

View File

@ -38,6 +38,10 @@ public class ClusterShardHealth implements Streamable {
int relocatingShards = 0; int relocatingShards = 0;
int initializingShards = 0;
int unassignedShards = 0;
boolean primaryActive = false; boolean primaryActive = false;
private ClusterShardHealth() { private ClusterShardHealth() {
@ -88,6 +92,22 @@ public class ClusterShardHealth implements Streamable {
return primaryActive(); 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 { static ClusterShardHealth readClusterShardHealth(StreamInput in) throws IOException {
ClusterShardHealth ret = new ClusterShardHealth(); ClusterShardHealth ret = new ClusterShardHealth();
ret.readFrom(in); ret.readFrom(in);
@ -99,6 +119,8 @@ public class ClusterShardHealth implements Streamable {
status = ClusterHealthStatus.fromValue(in.readByte()); status = ClusterHealthStatus.fromValue(in.readByte());
activeShards = in.readVInt(); activeShards = in.readVInt();
relocatingShards = in.readVInt(); relocatingShards = in.readVInt();
initializingShards = in.readVInt();
unassignedShards = in.readVInt();
primaryActive = in.readBoolean(); primaryActive = in.readBoolean();
} }
@ -107,6 +129,8 @@ public class ClusterShardHealth implements Streamable {
out.writeByte(status.value()); out.writeByte(status.value());
out.writeVInt(activeShards); out.writeVInt(activeShards);
out.writeVInt(relocatingShards); out.writeVInt(relocatingShards);
out.writeVInt(initializingShards);
out.writeVInt(unassignedShards);
out.writeBoolean(primaryActive); out.writeBoolean(primaryActive);
} }
} }

View File

@ -187,6 +187,10 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc
if (shardRouting.primary()) { if (shardRouting.primary()) {
shardHealth.primaryActive = true; shardHealth.primaryActive = true;
} }
} else if (shardRouting.initializing()) {
shardHealth.initializingShards++;
} else if (shardRouting.unassigned()) {
shardHealth.unassignedShards++;
} }
} }
if (shardHealth.primaryActive) { if (shardHealth.primaryActive) {
@ -207,6 +211,8 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc
} }
indexHealth.activeShards += shardHealth.activeShards; indexHealth.activeShards += shardHealth.activeShards;
indexHealth.relocatingShards += shardHealth.relocatingShards; indexHealth.relocatingShards += shardHealth.relocatingShards;
indexHealth.initializingShards += shardHealth.initializingShards;
indexHealth.unassignedShards += shardHealth.unassignedShards;
} }
// update the index status // update the index status
indexHealth.status = ClusterHealthStatus.GREEN; indexHealth.status = ClusterHealthStatus.GREEN;
@ -231,6 +237,8 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc
response.activePrimaryShards += indexHealth.activePrimaryShards; response.activePrimaryShards += indexHealth.activePrimaryShards;
response.activeShards += indexHealth.activeShards; response.activeShards += indexHealth.activeShards;
response.relocatingShards += indexHealth.relocatingShards; response.relocatingShards += indexHealth.relocatingShards;
response.initializingShards += indexHealth.initializingShards;
response.unassignedShards += indexHealth.unassignedShards;
} }
response.status = ClusterHealthStatus.GREEN; response.status = ClusterHealthStatus.GREEN;

View File

@ -90,6 +90,8 @@ public class RestClusterHealthAction extends BaseRestHandler {
builder.field("active_primary_shards", response.activePrimaryShards()); builder.field("active_primary_shards", response.activePrimaryShards());
builder.field("active_shards", response.activeShards()); builder.field("active_shards", response.activeShards());
builder.field("relocating_shards", response.relocatingShards()); builder.field("relocating_shards", response.relocatingShards());
builder.field("initializing_shards", response.initializingShards());
builder.field("unassigned_shards", response.unassignedShards());
if (!response.validationFailures().isEmpty()) { if (!response.validationFailures().isEmpty()) {
builder.startArray("validation_failures"); builder.startArray("validation_failures");
@ -127,6 +129,8 @@ public class RestClusterHealthAction extends BaseRestHandler {
builder.field("active_primary_shards", indexHealth.activePrimaryShards()); builder.field("active_primary_shards", indexHealth.activePrimaryShards());
builder.field("active_shards", indexHealth.activeShards()); builder.field("active_shards", indexHealth.activeShards());
builder.field("relocating_shards", indexHealth.relocatingShards()); builder.field("relocating_shards", indexHealth.relocatingShards());
builder.field("initializing_shards", indexHealth.initializingShards());
builder.field("unassigned_shards", indexHealth.unassignedShards());
if (!indexHealth.validationFailures().isEmpty()) { if (!indexHealth.validationFailures().isEmpty()) {
builder.startArray("validation_failures"); builder.startArray("validation_failures");
@ -146,6 +150,8 @@ public class RestClusterHealthAction extends BaseRestHandler {
builder.field("primary_active", shardHealth.primaryActive()); builder.field("primary_active", shardHealth.primaryActive());
builder.field("active_shards", shardHealth.activeShards()); builder.field("active_shards", shardHealth.activeShards());
builder.field("relocating_shards", shardHealth.relocatingShards()); builder.field("relocating_shards", shardHealth.relocatingShards());
builder.field("initializing_shards", shardHealth.initializingShards());
builder.field("unassigned_shards", shardHealth.unassignedShards());
builder.endObject(); builder.endObject();
} }