You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2017/02/15 18:30:58 UTC
[05/28] brooklyn-server git commit: implement inheritance of config
default values
implement inheritance of config default values
test and code changes to respect the additional inheritance argument added in the previous request:
resolves https://issues.apache.org/jira/browse/BROOKLYN-267
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/667c3dff
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/667c3dff
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/667c3dff
Branch: refs/heads/master
Commit: 667c3dffbe654dfb409a64ab7e2675784c7d7433
Parents: aef2c7c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Nov 17 15:12:09 2016 +0000
Committer: Alex Heneveld <al...@Alexs-MacBook-Pro.local>
Committed: Tue Dec 6 10:05:21 2016 +0000
----------------------------------------------------------------------
.../core/config/BasicConfigInheritance.java | 15 +++++-----
.../brooklyn/core/entity/EntityConfigTest.java | 10 +++++++
.../brooklyn/config/ConfigInheritances.java | 30 ++++++++++++++------
.../org/apache/brooklyn/util/guava/Maybe.java | 2 ++
4 files changed, 40 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/667c3dff/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java b/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
index dd3b336..54336a0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
@@ -184,12 +184,6 @@ public class BasicConfigInheritance implements ConfigInheritance {
@Nonnull
protected final Boolean ancestorDefaultInheritable;
- /* TODO
- * - document key definition inference vs explicitness (conflict resolution is inferred from nearest descendant explicit key; whereas other values don't apply if no explicit key)
- * - ancestor default value inheritance -- https://issues.apache.org/jira/browse/BROOKLYN-267
- * - immediate config evaluation
- */
-
@Deprecated /** @deprecated since 0.10.0 use four-arg constructor */
protected BasicConfigInheritance(boolean isReinherited, @Nullable String conflictResolutionStrategy, boolean localDefaultResolvesWithAncestorValue) {
this(isReinherited, conflictResolutionStrategy, localDefaultResolvesWithAncestorValue, true);
@@ -252,8 +246,12 @@ public class BasicConfigInheritance implements ConfigInheritance {
checkInheritanceContext(local, context);
- if (!parent.isValueExplicitlySet() && !getLocalDefaultResolvesWithAncestorValue())
+ if (!parent.isValueExplicitlySet() && !getLocalDefaultResolvesWithAncestorValue()) {
+ if (getAncestorDefaultInheritable() && !local.isValueExplicitlySet() && local.getDefaultValue().isAbsentOrNull() && parent.getDefaultValue().isPresentAndNonNull()) {
+ return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(parent));
+ }
return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(local));
+ }
// parent explicitly set (or we might have to merge defaults),
// and by the contract of this method we can assume reinheritable
@@ -266,7 +264,8 @@ public class BasicConfigInheritance implements ConfigInheritance {
BasicConfigValueAtContainer<TContainer, TValue> result = new BasicConfigValueAtContainer<TContainer,TValue>(local);
ReferenceWithError<Maybe<? extends TValue>> resolvedValue = deepMerge(
local.isValueExplicitlySet() ? local.asMaybe() : local.getDefaultValue(),
- parent.isValueExplicitlySet() ? parent.asMaybe() : parent.getDefaultValue());
+ parent.isValueExplicitlySet() ? parent.asMaybe() :
+ getAncestorDefaultInheritable() ? parent.getDefaultValue() : Maybe.<TValue>absent());
result.setValue(resolvedValue.getWithoutError());
return ReferenceWithError.newInstanceThrowingError(result, resolvedValue.getError());
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/667c3dff/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java
index c25e6d2..a16548b 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java
@@ -42,6 +42,7 @@ import org.apache.brooklyn.core.config.ConfigPredicates;
import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey.IntegerAttributeSensorAndConfigKey;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
import org.apache.brooklyn.util.core.task.BasicTask;
import org.apache.brooklyn.util.core.task.DeferredSupplier;
@@ -533,4 +534,13 @@ public class EntityConfigTest extends BrooklynAppUnitTestSupport {
@SetFromFlag("mychildconfigflagname")
public static final ConfigKey<String> MY_CHILD_CONFIG_WITH_FLAGNAME = ConfigKeys.newStringConfigKey("mychildentity.myconfigwithflagname");
}
+
+ @Test
+ public void testInheritedDefault() {
+ final Entity e1 = app.addChild(EntitySpec.create(MyBaseEntity.class));
+ final Entity e2 = e1.addChild(EntitySpec.create(BasicEntity.class));
+ Assert.assertEquals(e2.config().get(MyBaseEntity.SUPER_KEY_1), MyBaseEntity.SUPER_KEY_1.getDefaultValue());
+ Assert.assertEquals(e2.config().get(ConfigKeys.newStringConfigKey(MyBaseEntity.SUPER_KEY_1.getName())), MyBaseEntity.SUPER_KEY_1.getDefaultValue());
+ }
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/667c3dff/utils/common/src/main/java/org/apache/brooklyn/config/ConfigInheritances.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/config/ConfigInheritances.java b/utils/common/src/main/java/org/apache/brooklyn/config/ConfigInheritances.java
index bac207d..02e9ef0 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/config/ConfigInheritances.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/config/ConfigInheritances.java
@@ -69,7 +69,7 @@ public class ConfigInheritances {
ancestorContainerKeyValues, key, context, defaultInheritance);
}
- /** as {@link #resolveInheriting(Object, ConfigKey, Maybe, Iterator, ConfigInheritanceContext, ConfigInheritance)}
+ /** as {@link #resolveInheriting(Object, ConfigKey, Maybe, Maybe, Iterator, ConfigInheritanceContext, ConfigInheritance)}
* but convenient when the local info is already in a {@link ConfigValueAtContainer} */
public static <TContainer,TValue> ReferenceWithError<ConfigValueAtContainer<TContainer,TValue>> resolveInheriting(
ConfigValueAtContainer<TContainer,TValue> local,
@@ -77,7 +77,9 @@ public class ConfigInheritances {
ConfigKey<TValue> queryKey,
ConfigInheritanceContext context,
ConfigInheritance defaultInheritance) {
-
+
+ BasicConfigValueAtContainer<TContainer, TValue> result = null;
+
if (ancestorContainerKeyValues.hasNext()) {
ConfigValueAtContainer<TContainer, TValue> parent = ancestorContainerKeyValues.next();
ConfigInheritance parentInheritance = findInheritance(parent, context, null);
@@ -86,18 +88,28 @@ public class ConfigInheritances {
if (currentInheritance.considerParent(local, parent, context)) {
ReferenceWithError<ConfigValueAtContainer<TContainer, TValue>> parentResult = resolveInheriting(parent, ancestorContainerKeyValues, queryKey, context, currentInheritance);
ReferenceWithError<ConfigValueAtContainer<TContainer,TValue>> resultWithParent = currentInheritance.resolveWithParent(local, parentResult.getWithoutError(), context);
- if (resultWithParent!=null && resultWithParent.getWithoutError()!=null && resultWithParent.getWithoutError().isValueExplicitlySet()) {
- if (!resultWithParent.hasError() && parentResult!=null && parentResult.hasError()) {
- return ReferenceWithError.newInstanceThrowingError(resultWithParent.getWithoutError(), parentResult.getError());
+ if (resultWithParent!=null) {
+ if (resultWithParent.getWithoutError()!=null && resultWithParent.getWithoutError().isValueExplicitlySet()) {
+ if (!resultWithParent.hasError() && parentResult!=null && parentResult.hasError()) {
+ return ReferenceWithError.newInstanceThrowingError(resultWithParent.getWithoutError(), parentResult.getError());
+ }
+ return resultWithParent;
+ } else {
+ result = new BasicConfigValueAtContainer<TContainer, TValue>( resultWithParent.getWithoutError() );
}
- return resultWithParent;
}
}
}
}
- BasicConfigValueAtContainer<TContainer, TValue> result = new BasicConfigValueAtContainer<TContainer, TValue>(local);
- if (!local.isValueExplicitlySet() && local.getDefaultValue().isPresent()) {
- result.value = local.getDefaultValue();
+ if (result==null) {
+ result = new BasicConfigValueAtContainer<TContainer, TValue>(local);
+ if (!local.isValueExplicitlySet() && local.getDefaultValue().isPresent()) {
+ result.value = local.getDefaultValue();
+ }
+ } else {
+ if (!result.isValueExplicitlySet()) {
+ result.value = result.getDefaultValue();
+ }
}
return ReferenceWithError.newInstanceWithoutError(result);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/667c3dff/utils/common/src/main/java/org/apache/brooklyn/util/guava/Maybe.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/guava/Maybe.java b/utils/common/src/main/java/org/apache/brooklyn/util/guava/Maybe.java
index 5270595..37fade3 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/guava/Maybe.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/guava/Maybe.java
@@ -457,6 +457,8 @@ public abstract class Maybe<T> implements Serializable, Supplier<T> {
Maybe<?> other = (Maybe<?>)obj;
if (!isPresent())
return !other.isPresent();
+ if (!other.isPresent())
+ return false;
return Objects.equal(get(), other.get());
}