brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [20/45] git commit: add README for CAMP and test in core that it can access some of the CAMP assembly items, with simple instantiators
Date Fri, 04 Jul 2014 09:51:02 GMT
add README for CAMP and test in core that it can access some of the CAMP assembly items, with
simple instantiators


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

Branch: refs/heads/master
Commit: 646e20229cac1ea1d22da867fd972bb59412f197
Parents: 7d5ce73
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Jul 2 11:52:28 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Jul 2 11:53:52 2014 +0100

----------------------------------------------------------------------
 camp/README.md                                  | 17 +++++
 .../camp/test/mock/web/MockWebPlatform.java     | 33 +++++++++
 core/pom.xml                                    |  7 ++
 .../brooklyn/camp/lite/CampYamlLiteTest.java    | 75 ++++++++++++++++++++
 .../brooklyn/camp/lite/TestAppAssembly.java     | 18 +++++
 .../camp/lite/TestAppAssemblyInstantiator.java  | 43 +++++++++++
 .../camp/lite/test-app-service-blueprint.yaml   | 11 +++
 7 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/camp/README.md
----------------------------------------------------------------------
diff --git a/camp/README.md b/camp/README.md
new file mode 100644
index 0000000..db71dd5
--- /dev/null
+++ b/camp/README.md
@@ -0,0 +1,17 @@
+OASIS CAMP Server
+=================
+
+The projects in this directory provide the necessary components for a server which 
+speaks the CAMP REST API and which understands the CAMP YAML plan language.
+
+It is not dependent on Brooklyn (apart from utils) and does not expose any
+types.  The brooklyn-camp project provides the links for Brooklyn entities
+to be available through the CAMP REST API, and for Brooklyn to deploy blueprints
+described using the CAMP YAML.
+
+The projects in this directory are designed so they could be used to build
+other CAMP servers not based on Brooklyn, if desired.
+
+These projects are part of the Apache Software Foundation Brooklyn project
+(brooklyn.io) and released under the Apache License 2.0.
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/camp/camp-base/src/test/java/io/brooklyn/camp/test/mock/web/MockWebPlatform.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/test/java/io/brooklyn/camp/test/mock/web/MockWebPlatform.java
b/camp/camp-base/src/test/java/io/brooklyn/camp/test/mock/web/MockWebPlatform.java
index 9ad8d33..e547d91 100644
--- a/camp/camp-base/src/test/java/io/brooklyn/camp/test/mock/web/MockWebPlatform.java
+++ b/camp/camp-base/src/test/java/io/brooklyn/camp/test/mock/web/MockWebPlatform.java
@@ -1,12 +1,15 @@
 package io.brooklyn.camp.test.mock.web;
 
+import brooklyn.util.guava.Maybe;
 import io.brooklyn.camp.BasicCampPlatform;
 import io.brooklyn.camp.spi.ApplicationComponentTemplate;
 import io.brooklyn.camp.spi.AssemblyTemplate;
 import io.brooklyn.camp.spi.PlatformComponentTemplate;
 import io.brooklyn.camp.spi.collection.BasicResourceLookup;
+import io.brooklyn.camp.spi.collection.ResolvableLink;
 import io.brooklyn.camp.spi.pdp.Artifact;
 import io.brooklyn.camp.spi.pdp.AssemblyTemplateConstructor;
+import io.brooklyn.camp.spi.pdp.Service;
 import io.brooklyn.camp.spi.resolve.PdpMatcher;
 
 public class MockWebPlatform {
@@ -53,6 +56,35 @@ public class MockWebPlatform {
             return true;
         }
     };
+
+    public static final PdpMatcher newLiteralServiceTypeToPlatformComponentTemplateMatcher(final
BasicCampPlatform platform) {
+        return new PdpMatcher() {
+            public boolean apply(Object item, AssemblyTemplateConstructor atc) {
+                if (!(item instanceof Service)) return false;
+                Service svc = (Service)item;
+                String type = svc.getServiceType();
+                
+                for (ResolvableLink<PlatformComponentTemplate> t: platform.platformComponentTemplates().links())
{
+                    if (type.equals(t.getName())) {
+                        PlatformComponentTemplate pct = PlatformComponentTemplate.builder()
+                            .name(svc.getName())
+                            .customAttribute("serviceType", type)
+                            .description(Maybe.fromNullable(svc.getDescription()).or(t.resolve().getDescription()))
+                            .build();
+                        if (atc!=null)
+                            atc.add(pct);
+                        return true;
+                    }
+                }
+                return false;
+            }
+
+            @Override
+            public boolean accepts(Object deploymentPlanItem) {
+                return apply(deploymentPlanItem, null);
+            }
+        };
+    }
     
     public static <T extends BasicCampPlatform> T populate(T platform) {
         platform.platformComponentTemplates().addAll(APPSERVER, DATABASE);
@@ -60,6 +92,7 @@ public class MockWebPlatform {
         platform.assemblyTemplates().add(ASSEMBLY1);
         
         platform.pdp().addMatcher(WAR_GETS_WAR_MATCHER);
+        platform.pdp().addMatcher(newLiteralServiceTypeToPlatformComponentTemplateMatcher(platform));
         
         return platform;
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index a7c6846..05dd10b 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -37,6 +37,13 @@
             <artifactId>camp-base</artifactId>
             <version>${brooklyn.version}</version>
         </dependency>
+        <dependency>
+            <groupId>io.brooklyn.camp</groupId>
+            <artifactId>camp-base</artifactId>
+            <version>${brooklyn.version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>net.schmizz</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java b/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
new file mode 100644
index 0000000..6a17c28
--- /dev/null
+++ b/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
@@ -0,0 +1,75 @@
+package brooklyn.camp.lite;
+
+import io.brooklyn.camp.BasicCampPlatform;
+import io.brooklyn.camp.spi.Assembly;
+import io.brooklyn.camp.spi.AssemblyTemplate;
+import io.brooklyn.camp.spi.pdp.PdpYamlTest;
+import io.brooklyn.camp.test.mock.web.MockWebPlatform;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.test.entity.TestApplication;
+import brooklyn.test.entity.TestEntity;
+
+import com.google.common.collect.Iterables;
+
+/** Tests of lightweight CAMP integration. Since the "real" integration is in brooklyn-camp
project,
+ * but some aspects of CAMP we want to be able to test here. */
+public class CampYamlLiteTest {
+
+    private static final Logger log = LoggerFactory.getLogger(CampYamlLiteTest.class);
+    
+    protected LocalManagementContext mgmt;
+    
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() {
+        mgmt = new LocalManagementContextForTests();        
+    }
+    
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() {
+        if (mgmt!=null) mgmt.terminate();
+    }
+    
+    /** based on {@link PdpYamlTest} for parsing,
+     * then creating a {@link TestAppAssembly} */
+    @Test
+    public void testYamlServiceMatchAndBrooklynInstantiate() throws IOException {
+        BasicCampPlatform platform = MockWebPlatform.populate(new BasicCampPlatform());
+        Reader input = new InputStreamReader(getClass().getResourceAsStream("test-app-service-blueprint.yaml"));
+        AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input);
+        log.info("AT is:\n"+at.toString());
+        Assert.assertEquals(at.getName(), "sample");
+        Assert.assertEquals(at.getPlatformComponentTemplates().links().size(), 1);
+        
+        // now use brooklyn to instantiate
+        Assembly assembly = new TestAppAssemblyInstantiator(mgmt).instantiate(at, platform);
+        
+        TestApplication app = ((TestAppAssembly)assembly).getBrooklynApp();
+        Assert.assertEquals( app.getConfig(TestEntity.CONF_NAME), "sample" );
+        Map<String, String> map = app.getConfig(TestEntity.CONF_MAP_THING);
+        Assert.assertEquals( map.get("desc"), "Tomcat sample JSP and servlet application."
);
+        
+        Assert.assertEquals( app.getChildren().size(), 1 );
+        Entity svc = Iterables.getOnlyElement(app.getChildren());
+        Assert.assertEquals( svc.getConfig(TestEntity.CONF_NAME), "Hello WAR" );
+        map = svc.getConfig(TestEntity.CONF_MAP_THING);
+        Assert.assertEquals( map.get("type"), MockWebPlatform.APPSERVER.getType() );
+        // desc ensures we got the information from the matcher, as this value is NOT in
the yaml
+        Assert.assertEquals( map.get("desc"), MockWebPlatform.APPSERVER.getDescription()
);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/core/src/test/java/brooklyn/camp/lite/TestAppAssembly.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/camp/lite/TestAppAssembly.java b/core/src/test/java/brooklyn/camp/lite/TestAppAssembly.java
new file mode 100644
index 0000000..0f220a7
--- /dev/null
+++ b/core/src/test/java/brooklyn/camp/lite/TestAppAssembly.java
@@ -0,0 +1,18 @@
+package brooklyn.camp.lite;
+
+import io.brooklyn.camp.spi.Assembly;
+import brooklyn.test.entity.TestApplication;
+
+public class TestAppAssembly extends Assembly {
+
+    private TestApplication brooklynApp;
+
+    public TestAppAssembly(TestApplication brooklynApp) {
+        this.brooklynApp = brooklynApp;
+    }
+    
+    public TestApplication getBrooklynApp() {
+        return brooklynApp;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/core/src/test/java/brooklyn/camp/lite/TestAppAssemblyInstantiator.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/camp/lite/TestAppAssemblyInstantiator.java b/core/src/test/java/brooklyn/camp/lite/TestAppAssemblyInstantiator.java
new file mode 100644
index 0000000..a00a3bf
--- /dev/null
+++ b/core/src/test/java/brooklyn/camp/lite/TestAppAssemblyInstantiator.java
@@ -0,0 +1,43 @@
+package brooklyn.camp.lite;
+
+import io.brooklyn.camp.CampPlatform;
+import io.brooklyn.camp.spi.Assembly;
+import io.brooklyn.camp.spi.AssemblyTemplate;
+import io.brooklyn.camp.spi.PlatformComponentTemplate;
+import io.brooklyn.camp.spi.collection.ResolvableLink;
+import io.brooklyn.camp.spi.instantiate.BasicAssemblyTemplateInstantiator;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.test.entity.TestApplication;
+import brooklyn.test.entity.TestEntity;
+import brooklyn.util.collections.MutableMap;
+
+/** simple illustrative instantiator which always makes a {@link TestApplication}, populated
with {@link TestEntity} children,
+ * all setting {@link TestEntity#CONF_NAME} for the name in the plan and in the service specs
+ * <p>
+ * the "real" instantiator for brooklyn is in brooklyn-camp project, not visible here, so
let's have something we can test */
+public class TestAppAssemblyInstantiator extends BasicAssemblyTemplateInstantiator {
+
+    protected final LocalManagementContext mgmt;
+    
+    public TestAppAssemblyInstantiator(LocalManagementContext mgmt) {
+        this.mgmt = mgmt;
+    }
+    
+    @Override
+    public Assembly instantiate(AssemblyTemplate template, CampPlatform platform) {
+        TestApplication app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class)
+            .configure(TestEntity.CONF_NAME, template.getName())
+            .configure(TestEntity.CONF_MAP_THING, MutableMap.of("type", template.getType(),
"desc", template.getDescription()))
+            , mgmt);
+        for (ResolvableLink<PlatformComponentTemplate> t: template.getPlatformComponentTemplates().links())
{
+            app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                .configure(TestEntity.CONF_NAME, t.getName())
+                .configure(TestEntity.CONF_MAP_THING, MutableMap.of("type", t.resolve().getType(),
"desc", t.resolve().getDescription()))
+                );
+        }
+        return new TestAppAssembly(app);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/646e2022/core/src/test/resources/brooklyn/camp/lite/test-app-service-blueprint.yaml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/camp/lite/test-app-service-blueprint.yaml b/core/src/test/resources/brooklyn/camp/lite/test-app-service-blueprint.yaml
new file mode 100644
index 0000000..96db31c
--- /dev/null
+++ b/core/src/test/resources/brooklyn/camp/lite/test-app-service-blueprint.yaml
@@ -0,0 +1,11 @@
+name: sample
+description: Tomcat sample JSP and servlet application.
+origin: http://www.oracle.com/nCAMP/Hand
+services:
+  -
+    type: io.camp.mock:AppServer
+    name: Hello WAR
+    wars:
+        /: hello.war
+    controller.spec:
+        port: 80


Mime
View raw message