brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [2/8] git commit: Internal*Factory: remove duplication
Date Fri, 01 Aug 2014 20:12:57 GMT
Internal*Factory: remove duplication

- Remove duplication across InternalEntityFactory, InternalPolicyFactory
  and InternalLocationFactory
- Remove duplication in callers of InternalEntityFactory.createEntity


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

Branch: refs/heads/master
Commit: e07155ad3fafa6bd6f3bc0ac2060ceaa95426c72
Parents: 9138317
Author: Aled Sage <aled.sage@gmail.com>
Authored: Mon Jul 14 12:48:46 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Mon Jul 14 23:45:19 2014 +0100

----------------------------------------------------------------------
 .../entity/proxying/InternalEntityFactory.java  | 107 +++++++++++--------
 .../entity/proxying/InternalFactory.java        |  16 +--
 .../proxying/InternalLocationFactory.java       |   9 +-
 .../entity/proxying/InternalPolicyFactory.java  |  18 +---
 .../entity/rebind/RebindManagerImpl.java        |  40 ++-----
 .../BrooklynComponentTemplateResolver.java      |  13 ---
 6 files changed, 79 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e07155ad/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java b/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
index e572ce9..7abf68f 100644
--- a/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
+++ b/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
@@ -19,6 +19,7 @@
 package brooklyn.entity.proxying;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
@@ -29,11 +30,11 @@ import org.slf4j.LoggerFactory;
 
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
+import brooklyn.entity.basic.AbstractApplication;
 import brooklyn.entity.basic.AbstractEntity;
 import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.basic.EntityLocal;
-import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalEntityManager;
 import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.policy.Enricher;
@@ -46,10 +47,11 @@ import brooklyn.util.collections.MutableSet;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.flags.FlagUtils;
 import brooklyn.util.javalang.AggregateClassLoader;
-import brooklyn.util.javalang.Reflections;
 import brooklyn.util.task.Tasks;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
 
 /**
  * Creates entities (and proxies) of required types, given the 
@@ -57,6 +59,13 @@ import com.google.common.collect.ImmutableMap;
  * This is an internal class for use by core-brooklyn. End-users are strongly discouraged
from
  * using this class directly.
  * 
+ * Used in three situations:
+ * <ul>
+ *   <li>Normal entity creation (through entityManager.createEntity)
+ *   <li>rebind (i.e. Brooklyn restart, or promotion of HA standby manager node)
+ *   <li>yaml parsing
+ * </ul>
+ * 
  * @author aled
  */
 public class InternalEntityFactory extends InternalFactory {
@@ -66,41 +75,33 @@ public class InternalEntityFactory extends InternalFactory {
     private final EntityTypeRegistry entityTypeRegistry;
     private final InternalPolicyFactory policyFactory;
     
-    /**
-     * Returns true if this is a "new-style" entity (i.e. where not expected to call the
constructor to instantiate it).
-     * That means it is an entity with a no-arg constructor.
-     * @param managementContext
-     * @param clazz
-     */
-    public static boolean isNewStyleEntity(ManagementContext managementContext, Class<?>
clazz) {
-        return InternalFactory.isNewStyle(managementContext, clazz);
-    }
-    
-    public static boolean isNewStyleEntity(Class<?> clazz) {
-        return InternalFactory.isNewStyle(clazz);
-    }
-    
     public InternalEntityFactory(ManagementContextInternal managementContext, EntityTypeRegistry
entityTypeRegistry, InternalPolicyFactory policyFactory) {
         super(managementContext);
         this.entityTypeRegistry = checkNotNull(entityTypeRegistry, "entityTypeRegistry");
         this.policyFactory = checkNotNull(policyFactory, "policyFactory");
     }
 
-    @SuppressWarnings("unchecked")
     public <T extends Entity> T createEntityProxy(EntitySpec<T> spec, T entity)
{
-        // TODO Don't want the proxy to have to implement EntityLocal, but required by how

-        // AbstractEntity.parent is used (e.g. parent.getAllConfig)
-        ClassLoader classloader = (spec.getImplementation() != null ? spec.getImplementation()
: spec.getType()).getClassLoader();
-        MutableSet.Builder<Class<?>> builder = MutableSet.<Class<?>>builder()
-                .add(EntityProxy.class, Entity.class, EntityLocal.class, EntityInternal.class);
+        Set<Class<?>> interfaces = Sets.newLinkedHashSet();
         if (spec.getType().isInterface()) {
-            builder.add(spec.getType());
+            interfaces.add(spec.getType());
         } else {
             log.warn("EntitySpec declared in terms of concrete type "+spec.getType()+"; should
be supplied in terms of interface");
         }
-        builder.addAll(spec.getAdditionalInterfaces());
-        Set<Class<?>> interfaces = builder.build();
+        interfaces.addAll(spec.getAdditionalInterfaces());
         
+        return createEntityProxy(interfaces, entity);
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T extends Entity> T createEntityProxy(Iterable<Class<?>> interfaces,
T entity) {
+        // TODO Don't want the proxy to have to implement EntityLocal, but required by how

+        // AbstractEntity.parent is used (e.g. parent.getAllConfig)
+        Set<Class<?>> allInterfaces = MutableSet.<Class<?>>builder()
+                .add(EntityProxy.class, Entity.class, EntityLocal.class, EntityInternal.class)
+                .addAll(interfaces)
+                .build();
+
         // TODO OSGi strangeness! The classloader obtained from the type should be enough.
         // If an OSGi class loader, it should delegate to find things like Entity.class etc.
         // However, we get errors such as:
@@ -108,18 +109,17 @@ public class InternalEntityFactory extends InternalFactory {
         // Building our own aggregating class loader gets around this.
         // But we really should not have to do this! What are the consequences?
         AggregateClassLoader aggregateClassLoader =  AggregateClassLoader.newInstanceWithNoLoaders();
-        aggregateClassLoader.addFirst(classloader);
         aggregateClassLoader.addFirst(entity.getClass().getClassLoader());
-        for(Class<?> iface : interfaces) {
+        for(Class<?> iface : allInterfaces) {
             aggregateClassLoader.addLast(iface.getClassLoader());
         }
 
         return (T) java.lang.reflect.Proxy.newProxyInstance(
                 aggregateClassLoader,
-                interfaces.toArray(new Class[interfaces.size()]),
+                allInterfaces.toArray(new Class[allInterfaces.size()]),
                 new EntityProxyImpl(entity));
     }
-
+    
     public <T extends Entity> T createEntity(EntitySpec<T> spec) {
         /* Order is important here. Changed Jul 2014 when supporting children in spec.
          * (Previously was much simpler, and parent was set right after running initializers;
and there were no children.)
@@ -147,8 +147,11 @@ public class InternalEntityFactory extends InternalFactory {
         if (spec.getFlags().containsKey("id")) {
             throw new IllegalArgumentException("Spec's flags must not contain id; use spec.id()
instead for "+spec);
         }
-        if (spec.getId() != null && ((LocalEntityManager)managementContext.getEntityManager()).isKnownEntityId(spec.getId()))
{
-            throw new IllegalArgumentException("Entity with id "+spec.getId()+" already exists;
cannot create new entity with this explicit id from spec "+spec);
+        if (spec.getId() != null) {
+            log.warn("Use of deprecated EntitySpec.id ({}); instead let management context
pick the random+unique id", spec);
+            if (((LocalEntityManager)managementContext.getEntityManager()).isKnownEntityId(spec.getId()))
{
+                throw new IllegalArgumentException("Entity with id "+spec.getId()+" already
exists; cannot create new entity with this explicit id from spec "+spec);
+            }
         }
         
         try {
@@ -156,13 +159,6 @@ public class InternalEntityFactory extends InternalFactory {
             
             T entity = constructEntity(clazz, spec);
             
-            // TODO Could move setManagementContext call into constructEntity; would that
break rebind?
-            if (spec.getId() != null) {
-                FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", spec.getId()), entity);
-            }
-            ((AbstractEntity)entity).setManagementContext(managementContext);
-            managementContext.prePreManage(entity);
-
             loadUnitializedEntity(entity, spec);
 
             entitiesByEntityId.put(entity.getId(), entity);
@@ -194,7 +190,6 @@ public class InternalEntityFactory extends InternalFactory {
             if (spec.getDisplayName()!=null)
                 ((AbstractEntity)entity).setDisplayName(spec.getDisplayName());
             
-            if (((AbstractEntity)entity).getProxy() == null) ((AbstractEntity)entity).setProxy(createEntityProxy(spec,
entity));
             ((AbstractEntity)entity).configure(MutableMap.copyOf(spec.getFlags()));
             
             for (Map.Entry<ConfigKey<?>, Object> entry : spec.getConfig().entrySet())
{
@@ -281,18 +276,46 @@ public class InternalEntityFactory extends InternalFactory {
     
     /**
      * Constructs an entity (if new-style, calls no-arg constructor; if old-style, uses spec
to pass in config).
+     * Sets the entity's proxy. If {@link EntitySpec#id(String)} was set then uses that to
override the entity's id, 
+     * but that behaviour is deprecated.
      */
     public <T extends Entity> T constructEntity(Class<? extends T> clazz, EntitySpec<T>
spec) {
-        return super.construct(clazz, spec.getFlags());
+        T entity = constructEntityImpl(clazz, spec.getFlags(), spec.getId());
+        if (((AbstractEntity)entity).getProxy() == null) ((AbstractEntity)entity).setProxy(createEntityProxy(spec,
entity));
+        return entity;
     }
 
     /**
      * Constructs a new-style entity (fails if no no-arg constructor).
+     * Sets the entity's id and proxy.
      */
-    public <T extends Entity> T constructEntity(Class<T> clazz) {
-        return super.constructNewStyle(clazz);
+    public <T extends Entity> T constructEntity(Class<T> clazz, Iterable<Class<?>>
interfaces, String entityId) {
+        if (!isNewStyle(clazz)) {
+            throw new IllegalStateException("Cannot construct old-style entity "+clazz);
+        }
+        checkNotNull(entityId, "entityId");
+        checkState(interfaces != null && !Iterables.isEmpty(interfaces), "must have
at least one interface for entity %s:%s", clazz, entityId);
+        
+        T entity = constructEntityImpl(clazz, ImmutableMap.<String, Object>of(), entityId);
+        if (((AbstractEntity)entity).getProxy() == null) ((AbstractEntity)entity).setProxy(createEntityProxy(interfaces,
entity));
+        return entity;
     }
     
+    protected <T extends Entity> T constructEntityImpl(Class<? extends T> clazz,
Map<String, ?> constructionFlags, String entityId) {
+        T entity = super.construct(clazz, constructionFlags);
+        
+        if (entityId != null) {
+            FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", entityId), entity);
+        }
+        if (entity instanceof AbstractApplication) {
+            FlagUtils.setFieldsFromFlags(ImmutableMap.of("mgmt", managementContext), entity);
+        }
+        managementContext.prePreManage(entity);
+        ((AbstractEntity)entity).setManagementContext(managementContext);
+
+        return entity;
+    }
+
     @Override
     protected <T> T constructOldStyle(Class<T> clazz, Map<String,?> flags)
throws InstantiationException, IllegalAccessException, InvocationTargetException {
         if (flags.containsKey("parent") || flags.containsKey("owner")) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e07155ad/core/src/main/java/brooklyn/entity/proxying/InternalFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/proxying/InternalFactory.java b/core/src/main/java/brooklyn/entity/proxying/InternalFactory.java
index e024872..3b77526 100644
--- a/core/src/main/java/brooklyn/entity/proxying/InternalFactory.java
+++ b/core/src/main/java/brooklyn/entity/proxying/InternalFactory.java
@@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
 
-import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.exceptions.Exceptions;
@@ -62,19 +61,10 @@ public class InternalFactory {
     }
 
     /**
-     * Returns true if this is a "new-style" policy (i.e. where not expected to call the
constructor to instantiate it).
+     * Returns true if this is a "new-style" policy (i.e. where not expected callers to use
the constructor directly to instantiate it).
      * 
-     * @param managementContext
      * @param clazz
      */
-    public static boolean isNewStyle(ManagementContext managementContext, Class<?>
clazz) {
-        try {
-            return isNewStyle(clazz);
-        } catch (IllegalArgumentException e) {
-            return false;
-        }
-    }
-    
     public static boolean isNewStyle(Class<?> clazz) {
         try {
             clazz.getConstructor(new Class[0]);
@@ -88,6 +78,10 @@ public class InternalFactory {
         this.managementContext = checkNotNull(managementContext, "managementContext");
     }
 
+    /**
+     * Constructs an instance (e.g. of entity, location, enricher or policy.
+     * If new-style, calls no-arg constructor; if old-style, uses spec to pass in config.
+     */
     protected <T> T construct(Class<? extends T> clazz, Map<String, ?>
constructorFlags) {
         try {
             if (isNewStyle(clazz)) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e07155ad/core/src/main/java/brooklyn/entity/proxying/InternalLocationFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/proxying/InternalLocationFactory.java b/core/src/main/java/brooklyn/entity/proxying/InternalLocationFactory.java
index ffcfac2..804b5d5 100644
--- a/core/src/main/java/brooklyn/entity/proxying/InternalLocationFactory.java
+++ b/core/src/main/java/brooklyn/entity/proxying/InternalLocationFactory.java
@@ -87,7 +87,7 @@ public class InternalLocationFactory extends InternalFactory {
         try {
             Class<? extends T> clazz = spec.getType();
             
-            T loc = constructLocation(clazz, spec);
+            T loc = construct(clazz, spec.getFlags());
 
             if (spec.getId() != null) {
                 FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", spec.getId()), loc);
@@ -122,13 +122,6 @@ public class InternalLocationFactory extends InternalFactory {
     }
     
     /**
-     * Constructs an entity (if new-style, calls no-arg constructor; if old-style, uses spec
to pass in config).
-     */
-    public <T extends Location> T constructLocation(Class<? extends T> clazz,
LocationSpec<T> spec) {
-        return super.construct(clazz, spec.getFlags());
-    }
-
-    /**
      * Constructs a new-style entity (fails if no no-arg constructor).
      */
     public <T extends Location> T constructLocation(Class<T> clazz) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e07155ad/core/src/main/java/brooklyn/entity/proxying/InternalPolicyFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/proxying/InternalPolicyFactory.java b/core/src/main/java/brooklyn/entity/proxying/InternalPolicyFactory.java
index 5480823..3839ce1 100644
--- a/core/src/main/java/brooklyn/entity/proxying/InternalPolicyFactory.java
+++ b/core/src/main/java/brooklyn/entity/proxying/InternalPolicyFactory.java
@@ -89,7 +89,7 @@ public class InternalPolicyFactory extends InternalFactory {
         try {
             Class<? extends T> clazz = spec.getType();
             
-            T pol = constructPolicy(clazz, spec);
+            T pol = construct(clazz, spec.getFlags());
 
             if (spec.getDisplayName()!=null)
                 ((AbstractPolicy)pol).setName(spec.getDisplayName());
@@ -124,7 +124,7 @@ public class InternalPolicyFactory extends InternalFactory {
         try {
             Class<? extends T> clazz = spec.getType();
             
-            T enricher = constructEnricher(clazz, spec);
+            T enricher = construct(clazz, spec.getFlags());
             
             if (spec.getDisplayName()!=null)
                 ((AbstractEnricher)enricher).setName(spec.getDisplayName());
@@ -151,20 +151,6 @@ public class InternalPolicyFactory extends InternalFactory {
     }
     
     /**
-     * Constructs a policy (if new-style, calls no-arg constructor; if old-style, uses spec
to pass in config).
-     */
-    public <T extends Policy> T constructPolicy(Class<? extends T> clazz, PolicySpec<T>
spec) {
-        return super.construct(clazz, spec.getFlags());
-    }
-
-    /**
-     * Constructs an enricher (if new-style, calls no-arg constructor; if old-style, uses
spec to pass in config).
-     */
-    public <T extends Enricher> T constructEnricher(Class<? extends T> clazz,
EnricherSpec<T> spec) {
-        return super.construct(clazz, spec.getFlags());
-    }
-
-    /**
      * Constructs a new-style policy (fails if no no-arg constructor).
      */
     public <T extends Policy> T constructPolicy(Class<T> clazz) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e07155ad/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
index 8814aa1..34a529e 100644
--- a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
+++ b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
@@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
@@ -41,6 +42,7 @@ import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.proxying.InternalEntityFactory;
+import brooklyn.entity.proxying.InternalFactory;
 import brooklyn.entity.proxying.InternalLocationFactory;
 import brooklyn.entity.proxying.InternalPolicyFactory;
 import brooklyn.internal.BrooklynFeatureEnablement;
@@ -566,41 +568,11 @@ public class RebindManagerImpl implements RebindManager {
     private Entity newEntity(String entityId, String entityType, Reflections reflections)
{
         Class<? extends Entity> entityClazz = (Class<? extends Entity>) reflections.loadClass(entityType);
         
-        if (InternalEntityFactory.isNewStyleEntity(managementContext, entityClazz)) {
-            // Not using entityManager.createEntity(EntitySpec) because don't want init()
to be called
-            // TODO Need to rationalise this to move code into methods of InternalEntityFactory.
-            //      The InternalEntityFactory.constructEntity is used in three places:
-            //       1. normal entity creation (through entityManager.createEntity)
-            //       2. rebind (i.e. here)
-            //       3. yaml parsing
-            //      Purpose is to create a new (unconfigured/uninitialised) entity, but that
is
-            //      known about by the managementContext and that has things like the right
id and 
-            //      a proxy for if another entity needs to reference it during the init phase.
+        if (InternalFactory.isNewStyle(entityClazz)) {
+            // Not using entityManager.createEntity(EntitySpec) because don't want init()
to be called.
+            // Creates an uninitialized entity, but that has correct id + proxy.
             InternalEntityFactory entityFactory = managementContext.getEntityFactory();
-            Entity entity = entityFactory.constructEntity(entityClazz);
-            FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", entityId), entity);
-            if (entity instanceof AbstractApplication) {
-                FlagUtils.setFieldsFromFlags(ImmutableMap.of("mgmt", managementContext),
entity);
-            }
-            managementContext.prePreManage(entity);
-            ((AbstractEntity)entity).setManagementContext(managementContext);
-            
-            Class<?> entityInterface;
-            List<Class<?>> additionalInterfaces;
-            try {
-                entityInterface = managementContext.getEntityManager().getEntityTypeRegistry().getEntityTypeOf((Class)entityClazz);
-                additionalInterfaces = Reflections.getAllInterfaces(entityClazz);
-            } catch (IllegalArgumentException e) {
-                // TODO this can happen if it's an app with no annotation, for example; not
nice catching exception
-                entityInterface = Entity.class;
-                additionalInterfaces = Reflections.getAllInterfaces(entityClazz);
-            }
-            EntitySpec<Entity> entitySpec = EntitySpec.create((Class)entityInterface)
-                    .additionalInterfaces(additionalInterfaces)
-                    .impl((Class)entityClazz)
-                    .id(entityId);
-
-            ((AbstractEntity)entity).setProxy(entityFactory.createEntityProxy(entitySpec,
entity));
+            Entity entity = entityFactory.constructEntity(entityClazz, Reflections.getAllInterfaces(entityClazz),
entityId);
             
             return entity;
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e07155ad/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index 2f000e8..c8112ee 100644
--- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -36,7 +36,6 @@ import brooklyn.catalog.CatalogItem;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Application;
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.AbstractApplication;
 import brooklyn.entity.basic.AbstractEntity;
 import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.basic.EntityInternal;
@@ -61,7 +60,6 @@ import brooklyn.util.javalang.Reflections;
 import brooklyn.util.text.Strings;
 
 import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 
@@ -282,22 +280,11 @@ public class BrooklynComponentTemplateResolver {
         Class<? extends T> entityImpl = (spec.getImplementation() != null) ? spec.getImplementation()
: mgmt.getEntityManager().getEntityTypeRegistry().getImplementedBy(spec.getType());
         InternalEntityFactory entityFactory = ((ManagementContextInternal)mgmt).getEntityFactory();
         T entity = entityFactory.constructEntity(entityImpl, spec);
-        if (entity instanceof AbstractApplication) {
-            FlagUtils.setFieldsFromFlags(ImmutableMap.of("mgmt", mgmt), entity);
-        }
 
-        // TODO Some of the code below could go into constructEntity?
-        if (spec.getId() != null) {
-            FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", spec.getId()), entity);
-        }
         String planId = (String)spec.getConfig().get(BrooklynCampConstants.PLAN_ID.getConfigKey());
         if (planId != null) {
             ((EntityInternal)entity).setConfig(BrooklynCampConstants.PLAN_ID, planId);
         }
-        ((ManagementContextInternal)mgmt).prePreManage(entity);
-        ((AbstractEntity)entity).setManagementContext((ManagementContextInternal)mgmt);
-        
-        ((AbstractEntity)entity).setProxy(entityFactory.createEntityProxy(spec, entity));
         
         if (spec.getLocations().size() > 0) {
             ((AbstractEntity)entity).addLocations(spec.getLocations());


Mime
View raw message