Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 74b15c0ef -> 761f471ab


prototype of service_up being derived from service_not_up_indicators


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

Branch: refs/heads/master
Commit: 238fab7f0f520a462175ca88b2a807c081e32145
Parents: 0be9f25
Author: Alex Heneveld <[email protected]>
Authored: Wed Aug 6 11:16:23 2014 -0400
Committer: Alex Heneveld <[email protected]>
Committed: Mon Aug 25 09:32:25 2014 +0100

----------------------------------------------------------------------
 .../java/brooklyn/entity/basic/Attributes.java  |  6 ++++
 .../brooklyn/entity/basic/SoftwareProcess.java  |  3 ++
 .../entity/basic/SoftwareProcessImpl.java       | 34 +++++++++++++++++---
 3 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/238fab7f/core/src/main/java/brooklyn/entity/basic/Attributes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/Attributes.java 
b/core/src/main/java/brooklyn/entity/basic/Attributes.java
index 3752752..4453cad 100644
--- a/core/src/main/java/brooklyn/entity/basic/Attributes.java
+++ b/core/src/main/java/brooklyn/entity/basic/Attributes.java
@@ -31,6 +31,7 @@ import brooklyn.event.basic.Sensors;
 import brooklyn.util.net.UserAndHostAndPort;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.reflect.TypeToken;
 
 /**
  * This interface should be used to access {@link Sensor} definitions.
@@ -91,6 +92,11 @@ public interface Attributes {
      */
     AttributeSensor<Boolean> SERVICE_UP = 
Sensors.newBooleanSensor("service.isUp", 
             "Whether the service is active and availability (confirmed and 
monitored)");
+    @SuppressWarnings("serial")
+    AttributeSensor<Map<String,Object>> SERVICE_NOT_UP_INDICATORS = 
Sensors.newSensor(
+        new TypeToken<Map<String,Object>>() {},
+        "service.notUp.indicators", 
+        "A map of namespaced indicators that the service is not up");
     
     AttributeSensor<Lifecycle> SERVICE_STATE = 
Sensors.newSensor(Lifecycle.class,
             "service.state", "Expected lifecycle state of the service");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/238fab7f/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 368619d..eb90660 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
@@ -153,6 +153,9 @@ public interface SoftwareProcess extends Entity, Startable {
     public static final AttributeSensor<MachineProvisioningLocation> 
PROVISIONING_LOCATION = new BasicAttributeSensor<MachineProvisioningLocation>(
             MachineProvisioningLocation.class, 
"softwareservice.provisioningLocation", "Location used to provision a machine 
where this is running");
 
+    public static final AttributeSensor<Boolean> SERVICE_PROCESS_IS_RUNNING = 
Sensors.newBooleanSensor("service.process.isRunning", 
+        "Whether the process for the service is confirmed as running");
+    
     public static final AttributeSensor<Lifecycle> SERVICE_STATE = 
Attributes.SERVICE_STATE;
  
     public static final AttributeSensor<String> PID_FILE = 
Sensors.newStringSensor("softwareprocess.pid.file", "PID file");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/238fab7f/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 741cb4d..fb872b0 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
@@ -32,6 +32,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import brooklyn.config.ConfigKey;
+import brooklyn.enricher.Enrichers;
 import brooklyn.entity.Entity;
 import brooklyn.entity.drivers.DriverDependentEntity;
 import brooklyn.entity.drivers.EntityDriverManager;
@@ -45,6 +46,7 @@ import brooklyn.location.basic.LocationConfigKeys;
 import brooklyn.location.basic.Machines;
 import brooklyn.location.cloud.CloudLocationConfig;
 import brooklyn.management.Task;
+import brooklyn.util.collections.CollectionFunctionals;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.config.ConfigBag;
@@ -55,6 +57,7 @@ import brooklyn.util.time.CountdownTimer;
 import brooklyn.util.time.Duration;
 import brooklyn.util.time.Time;
 
+import com.google.common.base.Function;
 import com.google.common.base.Functions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -72,7 +75,7 @@ public abstract class SoftwareProcessImpl extends 
AbstractEntity implements Soft
        private transient SoftwareProcessDriver driver;
 
     /** @see #connectServiceUpIsRunning() */
-    private volatile FunctionFeed serviceUp;
+    private volatile FunctionFeed serviceProcessIsRunning;
 
     private static final SoftwareProcessDriverLifecycleEffectorTasks 
LIFECYCLE_TASKS =
             new SoftwareProcessDriverLifecycleEffectorTasks();
@@ -148,10 +151,10 @@ public abstract class SoftwareProcessImpl extends 
AbstractEntity implements Soft
      * @see #disconnectServiceUpIsRunning()
      */
     protected void connectServiceUpIsRunning() {
-        serviceUp = FunctionFeed.builder()
+        serviceProcessIsRunning = FunctionFeed.builder()
                 .entity(this)
                 .period(5000)
-                .poll(new FunctionPollConfig<Boolean, Boolean>(SERVICE_UP)
+                .poll(new FunctionPollConfig<Boolean, 
Boolean>(SERVICE_PROCESS_IS_RUNNING)
                         .onException(Functions.constant(Boolean.FALSE))
                         .callable(new Callable<Boolean>() {
                             public Boolean call() {
@@ -159,6 +162,29 @@ public abstract class SoftwareProcessImpl extends 
AbstractEntity implements Soft
                             }
                         }))
                 .build();
+
+        // FIXME quick-and-dirty change
+        Function<Boolean, Map<String,Object>> f = new Function<Boolean, 
Map<String,Object>>() {
+            @Override
+            public Map<String, Object> apply(Boolean input) {
+                Map<String, Object> result = 
getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS);
+                if (result==null) result = MutableMap.of();
+                // TODO only change/publish if it needs changing...
+                if (Boolean.TRUE.equals(input)) {
+                    result.remove(SERVICE_PROCESS_IS_RUNNING.getName());
+                    return result;
+                } else {
+                    result.put(SERVICE_PROCESS_IS_RUNNING.getName(), "Process 
not running (according to driver checkRunning)");                    
+                    return result;
+                }
+            }
+        };
+        
addEnricher(Enrichers.builder().transforming(SERVICE_PROCESS_IS_RUNNING).publishing(Attributes.SERVICE_NOT_UP_INDICATORS)
+            .computing(f).build());
+        
+        // FIXME lives elsewhere
+        
addEnricher(Enrichers.builder().transforming(Attributes.SERVICE_NOT_UP_INDICATORS).publishing(Attributes.SERVICE_UP)
+            .computing( 
Functions.forPredicate(CollectionFunctionals.<String>mapSizeEquals(0)) 
).build());
     }
 
     /**
@@ -169,7 +195,7 @@ public abstract class SoftwareProcessImpl extends 
AbstractEntity implements Soft
      * @see #connectServiceUpIsRunning()
      */
     protected void disconnectServiceUpIsRunning() {
-        if (serviceUp != null) serviceUp.stop();
+        if (serviceProcessIsRunning != null) serviceProcessIsRunning.stop();
     }
 
     /**

Reply via email to