-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation in Decommission Request for minimum awareness attributes #4767
Conversation
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Codecov Report
@@ Coverage Diff @@
## main #4767 +/- ##
============================================
- Coverage 70.82% 70.80% -0.03%
+ Complexity 57885 57855 -30
============================================
Files 4689 4689
Lines 276913 276914 +1
Branches 40301 40303 +2
============================================
- Hits 196122 196063 -59
+ Misses 64548 64490 -58
- Partials 16243 16361 +118
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
if (awarenessAttributes == null) { | ||
msg = "awareness attribute not set to the cluster."; | ||
msg = "awareness attribute not set to the cluster"; | ||
} else if (forcedAwarenessAttributes == null) { | ||
msg = "forced awareness attribute not set to the cluster."; | ||
msg = "forced awareness attribute not set to the cluster"; | ||
} else if (awarenessAttributes.contains(decommissionAttribute.attributeName()) == false) { | ||
msg = "invalid awareness attribute requested for decommissioning"; | ||
msg = "invalid awareness attribute requested for decommissioning, eligible attributes are [" | ||
+ awarenessAttributes.toString() | ||
+ "]"; | ||
} else if (forcedAwarenessAttributes.containsKey(decommissionAttribute.attributeName()) == false) { | ||
msg = "forced awareness attribute [" + forcedAwarenessAttributes.toString() + "] doesn't have the decommissioning attribute"; | ||
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()) | ||
.contains(decommissionAttribute.attributeValue()) == false) { | ||
msg = "invalid awareness attribute value requested for decommissioning. Set forced awareness values before to decommission"; | ||
msg = "invalid awareness attribute value requested for decommissioning. Eligible forced awareness attributes [" | ||
+ forcedAwarenessAttributes.toString() | ||
+ "]"; | ||
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) { | ||
msg = "total awareness attribute value set to cluster is [" | ||
+ forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() | ||
+ "] which is less than minimum attribute value count required [3]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than so many if..else if
, this can be simplified with asserting just the expected values. If not we throw generic validation exception .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it can be simplified to a single if statement or two, but the disadvantage of it would be not exposing a verbose exception to the end user which would just leave the user wondering what went wrong with the request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the validations a bit now
Signed-off-by: Rishab Nahata <[email protected]>
|
||
if (awarenessAttributes == null | ||
|| forcedAwarenessAttributes == null | ||
|| awarenessAttributes.isEmpty() | ||
|| forcedAwarenessAttributes.isEmpty()) { | ||
msg = "awareness attribute [" | ||
+ awarenessAttributes | ||
+ "] and forced awareness attribute [" | ||
+ forcedAwarenessAttributes | ||
+ "] must be set to execute decommissioning"; | ||
} else if (awarenessAttributes.contains(decommissionAttribute.attributeName()) == false | ||
|| forcedAwarenessAttributes.containsKey(decommissionAttribute.attributeName()) == false) { | ||
msg = "invalid awareness attribute requested for decommissioning, eligible attributes are [" | ||
+ forcedAwarenessAttributes | ||
+ "]"; | ||
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()) | ||
.contains(decommissionAttribute.attributeValue()) == false) { | ||
msg = "invalid awareness attribute value requested for decommissioning. Eligible forced awareness attributes [" | ||
+ forcedAwarenessAttributes | ||
+ "]"; | ||
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) { | ||
msg = "total awareness attribute value set to cluster is [" | ||
+ forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() | ||
+ "] which is less than minimum attribute value count required [3]"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the spotless check is messing up the indentation in the same level of if/else block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LTGM . Thanks Rishabh.
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()) | ||
.contains(decommissionAttribute.attributeValue()) == false) { | ||
msg = "invalid awareness attribute value requested for decommissioning. Eligible forced awareness attributes [" | ||
+ forcedAwarenessAttributes | ||
+ "]"; | ||
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) { | ||
msg = "total awareness attribute value set to cluster is [" | ||
+ forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() | ||
+ "] which is less than minimum attribute value count required [3]"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets say force zone awareness is set to AZ1, AZ2, AZ3 while actual discovered zone values are only
- AZ1, AZ4, AZ5
- AZ1 only
will decommission on AZ1 be supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think force zone awareness values is the only source of truth today to know the actual zone values. If the user has set the zones to AZ1, AZ2, AZ3 would it be wrong to assume that these are the actual zone values? And force zone values is a dynamically updatable setting which is set by the user and defaults to empty.
Another point here is, if the zone values that are set by the user is AZ1,AZ2,AZ3 and user requests to decommission to AZ4, these checks would anyways fail and hence decommission would fail
…tion Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
59eedb6
to
e3a9d04
Compare
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
…tion Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Rishab Nahata <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
+ "]" | ||
); | ||
} | ||
if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get you. Configuration as in?
Description
This PR adds another layer of validation before executing decommission request. The decommission request hence would be acknowledged only if there are atleast 3 awareness attribute value set to the cluster to fail fast
Issues Resolved
#4768
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.