You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2016/03/22 19:06:49 UTC

[07/10] brooklyn-server git commit: LocationFactor’s “special constructor” for pre-existing loc

LocationFactor’s “special constructor” for pre-existing loc

If location already existed, then don’t try to manage it and don’t
reset its config. Previously we got a log.warn about an attempt to
manage the location when it was already managed.

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/89b3a663
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/89b3a663
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/89b3a663

Branch: refs/heads/master
Commit: 89b3a663902fb6ecdfe6666c641ce75ffca514e0
Parents: 3118f42
Author: Aled Sage <al...@gmail.com>
Authored: Tue Mar 22 12:46:02 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Mar 22 12:46:02 2016 +0000

----------------------------------------------------------------------
 .../core/objs/proxy/InternalLocationFactory.java       | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/89b3a663/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
index baf0e5b..4ba0658 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
@@ -27,12 +27,15 @@ import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.location.AbstractLocation;
+import org.apache.brooklyn.core.location.Locations;
 import org.apache.brooklyn.core.location.internal.LocationInternal;
 import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.flags.FlagUtils;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableMap;
 
@@ -46,6 +49,8 @@ import com.google.common.collect.ImmutableMap;
  */
 public class InternalLocationFactory extends InternalFactory {
 
+    private static final Logger LOG = LoggerFactory.getLogger(InternalLocationFactory.class);
+
     /**
      * Returns true if this is a "new-style" location (i.e. where not expected to call the constructor to instantiate it).
      * 
@@ -96,9 +101,17 @@ public class InternalLocationFactory extends InternalFactory {
             
             T loc = construct(clazz, spec, null);
 
+            if (Locations.isManaged(loc)) {
+                // Construct can return an existing instance, if using SpecialBrooklynObjectConstructor.Config.SPECIAL_CONSTRUCTOR.
+                // In which case, don't reconfigure it (don't change its parent, etc).
+                LOG.debug("Location-factory returning pre-existing location; skipping initialization of {}", loc);
+                return loc;
+            }
+
             if (spec.getId() != null) {
                 FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", spec.getId()), loc);
             }
+            
             managementContext.prePreManage(loc);
 
             if (spec.getDisplayName()!=null)