brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [5/6] brooklyn-server git commit: BROOKLYN-249: Adds JcloudsRebindWithExternalConfigTest
Date Wed, 06 Apr 2016 11:23:29 GMT
BROOKLYN-249: Adds JcloudsRebindWithExternalConfigTest


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

Branch: refs/heads/0.9.0
Commit: b9fa909c47d6ce9c0943c136e0cce7089727b45e
Parents: bc5c1bb
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Apr 6 10:33:21 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Apr 6 11:25:43 2016 +0100

----------------------------------------------------------------------
 .../JcloudsRebindWithExternalConfigTest.java    | 139 +++++++++++++++++++
 1 file changed, 139 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b9fa909c/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
new file mode 100644
index 0000000..6d0d4ec
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
@@ -0,0 +1,139 @@
+package org.apache.brooklyn.camp.brooklyn;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
+import org.apache.brooklyn.core.config.external.InPlaceExternalConfigSupplier;
+import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
+import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
+import org.apache.brooklyn.location.jclouds.ComputeServiceRegistry;
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsPropertiesFromBrooklynProperties;
+import org.apache.brooklyn.location.jclouds.JcloudsRebindStubTest;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+/**
+ * Implementation notes. This relies on the test {@link JcloudsRebindStubTest#testRebind()}.
+ * It changes the setup for the test in the following ways:
+ * <ul>
+ *   <li>Brooklyn properties defines external config
+ *   <li>Location is defined in YAML, and refers to the external config for the identity/credential.
+ *   <li>When creating management context, it also creates {@link BrooklynCampPlatformLauncherNoServer}.
+ *   <li>It uses {@link JcloudsRebindWithExternalConfigTest#ByonComputeServiceStaticRef}
to allow
+ *       the test's {@link ComputeServiceRegistry} to be wired up via YAML.
+ * </ul>
+ * 
+ * See {@link JcloudsRebindStubTest} for explanation why this is "Live" - it will not create
VMs,
+ * but does retrieve list of images etc.
+ */
+@Test(groups={"Live", "Live-sanity"})
+public class JcloudsRebindWithExternalConfigTest extends JcloudsRebindStubTest {
+
+    private BrooklynCampPlatformLauncherNoServer origLauncher;
+    private BrooklynCampPlatformLauncherNoServer newLauncher;
+
+    @Override
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        try {
+            super.tearDown();
+        } finally {
+            ByonComputeServiceStaticRef.clearInstance();
+            if (origLauncher != null) origLauncher.stopServers();
+            if (newLauncher != null) newLauncher.stopServers();
+        }
+    }
+    
+    @Override
+    protected BrooklynProperties createBrooklynProperties() {
+        BrooklynProperties result = super.createBrooklynProperties();
+        
+        Map<Object,Object> jcloudsProps = MutableMap.<Object,Object>copyOf(new
JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties(PROVIDER, null, "testname",
result.asMapWithStringKeys()));
+        String identity = checkNotNull((String)jcloudsProps.get("identity"), "identity");
+        String credential = checkNotNull((String)jcloudsProps.get("credential"), "credential");
+        
+        result.put("brooklyn.external.creds", InPlaceExternalConfigSupplier.class.getName());
+        result.put("brooklyn.external.creds.test-identity", identity);
+        result.put("brooklyn.external.creds.test-credential", credential);
+        
+        return result;
+    }
+    
+    @Override
+    protected LocalManagementContext createOrigManagementContext() {
+        origLauncher = new BrooklynCampPlatformLauncherNoServer() {
+            @Override
+            protected LocalManagementContext newMgmtContext() {
+                return JcloudsRebindWithExternalConfigTest.super.createOrigManagementContext();
+            }
+        };
+        origLauncher.launch();
+        LocalManagementContext mgmt = (LocalManagementContext) origLauncher.getBrooklynMgmt();
+        return mgmt;
+    }
+
+    @Override
+    protected LocalManagementContext createNewManagementContext(final File mementoDir) {
+        newLauncher = new BrooklynCampPlatformLauncherNoServer() {
+            @Override
+            protected LocalManagementContext newMgmtContext() {
+                return JcloudsRebindWithExternalConfigTest.super.createNewManagementContext(mementoDir);
+            }
+        };
+        newLauncher.launch();
+        return (LocalManagementContext) newLauncher.getBrooklynMgmt();
+    }
+    
+    @Override
+    protected JcloudsLocation newJcloudsLocation(ComputeServiceRegistry computeServiceRegistry)
throws Exception {
+        ByonComputeServiceStaticRef.setInstance(computeServiceRegistry);
+        
+        String yaml = Joiner.on("\n").join(
+                "location:",
+                "  jclouds:softlayer:",
+                "    identity: $brooklyn:external(\"creds\", \"test-identity\")",
+                "    credential: $brooklyn:external(\"creds\", \"test-credential\")",
+                "    jclouds.computeServiceRegistry:",
+                "      $brooklyn:object:",
+                "        type: "+ByonComputeServiceStaticRef.class.getName(),
+                "    waitForSshable: false",
+                "    useJcloudsSshInit: false",
+                "services:\n"+
+                "- type: org.apache.brooklyn.entity.stock.BasicApplication");
+        
+        EntitySpec<?> spec = 
+                mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT,
yaml, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
+        final Entity app = mgmt().getEntityManager().createEntity(spec);
+        app.invoke(Startable.START, ImmutableMap.<String, Object>of()).get();
+
+        return (JcloudsLocation) Iterables.getOnlyElement(app.getLocations());
+    }
+
+    public static class ByonComputeServiceStaticRef {
+        private static volatile ComputeServiceRegistry instance;
+
+        public ComputeServiceRegistry asComputeServiceRegistry() {
+            return checkNotNull(instance, "instance");
+        }
+        static void setInstance(ComputeServiceRegistry val) {
+            instance = val;
+        }
+        static void clearInstance() {
+            instance = null;
+        }
+    }
+}


Mime
View raw message