You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/02/26 12:27:29 UTC

[1/6] incubator-brooklyn git commit: Remove useless code - getting the catalog item no longer creates a loader

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master fc720ef3f -> 477e2309a


Remove useless code - getting the catalog item no longer creates a loader

The loader is always passed by the caller.


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

Branch: refs/heads/master
Commit: 9090aab0cca3a924fd2bae08f2665a9f8e84fec3
Parents: eab2d39
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Feb 25 15:05:55 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Feb 25 15:05:55 2015 +0200

----------------------------------------------------------------------
 .../brooklyn/spi/creation/BrooklynComponentTemplateResolver.java  | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9090aab0/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 403a40e..9584e78 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
@@ -233,9 +233,6 @@ public class BrooklynComponentTemplateResolver {
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     private <T extends Entity> EntitySpec<T> createSpec() {
-        // ensure loader is updated
-        getCatalogItem();
-        
         Class<T> type = (Class<T>) loadEntityClass();
         
         EntitySpec<T> spec;


[4/6] incubator-brooklyn git commit: SimpleApplicationImpl must extend SimpleApplication interface

Posted by sj...@apache.org.
SimpleApplicationImpl must extend SimpleApplication interface


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

Branch: refs/heads/master
Commit: e7b9a74506ad6089179faa2f3748281cf4d11988
Parents: e09ddb0
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Feb 25 17:06:29 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Feb 25 17:06:29 2015 +0200

----------------------------------------------------------------------
 .../osgi/tests/SimpleApplicationImpl.java       |   2 +-
 .../osgi/brooklyn-test-osgi-entities.jar        | Bin 12406 -> 12419 bytes
 2 files changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e7b9a745/core/src/test/dependencies/osgi/entities/src/main/java/brooklyn/osgi/tests/SimpleApplicationImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/dependencies/osgi/entities/src/main/java/brooklyn/osgi/tests/SimpleApplicationImpl.java b/core/src/test/dependencies/osgi/entities/src/main/java/brooklyn/osgi/tests/SimpleApplicationImpl.java
index acf6a46..e9651f7 100644
--- a/core/src/test/dependencies/osgi/entities/src/main/java/brooklyn/osgi/tests/SimpleApplicationImpl.java
+++ b/core/src/test/dependencies/osgi/entities/src/main/java/brooklyn/osgi/tests/SimpleApplicationImpl.java
@@ -22,6 +22,6 @@ package brooklyn.osgi.tests;
 import brooklyn.entity.basic.AbstractApplication;
 import brooklyn.entity.basic.StartableApplication;
 
-public class SimpleApplicationImpl extends AbstractApplication implements StartableApplication {
+public class SimpleApplicationImpl extends AbstractApplication implements StartableApplication, SimpleApplication {
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e7b9a745/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar b/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
index 5dad391..008150a 100644
Binary files a/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar and b/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar differ


[5/6] incubator-brooklyn git commit: Tests for old-style catalog items when loaded from external classpath or OSGi bundle

Posted by sj...@apache.org.
Tests for old-style catalog items when loaded from external classpath or OSGi bundle


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

Branch: refs/heads/master
Commit: 8523e112dd783c9a516782b04d7c1dfb75498db9
Parents: e7b9a74
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Feb 25 18:08:48 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Feb 25 18:08:48 2015 +0200

----------------------------------------------------------------------
 .../management/osgi/OsgiTestResources.java      |   1 +
 .../catalog/AbstractCatalogXmlTest.java         | 107 +++++++++++++++++++
 .../brooklyn/catalog/CatalogXmlOsgiTest.java    |  37 +++++++
 .../brooklyn/catalog/CatalogXmlVersionTest.java |  28 ++---
 usage/camp/src/test/resources/osgi-catalog.xml  |  29 +++++
 .../camp/src/test/resources/simple-catalog.xml  |  22 ++--
 6 files changed, 195 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java b/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
index 48d01dc..ef0321d 100644
--- a/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
+++ b/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
@@ -41,6 +41,7 @@ public class OsgiTestResources {
      * defines an entity and an application, to confirm it can be read and used by brooklyn
      */
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = "/brooklyn/osgi/brooklyn-test-osgi-entities.jar";
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_APPLICATION = "brooklyn.osgi.tests.SimpleApplication";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY = "brooklyn.osgi.tests.SimpleEntity";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_POLICY = "brooklyn.osgi.tests.SimplePolicy";
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
new file mode 100644
index 0000000..44ea9a8
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.brooklyn.camp.brooklyn.catalog;
+
+import io.brooklyn.camp.brooklyn.AbstractYamlTest;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringReader;
+
+import brooklyn.config.BrooklynProperties;
+import brooklyn.config.BrooklynServerConfig;
+import brooklyn.entity.Entity;
+import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.management.osgi.OsgiTestResources;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.ResourceUtils;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.os.Os;
+import brooklyn.util.stream.ReaderInputStream;
+import brooklyn.util.stream.Streams;
+
+import com.google.common.io.ByteStreams;
+
+public class AbstractCatalogXmlTest extends AbstractYamlTest {
+    
+    private String catalogUrl;
+    
+    public AbstractCatalogXmlTest(String catalogUrl) {
+        this.catalogUrl = catalogUrl;
+    }
+    
+    @Override
+    protected LocalManagementContext newTestManagementContext() {
+        ResourceUtils ru = new ResourceUtils(this);
+        File jar = createJar(ru);
+        File catalog = createCatalog(ru, jar);
+
+        BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
+        properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, catalog.toURI().toString());
+        return LocalManagementContextForTests.builder(true)
+                .useProperties(properties)
+                .disableOsgi(false)
+                .build();
+    }
+
+    protected Entity startApp(String type) throws Exception {
+        String yaml = "name: simple-app-yaml\n" +
+                "location: localhost\n" +
+                "services: \n" +
+                "  - type: " + type;
+        return createAndStartApplication(yaml);
+    }
+
+    private File createCatalog(ResourceUtils ru, File tmpJar) {
+        String catalogTemplate = ru.getResourceAsString(catalogUrl);
+        String catalog = catalogTemplate.replace("${osgi-entities-path}", tmpJar.toURI().toString());
+        File catalogTmp = Os.newTempFile("simple-catalog-", ".xml");
+        copy(catalog, catalogTmp);
+        return catalogTmp;
+    }
+
+    private File createJar(ResourceUtils ru) {
+        File tmpJar = Os.newTempFile("osgi-entities-", ".jar");
+        InputStream in = ru.getResourceFromUrl("classpath://" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        copy(in, tmpJar);
+        return tmpJar;
+    }
+
+    private void copy(String src, File dst) {
+        try {
+            copy(new ReaderInputStream(new StringReader(src), "UTF-8"), dst);
+        } catch (Exception e) {
+            throw Exceptions.propagate(e);
+        }
+    }
+
+    private void copy(InputStream in, File tmpJar) {
+        try {
+            OutputStream out = new FileOutputStream(tmpJar);
+            ByteStreams.copy(in, out);
+            Streams.closeQuietly(in);
+            Streams.closeQuietly(out);
+        } catch (Exception e) {
+            throw Exceptions.propagate(e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java
new file mode 100644
index 0000000..bac2991
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.brooklyn.camp.brooklyn.catalog;
+
+import org.testng.annotations.Test;
+
+public class CatalogXmlOsgiTest extends AbstractCatalogXmlTest {
+
+    public CatalogXmlOsgiTest(String catalogUrl) {
+        super("classpath://osgi-catalog.xml");
+    }
+
+    //OSGi libraries not supported with old-style catalog items
+    //We treat those catalog items just as an alias to the java type they hold.
+    //No loader wrapping their libraries is ever created.
+    @Test(expectedExceptions=IllegalStateException.class)
+    public void testOsgiItem() throws Exception {
+        startApp("OsgiApp");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
index cf1e211..93e23e6 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
@@ -19,23 +19,16 @@
 package io.brooklyn.camp.brooklyn.catalog;
 
 import static org.testng.Assert.assertTrue;
-import io.brooklyn.camp.brooklyn.AbstractYamlTest;
 
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
-import brooklyn.config.BrooklynProperties;
-import brooklyn.config.BrooklynServerConfig;
 import brooklyn.entity.Entity;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.test.entity.LocalManagementContextForTests;
 
-public class CatalogXmlVersionTest extends AbstractYamlTest {
-    @Override
-    protected LocalManagementContext newTestManagementContext() {
-        BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
-        properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://simple-catalog.xml");
-        return LocalManagementContextForTests.newInstance(properties);
+public class CatalogXmlVersionTest extends AbstractCatalogXmlTest {
+
+    public CatalogXmlVersionTest(String catalogUrl) {
+        super("classpath://simple-catalog.xml");
     }
 
     @DataProvider(name = "types")
@@ -44,9 +37,10 @@ public class CatalogXmlVersionTest extends AbstractYamlTest {
                 {"brooklyn.entity.basic.BasicApplication"},
                 {"brooklyn.entity.basic.BasicApplication:0.0.0.SNAPSHOT"},
                 {"brooklyn.entity.basic.BasicApplication:2.0"},
-                {"BasicApp"},
+                {"BasicApp"}, // test that items with symbolicName not matching the type work
                 {"BasicApp:0.0.0.SNAPSHOT"},
-                {"BasicApp:2.0"}
+                {"BasicApp:2.0"},
+                {"brooklyn.osgi.tests.SimpleApplication"}, //test that classpath is used
         };
     }
 
@@ -61,12 +55,4 @@ public class CatalogXmlVersionTest extends AbstractYamlTest {
         assertTrue(entity instanceof TestBasicApp, "Entity is not a " + TestBasicApp.class.getName() + ", instead the type is " + entity.getEntityType().getName());
     }
 
-    private Entity startApp(String type) throws Exception {
-        String yaml = "name: simple-app-yaml\n" +
-                "location: localhost\n" +
-                "services: \n" +
-                "  - type: " + type;
-        return createAndStartApplication(yaml);
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/resources/osgi-catalog.xml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/osgi-catalog.xml b/usage/camp/src/test/resources/osgi-catalog.xml
new file mode 100644
index 0000000..f409a52
--- /dev/null
+++ b/usage/camp/src/test/resources/osgi-catalog.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+     http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+<catalog>
+    <name>OSGi catalogue</name>
+    <template name="Osgi App" type="brooklyn.osgi.tests.SimpleApplication">
+        <symbolicName>OsgiApp</symbolicName>
+        <libraries>
+            <bundle>${osgi-entities-path}</bundle>
+        </libraries>
+    </template>
+</catalog>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/resources/simple-catalog.xml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/simple-catalog.xml b/usage/camp/src/test/resources/simple-catalog.xml
index e3a1214..242478c 100644
--- a/usage/camp/src/test/resources/simple-catalog.xml
+++ b/usage/camp/src/test/resources/simple-catalog.xml
@@ -20,22 +20,28 @@
 
 <catalog>
     <name>Simple catalogue</name>
-    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication">
-        <description>An example application</description>
-    </template>
-    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0">
-        <description>An example application</description>
-    </template>
+    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" />
+    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0" />
     <template name="Basic App" type="brooklyn.entity.basic.BasicApplication">
         <symbolicName>BasicApp</symbolicName>
-        <description>An example application</description>
     </template>
     <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0">
         <symbolicName>BasicApp</symbolicName>
-        <description>An example application</description>
     </template>
     <template name="Custom App" type="brooklyn.entity.basic.BasicApplication">
         <symbolicName>io.brooklyn.camp.brooklyn.catalog.TestBasicApp</symbolicName>
         <!-- Tests that "java:" prefix won't load an old-style catalog item with the same id -->
     </template>
+    <template name="Osgi App" type="brooklyn.osgi.tests.SimpleApplication">
+        <symbolicName>OsgiApp</symbolicName>
+        <libraries>
+            <bundle>${osgi-entities-path}</bundle>
+        </libraries>
+    </template>
+    <catalog>
+        <template name="Simple App" type="brooklyn.osgi.tests.SimpleApplication" />
+        <classpath>
+            <entry>${osgi-entities-path}</entry>
+        </classpath>
+    </catalog>
 </catalog>


[6/6] incubator-brooklyn git commit: This closes #532

Posted by sj...@apache.org.
This closes #532


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

Branch: refs/heads/master
Commit: 477e2309af19449d67be4d7d1dd4d3ec3e270c74
Parents: fc720ef 8523e11
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Thu Feb 26 11:08:57 2015 +0000
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Thu Feb 26 11:08:57 2015 +0000

----------------------------------------------------------------------
 .../osgi/tests/SimpleApplicationImpl.java       |   2 +-
 .../management/osgi/OsgiTestResources.java      |   1 +
 .../osgi/brooklyn-test-osgi-entities.jar        | Bin 12406 -> 12419 bytes
 .../BrooklynAssemblyTemplateInstantiator.java   |  11 ++
 .../BrooklynComponentTemplateResolver.java      |  18 ++--
 .../catalog/AbstractCatalogXmlTest.java         | 107 +++++++++++++++++++
 .../brooklyn/catalog/CatalogXmlOsgiTest.java    |  37 +++++++
 .../brooklyn/catalog/CatalogXmlVersionTest.java |  58 ++++++++++
 .../camp/brooklyn/catalog/TestBasicApp.java     |  27 +++++
 .../camp/brooklyn/catalog/TestBasicAppImpl.java |  24 +++++
 usage/camp/src/test/resources/osgi-catalog.xml  |  29 +++++
 .../camp/src/test/resources/simple-catalog.xml  |  47 ++++++++
 12 files changed, 354 insertions(+), 7 deletions(-)
----------------------------------------------------------------------



[2/6] incubator-brooklyn git commit: Load old-style catalog items when referenced with explicit version

Posted by sj...@apache.org.
Load old-style catalog items when referenced with explicit version


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

Branch: refs/heads/master
Commit: 2bd6480c890698d37b07a34622ebaa3708c9f577
Parents: 9090aab
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Feb 25 16:08:30 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Feb 25 16:08:30 2015 +0200

----------------------------------------------------------------------
 .../BrooklynAssemblyTemplateInstantiator.java   | 11 ++++
 .../BrooklynComponentTemplateResolver.java      | 15 ++++-
 .../brooklyn/catalog/CatalogXmlVersionTest.java | 59 ++++++++++++++++++++
 .../camp/src/test/resources/simple-catalog.xml  | 37 ++++++++++++
 4 files changed, 119 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2bd6480c/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 17949d8..379cd43 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
@@ -195,13 +195,24 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         }
         
         if (spec == null) {
+            // - Load a java class from current loader (item == null || entityResolver.isJavaTypePrefix())
+            // - Load a java class specified in an old-style catalog item (item != null && item.getJavaType() != null)
+            //   Old-style catalog items (can be defined in catalog.xml only) don't have structure, only a single type, so
+            //   they are loaded as a simple java type, only taking the class name from the catalog item instead of the
+            //   type value in the YAML. Classpath entries in the item are also used (through the catalog root classloader).
             if (item == null || item.getJavaType() != null || entityResolver.isJavaTypePrefix()) {
                 spec = entityResolver.resolveSpec();
+
+            // Same as above case, but this time force java type loading (either as plain class or through an old-style
+            // catalog item, since we have already loaded a class item with the same name as the type value.
             } else if (recursiveButTryJava) {
                 if (entityResolver.tryLoadEntityClass().isAbsent()) {
                     throw new IllegalStateException("Recursive reference to " + brooklynType + " (and cannot be resolved as a Java type)");
                 }
                 spec = entityResolver.resolveSpec();
+
+            // Only case that's left is a catalog item with YAML content - try to parse it recursively
+            // including it's OSGi bundles in the loader classpath.
             } else {
                 //TODO migrate to catalog.createSpec
                 spec = resolveCatalogYamlReferenceSpec(mgmt, item, encounteredCatalogTypes);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2bd6480c/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 9584e78..416f2e8 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
@@ -200,9 +200,9 @@ public class BrooklynComponentTemplateResolver {
     }
     
     public boolean canResolve() {
-        if (getCatalogItem()!=null) 
+        if (getCatalogItem()!=null)
             return true;
-        if (loader.tryLoadClass(getBrooklynType(), Entity.class).isPresent())
+        if (loader.tryLoadClass(getJavaType(), Entity.class).isPresent())
             return true;
         return false;
     }
@@ -217,7 +217,16 @@ public class BrooklynComponentTemplateResolver {
     
     /** tries to load the Java entity class */
     public Maybe<Class<? extends Entity>> tryLoadEntityClass() {
-        return loader.tryLoadClass(getBrooklynType(), Entity.class);
+        return loader.tryLoadClass(getJavaType(), Entity.class);
+    }
+
+    private String getJavaType() {
+        CatalogItem<Entity, EntitySpec<?>> item = getCatalogItem();
+        if (item != null && item.getJavaType() != null) {
+            return item.getJavaType();
+        } else {
+            return getBrooklynType();
+        }
     }
 
     /** resolves the spec, updating the loader if a catalog item is loaded */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2bd6480c/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
new file mode 100644
index 0000000..5ae5493
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.brooklyn.camp.brooklyn.catalog;
+
+import io.brooklyn.camp.brooklyn.AbstractYamlTest;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import brooklyn.config.BrooklynProperties;
+import brooklyn.config.BrooklynServerConfig;
+import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
+
+public class CatalogXmlVersionTest extends AbstractYamlTest {
+    @Override
+    protected LocalManagementContext newTestManagementContext() {
+        BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
+        properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://simple-catalog.xml");
+        return LocalManagementContextForTests.newInstance(properties);
+    }
+
+    @DataProvider(name = "types")
+    public Object[][] createTypes() {
+        return new Object[][] {
+                {"brooklyn.entity.basic.BasicApplication"},
+                {"brooklyn.entity.basic.BasicApplication:0.0.0.SNAPSHOT"},
+                {"brooklyn.entity.basic.BasicApplication:2.0"},
+                {"BasicApp"},
+                {"BasicApp:0.0.0.SNAPSHOT"},
+                {"BasicApp:2.0"}
+        };
+    }
+
+    @Test(dataProvider = "types")
+    public void testXmlCatalogItem(String type) throws Exception {
+        String yaml = "name: simple-app-yaml\n" +
+                "location: localhost\n" +
+                "services: \n" +
+                "  - type: " + type;
+        createAndStartApplication(yaml);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2bd6480c/usage/camp/src/test/resources/simple-catalog.xml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/simple-catalog.xml b/usage/camp/src/test/resources/simple-catalog.xml
new file mode 100644
index 0000000..b0d88cc
--- /dev/null
+++ b/usage/camp/src/test/resources/simple-catalog.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+     http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+<catalog>
+    <name>Simple catalogue</name>
+    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication">
+        <description>An example application</description>
+    </template>
+    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0">
+        <description>An example application</description>
+    </template>
+    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication">
+        <symbolicName>BasicApp</symbolicName>
+        <description>An example application</description>
+    </template>
+    <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0">
+        <symbolicName>BasicApp</symbolicName>
+        <description>An example application</description>
+    </template>
+</catalog>


[3/6] incubator-brooklyn git commit: Don't load old-style catalog items when "java:" prefix is used

Posted by sj...@apache.org.
Don't load old-style catalog items when "java:" prefix is used


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

Branch: refs/heads/master
Commit: e09ddb0ca23c432b5d0e89e6a9776f5d9bec510b
Parents: 2bd6480
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Feb 25 16:32:17 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Feb 25 16:32:17 2015 +0200

----------------------------------------------------------------------
 .../BrooklynComponentTemplateResolver.java      |  2 +-
 .../brooklyn/catalog/CatalogXmlVersionTest.java | 15 ++++++++++-
 .../camp/brooklyn/catalog/TestBasicApp.java     | 27 ++++++++++++++++++++
 .../camp/brooklyn/catalog/TestBasicAppImpl.java | 24 +++++++++++++++++
 .../camp/src/test/resources/simple-catalog.xml  |  4 +++
 5 files changed, 70 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e09ddb0c/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 416f2e8..05faed5 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
@@ -222,7 +222,7 @@ public class BrooklynComponentTemplateResolver {
 
     private String getJavaType() {
         CatalogItem<Entity, EntitySpec<?>> item = getCatalogItem();
-        if (item != null && item.getJavaType() != null) {
+        if (!isJavaTypePrefix() && item != null && item.getJavaType() != null) {
             return item.getJavaType();
         } else {
             return getBrooklynType();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e09ddb0c/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
index 5ae5493..cf1e211 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
@@ -18,6 +18,7 @@
  */
 package io.brooklyn.camp.brooklyn.catalog;
 
+import static org.testng.Assert.assertTrue;
 import io.brooklyn.camp.brooklyn.AbstractYamlTest;
 
 import org.testng.annotations.DataProvider;
@@ -25,6 +26,7 @@ import org.testng.annotations.Test;
 
 import brooklyn.config.BrooklynProperties;
 import brooklyn.config.BrooklynServerConfig;
+import brooklyn.entity.Entity;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.test.entity.LocalManagementContextForTests;
 
@@ -50,10 +52,21 @@ public class CatalogXmlVersionTest extends AbstractYamlTest {
 
     @Test(dataProvider = "types")
     public void testXmlCatalogItem(String type) throws Exception {
+        startApp(type);
+    }
+
+    @Test
+    public void testJavaPrefixDoesNotLoadXMLCatalogItem() throws Exception {
+        Entity entity = startApp("java:io.brooklyn.camp.brooklyn.catalog.TestBasicApp");
+        assertTrue(entity instanceof TestBasicApp, "Entity is not a " + TestBasicApp.class.getName() + ", instead the type is " + entity.getEntityType().getName());
+    }
+
+    private Entity startApp(String type) throws Exception {
         String yaml = "name: simple-app-yaml\n" +
                 "location: localhost\n" +
                 "services: \n" +
                 "  - type: " + type;
-        createAndStartApplication(yaml);
+        return createAndStartApplication(yaml);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e09ddb0c/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicApp.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicApp.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicApp.java
new file mode 100644
index 0000000..46347c5
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicApp.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.brooklyn.camp.brooklyn.catalog;
+
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.proxying.ImplementedBy;
+
+@ImplementedBy(TestBasicAppImpl.class)
+public interface TestBasicApp extends BasicApplication {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e09ddb0c/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java
new file mode 100644
index 0000000..952ccd9
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.brooklyn.camp.brooklyn.catalog;
+
+import brooklyn.entity.basic.BasicApplicationImpl;
+
+public class TestBasicAppImpl extends BasicApplicationImpl implements TestBasicApp {
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e09ddb0c/usage/camp/src/test/resources/simple-catalog.xml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/simple-catalog.xml b/usage/camp/src/test/resources/simple-catalog.xml
index b0d88cc..e3a1214 100644
--- a/usage/camp/src/test/resources/simple-catalog.xml
+++ b/usage/camp/src/test/resources/simple-catalog.xml
@@ -34,4 +34,8 @@
         <symbolicName>BasicApp</symbolicName>
         <description>An example application</description>
     </template>
+    <template name="Custom App" type="brooklyn.entity.basic.BasicApplication">
+        <symbolicName>io.brooklyn.camp.brooklyn.catalog.TestBasicApp</symbolicName>
+        <!-- Tests that "java:" prefix won't load an old-style catalog item with the same id -->
+    </template>
 </catalog>