brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [19/50] git commit: Handle catalog item referencing other catalog item
Date Wed, 09 Jul 2014 21:46:32 GMT
Handle catalog item referencing other catalog item


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

Branch: refs/heads/master
Commit: 343622cd32451dd0714078e1d4319dfed6f49f95
Parents: 0317a44
Author: Aled Sage <aled.sage@gmail.com>
Authored: Mon Jul 7 19:32:18 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Jul 9 22:34:44 2014 +0100

----------------------------------------------------------------------
 .../BrooklynAssemblyTemplateInstantiator.java   | 37 ++++++++-------
 .../resources/CatalogBundleResourceTest.java    | 50 ++++++++++----------
 2 files changed, 46 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/343622cd/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
index a8c8ff6..8d73ccc 100644
--- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
+++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
@@ -66,6 +66,7 @@ import brooklyn.util.flags.TypeCoercions;
 import brooklyn.util.text.Strings;
 
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpecInstantiator
{
@@ -299,7 +300,10 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         EntitySpec<? extends Application> app = resolver.resolveSpec(StartableApplication.class,
BasicApplicationImpl.class);
         
         // first build the children into an empty shell app
-        buildTemplateServicesAsSpecs(loader, template, platform, app);
+        List<EntitySpec<?>> childSpecs = buildTemplateServicesAsSpecs(loader,
template, platform);
+        for (EntitySpec<?> childSpec : childSpecs) {
+            app.child(childSpec);
+        }
         
         if (shouldUnwrap(template, app)) {
             EntitySpec<? extends Application> oldApp = app;
@@ -346,15 +350,16 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         return true;
     }
 
-    private void buildTemplateServicesAsSpecs(BrooklynClassLoadingContext loader, AssemblyTemplate
template, CampPlatform platform, EntitySpec<? extends Application> root) {
+    private List<EntitySpec<?>> buildTemplateServicesAsSpecs(BrooklynClassLoadingContext
loader, AssemblyTemplate template, CampPlatform platform) {
+        List<EntitySpec<?>> result = Lists.newArrayList();
+        
         for (ResolvableLink<PlatformComponentTemplate> ctl: template.getPlatformComponentTemplates().links())
{
             PlatformComponentTemplate appChildComponentTemplate = ctl.resolve();
             BrooklynComponentTemplateResolver entityResolver = BrooklynComponentTemplateResolver.Factory.newInstance(loader,
appChildComponentTemplate);
-            
-            EntitySpec<? extends Entity> spec;
-            
             ManagementContext mgmt = loader.getManagementContext();
             
+            EntitySpec<?> spec;
+            
             CatalogItem<Entity, EntitySpec<?>> item = entityResolver.getCatalogItem();
             if (item != null) {
                 String yaml = item.getPlanYaml();
@@ -369,18 +374,17 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
                     BrooklynLoaderTracker.unsetLoader(itemLoader);
                 }
 
-
-                // FIXME Entitlement?
-//                if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.DEPLOY_APPLICATION,
at)) {
-//                    throw WebResourceUtils.unauthorized("User '%s' is not authorized to
start application %s",
-//                        Entitlements.getEntitlementContext().user(), yaml);
-//                }
-                
+                // TODO Should we check entitlements, or sufficient to do once for this being
called in the first place?
+                // TODO Is it acceptable to only allow a single  top-level entity in a catalog?
If not, we need to think
+                //      about what it would mean to subsequently call buildChildrenEntitySpecs
on the list of top-level entities!
                 try {
                     AssemblyTemplateInstantiator ati = at.getInstantiator().newInstance();
                     if (ati instanceof BrooklynAssemblyTemplateInstantiator) {
-                        spec = EntitySpec.create(BasicApplication.class);
-                        ((BrooklynAssemblyTemplateInstantiator)ati).buildTemplateServicesAsSpecs(itemLoader,
at, platform, (EntitySpec)spec);
+                        List<EntitySpec<?>> specs = ((BrooklynAssemblyTemplateInstantiator)ati).buildTemplateServicesAsSpecs(itemLoader,
at, platform);
+                        if (specs.size() > 1) {
+                            throw new UnsupportedOperationException("Only supporting single
service in catalog item currently");
+                        }
+                        spec = specs.get(0);
                     } else {
                         throw new IllegalStateException("Cannot create application with instantiator:
" + ati);
                     }
@@ -391,11 +395,12 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
                 spec = entityResolver.resolveSpec();
             }
 
-            root.child(spec);
-            
             BrooklynClassLoadingContext newLoader = entityResolver.loader;
             buildChildrenEntitySpecs(newLoader, spec, entityResolver.getChildren(appChildComponentTemplate.getCustomAttributes()));
+            
+            result.add(spec);
         }
+        return result;
     }
 
     protected void buildChildrenEntitySpecs(BrooklynClassLoadingContext loader, EntitySpec<?>
parent, List<Map<String, Object>> childConfig) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/343622cd/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
index c3ccaca..2161464 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
@@ -56,31 +56,31 @@ public class CatalogBundleResourceTest extends BrooklynRestResourceTest
{
         assertEquals(simpleEntity.getEntityType().getName(), "brooklyn.osgi.tests.SimpleEntity");
     }
 
-//    @Test
-//    public void testLaunchApplicationWithCatalogReferencingOtherCatalogYaml() throws Exception
{
-//        String referencedRegisteredTypeName = "my.catalog.app.id.referenced";
-//        String referrerRegisteredTypeName = "my.catalog.app.id.referring";
-//        addCatalogOSGiEntity(referencedRegisteredTypeName);
-//        addCatalogEntityReferencingCatalogEntry(referrerRegisteredTypeName, referencedRegisteredTypeName);
-//
-//        String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+referrerRegisteredTypeName+" } ] }";
-//        
-//        ClientResponse response = client().resource("/v1/applications")
-//            .entity(yaml, "application/x-yaml")
-//            .post(ClientResponse.class);
-//        assertTrue(response.getStatus()/100 == 2, "response is "+response);
-//        
-//        // Expect app to be running
-//        URI appUri = response.getLocation();
-//        waitForApplicationToBeRunning(response.getLocation());
-//        ApplicationSummary appSummary = client().resource(appUri).get(ApplicationSummary.class);
-//        String appId = appSummary.getId();
-//        assertEquals(appSummary.getSpec().getName(), "simple-app-yaml");
-//
-//        Application app = (Application) getManagementContext().getEntityManager().getEntity(appId);
-//        Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
-//        assertEquals(simpleEntity.getEntityType().getName(), "brooklyn.osgi.tests.SimpleEntity");
-//    }
+    @Test
+    public void testLaunchApplicationWithCatalogReferencingOtherCatalogYaml() throws Exception
{
+        String referencedRegisteredTypeName = "my.catalog.app.id.referenced";
+        String referrerRegisteredTypeName = "my.catalog.app.id.referring";
+        addCatalogOSGiEntity(referencedRegisteredTypeName);
+        addCatalogEntityReferencingCatalogEntry(referrerRegisteredTypeName, referencedRegisteredTypeName);
+
+        String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+referrerRegisteredTypeName+" } ] }";
+        
+        ClientResponse response = client().resource("/v1/applications")
+            .entity(yaml, "application/x-yaml")
+            .post(ClientResponse.class);
+        assertTrue(response.getStatus()/100 == 2, "response is "+response);
+        
+        // Expect app to be running
+        URI appUri = response.getLocation();
+        waitForApplicationToBeRunning(response.getLocation());
+        ApplicationSummary appSummary = client().resource(appUri).get(ApplicationSummary.class);
+        String appId = appSummary.getId();
+        assertEquals(appSummary.getSpec().getName(), "simple-app-yaml");
+
+        Application app = (Application) getManagementContext().getEntityManager().getEntity(appId);
+        Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
+        assertEquals(simpleEntity.getEntityType().getName(), "brooklyn.osgi.tests.SimpleEntity");
+    }
 
     private void addCatalogOSGiEntity(String registeredTypeName) {
         String catalogYaml =


Mime
View raw message