You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/02/18 12:32:12 UTC
[7/9] incubator-brooklyn git commit: fixes for non-inherited config
fixes for non-inherited config
- Fix Location’s getRaw(ConfigKey)
- Add comments
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b12e08de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b12e08de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b12e08de
Branch: refs/heads/master
Commit: b12e08de992a00daad4178325f25f8d41d705313
Parents: 1ed5484
Author: Aled Sage <al...@gmail.com>
Authored: Tue Feb 10 08:10:23 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Feb 18 11:02:35 2015 +0000
----------------------------------------------------------------------
.../brooklyn/basic/BrooklynObjectInternal.java | 5 ++++
.../location/basic/AbstractLocation.java | 24 +++++++++++---------
2 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b12e08de/core/src/main/java/brooklyn/basic/BrooklynObjectInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/basic/BrooklynObjectInternal.java b/core/src/main/java/brooklyn/basic/BrooklynObjectInternal.java
index 9575246..6115dd3 100644
--- a/core/src/main/java/brooklyn/basic/BrooklynObjectInternal.java
+++ b/core/src/main/java/brooklyn/basic/BrooklynObjectInternal.java
@@ -44,6 +44,11 @@ public interface BrooklynObjectInternal extends BrooklynObject, Rebindable {
/**
* Returns a read-only view of all the config key/value pairs on this entity, backed by a string-based map,
* including config names that did not match anything on this entity.
+ *
+ * TODO This method gives no information about which config is inherited versus local;
+ * this means {@link ConfigKey#getInheritance()} cannot be respected. This is an unsolvable problem
+ * for "config names that did not match anything on this entity". Therefore consider using
+ * alternative getters.
*/
@Beta
ConfigBag getBag();
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b12e08de/core/src/main/java/brooklyn/location/basic/AbstractLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/AbstractLocation.java b/core/src/main/java/brooklyn/location/basic/AbstractLocation.java
index c6dde27..9513cde 100644
--- a/core/src/main/java/brooklyn/location/basic/AbstractLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/AbstractLocation.java
@@ -413,7 +413,7 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
@Override
public Maybe<Object> getRaw(ConfigKey<?> key) {
if (hasConfig(key, false)) return Maybe.of(getLocalBag().getStringKey(key.getName()));
- if (getParent() != null) return ((AbstractLocation)getParent()).config().getRaw(key);
+ if (getParent() != null && isInherited(key)) return ((LocationInternal)getParent()).config().getRaw(key);
return Maybe.absent();
}
@@ -455,6 +455,16 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
return getLocalBag().containsKey(key);
}
}
+
+ private boolean isInherited(ConfigKey<?> key) {
+ ConfigInheritance inheritance = key.getInheritance();
+ if (inheritance==null) inheritance = getDefaultInheritance();
+ return inheritance.isInherited(key, getParent(), AbstractLocation.this);
+ }
+
+ private ConfigInheritance getDefaultInheritance() {
+ return ConfigInheritance.ALWAYS;
+ }
}
@Override
@@ -473,19 +483,11 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
return config.hasConfig(key, includeInherited);
}
- private boolean isInherited(ConfigKey<?> key) {
- ConfigInheritance inheritance = key.getInheritance();
- if (inheritance==null) inheritance = getDefaultInheritance();
- return inheritance.isInherited(key, getParent(), this);
- }
-
- private ConfigInheritance getDefaultInheritance() {
- return ConfigInheritance.ALWAYS;
- }
-
@Override
@Deprecated
public Map<String,Object> getAllConfig(boolean includeInherited) {
+ // TODO Have no information about what to include/exclude inheritance wise.
+ // however few things use getAllConfigBag()
ConfigBag bag = (includeInherited ? config().getBag() : config().getLocalBag());
return bag.getAllConfig();
}