You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2017/07/13 10:01:20 UTC
[1/6] brooklyn-server git commit: Add
LogWatcher.EventPredicates.containsMessages
Repository: brooklyn-server
Updated Branches:
refs/heads/master 1dfde7a4b -> 0e35b6151
Add LogWatcher.EventPredicates.containsMessages
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/93b7e188
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/93b7e188
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/93b7e188
Branch: refs/heads/master
Commit: 93b7e188fc391e00436459282b4d4595fe9b96b5
Parents: b97942d
Author: Aled Sage <al...@gmail.com>
Authored: Thu Jun 8 14:59:04 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Jun 16 13:01:51 2017 +0100
----------------------------------------------------------------------
.../main/java/org/apache/brooklyn/test/LogWatcher.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/93b7e188/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java b/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java
index e72383e..c35aadc 100644
--- a/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java
+++ b/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java
@@ -62,15 +62,22 @@ public class LogWatcher implements Closeable {
public static class EventPredicates {
public static Predicate<ILoggingEvent> containsMessage(final String expected) {
+ return containsMessages(expected);
+ }
+
+ public static Predicate<ILoggingEvent> containsMessages(final String... expecteds) {
return new Predicate<ILoggingEvent>() {
@Override public boolean apply(ILoggingEvent input) {
if (input == null) return false;
String msg = input.getFormattedMessage();
- return (msg != null) && msg.contains(expected);
+ if (msg == null) return false;
+ for (String expected : expecteds) {
+ if (!msg.contains(expected)) return false;
+ }
+ return true;
}
};
}
-
public static Predicate<ILoggingEvent> containsExceptionStackLine(final Class<?> clazz, final String methodName) {
return new Predicate<ILoggingEvent>() {
@Override public boolean apply(ILoggingEvent input) {
[5/6] brooklyn-server git commit: ServerPoolLocation.OWNER: fix naming
Posted by ge...@apache.org.
ServerPoolLocation.OWNER: fix naming
It overrides the DynamicLocation.OWNER, but previously had a different
name, with the same SetFromFlag.
Changed it to use the same name as the super-type (i.e. “owner”), with a deprecatedName of “pool.location.owner”.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/80c9a9a2
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/80c9a9a2
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/80c9a9a2
Branch: refs/heads/master
Commit: 80c9a9a2a0d851d5d406d23c030c32fe71e152ae
Parents: afa787c
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jun 28 22:02:12 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Jun 28 22:08:52 2017 +0100
----------------------------------------------------------------------
.../brooklyn/entity/machine/pool/ServerPoolLocation.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/80c9a9a2/software/base/src/main/java/org/apache/brooklyn/entity/machine/pool/ServerPoolLocation.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/machine/pool/ServerPoolLocation.java b/software/base/src/main/java/org/apache/brooklyn/entity/machine/pool/ServerPoolLocation.java
index 3bb985a..4e4538c 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/machine/pool/ServerPoolLocation.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/machine/pool/ServerPoolLocation.java
@@ -44,9 +44,9 @@ public class ServerPoolLocation extends AbstractLocation implements MachineProvi
private static final Logger LOG = LoggerFactory.getLogger(ServerPoolLocation.class);
- @SetFromFlag("owner")
- public static final ConfigKey<ServerPool> OWNER = ConfigKeys.newConfigKey(
- ServerPool.class, "pool.location.owner");
+ public static final ConfigKey<ServerPool> OWNER = ConfigKeys.builder(ServerPool.class, "owner")
+ .deprecatedNames("pool.location.owner")
+ .build();
@SetFromFlag("locationName")
public static final ConfigKey<String> LOCATION_NAME = ConfigKeys.newStringConfigKey("pool.location.name");
@@ -56,8 +56,8 @@ public class ServerPoolLocation extends AbstractLocation implements MachineProvi
@Override
public void init() {
- LOG.debug("Initialising. Owner is: {}", checkNotNull(getConfig(OWNER), OWNER.getName()));
super.init();
+ LOG.debug("Initialising. Owner is: {}", checkNotNull(getConfig(OWNER), OWNER.getName()));
}
@Override
[4/6] brooklyn-server git commit: PR #734: address comments for
configKey.deprecatedNames
Posted by ge...@apache.org.
PR #734: address comments for configKey.deprecatedNames
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/afa787c4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/afa787c4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/afa787c4
Branch: refs/heads/master
Commit: afa787c45f153352feb1ddd5c7347f811f172dad
Parents: 02b71ff
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jun 28 17:33:00 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Jun 28 22:08:52 2017 +0100
----------------------------------------------------------------------
.../brooklyn/core/entity/AbstractEntity.java | 3 +
.../core/location/AbstractLocation.java | 15 +-
.../core/objs/AbstractEntityAdjunct.java | 16 +-
.../brooklyn/util/core/config/ConfigBag.java | 6 +-
.../config/ConfigKeyDeprecationRebindTest.java | 12 ++
.../core/config/ConfigKeyDeprecationTest.java | 6 +-
.../core/enricher/BasicEnricherTest.java | 2 +-
.../core/enricher/EnricherConfigTest.java | 6 +-
.../core/entity/LocationSetFromFlagTest.java | 211 +++++++++++++++++++
.../core/policy/basic/BasicPolicyTest.java | 2 +-
.../core/policy/basic/PolicyConfigTest.java | 6 +-
.../util/core/config/ConfigBagTest.java | 82 ++++++-
12 files changed, 330 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index d0d3873..08b6591 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -396,6 +396,9 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
}
// allow config keys to be set by name (or deprecated name)
+ //
+ // The resulting `flags` will no longer contain the keys that we matched;
+ // we will not also use them to for `SetFromFlag` etc.
flags = ConfigUtilsInternal.setAllConfigKeys(flags, getEntityType().getConfigKeys(), this);
// allow config keys, and fields, to be set from these flags if they have a SetFromFlag annotation
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
index 58b2809..32b01fa 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
@@ -216,17 +216,14 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
config().removeKey(PARENT_LOCATION);
}
- // allow config keys to be set by name (or deprecated name)
+ // Allow config keys to be set by name (or deprecated name)
//
- // Aled thinks it would be sensible to remove the consumed flags below (i.e. properties = ...).
- // However, that caused ClockerDynamicLocationPatternTest to fail because there is a field of
- // StubContainerLocation annotated with `@SetFromFlag("owner")`, as well as a config key with
- // name "owner" (and with `@SetFromFlag("owner")`) in the super-type (DynamicLocation).
- // However, that looks mad - do we really need to support it?!
- // I've preserved that behaviour (for now).
- ConfigUtilsInternal.setAllConfigKeys(properties, getLocationTypeInternal().getConfigKeys().values(), this);
+ // The resulting `properties` will no longer contain the keys that we matched;
+ // we will not also use them to for `SetFromFlag` etc.
+ properties = ConfigUtilsInternal.setAllConfigKeys(properties, getLocationTypeInternal().getConfigKeys().values(), this);
// NB: flag-setting done here must also be done in BasicLocationRebindSupport
+ // Must call setFieldsFromFlagsWithBag, even if properites is empty, so defaults are extracted from annotations
ConfigBag configBag = ConfigBag.newInstance(properties);
FlagUtils.setFieldsFromFlagsWithBag(this, properties, configBag, firstTime);
FlagUtils.setAllConfigKeys(this, configBag, false);
@@ -252,7 +249,7 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
} else {
codes = TypeCoercions.coerce(rawCodes, new TypeToken<Set<String>>() {});
}
- configBag.put(LocationConfigKeys.ISO_3166, codes);
+ config().set(LocationConfigKeys.ISO_3166, codes);
}
return this;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index 7395d0a..3faf2a6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -153,19 +153,13 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject imple
}
}
- // Allow config keys to be set by name (or deprecated name).
+ // Allow config keys to be set by name (or deprecated name)
//
- // Aled thinks it would be sensible to remove the consumed flags below (i.e. flags = ...).
- // However, that causes PolicyConfigTest.testConfigFlagsPassedInAtConstructionIsAvailable to fail.
- // However, tht looks mad - do we really need to support it?!
- // The policy is defined with one key using a name in SetFromFlag, and another key using the same name.
- // It expects both of the config keys to have been set.
- // @SetFromFlag("strKey")
- // public static final ConfigKey<String> STR_KEY = new BasicConfigKey<String>(String.class, "akey", "a key");
- // public static final ConfigKey<String> STR_KEY_WITH_DEFAULT = new BasicConfigKey<String>(String.class, "strKey", "str key", "str key default");
- // I've preserved that behaviour (for now).
- ConfigUtilsInternal.setAllConfigKeys(flags, getAdjunctType().getConfigKeys(), this);
+ // The resulting `flags` will no longer contain the keys that we matched;
+ // we will not also use them to for `SetFromFlag` etc.
+ flags = ConfigUtilsInternal.setAllConfigKeys(flags, getAdjunctType().getConfigKeys(), this);
+ // Must call setFieldsFromFlagsWithBag, even if properites is empty, so defaults are extracted from annotations
ConfigBag bag = new ConfigBag().putAll(flags);
FlagUtils.setFieldsFromFlags(this, bag, isFirstTime);
FlagUtils.setAllConfigKeys(this, bag, false);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java b/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
index cfef3b0..9f9bf09 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
@@ -435,6 +435,7 @@ public class ConfigBag {
*
* @deprecated since 0.12.0; instead define deprecated names on key, see {@link ConfigKey#getDeprecatedNames()}
*/
+ @Deprecated
public Object getWithDeprecation(ConfigKey<?> key, ConfigKey<?> ...deprecatedKeys) {
return getWithDeprecation(new ConfigKey[] { key }, deprecatedKeys);
}
@@ -446,6 +447,7 @@ public class ConfigBag {
*
* @deprecated since 0.12.0; instead define deprecated names on key, see {@link ConfigKey#getDeprecatedNames()}
*/
+ @Deprecated
public synchronized Object getWithDeprecation(ConfigKey<?>[] currentKeysInOrderOfPreference, ConfigKey<?> ...deprecatedKeys) {
// Get preferred key (or null)
ConfigKey<?> preferredKeyProvidingValue = null;
@@ -541,7 +543,7 @@ public class ConfigBag {
log.warn("Duplicate value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ "using same value from preferred name "+key.getName());
}
- } else if (firstDeprecatedVal.isPresent()) {
+ } else if (firstDeprecatedVal != null && firstDeprecatedVal.isPresent()) {
if (!Objects.equal(firstDeprecatedVal.get(), deprecatedVal.get())) {
log.warn("Conflicting value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ "using earlier deprecated name "+firstDeprecatedName);
@@ -590,7 +592,7 @@ public class ConfigBag {
log.warn("Duplicate value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ "using same value from preferred name "+key.getName());
}
- } else if (firstDeprecatedVal != null) {
+ } else if (firstDeprecatedVal != null && firstDeprecatedVal.isPresent()) {
if (!Objects.equal(firstDeprecatedVal.get(), deprecatedVal.get())) {
log.warn("Conflicting value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ "using earlier deprecated name "+firstDeprecatedName);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
index b20f574..f25f544 100644
--- a/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
@@ -100,6 +100,18 @@ public class ConfigKeyDeprecationRebindTest extends AbstractRebindHistoricTest {
* .configure("oldFlagKey2", "myval"));
* }
* </pre>
+ *
+ * Note that (with Brooklyn 0.11.0) the above code wrote the persisted state as "key2".
+ * That is, it switched the name used at configure-time for the actual key name, so that
+ * is what is in persisted state.
+ *
+ * Therefore this test is a bit pointless! The persisted state does not contain the word
+ * "oldFlagKey2" so of course it won't contain that word after rebind.
+ *
+ * The purpose of the test is to illustrate that we thought about and tested the code
+ * path of someone having used the alias in an old Brooklyn version, and now is upgrading
+ * to a version where the alias annotation has been replaced by
+ * {@code .deprecatedNames("oldFlagKey2")}.
*/
@Test
public void testEntityPersistedWithSetFromFlagNameOnKey() throws Exception {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
index 7ab57cd..b85ad58 100644
--- a/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
@@ -80,8 +80,8 @@ public class ConfigKeyDeprecationTest extends BrooklynAppUnitTestSupport {
@Test
public void testPrefersFirstDeprecatedNameIfMultiple() throws Exception {
EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class)
- .configure("oldSuperKey1", "myval1")
- .configure("oldSuperKey1b", "myval2"));
+ .configure("oldSuperKey1b", "myval2")
+ .configure("oldSuperKey1", "myval1"));
assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval1");
}
@@ -180,7 +180,7 @@ public class ConfigKeyDeprecationTest extends BrooklynAppUnitTestSupport {
// Contrast this with EntityDynamicType.addSensorIfAbsent().
//
* However, it's (probably) not straight forward to just add and call a addConfigKeyIfAbsent. This
- * is because config().set() is used for dynamic config declard in yaml, which the entity doesn't
+ * is because config().set() is used for dynamic config declared in yaml, which the entity doesn't
* understand but that will be inherited by runtime children.
*/
@Test(groups="Broken")
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/enricher/BasicEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/enricher/BasicEnricherTest.java b/core/src/test/java/org/apache/brooklyn/core/enricher/BasicEnricherTest.java
index 98ab41c..5e47da3 100644
--- a/core/src/test/java/org/apache/brooklyn/core/enricher/BasicEnricherTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/enricher/BasicEnricherTest.java
@@ -62,7 +62,7 @@ public class BasicEnricherTest extends BrooklynAppUnitTestSupport {
@SetFromFlag("strKey")
public static final ConfigKey<String> STR_KEY = new BasicConfigKey<String>(String.class, "akey", "a key");
public static final ConfigKey<Integer> INT_KEY_WITH_DEFAULT = new BasicConfigKey<Integer>(Integer.class, "ckey", "c key", 1);
- public static final ConfigKey<String> STR_KEY_WITH_DEFAULT = new BasicConfigKey<String>(String.class, "strKey", "str key", "str key default");
+ public static final ConfigKey<String> STR_KEY_WITH_DEFAULT = new BasicConfigKey<String>(String.class, "strKeyWithDefault", "str key", "strKeyDefaultVal");
MyEnricher(Map<?,?> flags) {
super(flags);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/enricher/EnricherConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/enricher/EnricherConfigTest.java b/core/src/test/java/org/apache/brooklyn/core/enricher/EnricherConfigTest.java
index aae382c..7dcd50c 100644
--- a/core/src/test/java/org/apache/brooklyn/core/enricher/EnricherConfigTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/enricher/EnricherConfigTest.java
@@ -48,8 +48,7 @@ public class EnricherConfigTest extends BrooklynAppUnitTestSupport {
assertEquals(enricher.getConfig(MyEnricher.STR_KEY), "aval");
assertEquals(enricher.getConfig(MyEnricher.INT_KEY), (Integer)2);
- // this is set, because key name matches annotation on STR_KEY
- assertEquals(enricher.getConfig(MyEnricher.STR_KEY_WITH_DEFAULT), "aval");
+ assertEquals(enricher.getConfig(MyEnricher.STR_KEY_WITH_DEFAULT), MyEnricher.STR_KEY_WITH_DEFAULT.getDefaultValue());
}
@Test
@@ -74,7 +73,6 @@ public class EnricherConfigTest extends BrooklynAppUnitTestSupport {
assertEquals(enricher.getConfig(MyEnricher.STR_KEY), "aval");
assertEquals(enricher.getConfig(MyEnricher.INT_KEY), (Integer)2);
- // this is not set (contrast with above)
assertEquals(enricher.getConfig(MyEnricher.STR_KEY_WITH_DEFAULT), MyEnricher.STR_KEY_WITH_DEFAULT.getDefaultValue());
}
@@ -141,7 +139,7 @@ public class EnricherConfigTest extends BrooklynAppUnitTestSupport {
public void testConfigReturnsDefaultValueIfNotSet() throws Exception {
MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class));
- assertEquals(enricher.getConfig(MyEnricher.STR_KEY_WITH_DEFAULT), "str key default");
+ assertEquals(enricher.getConfig(MyEnricher.STR_KEY_WITH_DEFAULT), MyEnricher.STR_KEY_WITH_DEFAULT.getDefaultValue());
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/entity/LocationSetFromFlagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/LocationSetFromFlagTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/LocationSetFromFlagTest.java
new file mode 100644
index 0000000..30f35c3
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/LocationSetFromFlagTest.java
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.entity;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+
+import org.apache.brooklyn.api.location.PortRange;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.location.PortRanges;
+import org.apache.brooklyn.core.location.AbstractLocation;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.flags.SetFromFlag;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class LocationSetFromFlagTest extends BrooklynAppUnitTestSupport {
+
+ @Test
+ public void testSetFromFlagUsingFieldName() {
+ MyLocation loc = newLocation(MutableMap.of("str1", "myval"));
+ assertEquals(loc.str1, "myval");
+ }
+
+ @Test
+ public void testSetFromFlagUsingOverridenName() {
+ MyLocation loc = newLocation(MutableMap.of("altStr2", "myval"));
+ assertEquals(loc.str2, "myval");
+ }
+
+ @Test
+ public void testSetFromFlagWhenNoDefaultIsNull() {
+ MyLocation loc = newLocation();
+ assertEquals(loc.str1, null);
+ }
+
+ @Test
+ public void testSetFromFlagUsesDefault() {
+ MyLocation loc = newLocation();
+ assertEquals(loc.str3, "default str3");
+ }
+
+ @Test
+ public void testSetFromFlagOverridingDefault() {
+ MyLocation loc = newLocation(MutableMap.of("str3", "overridden str3"));
+ assertEquals(loc.str3, "overridden str3");
+ }
+
+ @Test
+ public void testSetFromFlagCastsPrimitives() {
+ MyLocation loc = newLocation(MutableMap.of("double1", 1f));
+ assertEquals(loc.double1, 1d);
+ }
+
+ @Test
+ public void testSetFromFlagCastsDefault() {
+ MyLocation loc = newLocation();
+ assertEquals(loc.byte1, (byte)1);
+ assertEquals(loc.short1, (short)2);
+ assertEquals(loc.int1, 3);
+ assertEquals(loc.long1, 4l);
+ assertEquals(loc.float1, 5f);
+ assertEquals(loc.double1, 6d);
+ assertEquals(loc.char1, 'a');
+ assertEquals(loc.bool1, true);
+
+ assertEquals(loc.byte2, Byte.valueOf((byte)1));
+ assertEquals(loc.short2, Short.valueOf((short)2));
+ assertEquals(loc.int2, Integer.valueOf(3));
+ assertEquals(loc.long2, Long.valueOf(4l));
+ assertEquals(loc.float2, Float.valueOf(5f));
+ assertEquals(loc.double2, Double.valueOf(6d));
+ assertEquals(loc.char2, Character.valueOf('a'));
+ assertEquals(loc.bool2, Boolean.TRUE);
+ }
+
+ @Test
+ public void testSetFromFlagCoercesDefaultToPortRange() {
+ MyLocation loc = newLocation();
+ assertEquals(loc.portRange1, PortRanges.fromInteger(1234));
+ }
+
+ @Test
+ public void testSetFromFlagCoercesStringValueToPortRange() {
+ MyLocation loc = newLocation(MutableMap.of("portRange1", "1-3"));
+ assertEquals(loc.portRange1, new PortRanges.LinearPortRange(1, 3));
+ }
+
+ @Test
+ public void testSetFromFlagCoercesStringValueToInt() {
+ MyLocation loc = newLocation(MutableMap.of("int1", "123"));
+ assertEquals(loc.int1, 123);
+ }
+
+ @Test
+ public void testFailsFastOnInvalidCoercion() {
+ try {
+ newLocation(MutableMap.of("int1", "thisisnotanint"));
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception e) {
+ if (Exceptions.getFirstThrowableOfType(e, IllegalArgumentException.class) == null) {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testSetFromFlagWithFieldThatIsExplicitySet() {
+ MyLocation loc = newLocation(MutableMap.of("str4", "myval"));
+ assertEquals(loc.str4, "myval");
+
+ MyLocation loc2 = newLocation();
+ assertEquals(loc2.str4, "explicit str4");
+ }
+
+ private MyLocation newLocation() {
+ return newLocation(ImmutableMap.of());
+ }
+
+ private MyLocation newLocation(Map<?, ?> config) {
+ return mgmt.getLocationManager().createLocation(LocationSpec.create(MyLocation.class)
+ .configure(config));
+ }
+
+ public static class MyLocation extends AbstractLocation {
+
+ @SetFromFlag(defaultVal="1234")
+ PortRange portRange1;
+
+ @SetFromFlag
+ String str1;
+
+ @SetFromFlag("altStr2")
+ String str2;
+
+ @SetFromFlag(defaultVal="default str3")
+ String str3;
+
+ @SetFromFlag
+ String str4 = "explicit str4";
+
+ @SetFromFlag(defaultVal="1")
+ byte byte1;
+
+ @SetFromFlag(defaultVal="2")
+ short short1;
+
+ @SetFromFlag(defaultVal="3")
+ int int1;
+
+ @SetFromFlag(defaultVal="4")
+ long long1;
+
+ @SetFromFlag(defaultVal="5")
+ float float1;
+
+ @SetFromFlag(defaultVal="6")
+ double double1;
+
+ @SetFromFlag(defaultVal="a")
+ char char1;
+
+ @SetFromFlag(defaultVal="true")
+ boolean bool1;
+
+ @SetFromFlag(defaultVal="1")
+ Byte byte2;
+
+ @SetFromFlag(defaultVal="2")
+ Short short2;
+
+ @SetFromFlag(defaultVal="3")
+ Integer int2;
+
+ @SetFromFlag(defaultVal="4")
+ Long long2;
+
+ @SetFromFlag(defaultVal="5")
+ Float float2;
+
+ @SetFromFlag(defaultVal="6")
+ Double double2;
+
+ @SetFromFlag(defaultVal="a")
+ Character char2;
+
+ @SetFromFlag(defaultVal="true")
+ Boolean bool2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java b/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
index 020b274..26f3915 100644
--- a/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
@@ -48,7 +48,7 @@ public class BasicPolicyTest extends BrooklynAppUnitTestSupport {
@SetFromFlag("strKey")
public static final ConfigKey<String> STR_KEY = new BasicConfigKey<String>(String.class, "akey", "a key");
public static final ConfigKey<Integer> INT_KEY_WITH_DEFAULT = new BasicConfigKey<Integer>(Integer.class, "ckey", "c key", 1);
- public static final ConfigKey<String> STR_KEY_WITH_DEFAULT = new BasicConfigKey<String>(String.class, "strKey", "str key", "str key default");
+ public static final ConfigKey<String> STR_KEY_WITH_DEFAULT = new BasicConfigKey<String>(String.class, "strKeyWithDefault", "str key", "strKeyDefaultVal");
public static final ConfigKey<String> RECONFIGURABLE_KEY = ConfigKeys.builder(String.class, "reconfigurableKey")
.reconfigurable(true)
.build();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicyConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicyConfigTest.java b/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicyConfigTest.java
index 784c076..c25122e 100644
--- a/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicyConfigTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicyConfigTest.java
@@ -55,8 +55,7 @@ public class PolicyConfigTest extends BrooklynAppUnitTestSupport {
assertEquals(policy.getConfig(MyPolicy.STR_KEY), "aval");
assertEquals(policy.getConfig(MyPolicy.INT_KEY), (Integer)2);
- // this is set, because key name matches annotation on STR_KEY
- assertEquals(policy.getConfig(MyPolicy.STR_KEY_WITH_DEFAULT), "aval");
+ assertEquals(policy.getConfig(MyPolicy.STR_KEY_WITH_DEFAULT), MyPolicy.STR_KEY_WITH_DEFAULT.getDefaultValue());
}
@Test
@@ -81,7 +80,6 @@ public class PolicyConfigTest extends BrooklynAppUnitTestSupport {
assertEquals(policy.getConfig(MyPolicy.STR_KEY), "aval");
assertEquals(policy.getConfig(MyPolicy.INT_KEY), (Integer)2);
- // this is not set (contrast with above)
assertEquals(policy.getConfig(MyPolicy.STR_KEY_WITH_DEFAULT), MyPolicy.STR_KEY_WITH_DEFAULT.getDefaultValue());
}
@@ -157,7 +155,7 @@ public class PolicyConfigTest extends BrooklynAppUnitTestSupport {
public void testConfigReturnsDefaultValueIfNotSet() throws Exception {
MyPolicy policy = app.policies().add(PolicySpec.create(MyPolicy.class));
- assertEquals(policy.getConfig(MyPolicy.STR_KEY_WITH_DEFAULT), "str key default");
+ assertEquals(policy.getConfig(MyPolicy.STR_KEY_WITH_DEFAULT), MyPolicy.STR_KEY_WITH_DEFAULT.getDefaultValue());
}
@Test
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/afa787c4/core/src/test/java/org/apache/brooklyn/util/core/config/ConfigBagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/config/ConfigBagTest.java b/core/src/test/java/org/apache/brooklyn/util/core/config/ConfigBagTest.java
index f85a117..bff9ca3 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/config/ConfigBagTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/config/ConfigBagTest.java
@@ -19,6 +19,7 @@
package org.apache.brooklyn.util.core.config;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import java.util.List;
import java.util.Map;
@@ -29,8 +30,6 @@ import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.core.config.ConfigBagTest;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.time.Duration;
import org.slf4j.Logger;
@@ -38,6 +37,8 @@ import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableMap;
+
public class ConfigBagTest {
@SuppressWarnings("unused")
@@ -136,6 +137,83 @@ public class ConfigBagTest {
}
@Test
+ public void testCopyKey() throws InterruptedException {
+ ConfigBag bag = ConfigBag.newInstance();
+ bag.put(K1, "v1");
+
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKey(bag, K1);
+
+ assertEquals(bag2.get(K1), "v1");
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testCopyKeys() throws InterruptedException {
+ ConfigBag bag = ConfigBag.newInstance();
+ bag.put(K1, "v1");
+ bag.put(K2, "v2");
+
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKeys(bag, K1, K2, K3);
+
+ assertEquals(bag2.get(K1), "v1");
+ assertEquals(bag2.get(K2), "v2");
+ assertFalse(bag2.containsKey(K3));
+ }
+
+ @Test
+ public void testCopyKeyAs() throws InterruptedException {
+ ConfigBag bag = ConfigBag.newInstance();
+ bag.put(K1, "v1");
+
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKeyAs(bag, K1, K2);
+
+ assertEquals(bag2.get(K2), "v1");
+ assertFalse(bag2.containsKey(K1));
+ }
+
+ @Test
+ public void testCopyKeyWithDeprecatedNames() throws InterruptedException {
+ ConfigKey<String> k = ConfigKeys.builder(String.class, "k")
+ .deprecatedNames("kOld", "kOld2")
+ .build();
+
+ {
+ ConfigBag bag = ConfigBag.newInstance().putAll(ImmutableMap.of("k", "v1"));
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKey(bag, k);
+ assertEquals(bag2.getAllConfigRaw(), ImmutableMap.of("k", "v1"));
+ }
+ {
+ ConfigBag bag = ConfigBag.newInstance().putAll(ImmutableMap.of("kOld", "v1"));
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKey(bag, k);
+ assertEquals(bag2.getAllConfigRaw(), ImmutableMap.of("k", "v1"));
+ }
+ {
+ ConfigBag bag = ConfigBag.newInstance().putAll(ImmutableMap.of("kOld", "v1", "kOld2", "v2"));
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKey(bag, k);
+ assertEquals(bag2.getAllConfigRaw(), ImmutableMap.of("k", "v1"));
+ }
+ {
+ ConfigBag bag = ConfigBag.newInstance().putAll(ImmutableMap.of("k", "v1", "kOld", "v2"));
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKey(bag, k);
+ assertEquals(bag2.getAllConfigRaw(), ImmutableMap.of("k", "v1"));
+ }
+ {
+ ConfigBag bag = ConfigBag.newInstance().putAll(ImmutableMap.of("k", "v1", "kOld", "v2", "kOld2", "v3"));
+ ConfigBag bag2 = ConfigBag.newInstance();
+ bag2.copyKey(bag, k);
+ assertEquals(bag2.getAllConfigRaw(), ImmutableMap.of("k", "v1"));
+ }
+ }
+
+
+ @Test
public void testConcurrent() throws InterruptedException {
ConfigBag bag = ConfigBag.newInstance();
bag.put(K1, "v1");
[6/6] brooklyn-server git commit: Closes #734
Posted by ge...@apache.org.
Closes #734
Support ConfigKey deprecated names
As discussed on the dev@brooklyn mailing list in the thread "[PROPOSAL] Deprecate @SetFromFlag".
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/0e35b615
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/0e35b615
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/0e35b615
Branch: refs/heads/master
Commit: 0e35b61511d0712e94acd43e06fc93b4ea5734e8
Parents: 1dfde7a 80c9a9a
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Thu Jul 13 11:01:00 2017 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Thu Jul 13 11:01:00 2017 +0100
----------------------------------------------------------------------
.../ConfigParametersDeprecationYamlTest.java | 203 ++++++++++
.../brooklyn/core/config/BasicConfigKey.java | 20 +
.../config/internal/AbstractConfigMapImpl.java | 31 +-
.../brooklyn/core/entity/AbstractEntity.java | 15 +-
.../entity/internal/ConfigUtilsInternal.java | 108 ++++++
.../core/location/AbstractLocation.java | 10 +-
.../mgmt/rebind/BasicLocationRebindSupport.java | 10 +
.../mgmt/rebind/BasicPolicyRebindSupport.java | 24 +-
.../core/objs/AbstractEntityAdjunct.java | 9 +
.../brooklyn/core/objs/BasicSpecParameter.java | 2 +
.../core/objs/BrooklynTypeSnapshot.java | 24 +-
.../brooklyn/util/core/config/ConfigBag.java | 120 +++++-
.../util/core/config/ResolvingConfigBag.java | 6 +
.../brooklyn/util/core/flags/FlagUtils.java | 4 +-
.../config/ConfigKeyDeprecationRebindTest.java | 385 +++++++++++++++++++
.../core/config/ConfigKeyDeprecationTest.java | 328 ++++++++++++++++
.../MapConfigKeyAndFriendsDeprecationTest.java | 124 ++++++
.../core/enricher/BasicEnricherTest.java | 2 +-
.../core/enricher/EnricherConfigTest.java | 6 +-
.../core/entity/LocationSetFromFlagTest.java | 211 ++++++++++
.../internal/ConfigUtilsInternalTest.java | 71 ++++
.../core/policy/basic/BasicPolicyTest.java | 2 +-
.../core/policy/basic/PolicyConfigTest.java | 6 +-
.../util/core/config/ConfigBagTest.java | 82 +++-
.../config-deprecated-enricher-j8rvs5fc16 | 36 ++
.../config-deprecated-enricherOwner-sb5w8w5tq0 | 36 ++
.../config/config-deprecated-feed-km6gu420a0 | 30 ++
.../config-deprecated-feedOwner-d8p4p8o4x7 | 36 ++
...config-deprecated-flagNameOnField-e86eode5yy | 48 +++
...precated-flagNameOnField-location-f4kj5hxcvx | 35 ++
...deprecated-flagNameOnField-policy-alq7mtwv0m | 35 ++
...cated-flagNameOnField-policyOwner-vfncjpljqf | 36 ++
.../config-deprecated-flagNameOnKey-ug77ek2tkd | 36 ++
.../config/config-deprecated-key-dyozzd948m | 48 +++
.../config/config-deprecated-key-pps2ttgijb | 36 ++
.../entity/machine/pool/ServerPoolLocation.java | 8 +-
.../org/apache/brooklyn/test/LogWatcher.java | 11 +-
.../org/apache/brooklyn/config/ConfigKey.java | 9 +
38 files changed, 2201 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0e35b615/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0e35b615/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0e35b615/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java
----------------------------------------------------------------------
[3/6] brooklyn-server git commit: Support configKey.deprecatedNames
Posted by ge...@apache.org.
Support configKey.deprecatedNames
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/02b71ffb
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/02b71ffb
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/02b71ffb
Branch: refs/heads/master
Commit: 02b71ffb5f81abb6ad76095a64903335b9692fda
Parents: 93b7e18
Author: Aled Sage <al...@gmail.com>
Authored: Thu Jun 8 14:58:46 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Jun 16 13:13:23 2017 +0100
----------------------------------------------------------------------
.../ConfigParametersDeprecationYamlTest.java | 203 ++++++++++
.../brooklyn/core/config/BasicConfigKey.java | 20 +
.../config/internal/AbstractConfigMapImpl.java | 31 +-
.../brooklyn/core/entity/AbstractEntity.java | 12 +-
.../entity/internal/ConfigUtilsInternal.java | 108 ++++++
.../core/location/AbstractLocation.java | 11 +
.../mgmt/rebind/BasicLocationRebindSupport.java | 10 +
.../mgmt/rebind/BasicPolicyRebindSupport.java | 24 +-
.../core/objs/AbstractEntityAdjunct.java | 15 +
.../brooklyn/core/objs/BasicSpecParameter.java | 2 +
.../core/objs/BrooklynTypeSnapshot.java | 24 +-
.../brooklyn/util/core/config/ConfigBag.java | 118 +++++-
.../util/core/config/ResolvingConfigBag.java | 6 +
.../brooklyn/util/core/flags/FlagUtils.java | 4 +-
.../config/ConfigKeyDeprecationRebindTest.java | 373 +++++++++++++++++++
.../core/config/ConfigKeyDeprecationTest.java | 328 ++++++++++++++++
.../MapConfigKeyAndFriendsDeprecationTest.java | 124 ++++++
.../internal/ConfigUtilsInternalTest.java | 71 ++++
.../config-deprecated-enricher-j8rvs5fc16 | 36 ++
.../config-deprecated-enricherOwner-sb5w8w5tq0 | 36 ++
.../config/config-deprecated-feed-km6gu420a0 | 30 ++
.../config-deprecated-feedOwner-d8p4p8o4x7 | 36 ++
...config-deprecated-flagNameOnField-e86eode5yy | 48 +++
...precated-flagNameOnField-location-f4kj5hxcvx | 35 ++
...deprecated-flagNameOnField-policy-alq7mtwv0m | 35 ++
...cated-flagNameOnField-policyOwner-vfncjpljqf | 36 ++
.../config-deprecated-flagNameOnKey-ug77ek2tkd | 36 ++
.../config/config-deprecated-key-dyozzd948m | 48 +++
.../config/config-deprecated-key-pps2ttgijb | 36 ++
.../org/apache/brooklyn/config/ConfigKey.java | 9 +
30 files changed, 1882 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersDeprecationYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersDeprecationYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersDeprecationYamlTest.java
new file mode 100644
index 0000000..4999b5f
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersDeprecationYamlTest.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.camp.brooklyn;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
+public class ConfigParametersDeprecationYamlTest extends AbstractYamlRebindTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigParametersDeprecationYamlTest.class);
+
+ @BeforeMethod(alwaysRun=true)
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ RecordingSshTool.clear();
+ }
+
+ @AfterMethod(alwaysRun=true)
+ @Override
+ public void tearDown() throws Exception {
+ try {
+ super.tearDown();
+ } finally {
+ RecordingSshTool.clear();
+ }
+ }
+
+ @Test
+ public void testParameterDefinesDeprecatedNames() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+BasicEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: key1",
+ " deprecatedNames:",
+ " - oldKey1",
+ " - oldKey1b",
+ " description: myDescription",
+ " type: String",
+ " default: myDefaultVal");
+
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+
+ ConfigKey<?> key = findKey(entity, "key1");
+ assertEquals(key.getDeprecatedNames(), ImmutableList.of("oldKey1", "oldKey1b"));
+
+ // Rebind, and then check again that the config key is listed
+ Entity newApp = rebind();
+ Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
+ ConfigKey<?> newKey = findKey(newEntity, "key1");
+ assertEquals(newKey.getDeprecatedNames(), ImmutableList.of("oldKey1", "oldKey1b"));
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInCatalog() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+BasicEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: key1",
+ " deprecatedNames:",
+ " - oldKey1",
+ " description: myDescription",
+ " type: String",
+ " brooklyn.config:",
+ " oldKey1: myval");
+
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.config().get(findKey(entity, "key1")), "myval");
+
+ // Rebind, and then check again the config key value
+ Entity newApp = rebind();
+ Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
+ assertEquals(newEntity.config().get(findKey(entity, "key1")), "myval");
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInUsage() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+BasicEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: key1",
+ " deprecatedNames:",
+ " - oldKey1",
+ " description: myDescription",
+ " type: String");
+
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " oldKey1: myval");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.config().get(findKey(entity, "key1")), "myval");
+
+ // Rebind, and then check again the config key value
+ Entity newApp = rebind();
+ Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
+ assertEquals(newEntity.config().get(findKey(entity, "key1")), "myval");
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInSubtype() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+BasicEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: key1",
+ " deprecatedNames:",
+ " - oldKey1",
+ " description: myDescription",
+ " type: String");
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: sub-entity",
+ " item:",
+ " type: entity-with-keys",
+ " brooklyn.config:",
+ " oldKey1: myval");
+
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: sub-entity");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.config().get(findKey(entity, "key1")), "myval");
+
+ // Rebind, and then check again the config key value
+ Entity newApp = rebind();
+ Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
+ assertEquals(newEntity.config().get(findKey(entity, "key1")), "myval");
+ }
+
+ protected ConfigKey<?> findKey(Entity entity, String keyName) {
+ ConfigKey<?> key = entity.getEntityType().getConfigKey(keyName);
+ assertNotNull(key, "No key '"+keyName+"'; keys="+entity.getEntityType().getConfigKeys());
+ return key;
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java b/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
index d3af701..8560361 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
@@ -47,6 +47,7 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
@@ -100,6 +101,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
public abstract static class Builder<T, B extends Builder<T,B>> {
protected String name;
+ protected Collection<String> deprecatedNames = ImmutableList.of();
protected TypeToken<T> type;
protected String description;
protected T defaultValue;
@@ -125,6 +127,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
public Builder(String newName, ConfigKey<T> key) {
this.type = checkNotNull(key.getTypeToken(), "type");
this.name = checkNotNull(newName, "name");
+ this.deprecatedNames = checkNotNull(key.getDeprecatedNames(), "deprecatedNames");
description(key.getDescription());
defaultValue(key.getDefaultValue());
reconfigurable(key.isReconfigurable());
@@ -135,6 +138,12 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
public B name(String val) {
this.name = val; return self();
}
+ public B deprecatedNames(Collection<String> val) {
+ this.deprecatedNames = val; return self();
+ }
+ public B deprecatedNames(String... val) {
+ return deprecatedNames(val == null ? ImmutableList.of() : ImmutableList.copyOf(val));
+ }
public B type(Class<T> val) {
this.type = TypeToken.of(val); return self();
}
@@ -187,6 +196,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
}
protected String name;
+ protected Collection<String> deprecatedNames;
protected TypeToken<T> typeToken;
protected Class<? super T> type;
protected String description;
@@ -237,6 +247,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
public BasicConfigKey(TypeToken<T> type, String name, String description, T defaultValue) {
this.description = description;
this.name = checkNotNull(name, "name");
+ this.deprecatedNames = ImmutableList.of();
this.type = TypeTokens.getRawTypeIfRaw(checkNotNull(type, "type"));
this.typeToken = TypeTokens.getTypeTokenIfNotRaw(type);
@@ -248,6 +259,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
public BasicConfigKey(Builder<T,?> builder) {
this.name = checkNotNull(builder.name, "name");
+ this.deprecatedNames = checkNotNull(builder.deprecatedNames, "deprecatedNames");
this.type = TypeTokens.getRawTypeIfRaw(checkNotNull(builder.type, "type"));
this.typeToken = TypeTokens.getTypeTokenIfNotRaw(builder.type);
this.description = builder.description;
@@ -264,6 +276,13 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
/** @see ConfigKey#getName() */
@Override public String getName() { return name; }
+ /** @see ConfigKey#getDeprecatedNames() */
+ @Override public Collection<String> getDeprecatedNames() {
+ // check for null, for backwards compatibility of serialized state
+ if (deprecatedNames == null) deprecatedNames = ImmutableList.of();
+ return deprecatedNames;
+ }
+
/** @see ConfigKey#getTypeName() */
@Override public String getTypeName() { return getType().getName(); }
@@ -365,6 +384,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializab
}
/** @see ConfigKey#getNameParts() */
+ @Deprecated
@Override public Collection<String> getNameParts() {
return Lists.newArrayList(dots.split(name));
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/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 091f874..bc4916b 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
@@ -226,7 +226,19 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
@Override @Deprecated
public Maybe<Object> getConfigRaw(ConfigKey<?> key, boolean includeInherited) {
// does not currently respect inheritance modes
- if (ownConfig.containsKey(key)) return Maybe.of(ownConfig.get(key));
+ if (ownConfig.containsKey(key)) {
+ return Maybe.of(ownConfig.get(key));
+ }
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ // Unfortunately `config.putAll(map.of(string, val))` (for dynamic config keys,
+ // i.e. where the key is not pre-defined on the entity). Unfortunately that
+ // means subsequent lookup must synthesise keys for each deprecated name.
+ ConfigKey<?> deprecatedKey = ConfigKeys.newConfigKeyRenamed(deprecatedName, key);
+ if (ownConfig.containsKey(deprecatedKey)) {
+ LOG.warn("Retrieving value with deprecated config key name '"+deprecatedName+"' for key "+key);
+ return Maybe.of(ownConfig.get(deprecatedKey));
+ }
+ }
if (!includeInherited || getParent()==null) return Maybe.absent();
return getParentInternal().config().getInternalConfigMap().getConfigRaw(key, includeInherited);
}
@@ -305,6 +317,23 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
* <p>
* this does not do any resolution with respect to ancestors. */
protected Maybe<Object> resolveRawValueFromContainer(TContainer container, ConfigKey<?> key, Maybe<Object> value) {
+ Maybe<Object> result = resolveRawValueFromContainerIgnoringDeprecatedNames(container, key, value);
+ if (result.isPresent()) return result;
+
+ // See AbstractconfigMapImpl.getConfigRaw(ConfigKey<?> key, boolean includeInherited) for how/why it
+ // handles deprecated names
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ ConfigKey<?> deprecatedKey = ConfigKeys.newConfigKeyRenamed(deprecatedName, key);
+ result = resolveRawValueFromContainerIgnoringDeprecatedNames(container, deprecatedKey, value);
+ if (result.isPresent()) {
+ LOG.warn("Retrieving value with deprecated config key name '"+deprecatedName+"' for key "+key);
+ return result;
+ }
+ }
+ return result;
+ }
+
+ private Maybe<Object> resolveRawValueFromContainerIgnoringDeprecatedNames(TContainer container, ConfigKey<?> key, Maybe<Object> value) {
Map<ConfigKey<?>, Object> oc = ((AbstractConfigMapImpl<?>) ((BrooklynObjectInternal)container).config().getInternalConfigMap()).ownConfig;
if (key instanceof ConfigKeySelfExtracting) {
if (((ConfigKeySelfExtracting<?>)key).isSet(oc)) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index 9935633..d0d3873 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -64,6 +64,7 @@ import org.apache.brooklyn.core.config.ConfigConstraints;
import org.apache.brooklyn.core.config.internal.AbstractConfigMapImpl;
import org.apache.brooklyn.core.config.render.RendererHints;
import org.apache.brooklyn.core.enricher.AbstractEnricher;
+import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal;
import org.apache.brooklyn.core.entity.internal.EntityConfigMap;
import org.apache.brooklyn.core.entity.lifecycle.PolicyDescriptor;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
@@ -393,11 +394,16 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
// shouldn't be used; CAMP parser leaves it as a top-level attribute which is converted to a tag
tags().addTag(BrooklynTags.newIconUrlTag((String) flags.remove(BrooklynConfigKeys.ICON_URL.getName())));
}
-
+
+ // allow config keys to be set by name (or deprecated name)
+ flags = ConfigUtilsInternal.setAllConfigKeys(flags, getEntityType().getConfigKeys(), this);
+
// allow config keys, and fields, to be set from these flags if they have a SetFromFlag annotation
// TODO the default values on flags are not used? (we should remove that support, since ConfigKeys gives a better way)
- FlagUtils.setFieldsFromFlags(flags, this);
- flags = FlagUtils.setAllConfigKeys(flags, this, false);
+ if (flags.size() > 0) {
+ FlagUtils.setFieldsFromFlags(flags, this);
+ flags = FlagUtils.setAllConfigKeys(flags, this, false);
+ }
// finally all config keys specified in map should be set as config
// TODO use a config bag and remove the ones set above in the code below
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternal.java b/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternal.java
new file mode 100644
index 0000000..fb3a0e0
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternal.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.entity.internal;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.brooklyn.api.objs.Configurable;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * Internal utility methods for getting/setting config, such that it handles any deprecated names
+ * defined in {@link ConfigKey#getDeprecatedNames()}.
+ */
+public class ConfigUtilsInternal {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigUtilsInternal.class);
+
+ public static Map<?,?> setAllConfigKeys(Map<?,?> flags, Iterable<? extends ConfigKey<?>> configKeys, Configurable obj) {
+ Map<?,?> unusedFlags = MutableMap.copyOf(flags);
+ for (ConfigKey<?> key : configKeys) {
+ ConfigValue values = getValue(unusedFlags, key);
+ Maybe<Object> valueToUse = values.preferredValue();
+ if (valueToUse.isPresent()) {
+ setValue(obj, key, valueToUse.get());
+ values.logIfDeprecatedValue(obj, key);
+ }
+ }
+ return unusedFlags;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private static void setValue(Configurable obj, ConfigKey<?> key, Object val) {
+ obj.config().set((ConfigKey)key, val);
+ }
+
+ private static ConfigValue getValue(Map<?,?> flags, ConfigKey<?> key) {
+ Maybe<Object> val;
+ String keyName = key.getName();
+ if (flags.containsKey(keyName)) {
+ val = Maybe.of(flags.get(keyName));
+ flags.remove(keyName);
+ } else {
+ val = Maybe.absent();
+ }
+ Map<String, Object> deprecatedValues = new LinkedHashMap<>(key.getDeprecatedNames().size());
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ if (flags.containsKey(deprecatedName)) {
+ deprecatedValues.put(deprecatedName, flags.get(deprecatedName));
+ flags.remove(deprecatedName);
+ }
+ }
+ return new ConfigValue(val, deprecatedValues);
+ }
+
+ private static class ConfigValue {
+ final Maybe<Object> val;
+ final Map<String, Object> deprecatedValues;
+
+ ConfigValue(Maybe<Object> val, Map<String, Object> deprecatedValues) {
+ this.val = val;
+ this.deprecatedValues = deprecatedValues;
+ }
+
+ Maybe<Object> preferredValue() {
+ if (val.isPresent()) return val;
+ return (deprecatedValues.isEmpty()) ? Maybe.absent() : Maybe.of(Iterables.get(deprecatedValues.values(), 0));
+ }
+
+ void logIfDeprecatedValue(Configurable obj, ConfigKey<?> key) {
+ if (deprecatedValues.isEmpty()) return;
+
+ if (val.isPresent()) {
+ LOG.warn("Ignoring deprecated config value(s) on "+obj+" because contains value for "
+ +"'"+key.getName()+"', other deprecated name(s) present were: "+deprecatedValues.keySet());
+ } else if (deprecatedValues.size() == 1) {
+ LOG.warn("Using deprecated config value on "+obj+", should use '"+key.getName()+"', but used "
+ +"'"+Iterables.getOnlyElement(deprecatedValues.keySet())+"'");
+ } else {
+ LOG.warn("Using deprecated config value on "+obj+", should use '"+key.getName()+"', but used "
+ +"'"+Iterables.get(deprecatedValues.keySet(), 1)+"' and ignored values present for other "
+ +"deprecated name(s) "+Iterables.skip(deprecatedValues.keySet(), 1));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
index 268d2a4..58b2809 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
@@ -47,6 +47,7 @@ import org.apache.brooklyn.core.config.BasicConfigKey;
import org.apache.brooklyn.core.config.ConfigConstraints;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.config.internal.AbstractConfigMapImpl;
+import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal;
import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.internal.storage.Reference;
import org.apache.brooklyn.core.internal.storage.impl.BasicReference;
@@ -215,6 +216,16 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
config().removeKey(PARENT_LOCATION);
}
+ // allow config keys to be set by name (or deprecated name)
+ //
+ // Aled thinks it would be sensible to remove the consumed flags below (i.e. properties = ...).
+ // However, that caused ClockerDynamicLocationPatternTest to fail because there is a field of
+ // StubContainerLocation annotated with `@SetFromFlag("owner")`, as well as a config key with
+ // name "owner" (and with `@SetFromFlag("owner")`) in the super-type (DynamicLocation).
+ // However, that looks mad - do we really need to support it?!
+ // I've preserved that behaviour (for now).
+ ConfigUtilsInternal.setAllConfigKeys(properties, getLocationTypeInternal().getConfigKeys().values(), this);
+
// NB: flag-setting done here must also be done in BasicLocationRebindSupport
ConfigBag configBag = ConfigBag.newInstance(properties);
FlagUtils.setFieldsFromFlagsWithBag(this, properties, configBag, firstTime);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicLocationRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicLocationRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicLocationRebindSupport.java
index e603395..072f2c8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicLocationRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicLocationRebindSupport.java
@@ -19,6 +19,7 @@
package org.apache.brooklyn.core.mgmt.rebind;
import java.lang.reflect.Field;
+import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -27,6 +28,7 @@ import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.mgmt.rebind.RebindContext;
import org.apache.brooklyn.api.mgmt.rebind.mementos.LocationMemento;
import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal;
import org.apache.brooklyn.core.location.AbstractLocation;
import org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators;
import org.apache.brooklyn.util.collections.MutableMap;
@@ -70,10 +72,18 @@ public class BasicLocationRebindSupport extends AbstractBrooklynObjectRebindSupp
// Note that the flags have been set in the constructor
// Sept 2016 - now ignores unused and config description
+ Collection<ConfigKey<?>> configKeys = location.getLocationTypeInternal().getConfigKeys().values();
+
for (Map.Entry<String, Object> entry : memento.getLocationConfig().entrySet()) {
String flagName = entry.getKey();
Object value = entry.getValue();
+ Map<?, ?> unused = ConfigUtilsInternal.setAllConfigKeys(MutableMap.of(flagName, value), configKeys, location);
+ if (unused.isEmpty()) {
+ // Config key was known explicitly; don't need to iterate over all the fields yet again!
+ continue;
+ }
+
Field field;
try {
field = FlagUtils.findFieldForFlag(flagName, location);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicPolicyRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicPolicyRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicPolicyRebindSupport.java
index a52df3a..6c06d00 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicPolicyRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicPolicyRebindSupport.java
@@ -18,8 +18,13 @@
*/
package org.apache.brooklyn.core.mgmt.rebind;
+import java.util.Collection;
+import java.util.Map;
+
import org.apache.brooklyn.api.mgmt.rebind.RebindContext;
import org.apache.brooklyn.api.mgmt.rebind.mementos.PolicyMemento;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal;
import org.apache.brooklyn.core.policy.AbstractPolicy;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.flags.FlagUtils;
@@ -37,11 +42,20 @@ public class BasicPolicyRebindSupport extends AbstractBrooklynObjectRebindSuppor
protected void addConfig(RebindContext rebindContext, PolicyMemento memento) {
// TODO entity does config-lookup differently; the memento contains the config keys.
// BasicEntityMemento.postDeserialize uses the injectTypeClass to call EntityTypes.getDefinedConfigKeys(clazz)
- //
- // Note that the flags may have been set in the constructor; but some policies have no-arg constructors
- ConfigBag configBag = ConfigBag.newInstance(memento.getConfig());
- FlagUtils.setFieldsFromFlags(policy, configBag);
- FlagUtils.setAllConfigKeys(policy, configBag, false);
+
+ Collection<ConfigKey<?>> configKeys = policy.getAdjunctType().getConfigKeys();
+
+ Map<?, ?> flags = memento.getConfig();
+
+ // First set the config keys that are known explicitly (including with deprecated names).
+ flags = ConfigUtilsInternal.setAllConfigKeys(flags, configKeys, policy);
+
+ // Note that the flags may have been set in the constructor; but non-legacy policies should have no-arg constructors
+ if (!flags.isEmpty()) {
+ ConfigBag configBag = ConfigBag.newInstance(flags);
+ FlagUtils.setFieldsFromFlags(policy, configBag);
+ FlagUtils.setAllConfigKeys(policy, configBag, false);
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index 69e51e6..7395d0a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -40,12 +40,14 @@ import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.BasicConfigKey;
import org.apache.brooklyn.core.config.ConfigConstraints;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.config.internal.AbstractConfigMapImpl;
import org.apache.brooklyn.core.enricher.AbstractEnricher;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal;
import org.apache.brooklyn.core.mgmt.internal.SubscriptionTracker;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.flags.FlagUtils;
@@ -151,6 +153,19 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject imple
}
}
+ // Allow config keys to be set by name (or deprecated name).
+ //
+ // Aled thinks it would be sensible to remove the consumed flags below (i.e. flags = ...).
+ // However, that causes PolicyConfigTest.testConfigFlagsPassedInAtConstructionIsAvailable to fail.
+ // However, tht looks mad - do we really need to support it?!
+ // The policy is defined with one key using a name in SetFromFlag, and another key using the same name.
+ // It expects both of the config keys to have been set.
+ // @SetFromFlag("strKey")
+ // public static final ConfigKey<String> STR_KEY = new BasicConfigKey<String>(String.class, "akey", "a key");
+ // public static final ConfigKey<String> STR_KEY_WITH_DEFAULT = new BasicConfigKey<String>(String.class, "strKey", "str key", "str key default");
+ // I've preserved that behaviour (for now).
+ ConfigUtilsInternal.setAllConfigKeys(flags, getAdjunctType().getConfigKeys(), this);
+
ConfigBag bag = new ConfigBag().putAll(flags);
FlagUtils.setFieldsFromFlags(this, bag, isFirstTime);
FlagUtils.setAllConfigKeys(this, bag, false);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/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 c890719..7c1bde0 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
@@ -253,6 +253,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
throw new IllegalArgumentException("Catalog input definition expected to be a map, but is " + obj.getClass() + " instead: " + obj);
}
String name = (String)inputDef.get("name");
+ Collection<String> deprecatedNames = (Collection<String>)inputDef.get("deprecatedNames");
String label = (String)inputDef.get("label");
String description = (String)inputDef.get("description");
String type = (String)inputDef.get("type");
@@ -296,6 +297,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
Builder builder = BasicConfigKey.builder(typeToken)
.name(name)
+ .deprecatedNames((deprecatedNames == null) ? ImmutableList.of() : deprecatedNames)
.description(description)
.defaultValue(immutableDefaultValue)
.constraint(constraint)
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/core/objs/BrooklynTypeSnapshot.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/BrooklynTypeSnapshot.java b/core/src/main/java/org/apache/brooklyn/core/objs/BrooklynTypeSnapshot.java
index 77fcb11..904b3c6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/BrooklynTypeSnapshot.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/BrooklynTypeSnapshot.java
@@ -18,12 +18,15 @@
*/
package org.apache.brooklyn.core.objs;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.brooklyn.api.objs.BrooklynType;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
@@ -34,15 +37,32 @@ import com.google.common.collect.ImmutableSet;
public class BrooklynTypeSnapshot implements BrooklynType {
private static final long serialVersionUID = 4670930188951106009L;
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynTypeSnapshot.class);
+
private final String name;
private transient volatile String simpleName;
private final Map<String, ConfigKey<?>> configKeys;
+ private final Map<String, ConfigKey<?>> configKeysByDeprecatedName;
+
private final Set<ConfigKey<?>> configKeysSet;
protected BrooklynTypeSnapshot(String name, Map<String, ConfigKey<?>> configKeys) {
this.name = name;
this.configKeys = ImmutableMap.copyOf(configKeys);
this.configKeysSet = ImmutableSet.copyOf(this.configKeys.values());
+
+ this.configKeysByDeprecatedName = new LinkedHashMap<>();
+ for (ConfigKey<?> key : configKeysSet) {
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ if (configKeys.containsKey(deprecatedName)) {
+ LOG.warn("Conflicting config key name '"+deprecatedName+"' used in "+configKeys.get(deprecatedName)+" and as deprecated name of "+key+"; will prefer "+key+" but may cause problems");
+ } else if (configKeysByDeprecatedName.containsKey(deprecatedName)) {
+ LOG.warn("Conflicting config key name '"+deprecatedName+"' used as deprecated name in both "+configKeysByDeprecatedName.get(deprecatedName)+" and "+key+"; may cause problems");
+ } else {
+ configKeysByDeprecatedName.put(deprecatedName, key);
+ }
+ }
+ }
}
@Override
@@ -73,7 +93,9 @@ public class BrooklynTypeSnapshot implements BrooklynType {
@Override
public ConfigKey<?> getConfigKey(String name) {
- return configKeys.get(name);
+ ConfigKey<?> result = configKeys.get(name);
+ if (result == null) result = configKeysByDeprecatedName.get(name);
+ return result;
}
@Override
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java b/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
index f34d881..cfef3b0 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java
@@ -330,7 +330,14 @@ public class ConfigBag {
}
public boolean containsKey(ConfigKey<?> key) {
- return containsKey(key.getName());
+ boolean found = containsKey(key.getName());
+ if (!found) {
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ found = containsKey(deprecatedName);
+ if (found) break;
+ }
+ }
+ return found;
}
public synchronized boolean containsKey(String key) {
@@ -357,8 +364,9 @@ public class ConfigBag {
@Beta
public Maybe<Object> getObjKeyMaybe(Object key) {
if (key instanceof HasConfigKey<?>) key = ((HasConfigKey<?>)key).getConfigKey();
- if (key instanceof ConfigKey<?>) key = ((ConfigKey<?>)key).getName();
- if (key instanceof String) {
+ if (key instanceof ConfigKey<?>) {
+ return getKeyMaybe((ConfigKey<?>)key, true);
+ } else if (key instanceof String) {
return getStringKeyMaybe((String)key, true);
} else {
logInvalidKey(key);
@@ -370,8 +378,9 @@ public class ConfigBag {
@Beta
private Maybe<Object> getRawObjKeyMaybe(Object key) {
if (key instanceof HasConfigKey<?>) key = ((HasConfigKey<?>)key).getConfigKey();
- if (key instanceof ConfigKey<?>) key = ((ConfigKey<?>)key).getName();
- if (key instanceof String) {
+ if (key instanceof ConfigKey<?>) {
+ return this.getRawKeyMaybe((ConfigKey<?>)key, true);
+ } else if (key instanceof String) {
return this.getRawStringKeyMaybe((String)key, true);
} else {
logInvalidKey(key);
@@ -398,7 +407,7 @@ public class ConfigBag {
@Beta
@SuppressWarnings("unchecked")
public <T> ConfigBag copyKeyAs(ConfigBag source, ConfigKey<T> sourceKey, ConfigKey<T> targetKey) {
- Maybe<Object> sourceValue = source.getRawObjKeyMaybe(sourceKey);
+ Maybe<Object> sourceValue = source.getRawKeyMaybe(sourceKey, true);
if (sourceValue.isPresent()) {
put(targetKey, (T) sourceValue.get());
}
@@ -421,14 +430,22 @@ public class ConfigBag {
return get(preferredKey);
}
- /** convenience for @see #getWithDeprecation(ConfigKey[], ConfigKey...) */
+ /**
+ * Convenience for @see #getWithDeprecation(ConfigKey[], ConfigKey...).
+ *
+ * @deprecated since 0.12.0; instead define deprecated names on key, see {@link ConfigKey#getDeprecatedNames()}
+ */
public Object getWithDeprecation(ConfigKey<?> key, ConfigKey<?> ...deprecatedKeys) {
return getWithDeprecation(new ConfigKey[] { key }, deprecatedKeys);
}
- /** returns the value for the first key in the list for which a value is set,
+ /**
+ * Returns the value for the first key in the list for which a value is set,
* warning if any of the deprecated keys have a value which is different to that set on the first set current key
- * (including warning if a deprecated key has a value but no current key does) */
+ * (including warning if a deprecated key has a value but no current key does).
+ *
+ * @deprecated since 0.12.0; instead define deprecated names on key, see {@link ConfigKey#getDeprecatedNames()}
+ */
public synchronized Object getWithDeprecation(ConfigKey<?>[] currentKeysInOrderOfPreference, ConfigKey<?> ...deprecatedKeys) {
// Get preferred key (or null)
ConfigKey<?> preferredKeyProvidingValue = null;
@@ -492,8 +509,9 @@ public class ConfigBag {
protected <T> T get(ConfigKey<T> key, boolean markUsed) {
// TODO for now, no evaluation -- maps / closure content / other smart (self-extracting) keys are NOT supported
// (need a clean way to inject that behaviour, as well as desired TypeCoercions)
- // this method, and the coercion, is not synchronized, nor does it need to be, because the "get" is synchronized.
- return coerceFirstNonNullKeyValue(key, getStringKey(key.getName(), markUsed));
+ // this method, and the coercion, is not synchronized, nor does it need to be, because the "get" is synchronized.
+ Maybe<Object> val = getKeyMaybe(key, markUsed);
+ return coerceFirstNonNullKeyValue(key, val.orNull());
}
/** returns the first non-null value to be the type indicated by the key, or the keys default value if no non-null values are supplied */
@@ -507,6 +525,44 @@ public class ConfigBag {
return getStringKeyMaybe(key, markUsed).orNull();
}
+ private synchronized Maybe<Object> getRawKeyMaybe(ConfigKey<?> key, boolean markUsed) {
+ Maybe<Object> val = getRawStringKeyMaybe(key.getName(), markUsed);
+
+ String firstDeprecatedName = null;
+ Maybe<Object> firstDeprecatedVal = null;
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ Maybe<Object> deprecatedVal = getRawStringKeyMaybe(deprecatedName, markUsed);
+ if (deprecatedVal.isPresent()) {
+ if (val.isPresent()) {
+ if (!Objects.equal(val.get(), deprecatedVal.get())) {
+ log.warn("Conflicting value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using value from preferred name "+key.getName());
+ } else {
+ log.warn("Duplicate value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using same value from preferred name "+key.getName());
+ }
+ } else if (firstDeprecatedVal.isPresent()) {
+ if (!Objects.equal(firstDeprecatedVal.get(), deprecatedVal.get())) {
+ log.warn("Conflicting value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using earlier deprecated name "+firstDeprecatedName);
+ } else {
+ log.warn("Duplicate value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using same value from earlier depreated name "+key.getName());
+ }
+ } else {
+ // new value, from deprecated name
+ log.warn("Value for key "+key+" found with deprecated name '"+deprecatedName+"'; "
+ + "recommend changing to preferred name '"+key.getName()+"'; this will not be supported in future versions");
+ firstDeprecatedName = deprecatedName;
+ firstDeprecatedVal = deprecatedVal;
+ }
+ }
+ }
+
+
+ return val.isPresent() ? val : (firstDeprecatedVal != null && firstDeprecatedVal.isPresent() ? firstDeprecatedVal : val);
+ }
+
private synchronized Maybe<Object> getRawStringKeyMaybe(String key, boolean markUsed) {
if (config.containsKey(key)) {
if (markUsed) markUsed(key);
@@ -518,6 +574,46 @@ public class ConfigBag {
/**
* @return Unresolved configuration value. May be overridden to provide resolution - @see {@link ResolvingConfigBag#getStringKeyMaybe(String, boolean)}
*/
+ protected synchronized Maybe<Object> getKeyMaybe(ConfigKey<?> key, boolean markUsed) {
+ Maybe<Object> val = getStringKeyMaybe(key.getName(), markUsed);
+
+ String firstDeprecatedName = null;
+ Maybe<Object> firstDeprecatedVal = null;
+ for (String deprecatedName : key.getDeprecatedNames()) {
+ Maybe<Object> deprecatedVal = getStringKeyMaybe(deprecatedName, markUsed);
+ if (deprecatedVal.isPresent()) {
+ if (val.isPresent()) {
+ if (!Objects.equal(val.get(), deprecatedVal.get())) {
+ log.warn("Conflicting value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using value from preferred name "+key.getName());
+ } else {
+ log.warn("Duplicate value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using same value from preferred name "+key.getName());
+ }
+ } else if (firstDeprecatedVal != null) {
+ if (!Objects.equal(firstDeprecatedVal.get(), deprecatedVal.get())) {
+ log.warn("Conflicting value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using earlier deprecated name "+firstDeprecatedName);
+ } else {
+ log.warn("Duplicate value for key "+key+" from deprecated name '"+deprecatedName+"'; "
+ + "using same value from earlier depreated name "+key.getName());
+ }
+ } else {
+ // new value, from deprecated name
+ log.warn("Value for key "+key+" found with deprecated name '"+deprecatedName+"'; "
+ + "recommend changing to preferred name '"+key.getName()+"'; this will not be supported in future versions");
+ firstDeprecatedName = deprecatedName;
+ firstDeprecatedVal = deprecatedVal;
+ }
+ }
+ }
+
+ return val.isPresent() ? val : (firstDeprecatedVal != null && firstDeprecatedVal.isPresent() ? firstDeprecatedVal : val);
+ }
+
+ /**
+ * @return Unresolved configuration value. May be overridden to provide resolution - @see {@link ResolvingConfigBag#getStringKeyMaybe(String, boolean)}
+ */
protected synchronized Maybe<Object> getStringKeyMaybe(String key, boolean markUsed) {
return getRawStringKeyMaybe(key, markUsed);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java b/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
index 53af175..5dcd90d 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
@@ -164,6 +164,12 @@ public class ResolvingConfigBag extends ConfigBag {
}
@Override
+ protected synchronized Maybe<Object> getKeyMaybe(ConfigKey<?> key, boolean markUsed) {
+ Maybe<Object> result = super.getKeyMaybe(key, markUsed);
+ return (result.isPresent()) ? Maybe.of(getTransformer().apply(result.get())) : result;
+ }
+
+ @Override
public Map<String,Object> getAllConfigMutable() {
throw new UnsupportedOperationException();
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java b/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
index d160a93..27b75cd 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
@@ -272,7 +272,7 @@ public class FlagUtils {
FlagConfigKeyAndValueRecord result = new FlagConfigKeyAndValueRecord();
result.configKey = key;
if (key!=null && input.containsKey(key))
- result.configKeyValue = Maybe.<Object>of(input.getStringKey(key.getName()));
+ result.configKeyValue = input.getObjKeyMaybe(key);
if (f != null) {
SetFromFlag flag = f.getAnnotation(SetFromFlag.class);
if (flag!=null) {
@@ -408,7 +408,7 @@ public class FlagUtils {
// first check whether it is a key
ConfigKey<?> key = getFieldAsConfigKey(o, f);
if (key!=null && bag.containsKey(key)) {
- Object uncoercedValue = bag.getStringKey(key.getName());
+ Object uncoercedValue = bag.getObjKeyMaybe(key).get();
setField(o, f, uncoercedValue, optionalAnnotation);
return;
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
new file mode 100644
index 0000000..b20f574
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.config;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.List;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.api.objs.BrooklynObjectType;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+import org.apache.brooklyn.core.entity.AbstractApplication;
+import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.feed.AbstractFeed;
+import org.apache.brooklyn.core.location.AbstractLocation;
+import org.apache.brooklyn.core.mgmt.rebind.AbstractRebindHistoricTest;
+import org.apache.brooklyn.core.policy.AbstractPolicy;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
+public class ConfigKeyDeprecationRebindTest extends AbstractRebindHistoricTest {
+
+ @Test
+ public void testUsingDeprecatedName() throws Exception {
+ MyApp entity = app().addChild(EntitySpec.create(MyApp.class)
+ .configure("oldKey1", "myval"));
+ assertEquals(entity.config().get(MyApp.KEY_1), "myval");
+
+ rebind();
+
+ Entity newEntity = mgmt().getEntityManager().getEntity(entity.getId());
+ assertEquals(newEntity.config().get(MyApp.KEY_1), "myval");
+
+ // Expect the persisted state of the entity to have used the non-deprecated name.
+ String allLines = getPersistanceFileContents(BrooklynObjectType.ENTITY, newEntity.getId());
+ assertFalse(allLines.contains("oldKey1"), "contains 'oldKey1', allLines="+allLines);
+ assertTrue(allLines.contains("key1"), "contains 'key1', allLines="+allLines);
+ }
+
+ /**
+ * Created with:
+ * <pre>
+ * {@code
+ * Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class)
+ * .configure("oldKey1", "myval"));
+ * }
+ * </pre>
+ */
+ @Test
+ public void testEntityPersistedWithDeprecatedKeyName() throws Exception {
+ String appId = "pps2ttgijb";
+ addMemento(BrooklynObjectType.ENTITY, "config-deprecated-key", appId);
+ rebind();
+
+ Entity newApp = mgmt().getEntityManager().getEntity(appId);
+ assertEquals(newApp.config().get(MyApp.KEY_1), "myval");
+
+ // Expect the persisted state to have been re-written with the new key value.
+ switchOriginalToNewManagementContext();
+ rebind();
+
+ String allLines = getPersistanceFileContents(BrooklynObjectType.ENTITY, appId);
+ assertFalse(allLines.contains("oldKey1"), "should not contain 'oldKey1', allLines="+allLines);
+ assertTrue(allLines.contains("<key1>"), "should contain '<key1>', allLines="+allLines);
+ }
+
+ /**
+ * Created with:
+ * <pre>
+ * {@code
+ * Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class)
+ * .configure("oldFlagKey2", "myval"));
+ * }
+ * </pre>
+ */
+ @Test
+ public void testEntityPersistedWithSetFromFlagNameOnKey() throws Exception {
+ String appId = "ug77ek2tkd";
+ addMemento(BrooklynObjectType.ENTITY, "config-deprecated-flagNameOnKey", appId);
+ rebind();
+
+ Entity newApp = mgmt().getEntityManager().getEntity(appId);
+ assertEquals(newApp.config().get(MyApp.KEY_2), "myval");
+
+ // Expect the persisted state to have been re-written with the new key value.
+ switchOriginalToNewManagementContext();
+ rebind();
+
+ String allLines = getPersistanceFileContents(BrooklynObjectType.ENTITY, appId);
+ assertFalse(allLines.contains("oldFlagKey2"), "should not contain 'oldFlagKey2', allLines="+allLines);
+ assertTrue(allLines.contains("<key2>"), "should contain '<key1>', allLines="+allLines);
+ }
+
+ /**
+ * Created with:
+ * <pre>
+ * {@code
+ * Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class)
+ * .policy(PolicySpec.create(MyPolicy.class)
+ * .configure("field1", "myval")));
+ * }
+ * </pre>
+ */
+ @Test
+ public void testPolicyPersistedWithSetFromFlagNameOnField() throws Exception {
+ String appId = "vfncjpljqf";
+ String policyId = "alq7mtwv0m";
+ addMemento(BrooklynObjectType.ENTITY, "config-deprecated-flagNameOnField-policyOwner", appId);
+ addMemento(BrooklynObjectType.POLICY, "config-deprecated-flagNameOnField-policy", policyId);
+ rebind();
+
+ MyApp newApp = (MyApp) mgmt().getEntityManager().getEntity(appId);
+ MyPolicy newPolicy = (MyPolicy) Iterables.find(newApp.policies(), Predicates.instanceOf(MyPolicy.class));
+ assertEquals(newPolicy.getField1(), "myval");
+ assertEquals(newPolicy.config().get(MyPolicy.REPLACEMENT_FOR_FIELD_1), "myval");
+
+ // Expect the persisted state to have been re-written with the new key value.
+ switchOriginalToNewManagementContext();
+ rebind();
+
+ String allLines = getPersistanceFileContents(BrooklynObjectType.POLICY, policyId);
+ assertFalse(allLines.contains("<field1>"), "should not contain '<field1>', allLines="+allLines);
+ assertTrue(allLines.contains("<replacementForField1>"), "should contain '<replacementForField1>', allLines="+allLines);
+ }
+
+ /**
+ * Created with:
+ * <pre>
+ * {@code
+ * Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class)
+ * .enricher(EnricherSpec.create(MyEnricher.class)
+ * .configure("oldKey1", "myval1")
+ * .configure("field1", "myval2")));
+ * }
+ * </pre>
+ */
+ @Test
+ public void testEnricherPersisted() throws Exception {
+ String appId = "sb5w8w5tq0";
+ String enricherId = "j8rvs5fc16";
+ addMemento(BrooklynObjectType.ENTITY, "config-deprecated-enricherOwner", appId);
+ addMemento(BrooklynObjectType.ENRICHER, "config-deprecated-enricher", enricherId);
+ rebind();
+
+ MyApp newApp = (MyApp) mgmt().getEntityManager().getEntity(appId);
+ MyEnricher newEnricher = (MyEnricher) Iterables.find(newApp.enrichers(), Predicates.instanceOf(MyEnricher.class));
+ assertEquals(newEnricher.config().get(MyEnricher.KEY_1), "myval1");
+ assertEquals(newEnricher.getField1(), "myval2");
+ assertEquals(newEnricher.config().get(MyEnricher.REPLACEMENT_FOR_FIELD_1), "myval2");
+
+ // Expect the persisted state to have been re-written with the new key value.
+ switchOriginalToNewManagementContext();
+ rebind();
+
+ String allLines = getPersistanceFileContents(BrooklynObjectType.ENRICHER, enricherId);
+ assertFalse(allLines.contains("<field1>"), "should not contain '<field1>', allLines="+allLines);
+ assertFalse(allLines.contains("<oldKey1>"), "should not contain '<oldKey1>', allLines="+allLines);
+ assertTrue(allLines.contains("<key1>"), "should contain '<key1>', allLines="+allLines);
+ assertTrue(allLines.contains("<replacementForField1>"), "should contain '<replacementForField1>', allLines="+allLines);
+ }
+
+ /**
+ * Created with:
+ * <pre>
+ * {@code
+ * MyApp app = mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class));
+ * MyFeed feed = app.feeds().add(new MyFeed());
+ * feed.config().set(MyFeed.KEY_1, "myval1");
+ * feed.config().set(ImmutableMap.of("oldKey2", "myval2"));
+ * }
+ * </pre>
+ */
+ @Test
+ public void testFeedPersisted() throws Exception {
+ String appId = "d8p4p8o4x7";
+ String feedId = "km6gu420a0";
+ addMemento(BrooklynObjectType.ENTITY, "config-deprecated-feedOwner", appId);
+ addMemento(BrooklynObjectType.FEED, "config-deprecated-feed", feedId);
+ rebind();
+
+ MyApp newApp = (MyApp) mgmt().getEntityManager().getEntity(appId);
+ MyFeed newFeed = (MyFeed) Iterables.find(newApp.feeds().getFeeds(), Predicates.instanceOf(MyFeed.class));
+ assertEquals(newFeed.config().get(MyFeed.KEY_1), "myval1");
+ assertEquals(newFeed.config().get(MyFeed.KEY_2), "myval2");
+
+ // Expect the persisted state to have been re-written with the new key value.
+ switchOriginalToNewManagementContext();
+ rebind();
+
+ String allLines = getPersistanceFileContents(BrooklynObjectType.FEED, feedId);
+ assertFalse(allLines.contains("<oldKey1>"), "should not contain '<oldKey1>', allLines="+allLines);
+ assertFalse(allLines.contains("<oldKey2>"), "should not contain '<oldKey2>', allLines="+allLines);
+ assertTrue(allLines.contains("<key1>"), "should contain '<key1>', allLines="+allLines);
+ assertTrue(allLines.contains("<key2>"), "should contain '<key2>', allLines="+allLines);
+ }
+
+ /**
+ * Created with:
+ * <pre>
+ * {@code
+ * MyLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyLocation.class)
+ * .configure("field1", "myval"));
+ * }
+ * </pre>
+ */
+ @Test
+ public void testLocationPersistedWithSetFromFlagNameOnField() throws Exception {
+ String locId = "f4kj5hxcvx";
+ addMemento(BrooklynObjectType.LOCATION, "config-deprecated-flagNameOnField-location", locId);
+ rebind();
+
+ MyLocation newLoc = (MyLocation) mgmt().getLocationManager().getLocation(locId);
+ assertEquals(newLoc.getField1(), "myval");
+ assertEquals(newLoc.config().get(MyLocation.REPLACEMENT_FOR_FIELD_1), "myval");
+
+ // Expect the persisted state to have been re-written with the new key value.
+ switchOriginalToNewManagementContext();
+ rebind();
+
+ String allLines = getPersistanceFileContents(BrooklynObjectType.LOCATION, locId);
+ assertFalse(allLines.contains("<field1>"), "should not contain '<field1>', allLines="+allLines);
+ assertTrue(allLines.contains("<replacementForField1>"), "should contain '<replacementForField1>', allLines="+allLines);
+ }
+
+ protected String getPersistanceFileContents(BrooklynObjectType type, String id) throws Exception {
+ File file = getPersistanceFile(type, id);
+ List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
+ return Joiner.on("\n").join(lines);
+ }
+
+ /**
+ * Interface previously had:
+ * <pre>
+ * {@code
+ * ConfigKey<String> KEY_1 = ConfigKeys.newStringConfigKey("oldKey1");
+ *
+ * @SetFromFlag("oldFlagKey2")
+ * ConfigKey<String> KEY_2 = ConfigKeys.newStringConfigKey("key2");
+ * }
+ * </pre>
+ */
+ @ImplementedBy(MyAppImpl.class)
+ public interface MyApp extends Application, EntityInternal {
+ ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1")
+ .build();
+
+ ConfigKey<String> KEY_2 = ConfigKeys.builder(String.class, "key2")
+ .deprecatedNames("oldFlagKey2")
+ .build();
+ }
+
+ public static class MyAppImpl extends AbstractApplication implements MyApp {
+ @Override
+ protected void initEnrichers() {
+ // no-op; no standard enrichers to keep state small and simple
+ }
+ }
+
+ /**
+ * Class previously had:
+ * <pre>
+ * {@code
+ * @SetFromFlag("field1")
+ * private String field1;
+ * }
+ * </pre>
+ */
+ public static class MyLocation extends AbstractLocation {
+ public static final ConfigKey<String> REPLACEMENT_FOR_FIELD_1 = ConfigKeys.builder(String.class, "replacementForField1")
+ .deprecatedNames("field1")
+ .build();
+
+ public String getField1() {
+ return config().get(REPLACEMENT_FOR_FIELD_1);
+ }
+ }
+
+ /**
+ * Class previously had:
+ * <pre>
+ * {@code
+ * @SetFromFlag("field1")
+ * private String field1;
+ * }
+ * </pre>
+ */
+ public static class MyPolicy extends AbstractPolicy {
+ public static final ConfigKey<String> REPLACEMENT_FOR_FIELD_1 = ConfigKeys.builder(String.class, "replacementForField1")
+ .deprecatedNames("field1")
+ .build();
+
+
+ public String getField1() {
+ return config().get(REPLACEMENT_FOR_FIELD_1);
+ }
+ }
+
+ /**
+ * Class previously had:
+ * <pre>
+ * {@code
+ * public static final ConfigKey<String> KEY_1 = ConfigKeys.newStringConfigKey("oldKey1");
+ * @SetFromFlag("field1")
+ * private String field1;
+ * }
+ * </pre>
+ */
+ public static class MyEnricher extends AbstractEnricher {
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1")
+ .build();
+
+ public static final ConfigKey<String> REPLACEMENT_FOR_FIELD_1 = ConfigKeys.builder(String.class, "replacementForField1")
+ .deprecatedNames("field1")
+ .build();
+
+ public String getField1() {
+ return config().get(REPLACEMENT_FOR_FIELD_1);
+ }
+
+ public String getKey1() {
+ return config().get(KEY_1);
+ }
+ }
+ /**
+ * Class previously had:
+ * <pre>
+ * {@code
+ * public static final ConfigKey<String> KEY_1 = ConfigKeys.newStringConfigKey("oldKey1");
+ * @SetFromFlag("oldKey2")
+ * public static final ConfigKey<String> KEY_2 = ConfigKeys.newStringConfigKey("key2");
+ * }
+ * </pre>
+ */
+ public static class MyFeed extends AbstractFeed {
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1")
+ .build();
+
+ public static final ConfigKey<String> KEY_2 = ConfigKeys.builder(String.class, "key2")
+ .deprecatedNames("oldKey2")
+ .build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
new file mode 100644
index 0000000..7ab57cd
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.config;
+
+import static org.testng.Assert.assertEquals;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntityInitializer;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.policy.PolicySpec;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.enricher.AbstractEnricher;
+import org.apache.brooklyn.core.entity.AbstractEntity;
+import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal;
+import org.apache.brooklyn.core.location.AbstractLocation;
+import org.apache.brooklyn.core.policy.AbstractPolicy;
+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.test.LogWatcher;
+import org.apache.brooklyn.test.LogWatcher.EventPredicates;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+
+public class ConfigKeyDeprecationTest extends BrooklynAppUnitTestSupport {
+
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ConfigKeyDeprecationTest.class);
+
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1", "oldKey1b")
+ .build();
+
+ @Test
+ public void testUsingDeprecatedName() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class)
+ .configure("oldSuperKey1", "myval"));
+ EntityInternal entity2 = app.addChild(EntitySpec.create(MyBaseEntity.class)
+ .configure("oldSuperKey1b", "myval"));
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval");
+ assertEquals(entity2.config().get(MyBaseEntity.SUPER_KEY_1), "myval");
+ }
+
+ @Test
+ public void testPrefersNonDeprecatedName() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class)
+ .configure("superKey1", "myval")
+ .configure("oldSuperKey1", "mywrongval"));
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval");
+ }
+
+ @Test
+ public void testPrefersFirstDeprecatedNameIfMultiple() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class)
+ .configure("oldSuperKey1", "myval1")
+ .configure("oldSuperKey1b", "myval2"));
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval1");
+ }
+
+ @Test
+ public void testInheritsDeprecatedKeyFromRuntimeParent() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class)
+ .configure("oldSuperKey1", "myval"));
+ EntityInternal child = entity.addChild(EntitySpec.create(MyBaseEntity.class));
+ assertEquals(child.config().get(MyBaseEntity.SUPER_KEY_1), "myval");
+ }
+
+ @Test
+ public void testInheritsDeprecatedKeyFromSuperType() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MySubEntity.class)
+ .configure("oldSuperKey1", "myval")
+ .configure("oldSuperKey2", "myval2")
+ .configure("oldSubKey2", "myval3")
+ .configure("oldInterfaceKey1", "myval4"));
+ assertEquals(entity.config().get(MySubEntity.SUPER_KEY_1), "myval");
+ assertEquals(entity.config().get(MySubEntity.SUPER_KEY_2), "myval2");
+ assertEquals(entity.config().get(MySubEntity.SUB_KEY_2), "myval3");
+ assertEquals(entity.config().get(MyInterface.INTERFACE_KEY_1), "myval4");
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInLocation() throws Exception {
+ MyLocation loc = mgmt.getLocationManager().createLocation(LocationSpec.create(MyLocation.class)
+ .configure("oldKey1", "myval"));
+ assertEquals(loc.config().get(MyLocation.KEY_1), "myval");
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInPolicy() throws Exception {
+ MyPolicy policy = app.policies().add(PolicySpec.create(MyPolicy.class)
+ .configure("oldKey1", "myval"));
+ assertEquals(policy.config().get(MyPolicy.KEY_1), "myval");
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInEnricher() throws Exception {
+ MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class)
+ .configure("oldKey1", "myval"));
+ assertEquals(enricher.config().get(MyEnricher.KEY_1), "myval");
+ }
+
+ @Test
+ public void testUsingDeprecatedNameInEntityInitializer() throws Exception {
+ Entity entity = app.addChild(EntitySpec.create(BasicEntity.class)
+ .addInitializer(new MyEntityInitializer(ConfigBag.newInstance(ImmutableMap.of("oldKey1", "myval")))));
+ assertEquals(entity.config().get(MyEntityInitializer.KEY_1), "myval");
+ }
+
+ @Test
+ public void testSetConfigUsingDeprecatedName() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class));
+
+ // Set using strongly typed key
+ entity.config().set(MyBaseEntity.SUPER_KEY_1, "myval");
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval");
+
+ // Set using correct string
+ entity.config().putAll(ImmutableMap.of("superKey1", "myval2"));
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval2");
+
+ // Set using deprecated name
+ entity.config().putAll(ImmutableMap.of("oldSuperKey1", "myval3"));
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval3");
+
+ // Set using pseudo-generated strongly typed key with deprecated name
+ entity.config().set(ConfigKeys.newConfigKey(Object.class, "oldSuperKey1"), "myval4");
+ assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval4");
+ }
+
+ @Test
+ public void testSetAndGetDynamicConfigUsingDeprecatedName() throws Exception {
+ // Using BasicEntity, which doesn't know about KEY_1
+ EntityInternal entity = (EntityInternal) app.addChild(EntitySpec.create(BasicEntity.class));
+
+ // Set using deprecated name
+ entity.config().putAll(ImmutableMap.of("oldKey1", "myval3"));
+ assertEquals(entity.config().get(KEY_1), "myval3");
+
+ // Set using pseudo-generated strongly typed key with deprecated name
+ entity.config().set(ConfigKeys.newConfigKey(Object.class, "oldKey1"), "myval4");
+ assertEquals(entity.config().get(KEY_1), "myval4");
+ }
+
+ /*
+ // Setting the value of a "dynamic config key" when using the deprecated key will not overwrite
+ // any existing value that was set using the real config key name. I think this is because
+ // EntityDynamicType.addConfigKey() is not called when KEY_1 is first set, so it doesn't have
+ // access to the deprecated names on subsequent calls to set(String, val). It therefore stores
+ // in EntityConfigMap (backed by a ConfigBag) the original key-value and the deprecated key-value.
+ // When we subsequently call get(key), it retrieved the original key-value.
+ //
+ // Contrast this with EntityDynamicType.addSensorIfAbsent().
+ //
+ * However, it's (probably) not straight forward to just add and call a addConfigKeyIfAbsent. This
+ * is because config().set() is used for dynamic config declard in yaml, which the entity doesn't
+ * understand but that will be inherited by runtime children.
+ */
+ @Test(groups="Broken")
+ public void testSetAndGetDynamicConfigUsingDeprecatedNameOverwritesExistingValue() throws Exception {
+ // Using BasicEntity, which doesn't know about KEY_1
+ EntityInternal entity = (EntityInternal) app.addChild(EntitySpec.create(BasicEntity.class));
+
+ // Set using strongly typed key
+ entity.config().set(KEY_1, "myval");
+ assertEquals(entity.config().get(KEY_1), "myval");
+
+ // Set using correct string
+ entity.config().putAll(ImmutableMap.of("key1", "myval2"));
+ assertEquals(entity.config().get(KEY_1), "myval2");
+
+ // Set using deprecated name
+ entity.config().putAll(ImmutableMap.of("oldKey1", "myval3"));
+ assertEquals(entity.config().get(KEY_1), "myval3");
+
+ // Set using pseudo-generated strongly typed key with deprecated name
+ entity.config().set(ConfigKeys.newConfigKey(Object.class, "oldKey1"), "myval4");
+ assertEquals(entity.config().get(KEY_1), "myval4");
+ }
+
+ @Test
+ public void testLogsIfDeprecatedNameUsed() throws Exception {
+ // FIXME Which logger?
+ String loggerName = ConfigUtilsInternal.class.getName();
+ ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN;
+ Predicate<ILoggingEvent> filter = EventPredicates.containsMessages(
+ "Using deprecated config value on MyBaseEntity",
+ "should use 'superKey1', but used 'oldSuperKey1'");
+ LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter);
+
+ watcher.start();
+ try {
+ testUsingDeprecatedName();
+ watcher.assertHasEvent();
+ } finally {
+ watcher.close();
+ }
+ }
+
+
+ @Test
+ public void testLogsWarningIfNonDeprecatedAndDeprecatedNamesUsed() throws Exception {
+ String loggerName = ConfigUtilsInternal.class.getName();
+ ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN;
+ Predicate<ILoggingEvent> filter = EventPredicates.containsMessages(
+ "Ignoring deprecated config value(s) on MyBaseEntity",
+ "because contains value for 'superKey1', other deprecated name(s) present were: [oldSuperKey1]");
+ LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter);
+
+ watcher.start();
+ try {
+ testPrefersNonDeprecatedName();
+ watcher.assertHasEvent();
+ } finally {
+ watcher.close();
+ }
+ }
+
+ @Test
+ public void testLogsWarningIfMultipleDeprecatedNamesUsed() throws Exception {
+ String loggerName = ConfigUtilsInternal.class.getName();
+ ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN;
+ Predicate<ILoggingEvent> filter = EventPredicates.containsMessages(
+ "Using deprecated config value on MyBaseEntity",
+ "should use 'superKey1', but used 'oldSuperKey1b' and ignored values present for other deprecated name(s) [oldSuperKey1b]");
+ LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter);
+
+ watcher.start();
+ try {
+ testPrefersFirstDeprecatedNameIfMultiple();
+ watcher.assertHasEvent();
+ } finally {
+ watcher.close();
+ }
+ }
+
+ @ImplementedBy(MyBaseEntityImpl.class)
+ public interface MyBaseEntity extends EntityInternal {
+ ConfigKey<String> SUPER_KEY_1 = ConfigKeys.builder(String.class, "superKey1")
+ .deprecatedNames("oldSuperKey1", "oldSuperKey1b")
+ .build();
+ ConfigKey<String> SUPER_KEY_2 = ConfigKeys.builder(String.class, "superKey2")
+ .deprecatedNames("oldSuperKey2")
+ .build();
+ }
+
+ public static class MyBaseEntityImpl extends AbstractEntity implements MyBaseEntity {
+ }
+
+ @ImplementedBy(MySubEntityImpl.class)
+ public interface MySubEntity extends MyBaseEntity, MyInterface {
+ ConfigKey<String> SUPER_KEY_1 = ConfigKeys.newConfigKeyWithDefault(MyBaseEntity.SUPER_KEY_1, "overridden superKey1 default");
+ ConfigKey<String> SUB_KEY_2 = ConfigKeys.builder(String.class, "subKey2")
+ .deprecatedNames("oldSubKey2")
+ .build();
+ }
+
+ public static class MySubEntityImpl extends MyBaseEntityImpl implements MySubEntity {
+ }
+
+ public interface MyInterface {
+ ConfigKey<String> INTERFACE_KEY_1 = ConfigKeys.builder(String.class, "interfaceKey1")
+ .deprecatedNames("oldInterfaceKey1")
+ .build();
+ }
+
+ public static class MyLocation extends AbstractLocation {
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1", "oldKey1b")
+ .build();
+ }
+
+ public static class MyPolicy extends AbstractPolicy {
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1", "oldKey1b")
+ .build();
+ }
+
+ public static class MyEnricher extends AbstractEnricher {
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1", "oldKey1b")
+ .build();
+ }
+
+ public static class MyEntityInitializer implements EntityInitializer {
+ public static final ConfigKey<String> KEY_1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1", "oldKey1b")
+ .build();
+
+ private String key1;
+
+ public MyEntityInitializer(ConfigBag params) {
+ this.key1 = params.get(KEY_1);
+ }
+
+ @Override
+ public void apply(EntityLocal entity) {
+ entity.config().set(KEY_1, key1);
+ }
+ }
+}
[2/6] brooklyn-server git commit: Support configKey.deprecatedNames
Posted by ge...@apache.org.
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/java/org/apache/brooklyn/core/config/MapConfigKeyAndFriendsDeprecationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/MapConfigKeyAndFriendsDeprecationTest.java b/core/src/test/java/org/apache/brooklyn/core/config/MapConfigKeyAndFriendsDeprecationTest.java
new file mode 100644
index 0000000..6103c86
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/config/MapConfigKeyAndFriendsDeprecationTest.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.config;
+
+import static org.testng.Assert.assertEquals;
+
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.core.entity.AbstractEntity;
+import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class MapConfigKeyAndFriendsDeprecationTest extends BrooklynAppUnitTestSupport {
+
+ @Test
+ public void testUsingDeprecatedName() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyEntity.class)
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey", "myval")));
+ assertEquals(entity.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval"));
+ }
+
+ @Test
+ public void testUsingDeprecatedNameSubkey() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyEntity.class)
+ .configure("confMapDeepMerge.mykey", "myval"));
+ assertEquals(entity.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval"));
+ }
+
+ @Test
+ public void testPrefersNonDeprecatedName() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyEntity.class)
+ .configure("confMapDeepMerge", ImmutableMap.of("mykey", "myval"))
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("wrongkey", "wrongval")));
+ assertEquals(entity.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval"));
+ }
+
+ @Test
+ public void testInheritsDeprecatedKeyFromRuntimeParent() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class)
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey", "myval"))
+ .configure("oldConfMapNotReinherited", ImmutableMap.of("mykey", "myval")));
+ EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class));
+ assertEquals(child.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval"));
+ assertEquals(child.config().get(MyEntity.CONF_MAP_NOT_REINHERITED), ImmutableMap.of("mykey", "myval"));
+ }
+
+ @Test
+ public void testMergesDeprecatedKeyFromRuntimeParent() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class)
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey", "myval")));
+ EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class)
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey2", "myval2")));
+ assertEquals(child.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
+ }
+
+ @Test
+ public void testMergesDeprecatedKeyFromRuntimeParentWithOwn() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class)
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey", "myval")));
+ EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class)
+ .configure("confMapDeepMerge", ImmutableMap.of("mykey2", "myval2")));
+ assertEquals(child.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
+ }
+
+ @Test
+ public void testMergesKeyFromRuntimeParentWithOwnDeprecated() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class)
+ .configure("confMapDeepMerge", ImmutableMap.of("mykey", "myval")));
+ EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class)
+ .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey2", "myval2")));
+ assertEquals(child.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
+ }
+
+ @Test
+ public void testDeprecatedKeyNotReinheritedIfNotSupposedToBe() throws Exception {
+ EntityInternal entity = app.addChild(EntitySpec.create(MyEntity.class)
+ .configure("oldConfMapNotReinherited", ImmutableMap.of("mykey", "myval")));
+ EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class));
+ assertEquals(entity.config().get(MyEntity.CONF_MAP_NOT_REINHERITED), ImmutableMap.of("mykey", "myval"));
+ assertEquals(child.config().get(MyEntity.CONF_MAP_NOT_REINHERITED), null);
+ }
+
+ @ImplementedBy(MyEntityImpl.class)
+ public interface MyEntity extends EntityInternal {
+ MapConfigKey<String> CONF_MAP_DEEP_MERGE = new MapConfigKey.Builder<String>(String.class, "confMapDeepMerge")
+ .deprecatedNames("oldConfMapDeepMerge")
+ .runtimeInheritance(BasicConfigInheritance.DEEP_MERGE)
+ .build();
+
+ MapConfigKey<Object> CONF_MAP_NOT_REINHERITED = new MapConfigKey.Builder<Object>(Object.class, "confMapNotReinherited")
+ .deprecatedNames("oldConfMapNotReinherited")
+ .runtimeInheritance(BasicConfigInheritance.NOT_REINHERITED)
+ .build();
+
+ // FIXME Need to support deprecatedNames for ListConfigKey and SetConfigKey?
+ ListConfigKey<String> CONF_LIST_THING = new ListConfigKey<String>(String.class, "test.confListThing", "Configuration key that's a list thing");
+ ListConfigKey<Object> CONF_LIST_OBJ_THING = new ListConfigKey<Object>(Object.class, "test.confListObjThing", "Configuration key that's a list thing, of objects");
+ SetConfigKey<String> CONF_SET_THING = new SetConfigKey<String>(String.class, "test.confSetThing", "Configuration key that's a set thing");
+ SetConfigKey<Object> CONF_SET_OBJ_THING = new SetConfigKey<Object>(Object.class, "test.confSetObjThing", "Configuration key that's a set thing, of objects");
+ }
+
+ public static class MyEntityImpl extends AbstractEntity implements MyEntity {
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternalTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternalTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternalTest.java
new file mode 100644
index 0000000..44d3ffb
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/internal/ConfigUtilsInternalTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.entity.internal;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class ConfigUtilsInternalTest extends BrooklynAppUnitTestSupport {
+
+ final ConfigKey<String> key1 = ConfigKeys.builder(String.class, "key1")
+ .deprecatedNames("oldKey1", "oldKey1b")
+ .build();
+
+ @Test
+ public void testSetConfig() throws Exception {
+ Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(ImmutableMap.of("key1", "myval"), ImmutableList.of(key1), app);
+ assertEquals(app.config().get(key1), "myval");
+ assertEquals(remaining, ImmutableMap.of());
+ }
+
+ @Test
+ public void testSetConfigUsingDeprecatedValue() throws Exception {
+ Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(ImmutableMap.of("oldKey1", "myval"), ImmutableList.of(key1), app);
+ assertEquals(app.config().get(key1), "myval");
+ assertEquals(remaining, ImmutableMap.of());
+ }
+
+ @Test
+ public void testSetConfigPrefersNonDeprecated() throws Exception {
+ Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(
+ ImmutableMap.of("key1", "myval", "oldKey1", "myOldVal1", "oldKey1b", "myOldVal1b"),
+ ImmutableList.of(key1),
+ app);
+ assertEquals(app.config().get(key1), "myval");
+
+ // Should remove deprecated value as well (and warn about it)
+ assertEquals(remaining, ImmutableMap.of());
+ }
+
+ @Test
+ public void testReturnsUnmatched() throws Exception {
+ Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(ImmutableMap.of("wrong", "myval"), ImmutableList.of(key1), app);
+ assertEquals(app.config().get(key1), null);
+ assertEquals(remaining, ImmutableMap.of("wrong", "myval"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricher-j8rvs5fc16
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricher-j8rvs5fc16 b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricher-j8rvs5fc16
new file mode 100644
index 0000000..9b15e24
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricher-j8rvs5fc16
@@ -0,0 +1,36 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<enricher>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyEnricher</type>
+ <id>j8rvs5fc16</id>
+ <displayName>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest.MyEnricher</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <oldKey1>myval1</oldKey1>
+ <field1>myval2</field1>
+ <uniqueTag>
+ <null/>
+ </uniqueTag>
+ <tags>
+ <set/>
+ </tags>
+ </config>
+</enricher>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricherOwner-sb5w8w5tq0
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricherOwner-sb5w8w5tq0 b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricherOwner-sb5w8w5tq0
new file mode 100644
index 0000000..6abc5fc
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-enricherOwner-sb5w8w5tq0
@@ -0,0 +1,36 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>sb5w8w5tq0</id>
+ <displayName>MyApp:sb5w</displayName>
+ <searchPath class="ImmutableList"/>
+ <attributes>
+ <entity.id>sb5w8w5tq0</entity.id>
+ <application.id>sb5w8w5tq0</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+ <enrichers>
+ <string>j8rvs5fc16</string>
+ </enrichers>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feed-km6gu420a0
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feed-km6gu420a0 b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feed-km6gu420a0
new file mode 100644
index 0000000..1d7f108
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feed-km6gu420a0
@@ -0,0 +1,30 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<feed>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyFeed</type>
+ <id>km6gu420a0</id>
+ <displayName>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest.MyFeed</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <oldKey1>myval1</oldKey1>
+ <oldKey2>myval2</oldKey2>
+ </config>
+</feed>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feedOwner-d8p4p8o4x7
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feedOwner-d8p4p8o4x7 b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feedOwner-d8p4p8o4x7
new file mode 100644
index 0000000..b2aacbf
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-feedOwner-d8p4p8o4x7
@@ -0,0 +1,36 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>d8p4p8o4x7</id>
+ <displayName>MyApp:d8p4</displayName>
+ <searchPath class="ImmutableList"/>
+ <attributes>
+ <entity.id>d8p4p8o4x7</entity.id>
+ <application.id>d8p4p8o4x7</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+ <feeds>
+ <string>km6gu420a0</string>
+ </feeds>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-e86eode5yy
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-e86eode5yy b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-e86eode5yy
new file mode 100644
index 0000000..ebeea74
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-e86eode5yy
@@ -0,0 +1,48 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>e86eode5yy</id>
+ <displayName>MyApp:e86e</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <field1>myval</field1>
+ </config>
+ <attributes>
+ <entity.id>e86eode5yy</entity.id>
+ <application.id>e86eode5yy</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+ <configKeys>
+ <field1>
+ <configKey>
+ <name>field1</name>
+ <deprecatedNames class="ImmutableList" reference="../../../../searchPath"/>
+ <type>java.lang.Object</type>
+ <description>field1</description>
+ <reconfigurable>false</reconfigurable>
+ <constraint class="com.google.common.base.Predicates$ObjectPredicate">ALWAYS_TRUE</constraint>
+ </configKey>
+ </field1>
+ </configKeys>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-location-f4kj5hxcvx
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-location-f4kj5hxcvx b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-location-f4kj5hxcvx
new file mode 100644
index 0000000..8e100a0
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-location-f4kj5hxcvx
@@ -0,0 +1,35 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<location>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyLocation</type>
+ <id>f4kj5hxcvx</id>
+ <displayName>MyLocation:f4kj</displayName>
+ <searchPath class="ImmutableList"/>
+ <locationConfig>
+ <field1>myval</field1>
+ <tags>
+ <set/>
+ </tags>
+ </locationConfig>
+ <locationConfigUnused>
+ <string>field1</string>
+ </locationConfigUnused>
+</location>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policy-alq7mtwv0m
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policy-alq7mtwv0m b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policy-alq7mtwv0m
new file mode 100644
index 0000000..15980df
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policy-alq7mtwv0m
@@ -0,0 +1,35 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<policy>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyPolicy</type>
+ <id>alq7mtwv0m</id>
+ <displayName>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest.MyPolicy</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <field1>myval</field1>
+ <uniqueTag>
+ <null/>
+ </uniqueTag>
+ <tags>
+ <set/>
+ </tags>
+ </config>
+</policy>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policyOwner-vfncjpljqf
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policyOwner-vfncjpljqf b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policyOwner-vfncjpljqf
new file mode 100644
index 0000000..8bb47ad
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnField-policyOwner-vfncjpljqf
@@ -0,0 +1,36 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>vfncjpljqf</id>
+ <displayName>MyApp:vfnc</displayName>
+ <searchPath class="ImmutableList"/>
+ <attributes>
+ <entity.id>vfncjpljqf</entity.id>
+ <application.id>vfncjpljqf</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+ <policies>
+ <string>alq7mtwv0m</string>
+ </policies>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnKey-ug77ek2tkd
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnKey-ug77ek2tkd b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnKey-ug77ek2tkd
new file mode 100644
index 0000000..561c81e
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-flagNameOnKey-ug77ek2tkd
@@ -0,0 +1,36 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>ug77ek2tkd</id>
+ <displayName>MyApp:ug77</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <key2>myval</key2>
+ </config>
+ <attributes>
+ <entity.id>ug77ek2tkd</entity.id>
+ <application.id>ug77ek2tkd</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-dyozzd948m
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-dyozzd948m b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-dyozzd948m
new file mode 100644
index 0000000..992d48e
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-dyozzd948m
@@ -0,0 +1,48 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>dyozzd948m</id>
+ <displayName>MyApp:dyoz</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <oldKey1>myval</oldKey1>
+ </config>
+ <attributes>
+ <entity.id>dyozzd948m</entity.id>
+ <application.id>dyozzd948m</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+ <configKeys>
+ <oldKey1>
+ <configKey>
+ <name>oldKey1</name>
+ <deprecatedNames class="ImmutableList" reference="../../../../searchPath"/>
+ <type>java.lang.Object</type>
+ <description>oldKey1</description>
+ <reconfigurable>false</reconfigurable>
+ <constraint class="com.google.common.base.Predicates$ObjectPredicate">ALWAYS_TRUE</constraint>
+ </configKey>
+ </oldKey1>
+ </configKeys>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-pps2ttgijb
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-pps2ttgijb b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-pps2ttgijb
new file mode 100644
index 0000000..541e79a
--- /dev/null
+++ b/core/src/test/resources/org/apache/brooklyn/core/config/config-deprecated-key-pps2ttgijb
@@ -0,0 +1,36 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<entity>
+ <brooklynVersion>0.12.0-SNAPSHOT</brooklynVersion>
+ <type>org.apache.brooklyn.core.config.ConfigKeyDeprecationRebindTest$MyAppImpl</type>
+ <id>pps2ttgijb</id>
+ <displayName>MyApp:pps2</displayName>
+ <searchPath class="ImmutableList"/>
+ <config>
+ <oldKey1>myval</oldKey1>
+ </config>
+ <attributes>
+ <entity.id>pps2ttgijb</entity.id>
+ <application.id>pps2ttgijb</application.id>
+ <catalog.id>
+ <null/>
+ </catalog.id>
+ </attributes>
+</entity>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/02b71ffb/utils/common/src/main/java/org/apache/brooklyn/config/ConfigKey.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/config/ConfigKey.java b/utils/common/src/main/java/org/apache/brooklyn/config/ConfigKey.java
index a494c0b..d5cc8f4 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/config/ConfigKey.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/config/ConfigKey.java
@@ -47,8 +47,17 @@ public interface ConfigKey<T> {
String getName();
/**
+ * Returns deprecated names that will could also be used, but that are discouraged and will
+ * likely not be supported for the given config key in future versions.
+ */
+ Collection<String> getDeprecatedNames();
+
+ /**
* Returns the constituent parts of the configuration parameter name as a {@link Collection}.
+ *
+ * @deprecated since 0.12.0; use {@link #getName()}
*/
+ @Deprecated
Collection<String> getNameParts();
/**