brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grk...@apache.org
Subject [1/5] incubator-brooklyn git commit: Add configuration to skip start if entity already running
Date Tue, 13 Jan 2015 15:55:55 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 36f7c922e -> 895fb9acc


Add configuration to skip start if entity already running


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

Branch: refs/heads/master
Commit: d5b34e145ebf08fb834ef0eea48a8754f7e32db5
Parents: eeb681a
Author: Andrew Kennedy <grkvlt@apache.org>
Authored: Tue Nov 25 23:55:50 2014 +0000
Committer: Andrew Kennedy <grkvlt@apache.org>
Committed: Mon Jan 12 21:45:00 2015 +0000

----------------------------------------------------------------------
 .../entity/basic/BrooklynConfigKeys.java        |  5 ++--
 .../basic/PortAttributeSensorAndConfigKey.java  | 10 +++++---
 .../basic/AbstractSoftwareProcessDriver.java    | 25 ++++++++++++++++----
 .../brooklyn/entity/basic/SoftwareProcess.java  |  3 +++
 4 files changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d5b34e14/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java b/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java
index be627f3..f26280d 100644
--- a/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java
+++ b/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java
@@ -55,8 +55,9 @@ public class BrooklynConfigKeys {
             "this should include something readable, and must include a hash of all data
which differentiates an installation " +
             "(e.g. version, plugins, etc), but should be the same where install dirs can
be shared to allow for re-use");
 
-    public static final ConfigKey<Boolean> ENTITY_STARTED = newBooleanConfigKey("entity.started",
"Skip the startup process entirely, for running services", Boolean.FALSE);
-    public static final ConfigKey<Boolean> SKIP_INSTALLATION = newBooleanConfigKey("install.skip",
"Skip the driver install commands entirely, for pre-installed software", Boolean.FALSE);
+    public static final ConfigKey<Boolean> ENTITY_STARTED = newBooleanConfigKey("entity.started",
"Skip the startup process entirely, for running services");
+    public static final ConfigKey<Boolean> ENTITY_RUNNING = newBooleanConfigKey("entity.running",
"Skip the startup process entirely, if service already running");
+    public static final ConfigKey<Boolean> SKIP_INSTALLATION = newBooleanConfigKey("install.skip",
"Skip the driver install commands entirely, for pre-installed software");
 
     // The implementation in AbstractSoftwareSshDriver runs this command as an SSH command

     public static final ConfigKey<String> PRE_INSTALL_COMMAND = ConfigKeys.newStringConfigKey("pre.install.command",

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d5b34e14/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java
b/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java
index 7d21d6d..e68fa92 100644
--- a/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java
+++ b/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java
@@ -93,8 +93,12 @@ public class PortAttributeSensorAndConfigKey extends AttributeSensorAndConfigKey
             }
             if (lo.isPresent()) {
                 Location l = lo.get();
-                Boolean skip = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION)).or(false);
-                Boolean started = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.ENTITY_STARTED)).or(false);
+                Optional<Boolean> locationRunning = Optional.fromNullable(l.getConfig(BrooklynConfigKeys.ENTITY_RUNNING));
+                Optional<Boolean> entityRunning = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.ENTITY_RUNNING));
+                Optional<Boolean> locationInstalled = Optional.fromNullable(l.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION));
+                Optional<Boolean> entityInstalled = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION));
+                Optional<Boolean> entityStarted = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.ENTITY_STARTED));
+                boolean skipCheck = locationRunning.or(entityRunning).or(locationInstalled).or(entityInstalled).or(entityStarted).or(false);
                 if (l instanceof PortSupplier) {
                     int p = ((PortSupplier) l).obtainPort(value);
                     if (p != -1) {
@@ -102,7 +106,7 @@ public class PortAttributeSensorAndConfigKey extends AttributeSensorAndConfigKey
                         return p;
                     }
                     // If we are not skipping install or already started, fail now
-                    if (!(skip || started)) {
+                    if (!skipCheck) {
                         int rangeSize = Iterables.size(value);
                         if (rangeSize == 0) {
                             LOG.warn("{}: no port available for {} (empty range {})", new
Object[] { entity, getName(), value });

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d5b34e14/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
index e4a26da..b9fcff0 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
@@ -74,13 +74,28 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
      * be called after the {@link #launch()} metheod is executed, but the
      * process may not be completely initialised at this stage, so care is
      * required when implementing these stages.
+     * <p>
+     * The {@link BrooklynConfigKeys#ENTITY_RUNNING} key can be set on the location
+     * or the entity to skip the startup process if the entity is already running,
+     * according to the {@link #isRunning()} method. To force the startup to be
+     * skipped, {@link BrooklynConfigKeys#ENTITY_STARTED} can be set on the entity.
+     * The {@link BrooklynConfigKeys#SKIP_INSTALLATION} key can also be used to
+     * skip the {@link #setup()}, {@link #copyInstallResources()} and
+     * {@link #install()} methods if set on the entity or location. 
      *
      * @see #stop()
      */
     @Override
     public void start() {
-        Boolean started = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.ENTITY_STARTED)).or(false);
-        if (!started) {
+        boolean skipStart = false;
+        Optional<Boolean> locationRunning = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.ENTITY_RUNNING));
+        Optional<Boolean> entityRunning = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.ENTITY_RUNNING));
+        if (locationRunning.or(entityRunning).or(false)) {
+            skipStart = isRunning();
+        } else {
+            skipStart = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.ENTITY_STARTED)).or(false);
+        }
+        if (!skipStart) {
             DynamicTasks.queue("pre-install", new Runnable() { public void run() {
                 preInstall();
             }});
@@ -91,8 +106,10 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
                 }});
             };
 
-            Boolean skip = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION)).or(false);
-            if (!skip) {
+            Optional<Boolean> locationInstalled = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_INSTALLATION));
+            Optional<Boolean> entityInstalled = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION));
+            boolean skipInstall = locationInstalled.or(entityInstalled).or(false);
+            if (!skipInstall) {
                 DynamicTasks.queue("setup", new Runnable() { public void run() {
                     waitForConfigKey(BrooklynConfigKeys.SETUP_LATCH);
                     setup();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d5b34e14/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
index 62fe9e0..717b7ea 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
@@ -69,6 +69,9 @@ public interface SoftwareProcess extends Entity, Startable {
     @SetFromFlag("entityStarted")
     ConfigKey<Boolean> ENTITY_STARTED = BrooklynConfigKeys.ENTITY_STARTED;
 
+    @SetFromFlag("entityRunning")
+    ConfigKey<Boolean> ENTITY_RUNNING = BrooklynConfigKeys.ENTITY_RUNNING;
+
     @SetFromFlag("skipInstall")
     ConfigKey<Boolean> SKIP_INSTALLATION = BrooklynConfigKeys.SKIP_INSTALLATION;
 


Mime
View raw message