brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bostko <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #558: BROOKLYN-433: regex/obj config key constr...
Date Mon, 13 Feb 2017 12:32:16 GMT
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/558#discussion_r100783030
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java ---
    @@ -310,6 +317,41 @@ private static Predicate parseConstraints(Object obj, BrooklynClassLoadingContex
                 }
             }
             
    +        private static Predicate<?> parseConstraint(Object untypedConstraint, BrooklynClassLoadingContext
loader) {
    +            // TODO Could try to handle deferred supplier as well?
    +            if (untypedConstraint instanceof Predicate) {
    +                // An explicit predicate (e.g. via "$brooklyn:object: ...")
    +                return (Predicate<?>) untypedConstraint;
    +            } else if (untypedConstraint instanceof String) {
    +                // build-in simple declaration, such as "required"
    +                String constraint = (String)untypedConstraint;
    +                if (BUILT_IN_CONSTRAINTS.containsKey(constraint)) {
    +                    return BUILT_IN_CONSTRAINTS.get(constraint);
    +                } else {
    +                    throw new IllegalArgumentException("The constraint '" + constraint
+ "' for a catalog input is not "
    +                            + "recognized as a built-in (" + BUILT_IN_CONSTRAINTS.keySet()
+ " or " 
    +                            + BUILT_IN_CONSTRAINT_FACTORIES.keySet() + ")");
    +                }
    +            } else if (untypedConstraint instanceof Map) {
    +                // For example "regex: foo.*"
    +                Map<?,?> constraint = (Map<?,?>)untypedConstraint;
    +                if (constraint.size() == 1) {
    +                    Object key = Iterables.getOnlyElement(constraint.keySet());
    +                    Object val = constraint.get(key);
    +                    if (BUILT_IN_CONSTRAINT_FACTORIES.containsKey(key)) {
    +                        Function<Object, Predicate<?>> factory = BUILT_IN_CONSTRAINT_FACTORIES.get(key);
    +                        return factory.apply(val);
    +                    } else {
    +                        throw new IllegalArgumentException("The constraint '" + constraint
+ "' for a catalog input is not recognized as a built-in (" + BUILT_IN_CONSTRAINTS.keySet()
+ ")");
    +                    }
    +                } else {
    +                    throw new IllegalArgumentException("The constraint '" + constraint
+ "' for a catalog input is not recognized - cannot handle multiple key:vales");
    --- End diff --
    
    Change to `The config key constraint '" + constraint + "' is not supported - it can handle
only single key:value constraint.`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message