brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/9] incubator-brooklyn git commit: introduce BrooklynTypeRegistry and start migrating Catalog to it
Date Mon, 02 Nov 2015 16:42:58 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master c0021ca1b -> 48e4fe3ca


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index e9d22f1..b1044ee 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -29,11 +29,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.Nullable;
 
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
 import org.apache.brooklyn.camp.brooklyn.spi.creation.service.CampServiceSpecResolver;
@@ -145,20 +145,20 @@ public class BrooklynComponentTemplateResolver {
         return serviceSpecResolver.accepts(type, loader);
     }
 
-    public <T extends Entity> EntitySpec<T> resolveSpec(Set<String> encounteredCatalogTypes) {
+    public <T extends Entity> EntitySpec<T> resolveSpec(Set<String> encounteredRegisteredTypeIds) {
         if (alreadyBuilt.getAndSet(true))
             throw new IllegalStateException("Spec can only be used once: "+this);
 
-        EntitySpec<?> spec = serviceSpecResolver.resolve(type, loader, encounteredCatalogTypes);
+        EntitySpec<?> spec = serviceSpecResolver.resolve(type, loader, encounteredRegisteredTypeIds);
 
         if (spec == null) {
             // Try to provide some troubleshooting details
             final String msgDetails;
-            CatalogItem<?, ?> item = CatalogUtils.getCatalogItemOptionalVersion(mgmt, Strings.removeFromStart(type, "catalog:"));
+            RegisteredType item = mgmt.getTypeRegistry().get(Strings.removeFromStart(type, "catalog:"), null, null);
             String proto = Urls.getProtocol(type);
-            if (item != null && encounteredCatalogTypes.contains(item.getSymbolicName())) {
+            if (item != null && encounteredRegisteredTypeIds.contains(item.getSymbolicName())) {
                 msgDetails = "Cycle between catalog items detected, starting from " + type +
-                        ". Other catalog items being resolved up the stack are " + encounteredCatalogTypes +
+                        ". Other catalog items being resolved up the stack are " + encounteredRegisteredTypeIds +
                         ". Tried loading it as a Java class instead but failed.";
             } else if (proto != null) {
                 msgDetails = "The reference " + type + " looks like a URL (running the CAMP Brooklyn assembly-template instantiator) but the protocol " +
@@ -170,7 +170,7 @@ public class BrooklynComponentTemplateResolver {
             throw new IllegalStateException("Unable to create spec for type " + type + ". " + msgDetails);
         }
 
-        populateSpec(spec, encounteredCatalogTypes);
+        populateSpec(spec, encounteredRegisteredTypeIds);
 
         @SuppressWarnings("unchecked")
         EntitySpec<T> typedSpec = (EntitySpec<T>) spec;
@@ -187,7 +187,7 @@ public class BrooklynComponentTemplateResolver {
     }
 
     @SuppressWarnings("unchecked")
-    private <T extends Entity> void populateSpec(EntitySpec<T> spec, Set<String> encounteredCatalogTypes) {
+    private <T extends Entity> void populateSpec(EntitySpec<T> spec, Set<String> encounteredRegisteredTypeIds) {
         String name, source=null, templateId=null, planId=null;
         if (template.isPresent()) {
             name = template.get().getName();
@@ -205,9 +205,9 @@ public class BrooklynComponentTemplateResolver {
             Iterable<Map<String,?>> children = (Iterable<Map<String,?>>)childrenObj;
             for (Map<String,?> childAttrs : children) {
                 BrooklynComponentTemplateResolver entityResolver = BrooklynComponentTemplateResolver.Factory.newInstance(loader, childAttrs);
-                // encounteredCatalogTypes must contain the items currently being loaded (the dependency chain),
-                // but not parent items in this catalog item already resolved.
-                EntitySpec<? extends Entity> childSpec = entityResolver.resolveSpec(encounteredCatalogTypes);
+                // encounteredRegisteredTypeIds must contain the items currently being loaded (the dependency chain),
+                // but not parent items in this type already resolved.
+                EntitySpec<? extends Entity> childSpec = entityResolver.resolveSpec(encounteredRegisteredTypeIds);
                 spec.child(childSpec);
             }
         }
@@ -307,7 +307,7 @@ public class BrooklynComponentTemplateResolver {
         /* TODO find a way to make do without loader here?
          * it is not very nice having to serialize it; but serialization of BLCL is now relatively clean.
          *
-         * it is only used to instantiate classes, and now most things should be registered with catalog;
+         * it is only used to instantiate classes, and now most types should be registered;
          * the notable exception is when one entity in a bundle is creating another in the same bundle,
          * it wants to use his bundle CLC to do that.  but we can set up some unique reference to the entity
          * which can be used to find it from mgmt, rather than pass the loader.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
index a7a7530..181265d 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
@@ -21,8 +21,6 @@ package org.apache.brooklyn.camp.brooklyn.spi.creation;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.brooklyn.api.catalog.BrooklynCatalog;
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.EntityInitializer;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -30,9 +28,10 @@ import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.policy.PolicySpec;
 import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.EnricherSpec;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
 import org.apache.brooklyn.camp.brooklyn.spi.creation.BrooklynYamlTypeInstantiator.InstantiatorFromKey;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 
@@ -108,29 +107,14 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
 
             String policyType = decoLoader.getTypeName().get();
             ManagementContext mgmt = instantiator.loader.getManagementContext();
-            BrooklynCatalog catalog = mgmt.getCatalog();
-            CatalogItem<Policy, PolicySpec<?>> item = getPolicyCatalogItem(catalog, policyType);
+            
+            RegisteredType item = mgmt.getTypeRegistry().get(policyType, BrooklynTypeRegistry.RegisteredTypeKind.SPEC, Policy.class);
             PolicySpec<? extends Policy> spec;
-            if (item != null) {
-                spec = (PolicySpec) catalog.createSpec((CatalogItem) item);
-                spec.configure(decoLoader.getConfigMap());
-            } else {
-                // this pattern of creating a spec could be simplified with a "Configurable" superinterface on *Spec  
-                spec = PolicySpec.create(decoLoader.getType(Policy.class))
-                    .configure( decoLoader.getConfigMap() );
-            }
+            if (item!=null) spec = mgmt.getTypeRegistry().createSpec(item, PolicySpec.class);
+            else spec = PolicySpec.create(decoLoader.getType(Policy.class));
+            spec.configure( decoLoader.getConfigMap() );
             decorations.add(spec);
         }
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        private CatalogItem<Policy, PolicySpec<?>> getPolicyCatalogItem(BrooklynCatalog catalog, String policyType) {
-            if (CatalogUtils.looksLikeVersionedId(policyType)) {
-                String id = CatalogUtils.getIdFromVersionedId(policyType);
-                String version = CatalogUtils.getVersionFromVersionedId(policyType);
-                return (CatalogItem) catalog.getCatalogItem(id, version);
-            } else {
-                return (CatalogItem) catalog.getCatalogItem(policyType, BrooklynCatalog.DEFAULT_VERSION);
-            }
-        }
     }
 
     public static class EnricherSpecResolver extends BrooklynEntityDecorationResolver<EnricherSpec<?>> {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
index ae995e4..cacd201 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
@@ -18,7 +18,6 @@
  */
 package org.apache.brooklyn.camp.brooklyn.spi.creation;
 
-import java.io.StringReader;
 import java.util.Set;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -27,6 +26,7 @@ import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.camp.CampPlatform;
+import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
 import org.apache.brooklyn.camp.brooklyn.api.AssemblyTemplateSpecInstantiator;
 import org.apache.brooklyn.camp.spi.AssemblyTemplate;
 import org.apache.brooklyn.camp.spi.instantiate.AssemblyTemplateInstantiator;
@@ -59,7 +59,7 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
     @Override
     public EntitySpec<? extends Application> createApplicationSpec(String plan) {
         try {
-            CampPlatform camp = CampCatalogUtils.getCampPlatform(mgmt);
+            CampPlatform camp = CampUtils.getCampPlatform(mgmt);
             BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
             AssemblyTemplate at = CampUtils.registerDeploymentPlan(plan, loader, camp);
             AssemblyTemplateInstantiator instantiator = CampUtils.getInstantiator(at);
@@ -69,7 +69,7 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
                 // The unknown instantiator can create the app (Assembly), but not a spec.
                 // Currently, all brooklyn plans should produce the above.
                 if (at.getPlatformComponentTemplates()==null || at.getPlatformComponentTemplates().isEmpty()) {
-                    if (at.getCustomAttributes().containsKey("brooklyn.catalog"))
+                    if (at.getCustomAttributes().containsKey(BrooklynCampReservedKeys.BROOKLYN_CATALOG))
                         throw new IllegalArgumentException("Unrecognized application blueprint format: expected an application, not a brooklyn.catalog");
                     throw new PlanNotRecognizedException("Unrecognized application blueprint format: no services defined");
                 }
@@ -99,6 +99,17 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
         return (SpecT) CampCatalogUtils.createSpec(mgmt, (CatalogItem)item, encounteredTypes);
     }
 
+    // TODO
+//    @SuppressWarnings({ "unchecked", "rawtypes" })
+//    public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(RegisteredType type, Set<String> encounteredTypes) {
+//        if (encounteredTypes.contains(type.getSymbolicName())) {
+//            throw new IllegalStateException("Already encountered types " + encounteredTypes + " must not contain catalog item being resolver " + type.getSymbolicName());
+//        }
+//
+//        // Not really clear what should happen to the top-level attributes, ignored until a good use case appears.
+//        return (SpecT) CampCatalogUtils.createSpec(mgmt, type, encounteredTypes);
+//    }
+
     @Override
     public void injectManagementContext(ManagementContext mgmt) {
         this.mgmt = mgmt;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlCombiTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlCombiTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlCombiTest.java
index 29c015a..8e10c20 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlCombiTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlCombiTest.java
@@ -18,13 +18,9 @@
  */
 package org.apache.brooklyn.camp.brooklyn.catalog;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.Entities;
@@ -32,6 +28,10 @@ import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.entity.stock.BasicStartable;
 import org.apache.brooklyn.policy.ha.ServiceRestarter;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
 
 import com.google.common.collect.Iterables;
 
@@ -60,7 +60,7 @@ public class CatalogYamlCombiTest extends AbstractYamlTest {
             "      type: A",
             "      brooklyn.config: { b: 1 }");
 
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem("B", TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get("B", TEST_VERSION, null, null);
         Assert.assertNotNull(item);
 
         Entity a = launchEntity("A");
@@ -113,7 +113,7 @@ public class CatalogYamlCombiTest extends AbstractYamlTest {
             "      brooklyn.policies:",
             "      - type: A");
 
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem("A", TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get("A", TEST_VERSION, null, null);
         Assert.assertNotNull(item);
 
         Entity b = launchEntity("B", false);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
index 20d0a1d..882332b 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
@@ -27,19 +27,23 @@ import java.util.Collection;
 import java.util.List;
 
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
-import org.apache.brooklyn.util.osgi.OsgiTestResources;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.core.test.entity.TestEntityImpl;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.osgi.OsgiTestResources;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -60,8 +64,9 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
             "  item:",
             "    type: "+ BasicEntity.class.getName());
 
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
-        assertTrue(item.getPlanYaml().indexOf("services:")>=0, "expected 'services:' block: "+item+"\n"+item.getPlanYaml());
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+        String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item);
+        assertTrue(planYaml.indexOf("services:")>=0, "expected 'services:' block: "+item+"\n"+planYaml);
 
         deleteCatalogEntity(symbolicName);
     }
@@ -71,7 +76,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
 
         String symbolicName = "my.catalog.app.id.load";
         addCatalogOSGiEntity(symbolicName);
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
 
         deleteCatalogEntity(symbolicName);
@@ -93,7 +98,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
             "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
             "  item: " + SIMPLE_ENTITY_TYPE);
 
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
 
         deleteCatalogEntity(symbolicName);
@@ -116,7 +121,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
             "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
             "  item: " + SIMPLE_ENTITY_TYPE);
 
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
 
         deleteCatalogEntity(symbolicName);
@@ -140,7 +145,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
             "services:",
             "- type: " + SIMPLE_ENTITY_TYPE);
 
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
 
         deleteCatalogEntity(symbolicName);
@@ -158,7 +163,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
             "  - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
             "  item:",
             "    type: "+ SIMPLE_ENTITY_TYPE);
-        CatalogItem<?, ?> catalogItem = mgmt().getCatalog().getCatalogItem(id, BrooklynCatalog.DEFAULT_VERSION);
+        RegisteredType catalogItem = mgmt().getTypeRegistry().get(id, BrooklynCatalog.DEFAULT_VERSION);
         assertEquals(catalogItem.getVersion(), "0.0.0.SNAPSHOT");
         mgmt().getCatalog().deleteCatalogItem(id, "0.0.0.SNAPSHOT");
     }
@@ -175,7 +180,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
             "  - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
             "services:",
             "- type: " + SIMPLE_ENTITY_TYPE);
-        CatalogItem<?, ?> catalogItem = mgmt().getCatalog().getCatalogItem(id, TEST_VERSION);
+        RegisteredType catalogItem = mgmt().getTypeRegistry().get(id, TEST_VERSION);
         assertEquals(catalogItem.getVersion(), TEST_VERSION);
         mgmt().getCatalog().deleteCatalogItem(id, TEST_VERSION);
     }
@@ -213,8 +218,9 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
         String referrerSymbolicName = "my.catalog.app.id.referring";
         addCatalogOSGiEntities(referencedSymbolicName, SIMPLE_ENTITY_TYPE, referrerSymbolicName, ver(referencedSymbolicName));
 
-        CatalogItem<?, ?> referrer = mgmt().getCatalog().getCatalogItem(referrerSymbolicName, TEST_VERSION);
-        Assert.assertTrue(referrer.getPlanYaml().indexOf("services")>=0, "expected services in: "+referrer.getPlanYaml());
+        RegisteredType referrer = mgmt().getTypeRegistry().get(referrerSymbolicName, TEST_VERSION);
+        String planYaml = RegisteredTypes.getImplementationDataStringForSpec(referrer);
+        Assert.assertTrue(planYaml.indexOf("services")>=0, "expected services in: "+planYaml);
         
         String yaml = "name: simple-app-yaml\n" +
                       "location: localhost\n" +
@@ -523,11 +529,12 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
 
         String id = "my.catalog.app.id.create_spec";
         addCatalogOSGiEntity(id);
-        BrooklynCatalog catalog = mgmt().getCatalog();
-        CatalogItem<?, ?> item = catalog.getCatalogItem(id, TEST_VERSION);
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        Object spec = catalog.createSpec((CatalogItem) item);
+        BrooklynTypeRegistry catalog = mgmt().getTypeRegistry();
+        RegisteredType item = catalog.get(id, TEST_VERSION);
+        EntitySpec<?> spec = catalog.createSpec(item, EntitySpec.class);
         Assert.assertNotNull(spec);
+        AbstractBrooklynObjectSpec<?,?> spec2 = catalog.createSpec(item, AbstractBrooklynObjectSpec.class);
+        Assert.assertNotNull(spec2);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
index e5a8457..eebaea5 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
@@ -24,21 +24,22 @@ import static org.testng.Assert.assertNull;
 import java.util.Collection;
 import java.util.List;
 
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationDefinition;
 import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
-import org.apache.brooklyn.core.catalog.CatalogPredicates;
 import org.apache.brooklyn.core.config.BasicConfigKey;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
+import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.text.StringFunctions;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -51,7 +52,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
 
     @AfterMethod
     public void tearDown() {
-        for (CatalogItem<Location, LocationSpec<?>> ci : mgmt().getCatalog().getCatalogItems(CatalogPredicates.IS_LOCATION)) {
+        for (RegisteredType ci : mgmt().getTypeRegistry().getAll(RegisteredTypePredicates.IS_LOCATION)) {
             mgmt().getCatalog().deleteCatalogItem(ci.getSymbolicName(), ci.getVersion());
         }
     }
@@ -99,16 +100,17 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     }
 
     private void assertOsgi(String symbolicName) {
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
-        Collection<CatalogBundle> libs = item.getLibraries();
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+        Collection<OsgiBundleWithUrl> libs = item.getLibraries();
         assertEquals(libs.size(), 1);
         assertEquals(Iterables.getOnlyElement(libs).getUrl(), Iterables.getOnlyElement(getOsgiLibraries()));
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @SuppressWarnings({ "rawtypes" })
     private void assertAdded(String symbolicName, String expectedJavaType) {
-        CatalogItem item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
+        Assert.assertTrue(Location.class.isAssignableFrom(item.getJavaType()), "Expected Location, not "+item.getJavaType());
         assertEquals(countCatalogLocations(), 1);
 
         // Item added to catalog should automatically be available in location registry
@@ -116,7 +118,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         assertEquals(def.getId(), symbolicName);
         assertEquals(def.getName(), symbolicName);
         
-        LocationSpec spec = (LocationSpec) mgmt().getCatalog().createSpec(item);
+        LocationSpec spec = (LocationSpec) mgmt().getTypeRegistry().createSpec(item, LocationSpec.class);
         assertEquals(spec.getType().getName(), expectedJavaType);
     }
     
@@ -243,6 +245,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     }
 
     private int countCatalogLocations() {
-        return Iterables.size(mgmt().getCatalog().getCatalogItems(CatalogPredicates.IS_LOCATION));
+        return Iterables.size(mgmt().getTypeRegistry().getAll(RegisteredTypePredicates.IS_LOCATION));
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
index b325c62..9f2a377 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
@@ -33,6 +33,9 @@ import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.spi.Assembly;
 import org.apache.brooklyn.camp.spi.AssemblyTemplate;
 import org.apache.brooklyn.camp.spi.pdp.PdpYamlTest;
@@ -45,12 +48,12 @@ import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.effector.AddChildrenEffector;
 import org.apache.brooklyn.core.effector.Effectors;
 import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.ResourceUtils;
@@ -127,7 +130,7 @@ public class CampYamlLiteTest {
             .configure(AddChildrenEffector.BLUEPRINT_YAML, childYaml)
             .configure(AddChildrenEffector.EFFECTOR_PARAMETER_DEFS, MutableMap.of("war", (Object)MutableMap.of(
                 "defaultValue", "foo.war"))) ) ;
-        TestApplication app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).addInitializer(newEff), mgmt);
+        TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class).addInitializer(newEff));
 
         // test adding, with a parameter
         Task<List> task = app.invoke(Effectors.effector(List.class, "add_tomcat").buildAbstract(), MutableMap.of("war", "foo.bar"));
@@ -227,19 +230,20 @@ public class CampYamlLiteTest {
     }
 
     private void assertMgmtHasSampleMyCatalogApp(String symbolicName, String bundleUrl) {
-        CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        RegisteredType item = mgmt.getTypeRegistry().get(symbolicName, BrooklynTypeRegistry.RegisteredTypeKind.SPEC, null);
         assertNotNull(item, "failed to load item with id=" + symbolicName + " from catalog. Entries were: " +
-                Joiner.on(",").join(mgmt.getCatalog().getCatalogItems()));
+                Joiner.on(",").join(mgmt.getTypeRegistry().getAll()));
         assertEquals(item.getSymbolicName(), symbolicName);
 
         // stored as yaml, not java
-        assertNotNull(item.getPlanYaml());
-        Assert.assertTrue(item.getPlanYaml().contains("io.camp.mock:AppServer"));
+        String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item);
+        assertNotNull(planYaml);
+        Assert.assertTrue(planYaml.contains("io.camp.mock:AppServer"));
 
         // and let's check we have libraries
-        Collection<CatalogBundle> libs = item.getLibraries();
+        Collection<OsgiBundleWithUrl> libs = item.getLibraries();
         assertEquals(libs.size(), 1);
-        CatalogBundle bundle = Iterables.getOnlyElement(libs);
+        OsgiBundleWithUrl bundle = Iterables.getOnlyElement(libs);
         assertEquals(bundle.getUrl(), bundleUrl);
 
         // now let's check other things on the item

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
index 422998b..6c0a09a 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
@@ -56,7 +56,6 @@ public class TestAppAssemblyInstantiator extends BasicAssemblyTemplateInstantiat
         ManagementContext mgmt = ((HasBrooklynManagementContext)platform).getBrooklynManagementContext();
         
         TestApplication app = (TestApplication) mgmt.getEntityManager().createEntity( createApplicationSpec(template, platform, null) );
-        mgmt.getEntityManager().manage(app);
 
         return new TestAppAssembly(app);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
index 157ba67..f30c7ec 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
@@ -18,13 +18,10 @@
  */
 package org.apache.brooklyn.rest.util;
 
-import static org.apache.brooklyn.rest.util.WebResourceUtils.notFound;
 import static com.google.common.collect.Iterables.transform;
-import groovy.lang.GroovyClassLoader;
+import static org.apache.brooklyn.rest.util.WebResourceUtils.notFound;
 
-import java.io.Serializable;
 import java.lang.reflect.Constructor;
-import java.net.URI;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -34,12 +31,7 @@ import java.util.Set;
 import java.util.concurrent.Future;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
-import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
-import org.apache.brooklyn.util.collections.MutableSet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Application;
@@ -55,26 +47,28 @@ import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslComponent;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslComponent.Scope;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
-import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements.StringAndArgument;
 import org.apache.brooklyn.core.objs.BrooklynTypes;
-import org.apache.brooklyn.core.policy.AbstractPolicy;
 import org.apache.brooklyn.enricher.stock.Enrichers;
 import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.rest.domain.ApplicationSpec;
 import org.apache.brooklyn.rest.domain.EntitySpec;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.javalang.Reflections;
 import org.apache.brooklyn.util.net.Urls;
 import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
@@ -210,7 +204,52 @@ public class BrooklynRestResourceUtils {
         return null;
     }
 
-    @SuppressWarnings({ "unchecked", "deprecation" })
+    private class FindItemAndClass {
+        String catalogItemId;
+        Class<? extends Entity> clazz;
+        
+        @SuppressWarnings("unchecked")
+        private FindItemAndClass inferFrom(String type) {
+            BrooklynCatalog catalog = getCatalog();
+            CatalogItem<?, ?> item = CatalogUtils.getCatalogItemOptionalVersion(mgmt, type);
+            if (item==null) {
+                // although the method was deprecated in 0.7.0, its use here was not warned until 0.9.0;
+                // therefore this behaviour should not be changed until after 0.9.0
+                item = catalog.getCatalogItemForType(type);
+                if (item!=null) {
+                    log.warn("Creating application for requested type `"+type+" using item "+item+"; "
+                        + "the registered type name ("+item.getSymbolicName()+") should be used from the spec instead, "
+                        + "or the type registered under its own name. "
+                        + "Future versions will likely change semantics to attempt a POJO load of the type instead.");
+                }
+            }
+            
+            if (item != null) {
+                return setAs(
+                    catalog.createSpec((CatalogItem<Entity,org.apache.brooklyn.api.entity.EntitySpec<Entity>>)item).getType(),
+                    item.getId());
+            } else {
+                try {
+                    setAs(
+                        (Class<? extends Entity>) catalog.getRootClassLoader().loadClass(type),
+                        null);
+                    log.info("Catalog does not contain item for type {}; loaded class directly instead", type);
+                    return this;
+                } catch (ClassNotFoundException e2) {
+                    log.warn("No catalog item for type {}, and could not load class directly; rethrowing", type);
+                    throw new NoSuchElementException("Unable to find catalog item for type "+type);
+                }
+            }
+        }
+
+        private FindItemAndClass setAs(Class<? extends Entity> clazz, String catalogItemId) {
+            this.clazz = clazz;
+            this.catalogItemId = catalogItemId;
+            return this;
+        }
+    }
+    
+    @SuppressWarnings({ "deprecation" })
     public Application create(ApplicationSpec spec) {
         log.warn("Using deprecated functionality (as of 0.9.0), ApplicationSpec style (pre CAMP plans). " +
                     "Transition to actively supported spec plans.");
@@ -229,88 +268,73 @@ public class BrooklynRestResourceUtils {
         final Application instance;
 
         // Load the class; first try to use the appropriate catalog item; but then allow anything that is on the classpath
-        final Class<? extends Entity> clazz;
-        final String catalogItemId;
+        FindItemAndClass itemAndClass;
         if (Strings.isEmpty(type)) {
-            clazz = BasicApplication.class;
-            catalogItemId = null;
+            itemAndClass = new FindItemAndClass().setAs(BasicApplication.class, null);
         } else {
-            Class<? extends Entity> tempclazz;
-            BrooklynCatalog catalog = getCatalog();
-            CatalogItem<?, ?> item = catalog.getCatalogItemForType(type);
-            if (item != null) {
-                catalogItemId = item.getId();
-                tempclazz = (Class<? extends Entity>) catalog.loadClass(item);
-            } else {
-                catalogItemId = null;
-                try {
-                    tempclazz = (Class<? extends Entity>) catalog.getRootClassLoader().loadClass(type);
-                    log.info("Catalog does not contain item for type {}; loaded class directly instead", type);
-                } catch (ClassNotFoundException e2) {
-                    log.warn("No catalog item for type {}, and could not load class directly; rethrowing", type);
-                    throw new NoSuchElementException("Unable to find catalog item for type "+type);
-                }
-            }
-            clazz = tempclazz;
+            itemAndClass = new FindItemAndClass().inferFrom(type);
         }
-        if (Entitlements.isEntitled(mgmt.getEntitlementManager(), Entitlements.INVOKE_EFFECTOR, null)) {
-
-            try {
-                if (ApplicationBuilder.class.isAssignableFrom(clazz)) {
-                    Constructor<?> constructor = clazz.getConstructor();
-                    ApplicationBuilder appBuilder = (ApplicationBuilder) constructor.newInstance();
-                    if (!Strings.isEmpty(name)) appBuilder.appDisplayName(name);
-                    if (entities.size() > 0)
-                        log.warn("Cannot supply additional entities when using an ApplicationBuilder; ignoring in spec {}", spec);
-
-                    log.info("REST placing '{}' under management", spec.getName());
-                    appBuilder.configure(convertFlagsToKeys(appBuilder.getType(), configO));
-                    configureRenderingMetadata(spec, appBuilder);
-                    instance = appBuilder.manage(mgmt);
-
-                } else if (Application.class.isAssignableFrom(clazz)) {
-                    org.apache.brooklyn.api.entity.EntitySpec<?> coreSpec = toCoreEntitySpec(clazz, name, configO, catalogItemId);
-                    configureRenderingMetadata(spec, coreSpec);
-                    for (EntitySpec entitySpec : entities) {
-                        log.info("REST creating instance for entity {}", entitySpec.getType());
-                        coreSpec.child(toCoreEntitySpec(entitySpec));
-                    }
-
-                    log.info("REST placing '{}' under management", spec.getName() != null ? spec.getName() : spec);
-                    instance = (Application) mgmt.getEntityManager().createEntity(coreSpec);
-
-                } else if (Entity.class.isAssignableFrom(clazz)) {
-                    if (entities.size() > 0)
-                        log.warn("Cannot supply additional entities when using a non-application entity; ignoring in spec {}", spec);
-
-                    org.apache.brooklyn.api.entity.EntitySpec<?> coreSpec = toCoreEntitySpec(BasicApplication.class, name, configO, catalogItemId);
-                    configureRenderingMetadata(spec, coreSpec);
-
-                    coreSpec.child(toCoreEntitySpec(clazz, name, configO, catalogItemId)
-                            .configure(BrooklynCampConstants.PLAN_ID, "soleChildId"));
-                    coreSpec.enricher(Enrichers.builder()
-                            .propagatingAllBut(Attributes.SERVICE_UP, Attributes.SERVICE_NOT_UP_INDICATORS, 
-                                    Attributes.SERVICE_STATE_ACTUAL, Attributes.SERVICE_STATE_EXPECTED, 
-                                    Attributes.SERVICE_PROBLEMS)
-                            .from(new DslComponent(Scope.CHILD, "soleChildId").newTask())
-                            .build());
-
-                    log.info("REST placing '{}' under management", spec.getName());
-                    instance = (Application) mgmt.getEntityManager().createEntity(coreSpec);
-
-                } else {
-                    throw new IllegalArgumentException("Class " + clazz + " must extend one of ApplicationBuilder, Application or Entity");
+        
+        if (!Entitlements.isEntitled(mgmt.getEntitlementManager(), Entitlements.INVOKE_EFFECTOR, null)) {
+            throw WebResourceUtils.unauthorized("User '%s' is not authorized to create application from applicationSpec %s",
+                Entitlements.getEntitlementContext().user(), spec);
+        }
+
+        try {
+            if (ApplicationBuilder.class.isAssignableFrom(itemAndClass.clazz)) {
+                // warning only added in 0.9.0
+                log.warn("Using deprecated ApplicationBuilder "+itemAndClass.clazz+"; callers must migrate to use of Application");
+                Constructor<?> constructor = itemAndClass.clazz.getConstructor();
+                ApplicationBuilder appBuilder = (ApplicationBuilder) constructor.newInstance();
+                if (!Strings.isEmpty(name)) appBuilder.appDisplayName(name);
+                if (entities.size() > 0)
+                    log.warn("Cannot supply additional entities when using an ApplicationBuilder; ignoring in spec {}", spec);
+
+                log.info("REST placing '{}' under management", spec.getName());
+                appBuilder.configure(convertFlagsToKeys(appBuilder.getType(), configO));
+                configureRenderingMetadata(spec, appBuilder);
+                instance = appBuilder.manage(mgmt);
+
+            } else if (Application.class.isAssignableFrom(itemAndClass.clazz)) {
+                org.apache.brooklyn.api.entity.EntitySpec<?> coreSpec = toCoreEntitySpec(itemAndClass.clazz, name, configO, itemAndClass.catalogItemId);
+                configureRenderingMetadata(spec, coreSpec);
+                for (EntitySpec entitySpec : entities) {
+                    log.info("REST creating instance for entity {}", entitySpec.getType());
+                    coreSpec.child(toCoreEntitySpec(entitySpec));
                 }
 
-                return instance;
+                log.info("REST placing '{}' under management", spec.getName() != null ? spec.getName() : spec);
+                instance = (Application) mgmt.getEntityManager().createEntity(coreSpec);
+
+            } else if (Entity.class.isAssignableFrom(itemAndClass.clazz)) {
+                if (entities.size() > 0)
+                    log.warn("Cannot supply additional entities when using a non-application entity; ignoring in spec {}", spec);
+
+                org.apache.brooklyn.api.entity.EntitySpec<?> coreSpec = toCoreEntitySpec(BasicApplication.class, name, configO, itemAndClass.catalogItemId);
+                configureRenderingMetadata(spec, coreSpec);
+
+                coreSpec.child(toCoreEntitySpec(itemAndClass.clazz, name, configO, itemAndClass.catalogItemId)
+                    .configure(BrooklynCampConstants.PLAN_ID, "soleChildId"));
+                coreSpec.enricher(Enrichers.builder()
+                    .propagatingAllBut(Attributes.SERVICE_UP, Attributes.SERVICE_NOT_UP_INDICATORS, 
+                        Attributes.SERVICE_STATE_ACTUAL, Attributes.SERVICE_STATE_EXPECTED, 
+                        Attributes.SERVICE_PROBLEMS)
+                        .from(new DslComponent(Scope.CHILD, "soleChildId").newTask())
+                        .build());
+
+                log.info("REST placing '{}' under management", spec.getName());
+                instance = (Application) mgmt.getEntityManager().createEntity(coreSpec);
 
-            } catch (Exception e) {
-                log.error("REST failed to create application: " + e, e);
-                throw Exceptions.propagate(e);
+            } else {
+                throw new IllegalArgumentException("Class " + itemAndClass.clazz + " must extend one of ApplicationBuilder, Application or Entity");
             }
+
+            return instance;
+
+        } catch (Exception e) {
+            log.error("REST failed to create application: " + e, e);
+            throw Exceptions.propagate(e);
         }
-        throw WebResourceUtils.unauthorized("User '%s' is not authorized to create application from applicationSpec %s",
-                Entitlements.getEntitlementContext().user(), spec);
     }
     
     public Task<?> start(Application app, ApplicationSpec spec) {
@@ -336,37 +360,21 @@ public class BrooklynRestResourceUtils {
         return locations;
     }
 
-    @SuppressWarnings({ "unchecked", "deprecation" })
     private org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> toCoreEntitySpec(org.apache.brooklyn.rest.domain.EntitySpec spec) {
         String type = spec.getType();
         String name = spec.getName();
         Map<String, String> config = (spec.getConfig() == null) ? Maps.<String,String>newLinkedHashMap() : Maps.newLinkedHashMap(spec.getConfig());
 
-        BrooklynCatalog catalog = getCatalog();
-        CatalogItem<?, ?> item = catalog.getCatalogItemForType(type);
-        Class<? extends Entity> tempclazz;
-        final String catalogItemId;
-        if (item != null) {
-            tempclazz = (Class<? extends Entity>) catalog.loadClass(item);
-            catalogItemId = item.getId();
-        } else {
-            catalogItemId = null;
-            try {
-                tempclazz = (Class<? extends Entity>) catalog.getRootClassLoader().loadClass(type);
-                log.info("Catalog does not contain item for type {}; loaded class directly instead", type);
-            } catch (ClassNotFoundException e2) {
-                log.warn("No catalog item for type {}, and could not load class directly; rethrowing", type);
-                throw new NoSuchElementException("Unable to find catalog item for type "+type);
-            }
-        }
-        final Class<? extends Entity> clazz = tempclazz;
+        FindItemAndClass itemAndClass = new FindItemAndClass().inferFrom(type);
+        
+        final Class<? extends Entity> clazz = itemAndClass.clazz;
         org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> result;
         if (clazz.isInterface()) {
             result = org.apache.brooklyn.api.entity.EntitySpec.create(clazz);
         } else {
             result = org.apache.brooklyn.api.entity.EntitySpec.create(Entity.class).impl(clazz).additionalInterfaces(Reflections.getAllInterfaces(clazz));
         }
-        result.catalogItemId(catalogItemId);
+        result.catalogItemId(itemAndClass.catalogItemId);
         if (!Strings.isEmpty(name)) result.displayName(name);
         result.configure( convertFlagsToKeys(result.getType(), config) );
         configureRenderingMetadata(spec, result);
@@ -469,30 +477,6 @@ public class BrooklynRestResourceUtils {
                     Entitlements.getEntitlementContext().user(), entity);
     }
 
-
-    @Deprecated
-    @SuppressWarnings({ "rawtypes" })
-    public Response createCatalogEntryFromGroovyCode(String groovyCode) {
-        ClassLoader parent = getCatalog().getRootClassLoader();
-        @SuppressWarnings("resource")
-        GroovyClassLoader loader = new GroovyClassLoader(parent);
-
-        Class clazz = loader.parseClass(groovyCode);
-
-        if (AbstractEntity.class.isAssignableFrom(clazz)) {
-            CatalogItem<?,?> item = getCatalog().addItem(clazz);
-            log.info("REST created "+item);
-            return Response.created(URI.create("entities/" + clazz.getName())).build();
-
-        } else if (AbstractPolicy.class.isAssignableFrom(clazz)) {
-            CatalogItem<?,?> item = getCatalog().addItem(clazz);
-            log.info("REST created "+item);
-            return Response.created(URI.create("policies/" + clazz.getName())).build();
-        }
-
-        throw WebResourceUtils.preconditionFailed("Unsupported type superclass "+clazz.getSuperclass()+"; expects Entity or Policy");
-    }
-
     @Deprecated
     public static String fixLocation(String locationId) {
         if (locationId.startsWith("/v1/locations/")) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/WebResourceUtils.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/WebResourceUtils.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/WebResourceUtils.java
index e8f2505..1a74a33 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/WebResourceUtils.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/WebResourceUtils.java
@@ -141,7 +141,7 @@ public class WebResourceUtils {
 
     public static String getPathFromVersionedId(String versionedId) {
         if (CatalogUtils.looksLikeVersionedId(versionedId)) {
-            String symbolicName = CatalogUtils.getIdFromVersionedId(versionedId);
+            String symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(versionedId);
             String version = CatalogUtils.getVersionFromVersionedId(versionedId);
             return Urls.encode(symbolicName) + "/" + Urls.encode(version);
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
index 2d264f3..020fe19 100644
--- a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
+++ b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
@@ -36,7 +36,6 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
 import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityFunctions;
@@ -244,12 +243,12 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
         assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-yaml");
     }
 
-    @SuppressWarnings("deprecation")
     @Test
     public void testReferenceCatalogEntity() throws Exception {
-        getManagementContext().getCatalog().addItem(BasicEntity.class);
+        getManagementContext().getCatalog().addItems("{ name: "+BasicEntity.class.getName()+", "
+            + "services: [ { type: "+BasicEntity.class.getName()+" } ] }");
 
-        String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType: " + BasicEntity.class.getName() + " } ] }";
+        String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { type: " + BasicEntity.class.getName() + " } ] }";
 
         ClientResponse response = client().resource("/v1/applications")
                 .entity(yaml, "application/x-yaml")
@@ -335,7 +334,7 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
                 .get(ApplicationSummary.class);
         assertEquals(summary.getStatus(), Status.RUNNING);
 
-        ((EntityLocal)app).sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        app.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         try {
             ApplicationSummary summary2 = client().resource("/v1/applications/"+app.getId())
                     .get(ApplicationSummary.class);
@@ -343,7 +342,7 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
             assertEquals(summary2.getStatus(), Status.ERROR);
             
         } finally {
-            ((EntityLocal)app).sensors().set(Attributes.SERVICE_STATE_ACTUAL, origState);
+            app.sensors().set(Attributes.SERVICE_STATE_ACTUAL, origState);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/DescendantsTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/DescendantsTest.java b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/DescendantsTest.java
index 43e7166..a8748a7 100644
--- a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/DescendantsTest.java
+++ b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/DescendantsTest.java
@@ -27,14 +27,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeoutException;
 
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.rest.domain.ApplicationSpec;
 import org.apache.brooklyn.rest.domain.EntitySpec;
@@ -43,6 +37,11 @@ import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
 import org.apache.brooklyn.rest.testing.mocks.RestMockSimpleEntity;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.text.StringEscapes;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
@@ -101,9 +100,9 @@ public class DescendantsTest extends BrooklynRestResourceTest {
         assertEquals(sensors.size(), 0);
 
         long v = 0;
-        ((EntityLocal)application).sensors().set(Sensors.newLongSensor("foo"), v);
+        application.sensors().set(Sensors.newLongSensor("foo"), v);
         for (Entity e: entities)
-            ((EntityLocal)e).sensors().set(Sensors.newLongSensor("foo"), v+=123);
+            e.sensors().set(Sensors.newLongSensor("foo"), v+=123);
         
         sensors = client().resource("/v1/applications/"+application.getApplicationId()+"/descendants/sensor/foo")
             .get(new GenericType<Map<String,Object>>() {});

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ScriptResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ScriptResourceTest.java b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ScriptResourceTest.java
index ddb4fe1..23a3e5a 100644
--- a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ScriptResourceTest.java
+++ b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/ScriptResourceTest.java
@@ -20,21 +20,23 @@ package org.apache.brooklyn.rest.resources;
 
 import java.util.Collections;
 
-import org.testng.Assert;
-import org.testng.annotations.Test;
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.rest.domain.ScriptExecutionSummary;
 import org.apache.brooklyn.rest.testing.mocks.RestMockApp;
+import org.testng.Assert;
+import org.testng.annotations.Test;
 
 public class ScriptResourceTest {
 
     @Test
     public void testGroovy() {
-        RestMockApp app = new RestMockApp();
-        Entities.startManagement(app);
-        ManagementContext mgmt = app.getManagementContext();
+        ManagementContext mgmt = LocalManagementContextForTests.newInstance();
+        Application app = mgmt.getEntityManager().createEntity( EntitySpec.create(Application.class, RestMockApp.class) );
         try {
         
             Entities.start(app, Collections.<Location>emptyList());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/dc968f9d/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/UsageResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/UsageResourceTest.java b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/UsageResourceTest.java
index 97793a3..697ae10 100644
--- a/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/UsageResourceTest.java
+++ b/usage/rest-server/src/test/java/org/apache/brooklyn/rest/resources/UsageResourceTest.java
@@ -35,10 +35,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
+import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.location.NoMachinesAvailableException;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.mgmt.internal.LocalUsageManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.test.entity.TestApplication;
@@ -46,7 +46,6 @@ import org.apache.brooklyn.entity.software.base.SoftwareProcessEntityTest;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.location.ssh.SshMachineLocation;
 import org.apache.brooklyn.rest.domain.ApplicationSpec;
-import org.apache.brooklyn.rest.domain.EntitySpec;
 import org.apache.brooklyn.rest.domain.Status;
 import org.apache.brooklyn.rest.domain.TaskSummary;
 import org.apache.brooklyn.rest.domain.UsageStatistic;
@@ -72,7 +71,7 @@ public class UsageResourceTest extends BrooklynRestResourceTest {
     private Calendar testStartTime;
     
     private final ApplicationSpec simpleSpec = ApplicationSpec.builder().name("simple-app").
-            entities(ImmutableSet.of(new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()))).
+            entities(ImmutableSet.of(new org.apache.brooklyn.rest.domain.EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()))).
             locations(ImmutableSet.of("localhost")).
             build();
 
@@ -238,7 +237,7 @@ public class UsageResourceTest extends BrooklynRestResourceTest {
     @Test
     public void testListAndGetMachineUsage() throws Exception {
         Location location = getManagementContext().getLocationManager().createLocation(LocationSpec.create(DynamicLocalhostMachineProvisioningLocation.class));
-        TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, getManagementContext());
+        TestApplication app = getManagementContext().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
         SoftwareProcessEntityTest.MyService entity = app.createAndManageChild(org.apache.brooklyn.api.entity.EntitySpec.create(SoftwareProcessEntityTest.MyService.class));
         
         Calendar preStart = new GregorianCalendar();
@@ -264,7 +263,7 @@ public class UsageResourceTest extends BrooklynRestResourceTest {
     @Test
     public void testListMachinesUsageForApp() throws Exception {
         Location location = getManagementContext().getLocationManager().createLocation(LocationSpec.create(DynamicLocalhostMachineProvisioningLocation.class));
-        TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, getManagementContext());
+        TestApplication app = getManagementContext().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
         SoftwareProcessEntityTest.MyService entity = app.createAndManageChild(org.apache.brooklyn.api.entity.EntitySpec.create(SoftwareProcessEntityTest.MyService.class));
         String appId = app.getId();
         


Mime
View raw message