brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [10/16] incubator-brooklyn git commit: SoftwareProcess exposes LifecycleEffectorTasks implementation as config
Date Tue, 14 Jul 2015 09:36:01 GMT
SoftwareProcess exposes LifecycleEffectorTasks implementation as config


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

Branch: refs/heads/master
Commit: 0576be63535d83e31d49d84fde1997b70215ff20
Parents: b2d3f33
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Thu Jul 9 14:23:51 2015 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Fri Jul 10 10:33:48 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/basic/SoftwareProcess.java  | 17 ++++++--
 .../entity/basic/SoftwareProcessImpl.java       | 17 ++++----
 .../test/entity/TestJavaWebAppEntity.java       | 41 ++++++++++++++++++++
 .../test/entity/TestJavaWebAppEntityImpl.java   | 35 +----------------
 4 files changed, 65 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0576be63/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 75b3573..1de84de 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
@@ -214,7 +214,16 @@ public interface SoftwareProcess extends Entity, Startable {
                     "several others. Set to null or to 0 to disable any delay.",
             Duration.TEN_SECONDS);
 
-    /** controls the behavior when starting (stop, restart) {@link Startable} children as
part of the start (stop, restart) effector on this entity
+    /**
+     * Sets the object that manages the sequence of calls of the entity's driver.
+     */
+    @Beta
+    @SetFromFlag("lifecycleEffectorTasks")
+    ConfigKey<SoftwareProcessDriverLifecycleEffectorTasks> LIFECYCLE_EFFECTOR_TASKS
= ConfigKeys.newConfigKey(SoftwareProcessDriverLifecycleEffectorTasks.class,
+            "softwareProcess.lifecycleTasks", "An object that handles lifecycle of an entity's
associated machine.",
+            new SoftwareProcessDriverLifecycleEffectorTasks());
+
+    /** Controls the behavior when starting (stop, restart) {@link Startable} children as
part of the start (stop, restart) effector on this entity
      * <p>
      * (NB: restarts are currently not propagated to children in the default {@link SoftwareProcess}
      * due to the various semantics which may be desired; this may change, but if entities
have specific requirements for restart,
@@ -258,7 +267,9 @@ public interface SoftwareProcess extends Entity, Startable {
     }
 
     @SetFromFlag("childStartMode")
-    ConfigKey<ChildStartableMode> CHILDREN_STARTABLE_MODE = ConfigKeys.newConfigKey(ChildStartableMode.class,
"children.startable.mode");
+    ConfigKey<ChildStartableMode> CHILDREN_STARTABLE_MODE = ConfigKeys.newConfigKey(ChildStartableMode.class,
+            "children.startable.mode", "Controls behaviour when starting Startable children
as part of this entity's lifecycle.",
+            ChildStartableMode.NONE);
 
     @SuppressWarnings("rawtypes")
     AttributeSensor<MachineProvisioningLocation> PROVISIONING_LOCATION = Sensors.newSensor(
@@ -301,7 +312,7 @@ public interface SoftwareProcess extends Entity, Startable {
 
         @Beta /** @since 0.7.0 semantics of parameters to restart being explored */
         public static final ConfigKey<StopMode> STOP_PROCESS_MODE = ConfigKeys.newConfigKey(StopMode.class,
"stopProcessMode",
-                "When to stop the process with regard to the entity state" +
+                "When to stop the process with regard to the entity state. " +
                 "ALWAYS will try to stop the process even if the entity is marked as stopped,
" +
                 "IF_NOT_STOPPED stops the process only if the entity is not marked as stopped,
" +
                 "NEVER doesn't stop the process.", StopMode.IF_NOT_STOPPED);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0576be63/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
index 3d5511f..9daed4c 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
@@ -85,9 +85,6 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
     /** @see #connectServiceUpIsRunning() */
     private volatile FunctionFeed serviceProcessIsRunning;
 
-    private static final SoftwareProcessDriverLifecycleEffectorTasks LIFECYCLE_TASKS =
-            new SoftwareProcessDriverLifecycleEffectorTasks();
-
     protected boolean connectedSensors = false;
     
     public SoftwareProcessImpl() {
@@ -129,7 +126,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
     @Override
     public void init() {
         super.init();
-        LIFECYCLE_TASKS.attachLifecycleEffectors(this);
+        getLifecycleEffectorTasks().attachLifecycleEffectors(this);
     }
     
     @Override
@@ -442,7 +439,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
 
     /** returns the ports that this entity wants to use;
      * default implementation returns {@link SoftwareProcess#REQUIRED_OPEN_LOGIN_PORTS} plus
first value 
-     * for each {@link PortAttributeSensorAndConfigKey} config key {@link PortRange}
+     * for each {@link brooklyn.event.basic.PortAttributeSensorAndConfigKey} config key {@link
PortRange}
      * plus any ports defined with a config keys ending in {@code .port}.
      */
     protected Collection<Integer> getRequiredOpenPorts() {
@@ -614,7 +611,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
      */
     @Deprecated
     protected final void doStart(Collection<? extends Location> locations) {
-        LIFECYCLE_TASKS.start(locations);
+        getLifecycleEffectorTasks().start(locations);
     }
     
     /**
@@ -624,7 +621,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
      */
     @Deprecated
     protected final void doStop() {
-        LIFECYCLE_TASKS.stop();
+        getLifecycleEffectorTasks().stop();
     }
     
     /**
@@ -634,7 +631,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
      */
     @Deprecated
     protected final void doRestart(ConfigBag parameters) {
-        LIFECYCLE_TASKS.restart(parameters);
+        getLifecycleEffectorTasks().restart(parameters);
     }
 
     @Deprecated /** @deprecated since 0.7.0 see {@link #doRestart(ConfigBag)} */
@@ -642,4 +639,8 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
         doRestart(ConfigBag.EMPTY);
     }
 
+    protected SoftwareProcessDriverLifecycleEffectorTasks getLifecycleEffectorTasks() {
+        return getConfig(LIFECYCLE_EFFECTOR_TASKS);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0576be63/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
index 8710d0b..003d81c 100644
--- a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
+++ b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
@@ -18,9 +18,20 @@
  */
 package brooklyn.test.entity;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.ConfigKeys;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.basic.SoftwareProcessDriverLifecycleEffectorTasks;
 import brooklyn.entity.java.VanillaJavaApp;
 import brooklyn.entity.proxying.ImplementedBy;
 import brooklyn.entity.webapp.WebAppService;
+import brooklyn.location.Location;
 
 /**
  * Mock web application server entity for testing.
@@ -28,8 +39,38 @@ import brooklyn.entity.webapp.WebAppService;
 @ImplementedBy(TestJavaWebAppEntityImpl.class)
 public interface TestJavaWebAppEntity extends VanillaJavaApp, WebAppService {
 
+    /**
+     * Injects the test entity's customised lifecycle tasks.
+     */
+    ConfigKey<SoftwareProcessDriverLifecycleEffectorTasks> LIFECYCLE_EFFECTOR_TASKS
= ConfigKeys.newConfigKeyWithDefault(
+            SoftwareProcess.LIFECYCLE_EFFECTOR_TASKS,
+            new TestJavaWebAppEntityLifecycleTasks());
+
     void spoofRequest();
     int getA();
     int getB();
     int getC();
+
+    static class TestJavaWebAppEntityLifecycleTasks extends SoftwareProcessDriverLifecycleEffectorTasks
{
+        private static final Logger LOG = LoggerFactory.getLogger(TestJavaWebAppEntityLifecycleTasks.class);
+
+        @Override
+        public void start(java.util.Collection<? extends Location> locations) {
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING);
+            LOG.trace("Starting {}", this);
+            entity().setAttribute(SERVICE_PROCESS_IS_RUNNING, true);
+            entity().setAttribute(Attributes.SERVICE_UP, true);
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
+        }
+
+        @Override
+        public void stop() {
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING);
+            LOG.trace("Stopping {}", this);
+            entity().setAttribute(Attributes.SERVICE_UP, false);
+            entity().setAttribute(SERVICE_PROCESS_IS_RUNNING, false);
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0576be63/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
index 579763d..be7fb8a 100644
--- a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
+++ b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
@@ -20,23 +20,13 @@ package brooklyn.test.entity;
 
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.Lifecycle;
-import brooklyn.entity.basic.ServiceStateLogic;
-import brooklyn.entity.basic.SoftwareProcessDriverLifecycleEffectorTasks;
 import brooklyn.entity.java.VanillaJavaAppImpl;
 import brooklyn.entity.webapp.WebAppServiceConstants;
-import brooklyn.location.Location;
 import brooklyn.util.flags.SetFromFlag;
 
 public class TestJavaWebAppEntityImpl extends VanillaJavaAppImpl implements TestJavaWebAppEntity
{
 
-    private static final Logger LOG = LoggerFactory.getLogger(TestJavaWebAppEntity.class);
-
     @SetFromFlag public int a;
     @SetFromFlag public int b;
     @SetFromFlag public int c;
@@ -46,30 +36,6 @@ public class TestJavaWebAppEntityImpl extends VanillaJavaAppImpl implements
Test
     // constructor required for use in DynamicCluster.factory
     public TestJavaWebAppEntityImpl(@SuppressWarnings("rawtypes") Map flags, Entity parent)
{ super(flags, parent); }
 
-    private static final SoftwareProcessDriverLifecycleEffectorTasks LIFECYCLE_TASKS =
-        new SoftwareProcessDriverLifecycleEffectorTasks() {
-        public void start(java.util.Collection<? extends Location> locations) {
-            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING);
-            LOG.trace("Starting {}", this);
-            entity().setAttribute(SERVICE_PROCESS_IS_RUNNING, true);
-            entity().setAttribute(Attributes.SERVICE_UP, true);
-            ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
-        }
-        public void stop() {
-            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING);
-            LOG.trace("Stopping {}", this);
-            entity().setAttribute(Attributes.SERVICE_UP, false);
-            entity().setAttribute(SERVICE_PROCESS_IS_RUNNING, false);
-            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED);
-        }
-    };
-
-    @Override
-    public void init() {
-        super.init();
-        LIFECYCLE_TASKS.attachLifecycleEffectors(this);
-    }
-
     @Override
     public synchronized void spoofRequest() {
         Integer rc = getAttribute(WebAppServiceConstants.REQUEST_COUNT);
@@ -91,4 +57,5 @@ public class TestJavaWebAppEntityImpl extends VanillaJavaAppImpl implements
Test
     public int getC() {
         return c;
     }
+
 }


Mime
View raw message