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:31:18 UTC
[25/28] brooklyn-server git commit: cleanup spec parameter
parsing/inheriting, tidy misc tests
cleanup spec parameter parsing/inheriting, tidy misc tests
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f1d4c59c
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f1d4c59c
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f1d4c59c
Branch: refs/heads/master
Commit: f1d4c59c6579621607b9ba9ee7ffd9ec7336e5c3
Parents: db1f752
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Feb 14 15:33:18 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Feb 14 16:07:17 2017 +0000
----------------------------------------------------------------------
.../BrooklynEntityDecorationResolver.java | 5 +-
.../spi/creation/CampInternalUtils.java | 38 +++---
.../brooklyn/ConfigInheritanceYamlTest.java | 121 ++++++++++---------
.../catalog/internal/BasicBrooklynCatalog.java | 2 +-
.../config/internal/AbstractConfigMapImpl.java | 6 +
.../core/entity/internal/EntityConfigMap.java | 1 +
.../brooklyn/core/objs/BasicSpecParameter.java | 85 +++++--------
.../objs/BasicSpecParameterFromListTest.java | 32 ++---
8 files changed, 143 insertions(+), 147 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
index 78bc795..071ec1b 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
@@ -211,12 +211,13 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
transformer = new BrooklynComponentTemplateResolver.SpecialFlagsTransformer(instantiator.loader, encounteredRegisteredTypeIds);
// entitySpec is the parent
List<? extends SpecParameter<?>> explicitParams = buildListOfTheseDecorationsFromEntityAttributes(attrs);
- BasicSpecParameter.addParameters(entitySpec, explicitParams, instantiator.loader);
+ BasicSpecParameter.initializeSpecWithExplicitParameters(entitySpec, explicitParams, instantiator.loader);
}
@Override
protected List<SpecParameter<?>> buildListOfTheseDecorationsFromIterable(Iterable<?> value) {
- return BasicSpecParameter.fromConfigList(ImmutableList.copyOf(value), transformer, instantiator.loader);
+ // returns definitions, used only by #decorate method above
+ return BasicSpecParameter.parseParameterDefinitionList(ImmutableList.copyOf(value), transformer, instantiator.loader);
}
@Override
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
index 07b94f5..7501552 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
@@ -140,12 +140,7 @@ class CampInternalUtils {
String versionedId = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "policy_type", "policyType", "type"), "policy type");
PolicySpec<? extends Policy> spec = resolvePolicySpec(versionedId, loader, encounteredCatalogTypes);
- Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
- if (brooklynConfig != null) {
- spec.configure(brooklynConfig);
- }
- List<?> parameters = (List<?>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
- initParameters(parameters, spec, loader);
+ initConfigAndParameters(spec, itemMap, loader);
return spec;
}
@@ -173,19 +168,21 @@ class CampInternalUtils {
String type = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "location_type", "locationType", "type"), "location type");
Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
- if (brooklynConfig==null) brooklynConfig = MutableMap.of();
LocationSpec<?> locationSpec = resolveLocationSpec(type, brooklynConfig, loader);
- List<?> explicitParams = (List<?>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
- initParameters(explicitParams, locationSpec, loader);
+ // config loaded twice, but used twice
+ initConfigAndParameters(locationSpec, itemMap, loader);
return locationSpec;
}
- private static void initParameters(List<?> explicitParams, AbstractBrooklynObjectSpec<?, ?> spec, BrooklynClassLoadingContext loader) {
- if (explicitParams != null) {
- BasicSpecParameter.addParameters(spec, BasicSpecParameter.fromConfigList(explicitParams, null, loader), loader);
- } else {
- BasicSpecParameter.addParameters(spec, ImmutableList.<SpecParameter<?>>of(), loader);
+ protected static void initConfigAndParameters(AbstractBrooklynObjectSpec<?,?> spec, Map<String, Object> itemMap, BrooklynClassLoadingContext loader) {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
+ if (brooklynConfig != null) {
+ spec.configure(brooklynConfig);
}
+
+ List<?> explicitParams = (List<?>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
+ BasicSpecParameter.initializeSpecWithExplicitParameters(spec, BasicSpecParameter.parseParameterDefinitionList(explicitParams, null, loader), loader);
}
public static DeploymentPlan makePlanFromYaml(ManagementContext mgmt, String yaml) {
@@ -224,21 +221,22 @@ class CampInternalUtils {
String type,
Map<String, Object> brooklynConfig,
BrooklynClassLoadingContext loader) {
+ if (brooklynConfig==null) {
+ brooklynConfig = MutableMap.of();
+ }
Maybe<Class<? extends Location>> javaClass = loader.tryLoadClass(type, Location.class);
+ LocationSpec<?> spec;
if (javaClass.isPresent()) {
- LocationSpec<?> spec = LocationSpec.create(javaClass.get());
- if (brooklynConfig != null) {
- spec.configure(brooklynConfig);
- }
- return spec;
+ spec = LocationSpec.create(javaClass.get());
} else {
Maybe<LocationSpec<? extends Location>> loc = loader.getManagementContext().getLocationRegistry().getLocationSpec(type, brooklynConfig);
if (loc.isPresent()) {
- return loc.get().configure(brooklynConfig);
+ spec = loc.get();
} else {
throw new IllegalStateException("No class or resolver found for location type "+type);
}
}
+ return spec;
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
index 9814a33..89f282b 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
@@ -204,7 +204,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
}
@Test
- public void testInheritsParentConfig() throws Exception {
+ public void testInheritsRuntimeParentConfig() throws Exception {
String yaml = Joiner.on("\n").join(
"location: localhost-stub",
"services:",
@@ -232,7 +232,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
// Fixed Sept 2016, attributeWhenReady self-reference is now resolved against the entity defining the config value.
// Prior to this it was resolved against the caller's scope.
@Test
- public void testInheritsParentConfigTaskWithSelfScope() throws Exception {
+ public void testInheritsRuntimeParentConfigTaskWithSelfScope() throws Exception {
String yaml = Joiner.on("\n").join(
"services:",
"- type: org.apache.brooklyn.entity.stock.BasicApplication",
@@ -259,7 +259,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
}
@Test
- public void testInheritsParentConfigTask() throws Exception {
+ public void testInheritsRuntimeParentConfigTask() throws Exception {
String yaml = Joiner.on("\n").join(
"services:",
"- type: org.apache.brooklyn.entity.stock.BasicApplication",
@@ -287,7 +287,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
}
@Test
- public void testInheritsParentConfigOfTypeMapWithIndividualKeys() throws Exception {
+ public void testInheritsRuntimeParentConfigOfTypeMapWithIndividualKeys() throws Exception {
String yaml = Joiner.on("\n").join(
"services:",
"- type: org.apache.brooklyn.entity.stock.BasicApplication",
@@ -305,7 +305,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
}
@Test
- public void testInheritsParentConfigOfTypeMapWithOneBigVal() throws Exception {
+ public void testInheritsRuntimeParentConfigOfTypeMapWithOneBigVal() throws Exception {
String yaml = Joiner.on("\n").join(
"services:",
"- type: org.apache.brooklyn.entity.stock.BasicApplication",
@@ -324,7 +324,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
}
@Test
- public void testOverridesParentConfig() throws Exception {
+ public void testOverridesRuntimeParentConfig() throws Exception {
String yaml = Joiner.on("\n").join(
"location: localhost-stub",
"services:",
@@ -441,9 +441,9 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-never", null);
}
// Test override defaults
@@ -462,9 +462,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyValueEquals(entity, "map.type-never", null);
+ assertAnonymousKeyValueEquals(entity, "map.type-never", ImmutableMap.of("mykey2", "myval2"));
}
// Test retrieval of explicit config
@@ -477,9 +478,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("mykey", "myval"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("mykey", "myval"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyValueEquals(entity, "map.type-never", null);
+ assertAnonymousKeyValueEquals(entity, "map.type-never", ImmutableMap.of("mykey", "myval"));
}
// Test merging/overriding of explicit config
@@ -498,14 +500,15 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyValueEquals(entity, "map.type-never", null);
+ assertAnonymousKeyValueEquals(entity, "map.type-never", ImmutableMap.of("mykey2", "myval2"));
}
}
@Test
- public void testParentInheritanceOptions() throws Exception {
+ public void testEntityRuntimeInheritanceOptions() throws Exception {
addCatalogItems(
"brooklyn.catalog:",
" itemType: entity",
@@ -516,19 +519,19 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
" brooklyn.parameters:",
" - name: map.type-merged",
" type: java.util.Map",
- " inheritance.parent: deep_merge",
+ " inheritance.runtime: deep_merge",
" default: {myDefaultKey: myDefaultVal}",
" - name: map.type-overwrite",
" type: java.util.Map",
- " inheritance.parent: overwrite",
+ " inheritance.runtime: overwrite",
" default: {myDefaultKey: myDefaultVal}",
" - name: map.type-never",
" type: java.util.Map",
- " inheritance.parent: never",
+ " inheritance.runtime: never",
" default: {myDefaultKey: myDefaultVal}",
" - name: map.type-not-reinherited",
" type: java.util.Map",
- " inheritance.parent: not_reinherited",
+ " inheritance.runtime: not_reinherited",
" default: {myDefaultKey: myDefaultVal}");
// An entity with same key names as "entity-with-keys", but no default values.
@@ -542,16 +545,16 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
" brooklyn.parameters:",
" - name: map.type-merged",
" type: java.util.Map",
- " inheritance.parent: deep_merge",
+ " inheritance.runtime: deep_merge",
" - name: map.type-overwrite",
" type: java.util.Map",
- " inheritance.parent: overwrite",
+ " inheritance.runtime: overwrite",
" - name: map.type-never",
" type: java.util.Map",
- " inheritance.parent: never",
+ " inheritance.runtime: never",
" - name: map.type-not-reinherited",
" type: java.util.Map",
- " inheritance.parent: not_reinherited");
+ " inheritance.runtime: not_reinherited");
// Test retrieval of defaults
{
@@ -564,10 +567,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(entity, "map.type-not-reinherited", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-never", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-not-reinherited", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
}
// Test override defaults in parent entity
@@ -590,10 +593,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("mykey", "myval"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("mykey", "myval"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(entity, "map.type-not-reinherited", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-never", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-not-reinherited", ImmutableMap.of("mykey", "myval"));
}
// Test merging/overriding of explicit config
@@ -625,10 +628,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
Entity app = createStartWaitAndLogApplication(yaml);
TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
- assertConfigEquals(entity, "map.type-merged", ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-overwrite", ImmutableMap.of("mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-never", ImmutableMap.of("mykey2", "myval2"));
- assertConfigEquals(entity, "map.type-not-reinherited", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-merged", ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-overwrite", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-never", ImmutableMap.of("mykey2", "myval2"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(entity, "map.type-not-reinherited", ImmutableMap.of("mykey2", "myval2"));
}
// Test inheritance by child that does not explicitly declare those keys itself
@@ -684,10 +687,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
// Note this merges the default values from the parent and child (i.e. the child's default
// value does not override the parent's.
- assertConfigEquals(child, "map.type-merged", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(child, "map.type-overwrite", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
- assertConfigEquals(child, "map.type-never", null);
- assertConfigEquals(child, "map.type-not-reinherited", null);
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-merged", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-overwrite", ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-never", null);
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-not-reinherited", null);
}
// Test inheritance by child with duplicated keys that have no defaults - does it get runtime-management parent's explicit vals?
@@ -712,10 +715,10 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
TestEntity child = (TestEntity) Iterables.getOnlyElement(entity.getChildren());
- assertConfigEquals(child, "map.type-merged", ImmutableMap.of("mykey", "myval"));
- assertConfigEquals(child, "map.type-overwrite", ImmutableMap.of("mykey", "myval"));
- assertConfigEquals(child, "map.type-never", null);
- assertConfigEquals(child, "map.type-not-reinherited", null);
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-merged", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-overwrite", ImmutableMap.of("mykey", "myval"));
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-never", null);
+ assertDeclaredKeyAndAnonymousKeyValuesEqual(child, "map.type-not-reinherited", null);
}
}
@@ -883,9 +886,8 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
ImmutableMap.of("mykey1", "myval1", "mykey2", "myval2", "mykey3", "myval3"));
}
- // Fixed Sept 2016, inheritance is now computed with respect to defined keys and propagated upwards when traversing ancestors
@Test
- public void testExtendsParentMultipleLevels() throws Exception {
+ public void testExtendsRuntimeParentMultipleLevels() throws Exception {
addCatalogItems(
"brooklyn.catalog:",
" itemType: entity",
@@ -896,7 +898,7 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
" brooklyn.parameters:",
" - name: map.type-merged",
" type: java.util.Map",
- " inheritance.parent: deep_merge");
+ " inheritance.runtime: deep_merge");
String yaml = Joiner.on("\n").join(
"location: localhost-stub",
@@ -925,13 +927,13 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
// See https://issues.apache.org/jira/browse/BROOKLYN-377
@Test(invocationCount=20, groups="Integration")
- public void testConfigOnParentUsesConfigKeyDeclaredOnParentManyTimes() throws Exception {
- testConfigOnParentUsesConfigKeyDeclaredOnParent();
+ public void testConfigOnRuntimeParentUsesConfigKeyDeclaredOnParentManyTimes() throws Exception {
+ testConfigOnRuntimeParentUsesConfigKeyDeclaredOnParent();
}
// See https://issues.apache.org/jira/browse/BROOKLYN-377
@Test
- public void testConfigOnParentUsesConfigKeyDeclaredOnParent() throws Exception {
+ public void testConfigOnRuntimeParentUsesConfigKeyDeclaredOnParent() throws Exception {
addCatalogItems(
"brooklyn.catalog:",
" version: 1.0.0",
@@ -1000,10 +1002,19 @@ public class ConfigInheritanceYamlTest extends AbstractYamlTest {
* <li>Construct a new untyped key (see {@link ConfigKeys#newConfigKey(Class, String)})
* </ul>
*/
- private void assertConfigEquals(Entity entity, String keyName, Object expected) {
+ private void assertDeclaredKeyAndAnonymousKeyValuesEqual(Entity entity, String keyName, Object expected) {
+ assertDeclaredKeyValueEquals(entity, keyName, expected);
+ assertAnonymousKeyValueEquals(entity, keyName, expected);
+ }
+
+ private void assertDeclaredKeyValueEquals(Entity entity, String keyName, Object expected) {
ConfigKey<?> key1 = entity.getEntityType().getConfigKey(keyName);
- ConfigKey<?> key2 = ConfigKeys.newConfigKey(Object.class, keyName);
assertEquals(entity.config().get(key1), expected, "key="+keyName);
+ }
+
+ private void assertAnonymousKeyValueEquals(Entity entity, String keyName, Object expected) {
+ ConfigKey<?> key2 = ConfigKeys.newConfigKey(Object.class, keyName);
assertEquals(entity.config().get(key2), expected, "key="+keyName);
}
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index 7e162b5..d6f7fc8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -606,7 +606,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
version = setFromItemIfUnset(version, itemAsMap, "version");
version = setFromItemIfUnset(version, itemAsMap, "template_version");
if (version==null) {
- log.warn("No version specified for catalog item " + symbolicName + ". Using default value.");
+ log.debug("No version specified for catalog item " + symbolicName + ". Using default value.");
version = null;
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
index f6a13f1..2d92617 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
@@ -332,6 +332,12 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
}
protected <T> ReferenceWithError<ConfigValueAtContainer<TContainer,T>> getConfigImpl(final ConfigKey<T> queryKey, final boolean raw) {
+ if (queryKey==null) {
+ return ReferenceWithError.newInstanceThrowingError(new BasicConfigValueAtContainer<TContainer,T>(getContainer(), null, null, false,
+ null),
+ new NullPointerException("Query key cannot be null"));
+ }
+
// In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key
Function<TContainer, ConfigKey<T>> keyFn = new Function<TContainer, ConfigKey<T>>() {
@Override public ConfigKey<T> apply(TContainer input) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java b/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
index 5529cef..fc8f78d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
@@ -101,6 +101,7 @@ public class EntityConfigMap extends AbstractConfigMapImpl<Entity> {
@Override
protected <T> ConfigKey<?> getKeyAtContainerImpl(Entity container, ConfigKey<T> queryKey) {
+ if (queryKey==null) return null;
return container.getEntityType().getConfigKey(queryKey.getName());
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
index eb5d052..1adf30d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
@@ -156,12 +156,14 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
}
// Not CAMP specific since it's used to get the parameters from catalog items meta which are syntax independent.
- public static List<SpecParameter<?>> fromConfigList(List<?> obj, Function<Object, Object> specialFlagsTransformer, BrooklynClassLoadingContext loader) {
+ /** Returns a list of {@link SpecParameterIncludingDefinitionForInheritance} objects from the given list;
+ * these should be resolved against ancestors before using, converting that object to {@link BasicSpecParameter} instances. */
+ public static List<SpecParameter<?>> parseParameterDefinitionList(List<?> obj, Function<Object, Object> specialFlagsTransformer, BrooklynClassLoadingContext loader) {
return ParseYamlInputs.parseParameters(obj, specialFlagsTransformer, loader);
}
public static List<SpecParameter<?>> fromClass(ManagementContext mgmt, Class<?> type) {
- return ParseClassParameters.parseParameters(getImplementedBy(mgmt, type));
+ return ParseClassParameters.collectParameters(getImplementedBy(mgmt, type));
}
public static List<SpecParameter<?>> fromSpec(ManagementContext mgmt, AbstractBrooklynObjectSpec<?, ?> spec) {
@@ -178,7 +180,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
if (type == null) {
type = getImplementedBy(mgmt, spec.getType());
}
- return ParseClassParameters.parseParameters(getImplementedBy(mgmt, type));
+ return ParseClassParameters.collectParameters(getImplementedBy(mgmt, type));
}
private static Class<?> getImplementedBy(ManagementContext mgmt, Class<?> type) {
@@ -227,7 +229,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- private static SpecParameterForInheritance<?> parseParameter(Object obj, Function<Object, Object> specialFlagTransformer, BrooklynClassLoadingContext loader) {
+ private static SpecParameterIncludingDefinitionForInheritance<?> parseParameter(Object obj, Function<Object, Object> specialFlagTransformer, BrooklynClassLoadingContext loader) {
Map inputDef;
if (obj instanceof String) {
inputDef = ImmutableMap.of("name", obj);
@@ -291,7 +293,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
configType = builder.build();
}
- return new SpecParameterForInheritance(label, pinned, configType, sensorType,
+ return new SpecParameterIncludingDefinitionForInheritance(label, pinned, configType, sensorType,
hasType, hasDefaultValue, hasConstraints, hasRuntimeInheritance, hasTypeInheritance);
}
@@ -385,7 +387,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
}
}
- public static List<SpecParameter<?>> parseParameters(Class<?> c) {
+ static List<SpecParameter<?>> collectParameters(Class<?> c) {
MutableList<WeightedParameter> parameters = MutableList.<WeightedParameter>of();
if (BrooklynObject.class.isAssignableFrom(c)) {
@SuppressWarnings("unchecked")
@@ -432,20 +434,25 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
*
* @see EntitySpec#parameters(List)
*/
- public static void addParameters(AbstractBrooklynObjectSpec<?, ?> spec, List<? extends SpecParameter<?>> explicitParams, BrooklynClassLoadingContext loader) {
+ @Beta
+ public static void initializeSpecWithExplicitParameters(AbstractBrooklynObjectSpec<?, ?> spec, List<? extends SpecParameter<?>> explicitParams, BrooklynClassLoadingContext loader) {
+ // spec params list is empty if created from java (or there are none); non-empty if created from a parent entity spec
+ // so if empty, we may need to populate (or it is no op), and if non-empty, we can skip
if (spec.getParameters().isEmpty()) {
spec.parametersAdd(BasicSpecParameter.fromSpec(loader.getManagementContext(), spec));
}
- if (explicitParams.size() > 0) {
- spec.parametersReplace(resolveParameters(explicitParams, spec.getParameters(), spec));
- }
+
+ // but now we need to filter non-reinheritable, and merge where params are extended/overridden
+ spec.parametersReplace(resolveParameters(explicitParams, 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) {
+ private static Collection<SpecParameter<?>> resolveParameters(Collection<? extends SpecParameter<?>> newParams, AbstractBrooklynObjectSpec<?,?> spec) {
+ Collection<? extends SpecParameter<?>> existingReferenceParams = spec.getParameters();
+
Map<String,SpecParameter<?>> existingToKeep = MutableMap.of();
- if (existingReferenceParamsToKeep!=null) {
- for (SpecParameter<?> p: existingReferenceParamsToKeep) {
+ if (existingReferenceParams!=null) {
+ for (SpecParameter<?> p: existingReferenceParams) {
if (ConfigInheritances.isKeyReinheritable(p.getConfigKey(), InheritanceContext.TYPE_DEFINITION)) {
existingToKeep.put(p.getConfigKey().getName(), p);
}
@@ -454,21 +461,19 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
List<SpecParameter<?>> result = MutableList.<SpecParameter<?>>of();
- for (SpecParameter<?> p: newParams) {
- final SpecParameter<?> existingP = existingToKeep.remove(p.getConfigKey().getName());
- if (p instanceof SpecParameterForInheritance) {
- if (existingP!=null) {
- p = ((SpecParameterForInheritance<?>)p).resolveWithAncestor(existingP);
+ if (newParams!=null) {
+ for (SpecParameter<?> p: newParams) {
+ final SpecParameter<?> existingP = existingToKeep.remove(p.getConfigKey().getName());
+ if (p instanceof SpecParameterIncludingDefinitionForInheritance) {
+ // config keys should be transformed to parameters and so should be found;
+ // so the code below is correct whether existingP is set or is null
+ p = ((SpecParameterIncludingDefinitionForInheritance<?>)p).resolveWithAncestor(existingP);
} else {
- ConfigKey<?> configKeyExtendedByThisParameter = null;
- // TODO find any matching config key declared on the type
- /* 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;
- * none of the fields from the config key in java will be inherited */
- p = ((SpecParameterForInheritance<?>)p).resolveWithAncestor(configKeyExtendedByThisParameter);
+ // shouldn't happen; all calling logic should get SpecParameterForInheritance;
+ log.warn("Found non-definitional spec parameter: "+p+" adding to "+spec);
}
+ result.add(p);
}
- result.add(p);
}
result.addAll(existingToKeep.values());
@@ -479,11 +484,11 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
* for use with a subsequent merge with ancestor config keys; see {@link #resolveParameters(Collection, Collection, AbstractBrooklynObjectSpec)}*/
@SuppressWarnings("serial")
@Beta
- static class SpecParameterForInheritance<T> extends BasicSpecParameter<T> {
+ static class SpecParameterIncludingDefinitionForInheritance<T> extends BasicSpecParameter<T> {
private final boolean hasType, hasLabelSet, hasPinnedSet, hasDefaultValue, hasConstraints, hasRuntimeInheritance, hasTypeInheritance;
- private <SensorType> SpecParameterForInheritance(String label, Boolean pinned, ConfigKey<T> config, AttributeSensor<SensorType> sensor,
+ private <SensorType> SpecParameterIncludingDefinitionForInheritance(String label, Boolean pinned, ConfigKey<T> config, AttributeSensor<SensorType> sensor,
boolean hasType, boolean hasDefaultValue, boolean hasConstraints, boolean hasRuntimeInheritance, boolean hasTypeInheritance) {
super(Preconditions.checkNotNull(label!=null ? label : config.getName(), "label or config name must be set"),
pinned==null ? true : pinned, config, sensor);
@@ -507,32 +512,6 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
hasType ? getSensor() : ancestor.getSensor());
}
- /** as {@link #resolveWithAncestor(SpecParameter)} but where the param redefines/extends a config key coming from a java supertype, rather than a parameter */
- // TODO not used yet; see calls to the other resolveWithAncestor method,
- // and see BrooklynComponentTemplateResolver.findAllConfigKeys;
- // also note whilst it is easiest to do this here, logically it is messy,
- // and arguably it should be done when converting the spec to an instance
- SpecParameter<?> resolveWithAncestor(ConfigKey<?> ancestor) {
- if (ancestor==null) return new BasicSpecParameter<>(getLabel(), isPinned(), getConfigKey(), getSensor());
-
- // TODO probably want to do this (but it could get expensive! - limited caching could help)
- // Set<Class<?>> types = MutableSet.<Class<?>>builder()
- // .add(spec.getImplementation())
- // .add(spec.getType())
- // .addAll(spec.getAdditionalInterfaces())
- // .remove(null)
- // .build();
- // // order above is important, respected below to take the first one defined
- // MutableMap<String, ConfigKey<?>> result = MutableMap.copyOf(FlagUtils.findAllConfigKeys(null, types));
-
- return new BasicSpecParameter<>(
- getLabel(),
- isPinned(),
- resolveWithAncestorConfigKey(ancestor),
- // TODO port sensor will be lost (see messy code above which sets the port sensor)
- getSensor());
- }
-
@SuppressWarnings({ "unchecked", "rawtypes" })
private ConfigKey<?> resolveWithAncestorConfigKey(ConfigKey<?> ancestor) {
ConfigKey<?> dominant = getConfigKey();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d4c59c/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java b/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
index dd893d9..887e054 100644
--- a/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
@@ -45,7 +45,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
@Test
public void testInlineName() {
String name = "minRam";
- SpecParameter<?> input = parse(name);
+ SpecParameter<?> input = parseSpecParameterDefinition(name);
assertEquals(input.getLabel(), name);
assertTrue(input.isPinned());
ConfigKey<?> type = input.getConfigKey();
@@ -53,14 +53,14 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
assertEquals(type.getTypeToken(), TypeToken.of(String.class));
assertNull(type.getDefaultValue());
assertNull(type.getDescription());
- assertNull(type.getInheritance());
+ assertTrue(type.getInheritanceByContext().values().isEmpty(), "Unexpected inheritance: "+type.getInheritanceByContext());
assertConstraint(type.getConstraint(), Predicates.alwaysTrue());
}
@Test
public void testOnlyName() {
String name = "minRam";
- SpecParameter<?> input = parse(ImmutableMap.of("name", name));
+ SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of("name", name));
assertEquals(input.getLabel(), name);
assertEquals(input.getConfigKey().getName(), name);
assertEquals(input.getConfigKey().getTypeToken(), TypeToken.of(String.class));
@@ -68,7 +68,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
@Test
public void testUnusualName() {
- parse(ImmutableMap.of("name", "name with spaces"));
+ parseSpecParameterDefinition(ImmutableMap.of("name", "name with spaces"));
}
@Test
@@ -80,7 +80,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
String defaultValue = "VALUE";
Boolean pinned = false;
String constraint = "required";
- SpecParameter<?> input = parse(ImmutableMap.builder()
+ SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.builder()
.put("name", name)
.put("label", label)
.put("description", description)
@@ -98,7 +98,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
assertEquals(type.getTypeToken(), TypeToken.of(String.class));
assertEquals(type.getDefaultValue(), defaultValue);
assertEquals(type.getDescription(), description);
- assertNull(type.getInheritance());
+ assertTrue(type.getInheritanceByContext().values().isEmpty(), "Unexpected inheritance: "+type.getInheritanceByContext());
assertConstraint(type.getConstraint(), StringPredicates.isNonBlank());
}
@@ -108,7 +108,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
String label = "1234";
String description = "5678.56";
String defaultValue = "444.12";
- SpecParameter<?> input = parse(ImmutableMap.of(
+ SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of(
"name", name,
"label", label,
"description", description,
@@ -121,14 +121,14 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
assertEquals(type.getName(), name);
assertEquals(type.getDefaultValue(), defaultValue);
assertEquals(type.getDescription(), description);
- assertNull(type.getInheritance());
+ assertTrue(type.getInheritanceByContext().values().isEmpty(), "Unexpected inheritance: "+type.getInheritanceByContext());
}
@Test
public void testConstraintAsArray() {
String name = "minRam";
String constraint = "required";
- SpecParameter<?> input = parse(ImmutableMap.of(
+ SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of(
"name", name,
"constraints", ImmutableList.of(constraint)));
ConfigKey<?> type = input.getConfigKey();
@@ -137,14 +137,14 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMissingName() {
- parse(ImmutableMap.of(
+ parseSpecParameterDefinition(ImmutableMap.of(
"type", "string"));
}
@Test
public void testJavaType() {
String name = "minRam";
- SpecParameter<?> input = parse(ImmutableMap.of(
+ SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of(
"name", name,
"type", BasicSpecParameterFromListTest.class.getName()));
assertEquals(input.getConfigKey().getTypeToken(), TypeToken.of(BasicSpecParameterFromListTest.class));
@@ -153,7 +153,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInvalidType() {
String name = "minRam";
- parse(ImmutableMap.of(
+ parseSpecParameterDefinition(ImmutableMap.of(
"name", name,
"type", "missing_type"));
}
@@ -161,7 +161,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInvalidConstraint() {
String name = "minRam";
- parse(ImmutableMap.of(
+ parseSpecParameterDefinition(ImmutableMap.of(
"name", name,
"type", "missing_type"));
}
@@ -171,7 +171,7 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
String name = "pinned";
String label = "Is pinned";
String description = "Is pinned description";
- SpecParameter<?> input = parse(ImmutableMap.of(
+ SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of(
"name", name,
"label", label,
"description", description));
@@ -179,9 +179,9 @@ public class BasicSpecParameterFromListTest extends BrooklynMgmtUnitTestSupport
assertTrue(input.isPinned());
}
- private SpecParameter<?> parse(Object def) {
+ private SpecParameter<?> parseSpecParameterDefinition(Object def) {
BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
- List<SpecParameter<?>> inputs = BasicSpecParameter.fromConfigList(ImmutableList.of(def), null, loader);
+ List<SpecParameter<?>> inputs = BasicSpecParameter.parseParameterDefinitionList(ImmutableList.of(def), null, loader);
return Iterables.getOnlyElement(inputs);
}