You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2017/01/24 12:27:08 UTC
[1/2] brooklyn-server git commit: BROOKLYN-404: improve
BrooklynProperties concurrency
Repository: brooklyn-server
Updated Branches:
refs/heads/master 972a0d8e1 -> 0570ca5a5
BROOKLYN-404: improve BrooklynProperties concurrency
BrooklynProperties no longer exposed as java.util.Map
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4c1fe060
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4c1fe060
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4c1fe060
Branch: refs/heads/master
Commit: 4c1fe06042eca2be3edcd8c603d8435559b4a9a9
Parents: 972a0d8
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jan 4 16:23:17 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Jan 24 10:14:30 2017 +0000
----------------------------------------------------------------------
.../brooklyn/core/config/ConfigUtils.java | 15 +-
.../core/internal/BrooklynProperties.java | 29 ++-
.../core/internal/BrooklynPropertiesImpl.java | 183 ++++++++++++++-----
.../core/location/BasicLocationDefinition.java | 4 +-
.../core/location/BasicLocationRegistry.java | 5 +-
.../BasicExternalConfigSupplierRegistry.java | 6 +-
.../internal/DeferredBrooklynProperties.java | 84 ++++-----
.../config/BrooklynPropertiesBuilderTest.java | 8 +-
.../core/config/BrooklynPropertiesTest.java | 13 +-
.../internal/LocalManagementContextTest.java | 6 +-
.../brooklyn/launcher/BrooklynLauncher.java | 2 +-
...lynLauncherRebindToCloudObjectStoreTest.java | 2 +-
.../jclouds/BailOutJcloudsLocation.java | 8 +-
.../location/jclouds/JcloudsLocationTest.java | 6 +-
.../brooklynnode/LocalBrooklynNodeImpl.java | 6 +-
15 files changed, 246 insertions(+), 131 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java b/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
index d5b0c41..bbccaa6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
@@ -35,6 +35,7 @@ import org.apache.brooklyn.core.config.WrappedConfigKey;
import org.apache.brooklyn.core.internal.BrooklynProperties;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.text.StringPredicates;
import org.apache.brooklyn.util.text.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,20 +82,18 @@ public class ConfigUtils {
public static BrooklynProperties filterFor(BrooklynProperties properties, Predicate<? super String> filter) {
BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: (Collection<String>)properties.keySet()) {
- if (filter.apply(k)) {
- result.put(k, properties.get(k));
- }
+ Set<ConfigKey<?>> keys = properties.findKeys(ConfigPredicates.nameSatisfies(filter));
+ for (ConfigKey<?> key : keys) {
+ result.put(key, properties.getConfig(key));
}
return result;
}
public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) {
BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: (Collection<String>)properties.keySet()) {
- if (k.startsWith(prefix)) {
- result.put(k, properties.get(k));
- }
+ Set<ConfigKey<?>> keys = properties.findKeys(ConfigPredicates.nameSatisfies(StringPredicates.startsWith(prefix)));
+ for (ConfigKey<?> key : keys) {
+ result.put(key, properties.getConfig(key));
}
return result;
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
index ad72e4a..9924a90 100644
--- a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
@@ -50,7 +50,7 @@ import com.google.common.base.Supplier;
* thereafter.
*/
@SuppressWarnings("rawtypes")
-public interface BrooklynProperties extends Map, StringConfigMap {
+public interface BrooklynProperties extends StringConfigMap {
public static class Factory {
private static final Logger LOG = LoggerFactory.getLogger(BrooklynProperties.Factory.class);
@@ -104,7 +104,7 @@ public interface BrooklynProperties extends Map, StringConfigMap {
* Creates a Builder that when built, will return the BrooklynProperties passed to this constructor
*/
private Builder(BrooklynProperties originalProperties) {
- this.originalProperties = new BrooklynPropertiesImpl().addFromMap(originalProperties);
+ this.originalProperties = new BrooklynPropertiesImpl().addFromMap(originalProperties.asMapWithStringKeys());
}
/**
@@ -157,7 +157,7 @@ public interface BrooklynProperties extends Map, StringConfigMap {
public BrooklynProperties build() {
if (originalProperties != null)
- return new BrooklynPropertiesImpl().addFromMap(originalProperties);
+ return new BrooklynPropertiesImpl().addFromMap(originalProperties.asMapWithStringKeys());
BrooklynProperties properties = new BrooklynPropertiesImpl();
@@ -181,6 +181,7 @@ public interface BrooklynProperties extends Map, StringConfigMap {
}
@Override
+ @SuppressWarnings("deprecation")
public String toString() {
return Objects.toStringHelper(this)
.omitNullValues()
@@ -280,11 +281,9 @@ public interface BrooklynProperties extends Map, StringConfigMap {
public String getFirst(Map flags, String ...keys);
/** like normal map.put, except config keys are dereferenced on the way in */
- @Override
public Object put(Object key, Object value);
- /** like normal map.putAll, except config keys are dereferenced on the way in */
- @Override
+ /** like normal {@link java.util.Map#putAll(Map)}, except config keys are dereferenced on the way in */
public void putAll(Map vals);
public <T> Object put(HasConfigKey<T> key, T value);
@@ -293,6 +292,21 @@ public interface BrooklynProperties extends Map, StringConfigMap {
public <T> boolean putIfAbsent(ConfigKey<T> key, T value);
+ @Beta
+ public boolean containsKey(String key);
+
+ @Beta
+ public boolean containsKey(ConfigKey<?> key);
+
+ @Beta
+ public boolean remove(String key);
+
+ @Beta
+ public boolean remove(ConfigKey<?> key);
+
+ @Beta
+ public Object getConfig(String key);
+
@Override
public <T> T getConfig(ConfigKey<T> key);
@@ -324,6 +338,9 @@ public interface BrooklynProperties extends Map, StringConfigMap {
@Override
public BrooklynProperties submap(Predicate<ConfigKey<?>> filter);
+ @Beta
+ public BrooklynProperties submapByName(Predicate<? super String> filter);
+
@Override
public Map<String, Object> asMapWithStringKeys();
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
index 6c50cde..10470d5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
@@ -62,9 +62,8 @@ import groovy.lang.Closure;
* intention is that they are set during startup and not modified thereafter.
*/
@SuppressWarnings("rawtypes")
-public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynProperties {
+public class BrooklynPropertiesImpl implements BrooklynProperties {
- private static final long serialVersionUID = -945875483083108978L;
private static final Logger LOG = LoggerFactory.getLogger(BrooklynPropertiesImpl.class);
public static class Factory {
@@ -122,7 +121,7 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
* Creates a Builder that when built, will return the BrooklynProperties passed to this constructor
*/
private Builder(BrooklynPropertiesImpl originalProperties) {
- this.originalProperties = new BrooklynPropertiesImpl().addFromMap(originalProperties);
+ this.originalProperties = new BrooklynPropertiesImpl().addFromMap(originalProperties.asMapWithStringKeys());
}
/**
@@ -167,7 +166,7 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
public BrooklynPropertiesImpl build() {
if (originalProperties != null)
- return new BrooklynPropertiesImpl().addFromMap(originalProperties);
+ return new BrooklynPropertiesImpl().addFromMap(originalProperties.asMapWithStringKeys());
BrooklynPropertiesImpl properties = new BrooklynPropertiesImpl();
@@ -190,6 +189,7 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
}
@Override
+ @SuppressWarnings("deprecation")
public String toString() {
return Objects.toStringHelper(this)
.omitNullValues()
@@ -226,6 +226,13 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
}
}
+ /**
+ * The actual properties.
+ * <p>
+ * Care must be taken accessing/modifying these, to ensure it is correctly synchronized.
+ */
+ private final Map<String, Object> contents = new LinkedHashMap<>();
+
protected BrooklynPropertiesImpl() {
}
@@ -343,17 +350,17 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
return true;
}
- /** @deprecated attempts to call get with this syntax are probably mistakes; get(key, defaultValue) is fine but
- * Map is unlikely the key, much more likely they meant getFirst(flags, key).
- */
- @Override
-@Deprecated
- public String get(Map flags, String key) {
- LOG.warn("Discouraged use of 'BrooklynProperties.get(Map,String)' (ambiguous); use getFirst(Map,String) or get(String) -- assuming the former");
- LOG.debug("Trace for discouraged use of 'BrooklynProperties.get(Map,String)'",
- new Throwable("Arguments: "+flags+" "+key));
- return getFirst(flags, key);
- }
+ /** @deprecated attempts to call get with this syntax are probably mistakes; get(key, defaultValue) is fine but
+ * Map is unlikely the key, much more likely they meant getFirst(flags, key).
+ */
+ @Override
+ @Deprecated
+ public String get(Map flags, String key) {
+ LOG.warn("Discouraged use of 'BrooklynProperties.get(Map,String)' (ambiguous); use getFirst(Map,String) or get(String) -- assuming the former");
+ LOG.debug("Trace for discouraged use of 'BrooklynProperties.get(Map,String)'",
+ new Throwable("Arguments: "+flags+" "+key));
+ return getFirst(flags, key);
+ }
/** returns the value of the first key which is defined
* <p>
@@ -398,11 +405,22 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
/** like normal map.put, except config keys are dereferenced on the way in */
@Override
- @SuppressWarnings("unchecked")
- public Object put(Object key, Object value) {
- if (key instanceof HasConfigKey) key = ((HasConfigKey)key).getConfigKey().getName();
- if (key instanceof ConfigKey) key = ((ConfigKey)key).getName();
- return super.put(key, value);
+ public Object put(Object rawKey, Object value) {
+ String key;
+ if (rawKey == null) {
+ throw new NullPointerException("Null key not permitted in BrooklynProperties");
+ } else if (rawKey instanceof String) {
+ key = (String) rawKey;
+ } else if (rawKey instanceof CharSequence) {
+ key = rawKey.toString();
+ } else if (rawKey instanceof HasConfigKey) {
+ key = ((HasConfigKey)rawKey).getConfigKey().getName();
+ } else if (rawKey instanceof ConfigKey) {
+ key = ((ConfigKey)rawKey).getName();
+ } else {
+ throw new IllegalArgumentException("Invalid key (value='" + rawKey + "', type=" + rawKey.getClass().getName() + ") for BrooklynProperties");
+ }
+ return putImpl(key, value);
}
/** like normal map.putAll, except config keys are dereferenced on the way in */
@@ -414,15 +432,13 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
}
@Override
- @SuppressWarnings("unchecked")
public <T> Object put(HasConfigKey<T> key, T value) {
- return super.put(key.getConfigKey().getName(), value);
+ return putImpl(key.getConfigKey().getName(), value);
}
@Override
- @SuppressWarnings("unchecked")
public <T> Object put(ConfigKey<T> key, T value) {
- return super.put(key.getName(), value);
+ return putImpl(key.getName(), value);
}
@Override
@@ -431,6 +447,11 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
}
@Override
+ public Object getConfig(String key) {
+ return get(key);
+ }
+
+ @Override
public <T> T getConfig(ConfigKey<T> key) {
return getConfig(key, null);
}
@@ -474,45 +495,119 @@ public class BrooklynPropertiesImpl extends LinkedHashMap implements BrooklynPro
return getConfigRaw(key);
}
- @Override
- public Map<ConfigKey<?>,Object> getAllConfigLocalRaw() {
- Map<ConfigKey<?>, Object> result = new LinkedHashMap<ConfigKey<?>, Object>();
- for (Object entry: entrySet())
- result.put(new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey()), ((Map.Entry)entry).getValue());
- return result;
- }
-
@Override @Deprecated
public Map<ConfigKey<?>, Object> getAllConfig() {
return getAllConfigLocalRaw();
}
@Override
+ public Map<ConfigKey<?>,Object> getAllConfigLocalRaw() {
+ Map<ConfigKey<?>, Object> result = new LinkedHashMap<>();
+ synchronized (contents) {
+ for (Map.Entry<String, Object> entry : contents.entrySet()) {
+ result.put(new BasicConfigKey<Object>(Object.class, entry.getKey()), entry.getValue());
+ }
+ }
+ return result;
+ }
+
+ @Override
public Set<ConfigKey<?>> findKeys(Predicate<? super ConfigKey<?>> filter) {
- Set<ConfigKey<?>> result = new LinkedHashSet<ConfigKey<?>>();
- for (Object entry: entrySet()) {
- ConfigKey<?> k = new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey());
- if (filter.apply(k))
- result.add(new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey()));
+ Set<ConfigKey<?>> result = new LinkedHashSet<>();
+ synchronized (contents) {
+ for (Map.Entry<String, Object> entry : contents.entrySet()) {
+ ConfigKey<?> k = new BasicConfigKey<Object>(Object.class, entry.getKey());
+ if (filter.apply(k)) {
+ result.add(k);
+ }
+ }
}
return result;
}
@Override
- public BrooklynPropertiesImpl submap(Predicate<ConfigKey<?>> filter) {
+ public BrooklynProperties submap(Predicate<ConfigKey<?>> filter) {
BrooklynPropertiesImpl result = Factory.newEmpty();
- for (Object entry: entrySet()) {
- ConfigKey<?> k = new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey());
- if (filter.apply(k))
- result.put(((Map.Entry)entry).getKey(), ((Map.Entry)entry).getValue());
+ synchronized (contents) {
+ for (Map.Entry<String, Object> entry : contents.entrySet()) {
+ ConfigKey<?> k = new BasicConfigKey<Object>(Object.class, entry.getKey());
+ if (filter.apply(k)) {
+ result.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public BrooklynProperties submapByName(Predicate<? super String> filter) {
+ BrooklynPropertiesImpl result = Factory.newEmpty();
+ synchronized (contents) {
+ for (Map.Entry<String, Object> entry : contents.entrySet()) {
+ if (filter.apply(entry.getKey())) {
+ result.put(entry.getKey(), entry.getValue());
+ }
+ }
}
return result;
}
- @SuppressWarnings("unchecked")
@Override
public Map<String, Object> asMapWithStringKeys() {
- return this;
+ synchronized (contents) {
+ return MutableMap.copyOf(contents).asUnmodifiable();
+ }
}
+ @Override
+ public boolean isEmpty() {
+ synchronized (contents) {
+ return contents.isEmpty();
+ }
+ }
+
+ @Override
+ public int size() {
+ synchronized (contents) {
+ return contents.size();
+ }
+ }
+
+ @Override
+ public boolean containsKey(String key) {
+ synchronized (contents) {
+ return contents.containsKey(key);
+ }
+ }
+
+ @Override
+ public boolean containsKey(ConfigKey<?> key) {
+ return containsKey(key.getName());
+ }
+
+ @Override
+ public boolean remove(String key) {
+ synchronized (contents) {
+ boolean result = contents.containsKey(key);
+ contents.remove(key);
+ return result;
+ }
+ }
+
+ @Override
+ public boolean remove(ConfigKey<?> key) {
+ return remove(key.getName());
+ }
+
+ protected Object get(String key) {
+ synchronized (contents) {
+ return contents.get(key);
+ }
+ }
+
+ protected Object putImpl(String key, Object value) {
+ synchronized (contents) {
+ return contents.put(key, value);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationDefinition.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationDefinition.java b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationDefinition.java
index 4add560..38023e0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationDefinition.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationDefinition.java
@@ -33,11 +33,11 @@ public class BasicLocationDefinition implements LocationDefinition {
private final String spec;
private final Map<String,Object> config;
- public BasicLocationDefinition(String name, String spec, Map<String,? extends Object> config) {
+ public BasicLocationDefinition(String name, String spec, Map<String, ?> config) {
this(Identifiers.makeRandomId(8), name, spec, config);
}
- public BasicLocationDefinition(String id, String name, String spec, Map<String,? extends Object> config) {
+ public BasicLocationDefinition(String id, String name, String spec, Map<String, ?> config) {
this.id = Preconditions.checkNotNull(id);
this.name = name;
this.spec = Preconditions.checkNotNull(spec);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
index d7e0000..e68c0dc 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.config.StringConfigMap;
import org.apache.brooklyn.core.config.ConfigPredicates;
import org.apache.brooklyn.core.config.ConfigUtils;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
import org.apache.brooklyn.core.location.internal.LocationInternal;
import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
@@ -282,8 +283,8 @@ public class BasicLocationRegistry implements LocationRegistry {
String spec = (String) namedLocationProps.asMapWithStringKeys().get(k);
// make up an ID
String id = Identifiers.makeRandomId(8);
- Map<String, Object> config = ConfigUtils.filterForPrefixAndStrip(namedLocationProps.asMapWithStringKeys(), k+".");
- definedLocations.put(id, new BasicLocationDefinition(id, name, spec, config));
+ BrooklynProperties config = ConfigUtils.filterForPrefixAndStrip(namedLocationProps.asMapWithStringKeys(), k+".");
+ definedLocations.put(id, new BasicLocationDefinition(id, name, spec, config.asMapWithStringKeys()));
count++;
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
index 1a388d5..c5dc551 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
@@ -26,6 +26,7 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.core.config.ConfigPredicates;
import org.apache.brooklyn.core.config.ConfigUtils;
import org.apache.brooklyn.core.config.external.ExternalConfigSupplier;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.javalang.Reflections;
@@ -99,11 +100,14 @@ public class BasicExternalConfigSupplierRegistry implements ExternalConfigSuppli
String name = strippedKey;
String providerClassname = (String) externalProviderProperties.get(key);
- Map<String, Object> config = ConfigUtils.filterForPrefixAndStrip(externalProviderProperties, key + ".");
+ BrooklynProperties config = ConfigUtils.filterForPrefixAndStrip(externalProviderProperties, key + ".");
try {
Maybe<ExternalConfigSupplier> configSupplier = Reflections.invokeConstructorFromArgs(classloader, ExternalConfigSupplier.class, providerClassname, mgmt, name, config);
if (!configSupplier.isPresent()) {
+ configSupplier = Reflections.invokeConstructorFromArgs(classloader, ExternalConfigSupplier.class, providerClassname, mgmt, name, config.asMapWithStringKeys());
+ }
+ if (!configSupplier.isPresent()) {
configSupplier = Reflections.invokeConstructorFromArgs(classloader, ExternalConfigSupplier.class, providerClassname, mgmt, name);
}
if (!configSupplier.isPresent()) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/DeferredBrooklynProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/DeferredBrooklynProperties.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/DeferredBrooklynProperties.java
index 1bc737e..8ddebd1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/DeferredBrooklynProperties.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/DeferredBrooklynProperties.java
@@ -31,6 +31,7 @@ import java.util.concurrent.ExecutionException;
import org.apache.brooklyn.api.mgmt.ExecutionContext;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.internal.BrooklynProperties;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.flags.TypeCoercions;
@@ -103,6 +104,32 @@ public class DeferredBrooklynProperties implements BrooklynProperties {
}
@Override
+ public boolean containsKey(String key) {
+ return delegate.containsKey(key);
+ }
+
+ @Override
+ public boolean containsKey(ConfigKey<?> key) {
+ return delegate.containsKey(key);
+ }
+
+ @Override
+ public boolean remove(String key) {
+ return delegate.remove(key);
+ }
+
+ @Override
+ public boolean remove(ConfigKey<?> key) {
+ return delegate.remove(key);
+ }
+
+ @Override
+ public Object getConfig(String key) {
+ Object raw = delegate.getConfig(key);
+ return resolve(ConfigKeys.newConfigKey(Object.class, key), raw);
+ }
+
+ @Override
public <T> T getConfig(ConfigKey<T> key) {
T raw = delegate.getConfig(key);
return resolve(key, raw);
@@ -144,7 +171,7 @@ public class DeferredBrooklynProperties implements BrooklynProperties {
@Override
public Map<ConfigKey<?>,Object> getAllConfigLocalRaw() {
- Map<ConfigKey<?>, Object> raw = delegate.getAllConfig();
+ Map<ConfigKey<?>, Object> raw = delegate.getAllConfigLocalRaw();
Map<ConfigKey<?>, Object> result = Maps.newLinkedHashMap();
for (Map.Entry<ConfigKey<?>, Object> entry : raw.entrySet()) {
result.put(entry.getKey(), transform(entry.getKey(), entry.getValue()));
@@ -159,7 +186,7 @@ public class DeferredBrooklynProperties implements BrooklynProperties {
@Override
public Map<String, Object> asMapWithStringKeys() {
- Map<ConfigKey<?>, Object> raw = delegate.getAllConfig();
+ Map<ConfigKey<?>, Object> raw = delegate.getAllConfigLocalRaw();
Map<String, Object> result = Maps.newLinkedHashMap();
for (Map.Entry<ConfigKey<?>, Object> entry : raw.entrySet()) {
result.put(entry.getKey().getName(), transform(entry.getKey(), entry.getValue()));
@@ -202,6 +229,13 @@ public class DeferredBrooklynProperties implements BrooklynProperties {
BrooklynProperties submap = delegate.submap(filter);
return new DeferredBrooklynProperties(submap, mgmt);
}
+
+ @Override
+ public BrooklynProperties submapByName(Predicate<? super String> filter) {
+ BrooklynProperties submap = delegate.submapByName(filter);
+ return new DeferredBrooklynProperties(submap, mgmt);
+ }
+
@Override
public Set<ConfigKey<?>> findKeys(Predicate<? super ConfigKey<?>> filter) {
return delegate.findKeys(filter);
@@ -307,7 +341,7 @@ public class DeferredBrooklynProperties implements BrooklynProperties {
//////////////////////////////////////////////////////////////////////////////////
- // Methods below from java.util.LinkedHashMap, which BrooklynProperties extends //
+ // Methods below from ConfigMap, which BrooklynProperties extends //
//////////////////////////////////////////////////////////////////////////////////
@Override
@@ -320,50 +354,12 @@ public class DeferredBrooklynProperties implements BrooklynProperties {
return delegate.isEmpty();
}
- @Override
- public boolean containsKey(Object key) {
- return delegate.containsKey(key);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return delegate.containsValue(value);
- }
-
- @Override
- public Object get(Object key) {
- return delegate.get(key);
- }
-
- @Override
- public Object remove(Object key) {
- return delegate.remove(key);
- }
-
- @Override
- public void clear() {
- delegate.clear();
- }
-
- @Override
- @SuppressWarnings("rawtypes")
- public Set keySet() {
- return delegate.keySet();
- }
- @Override
- @SuppressWarnings("rawtypes")
- public Collection values() {
- return delegate.values();
- }
+ //////////////////////////////////////////////////////////////////////////////////
+ // Methods below from Object //
+ //////////////////////////////////////////////////////////////////////////////////
@Override
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Set<Map.Entry> entrySet() {
- return delegate.entrySet();
- }
-
- @Override
public boolean equals(Object o) {
return delegate.equals(o);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesBuilderTest.java b/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesBuilderTest.java
index bc57824..f40ea52 100644
--- a/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesBuilderTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesBuilderTest.java
@@ -58,7 +58,7 @@ public class BrooklynPropertiesBuilderTest {
.globalPropertiesFile(globalPropertiesFile.getAbsolutePath())
.build();
- assertEquals(props.get("brooklyn.mykey"), "myval");
+ assertEquals(props.getConfig("brooklyn.mykey"), "myval");
}
@Test
@@ -76,8 +76,8 @@ public class BrooklynPropertiesBuilderTest {
.localPropertiesFile(localPropertiesFile.getAbsolutePath())
.build();
- assertEquals(props.get("brooklyn.mykey"), "myvaloverriding");
- assertEquals(props.get("brooklyn.mykey2"), "myvalglobal2");
- assertEquals(props.get("brooklyn.mykeyLocal"), "myvallocal2");
+ assertEquals(props.getConfig("brooklyn.mykey"), "myvaloverriding");
+ assertEquals(props.getConfig("brooklyn.mykey2"), "myvalglobal2");
+ assertEquals(props.getConfig("brooklyn.mykeyLocal"), "myvallocal2");
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesTest.java b/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesTest.java
index a427838..d802892 100644
--- a/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/config/BrooklynPropertiesTest.java
@@ -155,9 +155,9 @@ public class BrooklynPropertiesTest {
assertEquals(p2.getFirst("akey"), null);
BrooklynProperties p3a = props.submap(ConfigPredicates.startingWith("a."));
- assertEquals(p3a, p2);
+ assertPropertiesEquals(p3a, p2);
BrooklynProperties p3b = props.submap(ConfigPredicates.matchingRegex("a\\..*"));
- assertEquals(p3b, p2);
+ assertPropertiesEquals(p3b, p2);
BrooklynProperties p4 = props.submap(ConfigPredicates.matchingRegex("a.*"));
assertEquals(p4.getAllConfig().keySet().size(), 3, "wrong size submap: "+p4);
@@ -182,21 +182,24 @@ public class BrooklynPropertiesTest {
props.put(aString, "aval2");
assertEquals(props.getConfig(aString), "aval2");
- assertEquals(props.get("a.key"), "aval2");
+ assertEquals(props.getConfig("a.key"), "aval2");
props.put(nNum, "345");
assertEquals(props.getConfig(nNum), (Integer)345);
- assertEquals(props.get("n.key"), "345");
+ assertEquals(props.getConfig("n.key"), "345");
assertEquals(props.getConfig(aBsent), null);
assertEquals(props.getConfig(aBsent, 123), (Integer)123);
assertEquals(props.getConfig(aDfault), (Integer)123);
props.put(aMisstyped, "x1");
- assertEquals(props.get("am.isstyped"), "x1");
+ assertEquals(props.getConfig("am.isstyped"), "x1");
boolean workedWhenShouldntHave = false;
try { props.getConfig(aMisstyped); workedWhenShouldntHave = true; } catch (Exception e) {}
if (workedWhenShouldntHave) fail("should have failed getting "+aMisstyped+" because can't coerce");
}
+ protected void assertPropertiesEquals(BrooklynProperties actual, BrooklynProperties expected) {
+ assertEquals(actual.asMapWithStringKeys(), expected.asMapWithStringKeys());
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
index 2332793..683fedf 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
@@ -97,11 +97,11 @@ public class LocalManagementContextTest {
BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
properties.put("myname", "myval");
context = LocalManagementContextForTests.builder(true).useProperties(properties).build();
- assertEquals(context.getBrooklynProperties().get("myname"), "myval");
+ assertEquals(context.getBrooklynProperties().getConfig("myname"), "myval");
properties.put("myname", "newval");
- assertEquals(properties.get("myname"), "newval");
+ assertEquals(properties.getConfig("myname"), "newval");
// TODO: Should changes in the 'properties' collection be reflected in context.getBrooklynProperties()?
- assertNotEquals(context.getBrooklynProperties().get("myname"), "newval");
+ assertNotEquals(context.getBrooklynProperties().getConfig("myname"), "newval");
}
@Test
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
----------------------------------------------------------------------
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
index 0578f04..67ad368 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
@@ -318,7 +318,7 @@ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> {
if (port!=null) webServer.setPort(port);
if (useHttps!=null) webServer.setHttpsEnabled(useHttps);
webServer.setShutdownHandler(shutdownHandler);
- webServer.putAttributes(brooklynProperties);
+ webServer.putAttributes(brooklynProperties.asMapWithStringKeys());
webServer.skipSecurity(skipSecurity);
for (WebAppContextProvider webapp : webApps) {
webServer.addWar(webapp);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java
index 486e805..56467cc 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java
@@ -67,7 +67,7 @@ public class BrooklynLauncherRebindToCloudObjectStoreTest extends BrooklynLaunch
@Override
protected LocalManagementContextForTests newManagementContextForTests(BrooklynProperties props) {
BrooklynProperties p2 = BrooklynProperties.Factory.newDefault();
- if (props!=null) p2.putAll(props);
+ if (props!=null) p2.putAll(props.getAllConfigLocalRaw());
return new LocalManagementContextForTests(p2);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
index aabda7c..fa0a18a 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
@@ -169,10 +169,10 @@ public class BailOutJcloudsLocation extends JcloudsLocation {
*/
public static BailOutJcloudsLocation newBailOutJcloudsLocationForLiveTest(LocalManagementContext mgmt, Map<ConfigKey<?>, ?> config) {
BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties();
- String identity = (String) brooklynProperties.get("brooklyn.location.jclouds.aws-ec2.identity");
- if (identity == null) identity = (String) brooklynProperties.get("brooklyn.jclouds.aws-ec2.identity");
- String credential = (String) brooklynProperties.get("brooklyn.location.jclouds.aws-ec2.credential");
- if (credential == null) credential = (String) brooklynProperties.get("brooklyn.jclouds.aws-ec2.credential");
+ String identity = (String) brooklynProperties.getConfig("brooklyn.location.jclouds.aws-ec2.identity");
+ if (identity == null) identity = (String) brooklynProperties.getConfig("brooklyn.jclouds.aws-ec2.identity");
+ String credential = (String) brooklynProperties.getConfig("brooklyn.location.jclouds.aws-ec2.credential");
+ if (credential == null) credential = (String) brooklynProperties.getConfig("brooklyn.jclouds.aws-ec2.credential");
Map<ConfigKey<?>, ?> allConfig = MutableMap.<ConfigKey<?>, Object>builder()
.put(CLOUD_PROVIDER, AbstractJcloudsLiveTest.AWS_EC2_PROVIDER)
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
index 20e0242..c10a594 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
@@ -521,7 +521,6 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
Assert.assertEquals(geo.longitude, -20d, 0.00001);
}
- @SuppressWarnings("unchecked")
@Test
public void testInheritsGeoFromLocationMetadataProperties() throws Exception {
// in location-metadata.properties:
@@ -534,8 +533,9 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
.configure(ACCESS_IDENTITY, "bogus")
.configure(ACCESS_CREDENTIAL, "bogus")
.configure(MACHINE_CREATE_ATTEMPTS, 1);
- FakeLocalhostWithParentJcloudsLocation ll = managementContext.getLocationManager().createLocation(LocationSpec.create(FakeLocalhostWithParentJcloudsLocation.class)
- .configure(new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties("softlayer", "wdc01", null, managementContext.getBrooklynProperties()))
+ Map<String, Object> brooklynProperties = managementContext.getBrooklynProperties().asMapWithStringKeys();
+ FakeLocalhostWithParentJcloudsLocation ll = managementContext.getLocationManager().createLocation(LocationSpec.create(FakeLocalhostWithParentJcloudsLocation.class)
+ .configure(new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties("softlayer", "wdc01", null, brooklynProperties))
.configure(allConfig.getAllConfig()));
MachineLocation l = ll.obtain();
log.info("loc:" +l);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4c1fe060/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/LocalBrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/LocalBrooklynNodeImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/LocalBrooklynNodeImpl.java
index 8d95a39..adf46af 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/LocalBrooklynNodeImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/LocalBrooklynNodeImpl.java
@@ -32,11 +32,11 @@ public class LocalBrooklynNodeImpl extends BrooklynNodeImpl implements LocalBroo
// Override management username and password from brooklyn.properties
// TODO Why use BrooklynProperties, rather than StringConfigMap returned by mgmt.getConfig()?
BrooklynProperties properties = ((ManagementContextInternal)getManagementContext()).getBrooklynProperties();
- String user = (String) properties.get(String.format(LOCAL_BROOKLYN_NODE_KEY, "user"));
- String password = (String) properties.get(String.format(LOCAL_BROOKLYN_NODE_KEY, "password"));
+ String user = (String) properties.getConfig(String.format(LOCAL_BROOKLYN_NODE_KEY, "user"));
+ String password = (String) properties.getConfig(String.format(LOCAL_BROOKLYN_NODE_KEY, "password"));
if (Strings.isBlank(password)) {
if (Strings.isBlank(user)) user = "admin";
- password = (String) properties.get(String.format(BROOKLYN_WEBCONSOLE_PASSWORD_KEY, user));
+ password = (String) properties.getConfig(String.format(BROOKLYN_WEBCONSOLE_PASSWORD_KEY, user));
}
if (Strings.isNonBlank(user) && Strings.isNonBlank(password)) {
config().set(MANAGEMENT_USER, user);
[2/2] brooklyn-server git commit: This closes #505
Posted by sj...@apache.org.
This closes #505
BROOKLYN-404: fix ConcurrentModificationException in BrooklynProperties
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/0570ca5a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/0570ca5a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/0570ca5a
Branch: refs/heads/master
Commit: 0570ca5a54dbd045c2bd007ea1a18d9f139762fb
Parents: 972a0d8 4c1fe06
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Tue Jan 24 12:18:40 2017 +0000
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Tue Jan 24 12:18:40 2017 +0000
----------------------------------------------------------------------
.../brooklyn/core/config/ConfigUtils.java | 15 +-
.../core/internal/BrooklynProperties.java | 29 ++-
.../core/internal/BrooklynPropertiesImpl.java | 183 ++++++++++++++-----
.../core/location/BasicLocationDefinition.java | 4 +-
.../core/location/BasicLocationRegistry.java | 5 +-
.../BasicExternalConfigSupplierRegistry.java | 6 +-
.../internal/DeferredBrooklynProperties.java | 84 ++++-----
.../config/BrooklynPropertiesBuilderTest.java | 8 +-
.../core/config/BrooklynPropertiesTest.java | 13 +-
.../internal/LocalManagementContextTest.java | 6 +-
.../brooklyn/launcher/BrooklynLauncher.java | 2 +-
...lynLauncherRebindToCloudObjectStoreTest.java | 2 +-
.../jclouds/BailOutJcloudsLocation.java | 8 +-
.../location/jclouds/JcloudsLocationTest.java | 6 +-
.../brooklynnode/LocalBrooklynNodeImpl.java | 6 +-
15 files changed, 246 insertions(+), 131 deletions(-)
----------------------------------------------------------------------