You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2014/05/30 17:35:11 UTC

[2/3] git commit: Specify custom 'checkRunning' and 'stop' commands in yaml.

Specify custom 'checkRunning' and 'stop' commands in yaml.

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

Branch: refs/heads/master
Commit: c3798e540bbbe9a72867ab5ae59615554a6bb12b
Parents: c2508e7
Author: Alasdair Hodge <al...@cloudsoftcorp.com>
Authored: Fri May 30 11:41:08 2014 +0100
Committer: Alasdair Hodge <al...@cloudsoftcorp.com>
Committed: Fri May 30 14:40:25 2014 +0100

----------------------------------------------------------------------
 .../example_yaml/vanilla-bash-netcat.yaml       | 10 ++++++++
 .../entity/basic/VanillaSoftwareYamlTest.java   | 25 ++++++++++++++++++--
 .../resources/vanilla-software-blueprint.yaml   |  9 +++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c3798e54/docs/use/guide/defining-applications/example_yaml/vanilla-bash-netcat.yaml
----------------------------------------------------------------------
diff --git a/docs/use/guide/defining-applications/example_yaml/vanilla-bash-netcat.yaml b/docs/use/guide/defining-applications/example_yaml/vanilla-bash-netcat.yaml
index 10a13f5..d4cb37b 100644
--- a/docs/use/guide/defining-applications/example_yaml/vanilla-bash-netcat.yaml
+++ b/docs/use/guide/defining-applications/example_yaml/vanilla-bash-netcat.yaml
@@ -6,3 +6,13 @@ services:
   launch.command: |
     echo hello | nc -l 4321 &
     echo $! > $PID_FILE
+
+  # The following overrides demonstrate the use of a custom shell environment as well as
+  # check-running and stop commands. These are optional; default behavior will "do the
+  # right thing" with the pid file automatically.
+
+  env:                  { CHECK_MARKER: "checkRunning", STOP_MARKER: "stop" }
+  checkRunning.command: echo $CHECK_MARKER >> DATE && test -f "$PID_FILE" && ps -p `cat $PID_FILE` >/dev/null
+  stop.command:         echo $STOP_MARKER  >> DATE && test -f "$PID_FILE" && { kill -9 `cat $PID_FILE`; rm /tmp/vanilla.pid; }
+
+# can also define download.url, in which case the launch command defaults to ./start.sh in that (archive) file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c3798e54/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java b/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java
index 0eee88e..fc41af7 100644
--- a/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java
+++ b/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java
@@ -7,7 +7,9 @@ import org.testng.annotations.Test;
 
 import brooklyn.entity.Application;
 import brooklyn.entity.Entity;
+import brooklyn.entity.trait.Startable;
 import brooklyn.launcher.camp.SimpleYamlLauncher;
+import brooklyn.test.Asserts;
 import brooklyn.util.ResourceUtils;
 import brooklyn.util.os.Os;
 import brooklyn.util.text.Strings;
@@ -25,9 +27,28 @@ public class VanillaSoftwareYamlTest {
             Application app = l.launchAppYaml("vanilla-software-blueprint.yaml");
             log.info("started "+app);
 
-            Entity p1 = Iterables.getOnlyElement( app.getChildren() );
-            Long d1 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p1.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") );
+            String runDir = Iterables.getOnlyElement(app.getChildren()).getAttribute(SoftwareProcess.RUN_DIR);
+            final String filePath = Os.mergePaths(runDir, "DATE");
+
+            String fileContents = new ResourceUtils(this).getResourceAsString(filePath);
+            Long d1 = Long.parseLong( Strings.getFirstWordAfter(fileContents, "utc") );
             Assert.assertTrue( Math.abs(d1*1000-System.currentTimeMillis())<15000, "Time UTC does not match system; "+d1+" v "+System.currentTimeMillis() );
+
+            Asserts.succeedsEventually(new Runnable() {
+                public void run() {
+                    String fileContents = new ResourceUtils(this).getResourceAsString(filePath);
+                    Assert.assertTrue(fileContents.contains("checkRunning"));
+                }
+            });
+
+            app.invoke(Startable.STOP, null).getUnchecked();
+            Asserts.succeedsEventually(new Runnable() {
+                public void run() {
+                    String fileContents = new ResourceUtils(this).getResourceAsString(filePath);
+                    Assert.assertTrue(fileContents.contains("stop"));
+                }
+            });
+
         } finally {
             l.destroyAll();
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c3798e54/usage/launcher/src/test/resources/vanilla-software-blueprint.yaml
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/resources/vanilla-software-blueprint.yaml b/usage/launcher/src/test/resources/vanilla-software-blueprint.yaml
index bc9cc8c..67f0e0e 100644
--- a/usage/launcher/src/test/resources/vanilla-software-blueprint.yaml
+++ b/usage/launcher/src/test/resources/vanilla-software-blueprint.yaml
@@ -10,4 +10,13 @@ services:
     nohup sleep 60 &
     echo $! > $PID_FILE
     sleep 3
+
+  # The following overrides are to test the use of a custom shell environment as well as
+  # check-running and stop commands. These are optional; default behavior will "do the
+  # right thing" with the pid file automatically.
+
+  env:                  { CHECK_MARKER: "checkRunning", STOP_MARKER: "stop" }
+  checkRunning.command: echo $CHECK_MARKER >> DATE && test -f "$PID_FILE" && ps -p `cat $PID_FILE` >/dev/null
+  stop.command:         echo $STOP_MARKER  >> DATE && test -f "$PID_FILE" && { kill -9 `cat $PID_FILE`; rm /tmp/vanilla.pid; }
+
 # can also define download.url, in which case the launch command defaults to ./start.sh in that (archive) file