Skip to content

Commit

Permalink
Throw ActionRequestValidationException on invalid awareness attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
Anshu Agarwal committed Sep 2, 2022
1 parent f07a9ad commit e12d247
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

package org.opensearch.action.admin.cluster.shards.routing.wrr.put;

import org.opensearch.OpenSearchException;
import org.opensearch.action.ActionListener;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction;
import org.opensearch.cluster.ClusterState;
Expand All @@ -28,6 +28,8 @@
import java.io.IOException;
import java.util.List;

import static org.opensearch.action.ValidateActions.addValidationError;

/**
* Transport action for updating weights for weighted round-robin search routing policy
*
Expand Down Expand Up @@ -107,10 +109,14 @@ protected void clusterManagerOperation(

private void verifyAwarenessAttribute(String attributeName) {
// Currently, only zone is supported
if (!getAwarenessAttributes().contains(attributeName) || !attributeName.equalsIgnoreCase("zone")) throw new OpenSearchException(
"invalid awareness attribute {} requested for updating wrr weights",
attributeName
);
if (!getAwarenessAttributes().contains(attributeName) || !attributeName.equalsIgnoreCase("zone")) {
ActionRequestValidationException validationException = null;
validationException = addValidationError(
"invalid awareness attribute " + attributeName + " requested for " + "updating wrr weights",
validationException
);
throw validationException;
}
}

@Override
Expand Down

0 comments on commit e12d247

Please sign in to comment.