Skip to content

Commit

Permalink
Update validation structure
Browse files Browse the repository at this point in the history
Signed-off-by: Rishab Nahata <rnnahata@amazon.com>
  • Loading branch information
imRishN committed Oct 19, 2022
1 parent 0bcbac4 commit 4bfd385
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,22 @@ private static void validateAwarenessAttribute(
private static void ensureToBeDecommissionedAttributeWeighedAway(ClusterState state, DecommissionAttribute decommissionAttribute) {
String msg = null;
WeightedRoutingMetadata weightedRoutingMetadata = state.metadata().weightedRoutingMetadata();
if (weightedRoutingMetadata != null) {
WeightedRouting weightedRouting = weightedRoutingMetadata.getWeightedRouting();
if (weightedRouting.attributeName().equals(decommissionAttribute.attributeName())) {
Double attributeValueWeight = weightedRouting.weights().get(decommissionAttribute.attributeValue());
if (attributeValueWeight == null || attributeValueWeight != 0.0) {
msg = "weight for decommissioned attribute is expected to be [0.0] but found [" + attributeValueWeight + "]";
}
} else {
msg = "no weights are specified to attribute [" + decommissionAttribute.attributeName() + "]";
}
} else {
msg = "no weights are set to the attribute. Please set appropriate weights before triggering decommission action";
if (weightedRoutingMetadata == null) {
throw new DecommissioningFailedException(decommissionAttribute,
"no weights are set to the attribute. Please set appropriate weights before triggering decommission action"
);
}
if (msg != null) {
throw new DecommissioningFailedException(decommissionAttribute, msg);
WeightedRouting weightedRouting = weightedRoutingMetadata.getWeightedRouting();
if (weightedRouting.attributeName().equals(decommissionAttribute.attributeName()) == false) {
throw new DecommissioningFailedException(decommissionAttribute,
"no weights are specified to attribute [" + decommissionAttribute.attributeName() + "]"
);
}
Double attributeValueWeight = weightedRouting.weights().get(decommissionAttribute.attributeValue());
if (attributeValueWeight == null || attributeValueWeight.equals(0.0)) {
throw new DecommissioningFailedException(decommissionAttribute,
"weight for decommissioned attribute is expected to be [0.0] but found [" + attributeValueWeight + "]"
);
}
}

Expand Down

0 comments on commit 4bfd385

Please sign in to comment.