You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2014/01/14 15:55:21 UTC

svn commit: r1558063 - in /sling/trunk/bundles/extensions/healthcheck/core/src: main/java/org/apache/sling/hc/api/ main/java/org/apache/sling/hc/api/execution/ main/java/org/apache/sling/hc/core/impl/executor/ test/java/org/apache/sling/hc/jmx/impl/

Author: cziegeler
Date: Tue Jan 14 14:55:20 2014
New Revision: 1558063

URL: http://svn.apache.org/r1558063
Log:
SLING-3278 : Provide a HealthCheckExecutor service. Add hasTimedOut method to execution result

Modified:
    sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
    sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutionResult.java
    sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/ExecutionResult.java
    sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/jmx/impl/HealthCheckMBeanTest.java

Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java?rev=1558063&r1=1558062&r2=1558063&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java Tue Jan 14 14:55:20 2014
@@ -23,6 +23,14 @@ import aQute.bnd.annotation.ConsumerType
 /**
  * Health Check services can be executed and
  * return an execution {@link Result}.
+ *
+ * Clients should not look up health checks directly but
+ * rather use the {@link org.apache.sling.hc.api.execution.HealthCheckExecutor}
+ * service and executed checks based on tags.
+ *
+ * If the {@link #MBEAN_NAME} service registration property is set,
+ * the health check is registered as an mbean and can be invoked
+ * by getting the MBean from the JMX registry.
  */
 @ConsumerType
 public interface HealthCheck {

Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutionResult.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutionResult.java?rev=1558063&r1=1558062&r2=1558063&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutionResult.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutionResult.java Tue Jan 14 14:55:20 2014
@@ -9,6 +9,9 @@ import aQute.bnd.annotation.ProviderType
 
 /**
  * Interface for health check executions via the {@link HealthCheckExecutor}.
+ *
+ * If the execution of the health check timed out, the method
+ *
  */
 @ProviderType
 public interface HealthCheckExecutionResult {
@@ -25,12 +28,20 @@ public interface HealthCheckExecutionRes
 
     /**
      * Get the date, the health check finished or if the
-     * execution timed out, <code>null</code> is returned.
-     * @return The finished date of the execution or <code>null</code>
+     * execution timed out, the execution was aborted.
+     * @return The finished date of the execution.
      */
     Date getFinishedAt();
 
     /**
+     * Returns true if the execution has timed out. In this
+     * case the result does not reflect the real result of the
+     * underlying check, but a result indicating the timeout.
+     * @return <code>true</code> if execution timed out.
+     */
+    boolean hasTimedOut();
+
+    /**
      * Get the meta data about the health check service
      */
     HealthCheckMetadata getHealthCheckMetadata();

Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/ExecutionResult.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/ExecutionResult.java?rev=1558063&r1=1558062&r2=1558063&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/ExecutionResult.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/ExecutionResult.java Tue Jan 14 14:55:20 2014
@@ -35,18 +35,22 @@ public class ExecutionResult implements 
     private final HealthCheckMetadata metaData;
 
     private final Date finishedAt;
+
     private final long elapsedTimeInMs;
 
+    private final boolean timedOut;
+
     /**
      * Full constructor
      */
     ExecutionResult(final HealthCheckMetadata metadata,
             final Result simpleResult,
             final long elapsedTimeInMs,
-            final Date finishedAt) {
+            final boolean timedout) {
         this.metaData = metadata;
         this.resultFromHC = simpleResult;
-        this.finishedAt = finishedAt;
+        this.finishedAt = new Date();
+        this.timedOut = timedout;
         this.elapsedTimeInMs = elapsedTimeInMs;
     }
 
@@ -56,29 +60,26 @@ public class ExecutionResult implements 
     ExecutionResult(final HealthCheckMetadata metadata,
             final Result simpleResult,
             final long elapsedTimeInMs) {
-        this(metadata, simpleResult, elapsedTimeInMs, new Date());
+        this(metadata, simpleResult, elapsedTimeInMs, false);
     }
 
     /**
      * Shortcut constructor to create error result.
-     *
-     * @param healthCheckDescriptor
-     * @param status
-     * @param errorMessage
      */
-    ExecutionResult(HealthCheckMetadata metadata, Result.Status status, String errorMessage) {
-        this(metadata, new Result(status, errorMessage), 0L);
+    ExecutionResult(final HealthCheckMetadata metadata,
+            final Result.Status status,
+            final String errorMessage) {
+        this(metadata, new Result(status, errorMessage), 0L, false);
     }
 
     /**
      * Shortcut constructor to create error/timed out result.
-     *
-     * @param healthCheckDescriptor
-     * @param status
-     * @param errorMessage
      */
-    ExecutionResult(HealthCheckMetadata metadata, Result.Status status, String errorMessage, long elapsedTime) {
-        this(metadata, new Result(status, errorMessage), elapsedTime);
+    ExecutionResult(final HealthCheckMetadata metadata,
+            final Result.Status status,
+            final String errorMessage,
+            final long elapsedTime) {
+        this(metadata, new Result(status, errorMessage), elapsedTime, true);
     }
 
 
@@ -89,7 +90,11 @@ public class ExecutionResult implements 
 
     @Override
     public String toString() {
-        return "ExecutionResult [status=" + this.resultFromHC.getStatus() + ", finishedAt=" + finishedAt + ", elapsedTimeInMs=" + elapsedTimeInMs + "]";
+        return "ExecutionResult [status=" + this.resultFromHC.getStatus() +
+                ", finishedAt=" + finishedAt +
+                ", elapsedTimeInMs=" + elapsedTimeInMs +
+                ", timedOut=" + timedOut +
+                "]";
     }
 
     @Override
@@ -107,6 +112,11 @@ public class ExecutionResult implements 
         return finishedAt;
     }
 
+    @Override
+    public boolean hasTimedOut() {
+        return this.timedOut;
+    }
+
     /**
      * Natural order of results (failed results are sorted before ok results).
      */

Modified: sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/jmx/impl/HealthCheckMBeanTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/jmx/impl/HealthCheckMBeanTest.java?rev=1558063&r1=1558062&r2=1558063&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/jmx/impl/HealthCheckMBeanTest.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/jmx/impl/HealthCheckMBeanTest.java Tue Jan 14 14:55:20 2014
@@ -137,6 +137,12 @@ public class HealthCheckMBeanTest {
                         // TODO Auto-generated method stub
                         return 0;
                     }
+
+                    @Override
+                    public boolean hasTimedOut() {
+                        // TODO Auto-generated method stub
+                        return false;
+                    }
                 };
             }
         });