Skip to content

Commit

Permalink
Added changes as per comments
Browse files Browse the repository at this point in the history
Signed-off-by: Nishchay Malhotra <nishcha@amazon.com>
  • Loading branch information
nishchay21 committed Jan 10, 2023
1 parent b35667f commit 352c47f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ClusterHealthRequest(StreamInput in) throws IOException {
}
waitForNoInitializingShards = in.readBoolean();
indicesOptions = IndicesOptions.readIndicesOptions(in);
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_5_0)) {
awarenessAttribute = in.readOptionalString();
level = in.readEnum(Level.class);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public void writeTo(StreamOutput out) throws IOException {
}
out.writeBoolean(waitForNoInitializingShards);
indicesOptions.writeIndicesOptions(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_5_0)) {
out.writeOptionalString(awarenessAttribute);
out.writeEnum(level);
}
Expand Down Expand Up @@ -284,16 +284,16 @@ public void level(Level level) {
public void setLevel(String level) {
switch (level) {
case "indices":
this.level = ClusterHealthRequest.Level.INDICES;
level(ClusterHealthRequest.Level.INDICES);
break;
case "shards":
this.level = ClusterHealthRequest.Level.SHARDS;
level(ClusterHealthRequest.Level.SHARDS);
break;
case "awareness_attribute":
this.level = ClusterHealthRequest.Level.AWARENESS_ATTRIBUTE;
case "awareness_attributes":
level(ClusterHealthRequest.Level.AWARENESS_ATTRIBUTES);
break;
default:
this.level = ClusterHealthRequest.Level.CLUSTER;
level(ClusterHealthRequest.Level.CLUSTER);
}
}

Expand All @@ -316,10 +316,10 @@ public String getAwarenessAttribute() {

@Override
public ActionRequestValidationException validate() {
if (level.equals(Level.AWARENESS_ATTRIBUTE) && indices.length > 0) {
if (level.equals(Level.AWARENESS_ATTRIBUTES) && indices.length > 0) {
return addValidationError("awareness_attribute is not a supported parameter with index health", null);
} else if (!level.equals(Level.AWARENESS_ATTRIBUTE) && awarenessAttribute != null) {
return addValidationError("level=awareness_attribute is required with awareness_attribute parameter", null);
} else if (!level.equals(Level.AWARENESS_ATTRIBUTES) && awarenessAttribute != null) {
return addValidationError("level=awareness_attributes is required with awareness_attribute parameter", null);
}
return null;
}
Expand All @@ -333,6 +333,6 @@ public enum Level {
CLUSTER,
INDICES,
SHARDS,
AWARENESS_ATTRIBUTE
AWARENESS_ATTRIBUTES
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public ClusterHealthResponse(StreamInput in) throws IOException {
numberOfInFlightFetch = in.readInt();
delayedUnassignedShards = in.readInt();
taskMaxWaitingTime = in.readTimeValue();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_5_0)) {
if (in.readBoolean()) {
clusterAwarenessHealth = new ClusterAwarenessHealth(in);
}
Expand Down Expand Up @@ -239,20 +239,23 @@ public ClusterHealthResponse(
String clusterName,
ClusterState clusterState,
ClusterSettings clusterSettings,
String[] concreteIndices,
String awarenessAttributeName,
int numberOfPendingTasks,
int numberOfInFlightFetch,
int delayedUnassignedShards,
TimeValue taskMaxWaitingTime
) {
this.clusterName = clusterName;
this.numberOfPendingTasks = numberOfPendingTasks;
this.numberOfInFlightFetch = numberOfInFlightFetch;
this.delayedUnassignedShards = delayedUnassignedShards;
this.taskMaxWaitingTime = taskMaxWaitingTime;
this.clusterStateHealth = new ClusterStateHealth(clusterState);
this(
clusterName,
concreteIndices,
clusterState,
numberOfPendingTasks,
numberOfInFlightFetch,
delayedUnassignedShards,
taskMaxWaitingTime
);
this.clusterAwarenessHealth = new ClusterAwarenessHealth(clusterState, clusterSettings, awarenessAttributeName);
this.clusterHealthStatus = clusterStateHealth.getStatus();
}

/**
Expand Down Expand Up @@ -401,7 +404,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInt(numberOfInFlightFetch);
out.writeInt(delayedUnassignedShards);
out.writeTimeValue(taskMaxWaitingTime);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_5_0)) {
if (clusterAwarenessHealth != null) {
out.writeBoolean(true);
clusterAwarenessHealth.writeTo(out);
Expand Down Expand Up @@ -444,7 +447,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

String level = params.param("level", "cluster");
boolean outputIndices = "indices".equals(level) || "shards".equals(level);
boolean outputAwarenessHealth = "awareness_attribute".equals(level);
boolean outputAwarenessHealth = "awareness_attributes".equals(level);

if (outputIndices) {
builder.startObject(INDICES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,15 @@ private ClusterHealthResponse clusterHealth(
logger.trace("Calculating health based on state version [{}]", clusterState.version());
}

if (request.level().equals(ClusterHealthRequest.Level.AWARENESS_ATTRIBUTE)) {
String[] concreteIndices;
if (request.level().equals(ClusterHealthRequest.Level.AWARENESS_ATTRIBUTES)) {
String awarenessAttribute = request.getAwarenessAttribute();
concreteIndices = clusterState.getMetadata().getConcreteAllIndices();
return new ClusterHealthResponse(
clusterState.getClusterName().value(),
clusterState,
clusterService.getClusterSettings(),
concreteIndices,
awarenessAttribute,
numberOfPendingTasks,
numberOfInFlightFetch,
Expand All @@ -470,7 +473,6 @@ private ClusterHealthResponse clusterHealth(
);
}

String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
} catch (IndexNotFoundException e) {
Expand Down

0 comments on commit 352c47f

Please sign in to comment.