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:10 UTC

[1/3] git commit: New config keys for optional custom CHECK_RUNNING and STOP commands.

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master baad13372 -> 33bb6ce81


New config keys for optional custom CHECK_RUNNING and STOP commands.

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

Branch: refs/heads/master
Commit: c2508e7869a382dfbfa24d3329af0cc3c9dad3d8
Parents: 683915e
Author: Alasdair Hodge <al...@cloudsoftcorp.com>
Authored: Wed May 28 13:26:18 2014 +0100
Committer: Alasdair Hodge <al...@cloudsoftcorp.com>
Committed: Wed May 28 14:01:03 2014 +0100

----------------------------------------------------------------------
 .../entity/basic/VanillaSoftwareProcess.java    | 18 +++++++--------
 .../basic/VanillaSoftwareProcessSshDriver.java  | 24 ++++++++++++++++----
 2 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c2508e78/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
index 3f0348c..bc0c3a9 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
@@ -22,18 +22,18 @@ import brooklyn.event.basic.BasicAttributeSensorAndConfigKey;
  * (e.g. <code>export MY_PID_FILE=$PID_FILE ; ./my_start.sh</code> or <code>nohup ./start.sh & ; echo $! > $PID_FILE ; sleep 5</code>),
  * and of course you can supply both {@link #DOWNLOAD_URL} and {@link #LAUNCH_COMMAND}.
  * <p>
- * TODO:
  * by default the PID is used to stop the process (kill followed by kill -9 if needed) and restart (process stop followed by process start),
- * but we could instead supply (through config keys)
- * <li> a custom CHECK_RUNNING_COMMAND 
- * <li> a custom STOP_COMMAND
- * <li> or specify a PID_FILE to use (done)
+ * but it is possible to override this behavior through config keys:
+ * <li> a custom {@link #CHECK_RUNNING_COMMAND}
+ * <li> a custom {@link #STOP_COMMAND}
+ * <li> specify which {@link SoftwareProcess#PID_FILE} to use
  */
 @ImplementedBy(VanillaSoftwareProcessImpl.class)
 public interface VanillaSoftwareProcess extends SoftwareProcess {
     BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = SoftwareProcess.DOWNLOAD_URL;
-    ConfigKey<String> LAUNCH_COMMAND = ConfigKeys.newStringConfigKey("launch.command", "command to run to launch the process", "./start.sh");
-    // TODO CHECK_RUNNING_COMMAND STOP_COMMAND PID_FILE(templated config key and attribute?)
-    
     ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "0.0.0");
-}
\ No newline at end of file
+
+    ConfigKey<String> LAUNCH_COMMAND = ConfigKeys.newStringConfigKey("launch.command", "command to run to launch the process", "./start.sh");
+    ConfigKey<String> CHECK_RUNNING_COMMAND = ConfigKeys.newStringConfigKey("checkRunning.command", "command to determine whether the process is running");
+    ConfigKey<String> STOP_COMMAND = ConfigKeys.newStringConfigKey("stop.command", "command to run to stop the process");
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c2508e78/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java
index 8d8f3e8..9f88092 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java
@@ -4,6 +4,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import brooklyn.entity.basic.lifecycle.ScriptHelper;
 import brooklyn.entity.drivers.downloads.DownloadResolver;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.util.collections.MutableMap;
@@ -96,13 +97,28 @@ public class VanillaSoftwareProcessSshDriver extends AbstractSoftwareProcessSshD
 
     @Override
     public boolean isRunning() {
-        // TODO custom
-        return newScript(MutableMap.of(USE_PID_FILE, getPidFile()), CHECK_RUNNING).execute()==0;
+        String customCommand = getEntity().getConfig(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND);
+        ScriptHelper script = null;
+        if (customCommand == null) {
+            script = newScript(MutableMap.of(USE_PID_FILE, getPidFile()), CHECK_RUNNING);
+        } else {
+            // TODO: template substitutions?
+            script = newScript(CHECK_RUNNING).body.append(customCommand);
+        }
+        return script.execute() == 0;
     }
 
     @Override
     public void stop() {
-        // TODO custom
-        newScript(MutableMap.of(USE_PID_FILE, getPidFile()), STOPPING).execute();
+        String customCommand = getEntity().getConfig(VanillaSoftwareProcess.STOP_COMMAND);
+        ScriptHelper script = null;
+        if (customCommand == null) {
+            script = newScript(MutableMap.of(USE_PID_FILE, getPidFile()), STOPPING);
+        } else {
+            // TODO: template substitutions?
+            script = newScript(STOPPING).body.append(customCommand);
+        }
+        script.execute();
     }
+
 }


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

Posted by ri...@apache.org.
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


[3/3] git commit: Merge pull request #1421 from alasdairhodge/custom-check-running-and-stop

Posted by ri...@apache.org.
Merge pull request #1421 from alasdairhodge/custom-check-running-and-stop

New config keys for optional custom CHECK_RUNNING and STOP commands

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

Branch: refs/heads/master
Commit: 33bb6ce8159af318d931fa9f1c4d7d1dff8aa748
Parents: baad133 c3798e5
Author: Andrew Kennedy <gr...@apache.org>
Authored: Fri May 30 16:27:43 2014 +0100
Committer: Andrew Kennedy <gr...@apache.org>
Committed: Fri May 30 16:27:43 2014 +0100

----------------------------------------------------------------------
 .../example_yaml/vanilla-bash-netcat.yaml       | 10 ++++++++
 .../entity/basic/VanillaSoftwareProcess.java    | 18 +++++++-------
 .../basic/VanillaSoftwareProcessSshDriver.java  | 24 +++++++++++++++----
 .../entity/basic/VanillaSoftwareYamlTest.java   | 25 ++++++++++++++++++--
 .../resources/vanilla-software-blueprint.yaml   |  9 +++++++
 5 files changed, 71 insertions(+), 15 deletions(-)
----------------------------------------------------------------------