brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [1/3] git commit: New config keys for optional custom CHECK_RUNNING and STOP commands.
Date Fri, 30 May 2014 15:35:10 GMT
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 <alasdair.hodge@cloudsoftcorp.com>
Authored: Wed May 28 13:26:18 2014 +0100
Committer: Alasdair Hodge <alasdair.hodge@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();
     }
+
 }


Mime
View raw message