brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [35/50] git commit: CAMP: handle serviceType “java:” prefix
Date Wed, 09 Jul 2014 21:46:48 GMT
CAMP: handle serviceType “java:” prefix


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

Branch: refs/heads/master
Commit: 8e57fb0b78dcc667c61f6cbb43c9a72c7b4d0aec
Parents: 3ed846a
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Jul 8 12:29:21 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Jul 9 22:34:46 2014 +0100

----------------------------------------------------------------------
 .../BrooklynAssemblyTemplateInstantiator.java   | 10 ++-----
 .../BrooklynComponentTemplateResolver.java      |  6 ++++
 .../resources/CatalogBundleResourceTest.java    | 30 +++++++++++++-------
 3 files changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8e57fb0b/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 590f35d..175382e 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
@@ -226,16 +226,12 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
             ManagementContext mgmt = loader.getManagementContext();
 
             String catalogIdOrJavaType = entityResolver.getCatalogIdOrJavaType();
-
-            EntitySpec<?> spec;
-            
             CatalogItem<Entity, EntitySpec<?>> item = entityResolver.getCatalogItem();
             
-            // FIXME
-            log.warn("buildTemplateServicesAsSpecsImpl: catalogIdOrJavaType="+catalogIdOrJavaType+";
item="+item+"; loader="+loader+"; template="+template+"; encounteredCatalogTypes="+encounteredCatalogTypes);
+            if (log.isTraceEnabled()) log.trace("Building CAMP template services: type="+catalogIdOrJavaType+";
item="+item+"; loader="+loader+"; template="+template+"; encounteredCatalogTypes="+encounteredCatalogTypes);
 
-
-            if (item == null || item.getJavaType() != null) {
+            EntitySpec<?> spec;
+            if (item == null || item.getJavaType() != null || entityResolver.isJavaTypePrefix())
{
                 spec = entityResolver.resolveSpec();
             } else {
                 boolean firstOccurrence = encounteredCatalogTypes.add(catalogIdOrJavaType);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8e57fb0b/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 770b97f..ceb248b 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
@@ -152,6 +152,12 @@ public class BrooklynComponentTemplateResolver {
         return Factory.getDeclaredType(null, template.orNull(), attrs);
     }
     
+    // TODO Generalise to have other prefixes (e.g. explicit "catalog:" etc)?
+    protected boolean isJavaTypePrefix() {
+        String type = getDeclaredType();
+        return type != null && (type.toLowerCase().startsWith("java:") || type.toLowerCase().startsWith("brooklyn:java:"));
+    }
+
     protected String getCatalogIdOrJavaType() {
         String type = getDeclaredType();
         type = Strings.removeFromStart(type, "brooklyn:", "java:");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8e57fb0b/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 9780d30..f3a8477 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
@@ -62,6 +62,13 @@ public class CatalogBundleResourceTest extends BrooklynRestResourceTest
{
     }
 
     @Test
+    public void testLaunchApplicationWithTypeUsingJavaColonPrefixInYaml() throws Exception
{
+        String registeredTypeName = SIMPLE_ENTITY_TYPE;
+        String serviceName = "java:"+SIMPLE_ENTITY_TYPE;
+        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, serviceName);
+    }
+
+    @Test
     public void testLaunchApplicationLoopWithJavaTypeNameInYamlFails() throws Exception {
         String registeredTypeName = SIMPLE_ENTITY_TYPE;
         registerAndLaunchFailsWithRecursionError(registeredTypeName, registeredTypeName);
@@ -75,16 +82,19 @@ public class CatalogBundleResourceTest extends BrooklynRestResourceTest
{
 
     private void registerAndLaunchAndAssertSimpleEntity(String registeredTypeName, String
serviceType) {
         addCatalogOSGiEntity(registeredTypeName, serviceType);
-
-        String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+registeredTypeName+" } ] }";
-        ApplicationSummary appSummary = createAndWaitForApp(yaml);
-
-        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(), SIMPLE_ENTITY_TYPE);
+        try {
+            String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+registeredTypeName+" } ] }";
+            ApplicationSummary appSummary = createAndWaitForApp(yaml);
+    
+            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(), SIMPLE_ENTITY_TYPE);
+        } finally {
+            deleteCatalogEntity(registeredTypeName);
+        }
     }
 
     private void registerAndLaunchFailsWithRecursionError(String registeredTypeName, String
serviceType) {


Mime
View raw message