brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #173: BROOKLYN-286: merge config keys map value...
Date Thu, 02 Jun 2016 13:00:25 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/173#discussion_r65534125
  
    --- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
---
    @@ -257,37 +261,63 @@ private void configureEntityConfig(EntitySpec<?> spec, Set<String>
encounteredRe
             // attrs will contain only brooklyn.xxx properties when coming from BrooklynEntityMatcher.
             // Any top-level flags will go into "brooklyn.flags". When resolving a spec from
$brooklyn:entitySpec
             // top level flags remain in place. Have to support both cases.
    -
    +        //
    +        // For config values inherited from the super-type (be that the Java type or
another catalog item
    +        // being extended), we lookup the config key to find out if the values should
be merged, overridden or 
    +        // cleared.
    +        
             ConfigBag bag = ConfigBag.newInstance((Map<Object, Object>) attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_CONFIG));
             ConfigBag bagFlags = ConfigBag.newInstanceCopying(attrs);
             if (attrs.containsKey(BrooklynCampReservedKeys.BROOKLYN_FLAGS)) {
                 bagFlags.putAll((Map<String, Object>) attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_FLAGS));
             }
     
    -        Collection<FlagConfigKeyAndValueRecord> topLevelApparentConfig = findAllFlagsAndConfigKeys(spec,
bagFlags);
    +        Collection<FlagConfigKeyAndValueRecord> topLevelApparentConfig = findAllFlagsAndConfigKeyValues(spec,
bagFlags);
             for (FlagConfigKeyAndValueRecord r: topLevelApparentConfig) {
                 if (r.getConfigKeyMaybeValue().isPresent())
                     bag.putIfAbsent((ConfigKey)r.getConfigKey(), r.getConfigKeyMaybeValue().get());
                 if (r.getFlagMaybeValue().isPresent())
                     bag.putAsStringKeyIfAbsent(r.getFlagName(), r.getFlagMaybeValue().get());
             }
     
    +        
             // now set configuration for all the items in the bag
    -        Collection<FlagConfigKeyAndValueRecord> records = findAllFlagsAndConfigKeys(spec,
bag);
    +        Map<String, ConfigKey<?>> entityConfigKeys = findAllConfigKeys(spec);
    +        
    +        Collection<FlagConfigKeyAndValueRecord> records = findAllFlagsAndConfigKeyValues(spec,
bag);
             Set<String> keyNamesUsed = new LinkedHashSet<String>();
             for (FlagConfigKeyAndValueRecord r: records) {
                 if (r.getFlagMaybeValue().isPresent()) {
    -                Object transformed = new SpecialFlagsTransformer(loader, encounteredRegisteredTypeIds).apply(r.getFlagMaybeValue().get());
    -                spec.configure(r.getFlagName(), transformed);
    -                keyNamesUsed.add(r.getFlagName());
    +                String flag = r.getFlagName();
    +                Object ownVal = new SpecialFlagsTransformer(loader, encounteredRegisteredTypeIds).apply(r.getFlagMaybeValue().get());
    +                Maybe<?> superVal = spec.getFlags().containsKey(flag) ? Maybe.of(spec.getFlags().get(flag))
: Maybe.absent();
    +                Object combinedVal = combineValues(entityConfigKeys.get(flag), spec,
Maybe.of(ownVal), superVal).get();
    +                spec.configure(flag, combinedVal);
    +                keyNamesUsed.add(flag);
                 }
                 if (r.getConfigKeyMaybeValue().isPresent()) {
    -                Object transformed = new SpecialFlagsTransformer(loader, encounteredRegisteredTypeIds).apply(r.getConfigKeyMaybeValue().get());
    -                spec.configure((ConfigKey<Object>)r.getConfigKey(), transformed);
    -                keyNamesUsed.add(r.getConfigKey().getName());
    +                ConfigKey<Object> key = (ConfigKey<Object>) r.getConfigKey();
    +                Object ownVal = new SpecialFlagsTransformer(loader, encounteredRegisteredTypeIds).apply(r.getConfigKeyMaybeValue().get());
    +                Maybe<?> superVal = spec.getConfig().containsKey(key) ? Maybe.of(spec.getConfig().get(key))
: Maybe.absent();
    +                Object combinedVal = combineValues(entityConfigKeys.get(key.getName()),
spec, Maybe.of(ownVal), superVal).get();
    +                spec.configure(key, combinedVal);
    +                keyNamesUsed.add(key.getName());
                 }
             }
     
    +        // For anything that should not be inherited, clear if from the spec
    +        for (Map.Entry<String, ConfigKey<?>> entry : entityConfigKeys.entrySet())
{
    +            if (keyNamesUsed.contains(entry.getKey())) {
    +                continue;
    +            }
    +            ConfigKey<?> key = entry.getValue();
    +            InheritanceMode mode = getInheritanceMode(key, spec);
    +            if (mode == InheritanceMode.NONE) {
    +                spec.removeConfig(key);
    +                spec.removeFlag(key.getName());
    +            }
    +        }
    +        
    --- End diff --
    
    Should do analogous merging for locations?


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