brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geomacy <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #462: Inherit config default values
Date Tue, 20 Dec 2016 20:33:51 GMT
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/462#discussion_r93294912
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java ---
    @@ -404,7 +431,126 @@ public static void addParameters(AbstractBrooklynObjectSpec<?,
?> spec, List<? e
                 spec.parametersAdd(BasicSpecParameter.fromSpec(loader.getManagementContext(),
spec));
             }
             if (explicitParams.size() > 0) {
    -            spec.parametersAdd(explicitParams);
    +            spec.parametersReplace(resolveParameters(explicitParams, spec.getParameters(),
spec));
    +        }
    +    }
    +
    +    /** merge parameters against other parameters and known and type-inherited config
keys */
    +    static Collection<SpecParameter<?>> resolveParameters(Collection<?
extends SpecParameter<?>> newParams, Collection<? extends SpecParameter<?>>
existingReferenceParamsToKeep, AbstractBrooklynObjectSpec<?,?> spec) {
    +        Map<String,SpecParameter<?>> existingToKeep = MutableMap.of();
    +        if (existingReferenceParamsToKeep!=null) {
    +            for (SpecParameter<?> p: existingReferenceParamsToKeep) { 
    +                existingToKeep.put(p.getConfigKey().getName(), p);
    +            }
    +        }
    +
    +        List<SpecParameter<?>> result = MutableList.<SpecParameter<?>>of();
    +        for (SpecParameter<?> p: newParams) {
    +            if (p instanceof SpecParameterForInheritance) {
    --- End diff --
    
    It's a bit hard to parse this mentally - the `remove` and the `result.add` are both done
in both limbs of the `if`.  Also the cast `(ConfigKey<?>)` is strange, to force the
use of the overload for `resolveWithAncestor(ConfigKey<?> ancestor)`, especially when
that has a comment on it that says "// TODO not used yet;"
    
    Would it be clearer to leave the code for now just as 
    ```java
            for (SpecParameter<?> p: newParams) {
                final SpecParameter<?> existingP = existingToKeep.remove(p.getConfigKey().getName());
                if (p instanceof SpecParameterForInheritance) {
                        // TODO find config keys on the type (not available as parameters)
                        /* we don't currently do this due to low priority; all it means if
there is a config key in java,
                         * and a user wishes to expose it as a parameter, they have to redeclare
everything;
                         * nothing from the config key in java will be inherited */
                    p = ((SpecParameterForInheritance<?>)p).resolveWithAncestor(existingP);
                }
                result.add(p);
            }
    ```



---
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