brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grk...@apache.org
Subject [07/14] git commit: Added test for install and runtime file copy
Date Mon, 06 Oct 2014 11:56:39 GMT
Added test for install and runtime file copy


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

Branch: refs/heads/master
Commit: 401542d73208b556ca836ca5d71c71f69e0a9894
Parents: 975d5df
Author: Andrew Kennedy <grkvlt@apache.org>
Authored: Wed Oct 1 16:59:16 2014 +0100
Committer: Andrew Kennedy <grkvlt@apache.org>
Committed: Sun Oct 5 23:46:59 2014 +0100

----------------------------------------------------------------------
 .../java/brooklyn/entity/trait/Startable.java   |  2 -
 .../basic/AbstractSoftwareProcessSshDriver.java |  9 +--
 ...SoftwareProcessSshDriverIntegrationTest.java | 74 ++++++++++++++++++--
 .../resources/brooklyn/entity/basic/frogs.txt   | 10 +++
 .../brooklyn/entity/basic/template.yaml         |  6 ++
 5 files changed, 89 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/401542d7/core/src/main/java/brooklyn/entity/trait/Startable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/trait/Startable.java b/core/src/main/java/brooklyn/entity/trait/Startable.java
index 335a12f..bbed617 100644
--- a/core/src/main/java/brooklyn/entity/trait/Startable.java
+++ b/core/src/main/java/brooklyn/entity/trait/Startable.java
@@ -19,7 +19,6 @@
 package brooklyn.entity.trait;
 
 import java.util.Collection;
-import java.util.Collections;
 
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Effector;
@@ -32,7 +31,6 @@ import brooklyn.entity.effector.Effectors;
 import brooklyn.event.AttributeSensor;
 import brooklyn.location.Location;
 import brooklyn.util.config.ConfigBag;
-import brooklyn.util.text.StringEscapes.JavaStringEscapes;
 
 /**
  * This interface describes an {@link brooklyn.entity.Entity} that can be started and stopped.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/401542d7/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
index 52cb967..09dfd4c 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
@@ -524,13 +524,10 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
         }
         flags.putAll(sshFlags);
 
-        // prefix with runDir if relative target
-        String dest = Os.isAbsolutish(target) ? target : Urls.mergePaths(getRunDir(), target);
-        
         if (createParentDir) {
             // don't use File.separator because it's remote machine's format, rather than
local machine's
-            int lastSlashIndex = dest.lastIndexOf("/");
-            String parent = (lastSlashIndex > 0) ? dest.substring(0, lastSlashIndex) :
null;
+            int lastSlashIndex = target.lastIndexOf("/");
+            String parent = (lastSlashIndex > 0) ? target.substring(0, lastSlashIndex)
: null;
             if (parent != null) {
                 getMachine().execCommands("createParentDir", ImmutableList.of("mkdir -p "+parent));
             }
@@ -541,7 +538,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
         int result;
         String prevBlockingDetails = Tasks.setBlockingDetails("copying resource to server
at "+target);
         try {
-            result = getMachine().copyTo(flags, source, dest);
+            result = getMachine().copyTo(flags, source, target);
         } finally {
             Tasks.setBlockingDetails(prevBlockingDetails);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/401542d7/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
b/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
index e8a3877..d432754 100644
--- a/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
+++ b/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
@@ -18,17 +18,16 @@
  */
 package brooklyn.entity.basic;
 
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
+import static org.testng.Assert.*;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
+import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -41,13 +40,17 @@ import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.test.entity.TestApplication;
+import brooklyn.util.collections.MutableMap;
 import brooklyn.util.internal.ssh.SshException;
+import brooklyn.util.net.Networking;
 import brooklyn.util.os.Os;
 import brooklyn.util.stream.KnownSizeInputStream;
 import brooklyn.util.stream.Streams;
+import brooklyn.util.yaml.Yamls;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import com.google.common.io.ByteSource;
 import com.google.common.io.Files;
 
@@ -233,6 +236,7 @@ public class SoftwareProcessSshDriverIntegrationTest {
                 .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, String.format("echo inLaunch
>> %s", tempFile.getAbsoluteFile()))
                 .configure(SoftwareProcess.POST_LAUNCH_COMMAND, String.format("echo inPostLaunch
>> %s", tempFile.getAbsoluteFile())));
         app.start(ImmutableList.of(localhost));
+
         List<String> output = Files.readLines(tempFile, Charsets.UTF_8);
         assertEquals(output.size(), 3);
         assertEquals(output.get(0), "inPreLaunch");
@@ -241,6 +245,68 @@ public class SoftwareProcessSshDriverIntegrationTest {
         tempFile.delete();
     }
 
+    @Test
+    public void testInstallResourcesCopy() throws IOException {
+        localhost.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());
+        VanillaSoftwareProcess entity = app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "")
+                .configure(SoftwareProcess.INSTALL_FILES, MutableMap.of("classpath://brooklyn/entity/basic/frogs.txt",
"frogs.txt"))
+                .configure(SoftwareProcess.INSTALL_TEMPLATES, MutableMap.of("classpath://brooklyn/entity/basic/template.yaml",
"/tmp/template.yaml"))
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "date"));
+        app.start(ImmutableList.of(localhost));
+
+        File frogs = new File(entity.getAttribute(SoftwareProcess.INSTALL_DIR), "frogs.txt");
+        try {
+            Assert.assertTrue(frogs.canRead(), "File not readable: " + frogs);
+            String output = Files.toString(frogs, Charsets.UTF_8);
+            Assert.assertTrue(output.contains("Brekekekex"), "File content not found: " +
output);
+        } finally {
+            frogs.delete();
+        }
+
+        File template = new File("/tmp", "template.yaml");
+        try {
+            Map<?,?> data = (Map) Iterables.getOnlyElement(Yamls.parseAll(Files.toString(template,
Charsets.UTF_8)));
+            Assert.assertEquals(data.size(), 3);
+            Assert.assertEquals(data.get("entity.hostname"), Networking.getLocalHost().getHostName());
+            Assert.assertEquals(data.get("entity.address"), "127.0.0.1");
+            Assert.assertEquals(data.get("frogs"), Integer.valueOf(12));
+        } finally {
+            template.delete();
+        }
+    }
+
+    @Test
+    public void testRuntimeResourcesCopy() throws IOException {
+        localhost.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());
+        VanillaSoftwareProcess entity = app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "")
+                .configure(SoftwareProcess.RUNTIME_FILES, MutableMap.of("classpath://brooklyn/entity/basic/frogs.txt",
"frogs.txt"))
+                .configure(SoftwareProcess.RUNTIME_TEMPLATES, MutableMap.of("classpath://brooklyn/entity/basic/template.yaml",
"/tmp/template.yaml"))
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "date"));
+        app.start(ImmutableList.of(localhost));
+
+        File frogs = new File(entity.getAttribute(SoftwareProcess.RUN_DIR), "frogs.txt");
+        try {
+            Assert.assertTrue(frogs.canRead(), "File not readable: " + frogs);
+            String output = Files.toString(frogs, Charsets.UTF_8);
+            Assert.assertTrue(output.contains("Brekekekex"), "File content not found: " +
output);
+        } finally {
+            frogs.delete();
+        }
+
+        File template = new File("/tmp", "template.yaml");
+        try {
+            Map<?,?> data = (Map) Iterables.getOnlyElement(Yamls.parseAll(Files.toString(template,
Charsets.UTF_8)));
+            Assert.assertEquals(data.size(), 3);
+            Assert.assertEquals(data.get("entity.hostname"), Networking.getLocalHost().getHostName());
+            Assert.assertEquals(data.get("entity.address"), "127.0.0.1");
+            Assert.assertEquals(data.get("frogs"), Integer.valueOf(12));
+        } finally {
+            template.delete();
+        }
+    }
+
     @ImplementedBy(MyServiceImpl.class)
     public interface MyService extends SoftwareProcess {
         public SimulatedDriver getDriver();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/401542d7/software/base/src/test/resources/brooklyn/entity/basic/frogs.txt
----------------------------------------------------------------------
diff --git a/software/base/src/test/resources/brooklyn/entity/basic/frogs.txt b/software/base/src/test/resources/brooklyn/entity/basic/frogs.txt
new file mode 100644
index 0000000..cc1a97f
--- /dev/null
+++ b/software/base/src/test/resources/brooklyn/entity/basic/frogs.txt
@@ -0,0 +1,10 @@
+## The Frogs
+
+Frogs:
+> Brekekekex koax koax.
+
+Dionysus:
+> Go to hell with your koax
+> koax and nothing but koax!
+
+- Artistophanes, c. 400 BC
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/401542d7/software/base/src/test/resources/brooklyn/entity/basic/template.yaml
----------------------------------------------------------------------
diff --git a/software/base/src/test/resources/brooklyn/entity/basic/template.yaml b/software/base/src/test/resources/brooklyn/entity/basic/template.yaml
new file mode 100644
index 0000000..87149a6
--- /dev/null
+++ b/software/base/src/test/resources/brooklyn/entity/basic/template.yaml
@@ -0,0 +1,6 @@
+[#ftl]
+entity.hostname:
+    ${driver.hostname}
+entity.address:
+    ${driver.address}
+frogs: 12
\ No newline at end of file


Mime
View raw message