Ethanlm commented on a change in pull request #3215: Storm3585 - New compact
Constraint config including maxCoLocationCnt
URL: https://github.com/apache/storm/pull/3215#discussion_r387438072
##########
File path:
storm-client/src/jvm/org/apache/storm/validation/ConfigValidation.java
##########
@@ -850,6 +852,128 @@ public void validateField(String name, Object o) {
}
}
+ public static class CustomIsExactlyOneOfValidators extends Validator {
+ private Class<?>[] subValidators;
+ private List<String> validatorClassNames;
+
+ public CustomIsExactlyOneOfValidators(Map<String, Object> params) {
+ this.subValidators = (Class<?>[])
params.get(ConfigValidationAnnotations.ValidatorParams.VALUE_VALIDATOR_CLASSES);
+ this.validatorClassNames =
Arrays.asList(subValidators).stream().map(x ->
x.getName()).collect(Collectors.toList());
+ }
+
+ @Override
+ public void validateField(String name, Object o) {
+ if (o == null) {
+ throw new IllegalArgumentException("Field " + name + " must be
set.");
+ }
+
+ HashMap<String, Exception> validatorExceptions = new HashMap<>();
+ Set<String> selectedValidators = new HashSet<>();
+ for (Class<?> vv : subValidators) {
+ Object valueValidator;
+ try {
+ valueValidator = vv.getConstructor().newInstance();
+ } catch (Exception ex) {
+ throw new IllegalArgumentException(vv.getName() + "
instantiation failure", ex);
+ }
+ if (valueValidator instanceof Validator) {
+ try {
+ ((Validator) valueValidator).validateField(name + " "
+ vv.getSimpleName() + " value", o);
+ selectedValidators.add(vv.getName());
+ } catch (Exception ex) {
+ // only one will pass, so ignore all validation errors
- stored for future use
+ validatorExceptions.put(vv.getName(), ex);
+ }
+ } else {
+ String err = String.format("validator: %s cannot be used
in CustomExactlyOneOfValidators to validate values. "
+ + "Individual entry validators must a instance of
Validator class", vv.getName());
Review comment:
typo: missing 'be" in "must a instance"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services