brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [02/12] git commit: allow a CREATE_UNMANAGED mode for locations, used when peeking, so that we don't get lots of logging on the frequent location listings from REST API
Date Fri, 18 Jul 2014 13:42:13 GMT
allow a CREATE_UNMANAGED mode for locations, used when peeking, so that we don't get lots of
logging on the frequent location listings from REST API


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/965a3d1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/965a3d1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/965a3d1f

Branch: refs/heads/master
Commit: 965a3d1f92e878ad52f3cce389ad0dbad017bfc0
Parents: 920a092
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jul 17 16:07:59 2014 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Jul 18 09:15:17 2014 -0400

----------------------------------------------------------------------
 .../java/brooklyn/location/LocationRegistry.java   |  2 +-
 .../main/java/brooklyn/location/LocationSpec.java  |  7 ++++++-
 .../java/brooklyn/management/LocationManager.java  |  6 +++++-
 .../location/basic/BasicLocationRegistry.java      | 10 ++++++----
 .../management/internal/LocalLocationManager.java  | 17 ++++++++++++++++-
 .../main/java/brooklyn/util/config/ConfigBag.java  | 15 ++++++++++-----
 6 files changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/965a3d1f/api/src/main/java/brooklyn/location/LocationRegistry.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/LocationRegistry.java b/api/src/main/java/brooklyn/location/LocationRegistry.java
index 34a1637..e9db3f2 100644
--- a/api/src/main/java/brooklyn/location/LocationRegistry.java
+++ b/api/src/main/java/brooklyn/location/LocationRegistry.java
@@ -58,7 +58,7 @@ public interface LocationRegistry {
      * but callers should prefer this when they don't wish to create a new location which
will be managed in perpetuity!
      * 
      * @since 0.7.0, but beta and likely to change as the semantics of this class are tuned
*/
-    @Beta
+    @Beta   // see impl for notes
     public Location resolveForPeeking(LocationDefinition l);
 
     /** returns fully populated (config etc) location from the given definition */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/965a3d1f/api/src/main/java/brooklyn/location/LocationSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/LocationSpec.java b/api/src/main/java/brooklyn/location/LocationSpec.java
index d9027b5..32bf7c2 100644
--- a/api/src/main/java/brooklyn/location/LocationSpec.java
+++ b/api/src/main/java/brooklyn/location/LocationSpec.java
@@ -150,11 +150,16 @@ public class LocationSpec<T extends Location> implements Serializable
{
         return this;
     }
 
+    public <V> LocationSpec<T> removeConfig(ConfigKey<V> key) {
+        config.remove( checkNotNull(key, "key") );
+        return this;
+    }
+
     public <E> LocationSpec<T> extension(Class<E> extensionType, E extension)
{
         extensions.put(checkNotNull(extensionType, "extensionType"), checkNotNull(extension,
"extension"));
         return this;
     }
-
+    
     /**
      * @return The type of the location
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/965a3d1f/api/src/main/java/brooklyn/management/LocationManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/management/LocationManager.java b/api/src/main/java/brooklyn/management/LocationManager.java
index ef6f990..4708474 100644
--- a/api/src/main/java/brooklyn/management/LocationManager.java
+++ b/api/src/main/java/brooklyn/management/LocationManager.java
@@ -21,7 +21,10 @@ package brooklyn.management;
 import java.util.Collection;
 import java.util.Map;
 
+import javax.annotation.Nullable;
+
 import brooklyn.location.Location;
+import brooklyn.location.LocationDefinition;
 import brooklyn.location.LocationSpec;
 
 /**
@@ -35,7 +38,7 @@ public interface LocationManager {
      * @param spec
      */
     <T extends Location> T createLocation(LocationSpec<T> spec);
-    
+
     /**
      * Convenience (particularly for groovy code) to create a location.
      * Equivalent to {@code createLocation(LocationSpec.create(type).configure(config))}
@@ -83,4 +86,5 @@ public interface LocationManager {
      * (though it may be logged so duplicate calls are best avoided).
      */
     void unmanage(Location loc);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/965a3d1f/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java b/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
index b3b5d03..2c7cf36 100644
--- a/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
+++ b/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
@@ -42,6 +42,7 @@ import brooklyn.location.LocationRegistry;
 import brooklyn.location.LocationResolver;
 import brooklyn.location.LocationResolver.EnableableLocationResolver;
 import brooklyn.management.ManagementContext;
+import brooklyn.management.internal.LocalLocationManager;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.config.ConfigBag;
 import brooklyn.util.javalang.JavaClassNames;
@@ -333,10 +334,11 @@ public class BasicLocationRegistry implements LocationRegistry {
 
     @Override
     public Location resolveForPeeking(LocationDefinition ld) {
-        // TODO actually look it up
-        Location l = resolve(ld, Collections.emptyMap());
-        mgmt.getLocationManager().unmanage(l);
-        return l;
+        // TODO should clean up how locations are stored, figuring out whether they are shared
or not;
+        // or maybe better, the API calls to this might just want to get the LocationSpec
objects back
+        
+        // for now we use a 'CREATE_UNMANGED' flag to prevent management (leaks and logging)
+        return resolve(ld, ConfigBag.newInstance().configure(LocalLocationManager.CREATE_UNMANAGED,
true).getAllConfig());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/965a3d1f/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java b/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
index 72372bb..6c59f3b 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
@@ -26,6 +26,8 @@ import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.proxying.InternalLocationFactory;
 import brooklyn.internal.storage.BrooklynStorage;
@@ -35,6 +37,7 @@ import brooklyn.location.basic.AbstractLocation;
 import brooklyn.location.basic.LocationInternal;
 import brooklyn.management.AccessController;
 import brooklyn.management.LocationManager;
+import brooklyn.util.config.ConfigBag;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.exceptions.RuntimeInterruptedException;
 
@@ -44,6 +47,9 @@ import com.google.common.collect.Maps;
 
 public class LocalLocationManager implements LocationManager {
 
+    public static final ConfigKey<Boolean> CREATE_UNMANAGED = ConfigKeys.newBooleanConfigKey("brooklyn.internal.location.createUnmanaged",
+        "If set on a location or spec, causes the manager to create it in an unmanaged state
(for peeking)", false);
+    
     private static final Logger log = LoggerFactory.getLogger(LocalLocationManager.class);
 
     private final LocalManagementContext managementContext;
@@ -71,8 +77,17 @@ public class LocalLocationManager implements LocationManager {
     @Override
     public <T extends Location> T createLocation(LocationSpec<T> spec) {
         try {
+            boolean createUnmanaged = ConfigBag.coerceFirstNonNullKeyValue(CREATE_UNMANAGED,

+                spec.getConfig().get(CREATE_UNMANAGED), spec.getFlags().get(CREATE_UNMANAGED.getName()));
+            if (createUnmanaged) {
+                spec.removeConfig(CREATE_UNMANAGED);
+            }
+            
             T loc = locationFactory.createLocation(spec);
-            manage(loc);
+            if (!createUnmanaged) {
+                manage(loc);
+            }
+            
             return loc;
         } catch (Throwable e) {
             log.warn("Failed to create location using spec "+spec+" (rethrowing)", e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/965a3d1f/core/src/main/java/brooklyn/util/config/ConfigBag.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/config/ConfigBag.java b/core/src/main/java/brooklyn/util/config/ConfigBag.java
index 575c8e2..d35fb78 100644
--- a/core/src/main/java/brooklyn/util/config/ConfigBag.java
+++ b/core/src/main/java/brooklyn/util/config/ConfigBag.java
@@ -399,12 +399,17 @@ public class ConfigBag {
     protected <T> T get(ConfigKey<T> key, boolean remove) {
         // TODO for now, no evaluation -- closure content / smart (self-extracting) keys
are NOT supported
         // (need a clean way to inject that behaviour, as well as desired TypeCoercions)
-        Object value;
         if (config.containsKey(key.getName()))
-            value = getStringKey(key.getName(), remove);
-        else
-            value = key.getDefaultValue();
-        return TypeCoercions.coerce(value, key.getTypeToken());
+            return coerceFirstNonNullKeyValue(key, getStringKey(key.getName(), remove));
+        
+        return coerceFirstNonNullKeyValue(key);
+    }
+
+    /** 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 */
+    public static <T> T coerceFirstNonNullKeyValue(ConfigKey<T> key, Object ...values)
{
+        for (Object o: values)
+            if (o!=null) return TypeCoercions.coerce(o, key.getTypeToken());
+        return TypeCoercions.coerce(key.getDefaultValue(), key.getTypeToken());
     }
 
     protected Object getStringKey(String key, boolean markUsed) {


Mime
View raw message