brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [06/18] incubator-brooklyn git commit: Adds SoftwareProcess.SERVICE_NOT_UP_DIAGNOSTICS
Date Tue, 11 Aug 2015 20:42:44 GMT
Adds SoftwareProcess.SERVICE_NOT_UP_DIAGNOSTICS

In SoftwareProcess, only do expensive checks (e.g. process-running)
if serviceUp is false.


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

Branch: refs/heads/master
Commit: 0c52d9c27fd3c664d7e7f3f24b81cf1d2044708e
Parents: b416623
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Apr 23 21:21:18 2015 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Aug 11 20:04:27 2015 +0100

----------------------------------------------------------------------
 .../java/brooklyn/entity/basic/Attributes.java  | 10 +++
 .../entity/basic/ServiceStateLogic.java         |  1 +
 .../postgresql/PostgreSqlNodeSaltImpl.java      |  6 +-
 .../brooklyn/entity/basic/SoftwareProcess.java  |  7 +++
 .../entity/basic/SoftwareProcessImpl.java       | 64 ++++++++++++++++++++
 .../entity/brooklynnode/BrooklynNodeImpl.java   |  4 +-
 .../brooklyn/entity/chef/ChefEntityImpl.java    |  8 ++-
 .../entity/brooklynnode/MockBrooklynNode.java   |  4 ++
 .../brooklynnode/SameBrooklynNodeImpl.java      |  4 ++
 .../PostgreSqlNodeChefImplFromScratch.java      |  4 ++
 .../entity/webapp/jboss/JBoss7ServerImpl.java   |  2 -
 11 files changed, 106 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/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 f625652..3ff977c 100644
--- a/core/src/main/java/brooklyn/entity/basic/Attributes.java
+++ b/core/src/main/java/brooklyn/entity/basic/Attributes.java
@@ -102,6 +102,7 @@ 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>>() {},
@@ -114,6 +115,15 @@ public interface Attributes {
         "service.problems", 
         "A map of namespaced indicators of problems with a service");
 
+    /**
+     * @since 0.8.0
+     */
+    @SuppressWarnings("serial")
+    AttributeSensor<Map<String,Object>> SERVICE_NOT_UP_DIAGNOSTICS = Sensors.newSensor(
+        new TypeToken<Map<String,Object>>() {},
+        "service.notUp.diagnostics", 
+        "A map of namespaced diagnostics, from when the service is not up");
+    
     AttributeSensor<Lifecycle> SERVICE_STATE_ACTUAL = Sensors.newSensor(Lifecycle.class,
             "service.state", "Actual lifecycle state of the service");
     AttributeSensor<Lifecycle.Transition> SERVICE_STATE_EXPECTED = Sensors.newSensor(Lifecycle.Transition.class,

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
index 3b1efbe..135c1a3 100644
--- a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
+++ b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
@@ -75,6 +75,7 @@ public class ServiceStateLogic {
     
     public static final AttributeSensor<Boolean> SERVICE_UP = Attributes.SERVICE_UP;
     public static final AttributeSensor<Map<String,Object>> SERVICE_NOT_UP_INDICATORS
= Attributes.SERVICE_NOT_UP_INDICATORS;
+    public static final AttributeSensor<Map<String,Object>> SERVICE_NOT_UP_DIAGNOSTICS
= Attributes.SERVICE_NOT_UP_DIAGNOSTICS;
     
     public static final AttributeSensor<Lifecycle> SERVICE_STATE_ACTUAL = Attributes.SERVICE_STATE_ACTUAL;
     public static final AttributeSensor<Lifecycle.Transition> SERVICE_STATE_EXPECTED
= Attributes.SERVICE_STATE_EXPECTED;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/sandbox/extra/src/main/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlNodeSaltImpl.java
----------------------------------------------------------------------
diff --git a/sandbox/extra/src/main/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlNodeSaltImpl.java
b/sandbox/extra/src/main/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlNodeSaltImpl.java
index 66c7acb..e394187 100644
--- a/sandbox/extra/src/main/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlNodeSaltImpl.java
+++ b/sandbox/extra/src/main/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlNodeSaltImpl.java
@@ -18,10 +18,10 @@
  */
 package org.apache.brooklyn.entity.database.postgresql;
 
-import org.apache.brooklyn.entity.database.postgresql.PostgreSqlNodeSaltImpl;
 import org.apache.brooklyn.entity.salt.SaltConfig;
 import org.apache.brooklyn.entity.salt.SaltConfigs;
 import org.apache.brooklyn.entity.salt.SaltLifecycleEffectorTasks;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -176,4 +176,8 @@ public class PostgreSqlNodeSaltImpl extends EffectorStartableImpl implements
Pos
                 ConfigBag.newInstance().configure(ExecuteScriptEffectorBody.SCRIPT, commands).getAllConfig()).getUnchecked();
     }
 
+    @Override
+    public void populateServiceNotUpDiagnostics() {
+        // TODO no-op currently; should check ssh'able etc
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/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 05852d0..064f462 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
@@ -24,6 +24,7 @@ import java.util.Map;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Lifecycle.Transition;
+import brooklyn.entity.annotation.Effector;
 import brooklyn.entity.trait.Startable;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.basic.AttributeSensorAndConfigKey;
@@ -348,4 +349,10 @@ public interface SoftwareProcess extends Entity, Startable {
     
     // NB: the START, STOP, and RESTART effectors themselves are (re)defined by MachineLifecycleEffectorTasks
 
+    /**
+     * @since 0.8.0
+     */
+    @Effector(description="Populates the attribute service.notUp.diagnostics, with any available
health indicators")
+    @Beta
+    void populateServiceNotUpDiagnostics();
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/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 3ae2c9e..feb506a 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
@@ -49,6 +49,7 @@ import brooklyn.location.MachineLocation;
 import brooklyn.location.MachineProvisioningLocation;
 import brooklyn.location.PortRange;
 import brooklyn.location.basic.LocationConfigKeys;
+import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.location.cloud.CloudLocationConfig;
 import brooklyn.management.Task;
 import brooklyn.policy.EnricherSpec;
@@ -64,6 +65,7 @@ import brooklyn.util.time.Time;
 
 import com.google.common.base.Functions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import com.google.common.reflect.TypeToken;
@@ -133,8 +135,70 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
         ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_PROCESS_IS_RUNNING, "No information
yet on whether this service is running");
         // add an indicator above so that if is_running comes through, the map is cleared
and an update is guaranteed
         addEnricher(EnricherSpec.create(UpdatingNotUpFromServiceProcessIsRunning.class).uniqueTag("service-process-is-running-updating-not-up"));
+        addEnricher(EnricherSpec.create(ServiceNotUpDiagnosticsCollector.class).uniqueTag("service-not-up-diagnostics-collector"));
     }
     
+    /**
+     * @since 0.8.0
+     */
+    protected static class ServiceNotUpDiagnosticsCollector extends AbstractEnricher implements
SensorEventListener<Object> {
+        public ServiceNotUpDiagnosticsCollector() {
+        }
+        
+        @Override
+        public void setEntity(EntityLocal entity) {
+            super.setEntity(entity);
+            if (!(entity instanceof SoftwareProcess)) {
+                throw new IllegalArgumentException("Expected SoftwareProcess, but got entity
"+entity);
+            }
+            subscribe(entity, Attributes.SERVICE_UP, this);
+            onUpdated();
+        }
+
+        @Override
+        public void onEvent(SensorEvent<Object> event) {
+            onUpdated();
+        }
+
+        protected void onUpdated() {
+            Boolean up = entity.getAttribute(SERVICE_UP);
+            if (up == null || up) {
+                entity.setAttribute(ServiceStateLogic.SERVICE_NOT_UP_DIAGNOSTICS, ImmutableMap.<String,
Object>of());
+            } else {
+                ((SoftwareProcess)entity).populateServiceNotUpDiagnostics();
+            }
+        }
+    }
+    
+    @Override
+    public void populateServiceNotUpDiagnostics() {
+        if (getDriver() == null) {
+            ServiceStateLogic.updateMapSensorEntry(this, ServiceStateLogic.SERVICE_NOT_UP_DIAGNOSTICS,
"driver", "No driver");
+            return;
+        }
+
+        Location loc = getDriver().getLocation();
+        if (loc instanceof SshMachineLocation) {
+            if (!((SshMachineLocation)loc).isSshable()) {
+                ServiceStateLogic.updateMapSensorEntry(
+                        this, 
+                        ServiceStateLogic.SERVICE_NOT_UP_DIAGNOSTICS, 
+                        "sshable", 
+                        "The machine for this entity does not appear to be sshable");
+            }
+            return;
+        }
+
+        boolean processIsRunning = getDriver().isRunning();
+        if (!processIsRunning) {
+            ServiceStateLogic.updateMapSensorEntry(
+                    this, 
+                    ServiceStateLogic.SERVICE_NOT_UP_DIAGNOSTICS, 
+                    SERVICE_PROCESS_IS_RUNNING.getName(), 
+                    "The software process for this entity does not appear to be running");
+        }
+    }
+
     /** subscribes to SERVICE_PROCESS_IS_RUNNING and SERVICE_UP; the latter has no effect
if the former is set,
      * but to support entities which set SERVICE_UP directly we want to make sure that the
absence of 
      * SERVICE_PROCESS_IS_RUNNING does not trigger any not-up indicators */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
index 7be6dc5..a477c6f 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
@@ -476,8 +476,6 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl implements BrooklynNod
         }
         setAttribute(WEB_CONSOLE_URI, webConsoleUri);
 
-        connectServiceUpIsRunning();
-
         if (webConsoleUri != null) {
             httpFeed = HttpFeed.builder()
                     .entity(this)
@@ -505,6 +503,8 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl implements BrooklynNod
                 .from(WEB_CONSOLE_ACCESSIBLE)
                 .computing(Functionals.ifNotEquals(true).value("URL where Brooklyn listens
is not answering correctly") )
                 .build());
+        } else {
+            connectServiceUpIsRunning();
         }
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/software/base/src/main/java/brooklyn/entity/chef/ChefEntityImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/chef/ChefEntityImpl.java b/software/base/src/main/java/brooklyn/entity/chef/ChefEntityImpl.java
index a96668f..6ee9b1f 100644
--- a/software/base/src/main/java/brooklyn/entity/chef/ChefEntityImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/chef/ChefEntityImpl.java
@@ -30,7 +30,9 @@ public class ChefEntityImpl extends EffectorStartableImpl implements ChefEntity
         super.init();
         new ChefLifecycleEffectorTasks().attachLifecycleEffectors(this);
     }
-    
-    
-    
+
+    @Override
+    public void populateServiceNotUpDiagnostics() {
+        // TODO no-op currently; should check ssh'able etc
+    }    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/software/base/src/test/java/brooklyn/entity/brooklynnode/MockBrooklynNode.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/brooklynnode/MockBrooklynNode.java
b/software/base/src/test/java/brooklyn/entity/brooklynnode/MockBrooklynNode.java
index e20f493..b7c70d8 100644
--- a/software/base/src/test/java/brooklyn/entity/brooklynnode/MockBrooklynNode.java
+++ b/software/base/src/test/java/brooklyn/entity/brooklynnode/MockBrooklynNode.java
@@ -63,4 +63,8 @@ public class MockBrooklynNode extends AbstractEntity implements BrooklynNode
{
     public void restart() {
     }
 
+    @Override
+    public void populateServiceNotUpDiagnostics() {
+        // no-op
+    }    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/software/base/src/test/java/brooklyn/entity/brooklynnode/SameBrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/brooklynnode/SameBrooklynNodeImpl.java
b/software/base/src/test/java/brooklyn/entity/brooklynnode/SameBrooklynNodeImpl.java
index 198c257..4366873 100644
--- a/software/base/src/test/java/brooklyn/entity/brooklynnode/SameBrooklynNodeImpl.java
+++ b/software/base/src/test/java/brooklyn/entity/brooklynnode/SameBrooklynNodeImpl.java
@@ -88,4 +88,8 @@ public class SameBrooklynNodeImpl extends AbstractEntity implements BrooklynNode
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public void populateServiceNotUpDiagnostics() {
+        // no-op
+    }    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeChefImplFromScratch.java
----------------------------------------------------------------------
diff --git a/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeChefImplFromScratch.java
b/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeChefImplFromScratch.java
index 4e743c9..491c8e7 100644
--- a/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeChefImplFromScratch.java
+++ b/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeChefImplFromScratch.java
@@ -162,4 +162,8 @@ public class PostgreSqlNodeChefImplFromScratch extends EffectorStartableImpl
imp
                 ConfigBag.newInstance().configure(ExecuteScriptEffectorBody.SCRIPT, commands).getAllConfig()).getUnchecked();
     }
 
+    @Override
+    public void populateServiceNotUpDiagnostics() {
+        // TODO no-op currently; should check ssh'able etc
+    }    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0c52d9c2/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java
b/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java
index cf6ba59..5279d09 100644
--- a/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java
+++ b/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java
@@ -127,8 +127,6 @@ public class JBoss7ServerImpl extends JavaWebAppSoftwareProcessImpl implements
J
     }
     
     protected void connectServiceUp() {
-        connectServiceUpIsRunning();
-        
         addEnricher(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS)
             .from(MANAGEMENT_URL_UP)
             .computing(Functionals.ifNotEquals(true).value("Management URL not reachable")
)


Mime
View raw message