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/10 15:44:32 UTC
svn commit: r1557138 - in /sling/trunk/bundles/extensions/healthcheck:
core/src/main/java/org/apache/sling/hc/api/execution/
core/src/main/java/org/apache/sling/hc/core/impl/executor/
core/src/main/java/org/apache/sling/hc/util/ core/src/test/java/org/...
Author: cziegeler
Date: Fri Jan 10 14:44:31 2014
New Revision: 1557138
URL: http://svn.apache.org/r1557138
Log:
SLING-3278 : Provide a HealthCheckExecutor service. Change API to execute checks based on tags, add service reference to HealthCheckMetadata
Removed:
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckDescriptor.java
Modified:
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/api/execution/HealthCheckExecutor.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/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckFuture.java
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java
sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImplTest.java
sling/trunk/bundles/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java
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=1557138&r1=1557137&r2=1557138&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 Fri Jan 10 14:44:31 2014
@@ -8,8 +8,7 @@ import org.apache.sling.hc.util.HealthCh
import aQute.bnd.annotation.ProviderType;
/**
- * Interface for health check results.
- *
+ * Interface for health check executions via the {@link HealthCheckExecutor}.
*/
@ProviderType
public interface HealthCheckExecutionResult {
@@ -19,8 +18,14 @@ public interface HealthCheckExecutionRes
*/
Result getHealthCheckResult();
+ /**
+ * Get the elapsed time in ms
+ */
long getElapsedTimeInMs();
+ /**
+ * Get the date, the health check finished.
+ */
Date getFinishedAt();
/**
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutor.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutor.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/execution/HealthCheckExecutor.java Fri Jan 10 14:44:31 2014
@@ -20,7 +20,6 @@ package org.apache.sling.hc.api.executio
import java.util.List;
import org.apache.sling.hc.api.HealthCheck;
-import org.osgi.framework.ServiceReference;
import aQute.bnd.annotation.ProviderType;
@@ -33,9 +32,10 @@ import aQute.bnd.annotation.ProviderType
public interface HealthCheckExecutor {
/**
- * Executes all health checks
+ * Executes all health checks with the supplied list of tags.
+ * If no tags are supplied, all health checks are executed.
*
* @return List of results. The list might be empty.
*/
- List<HealthCheckExecutionResult> execute(ServiceReference... healthCheckReferences);
+ List<HealthCheckExecutionResult> execute(String... tags);
}
\ No newline at end of file
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=1557138&r1=1557137&r2=1557138&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 Fri Jan 10 14:44:31 2014
@@ -25,7 +25,9 @@ import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
import org.apache.sling.hc.util.HealthCheckMetadata;
-/** The result of executing a {@link HealthCheck} */
+/**
+ * The result of executing a {@link HealthCheck}.
+ */
public class ExecutionResult implements Comparable<ExecutionResult>, HealthCheckExecutionResult {
private final Result resultFromHC;
@@ -37,9 +39,9 @@ public class ExecutionResult implements
/** Build a single-value Result
* @param s if lower than OK, our status is set to OK */
- ExecutionResult(final HealthCheckMetadata healthCheckDescriptor, Result simpleResult,
+ ExecutionResult(final HealthCheckMetadata metadata, Result simpleResult,
long elapsedTimeInMs) {
- this.metaData = healthCheckDescriptor;
+ this.metaData = metadata;
this.resultFromHC = simpleResult;
this.finishedAt = new Date();
this.elapsedTimeInMs = elapsedTimeInMs;
@@ -52,8 +54,8 @@ public class ExecutionResult implements
* @param status
* @param errorMessage
*/
- ExecutionResult(HealthCheckMetadata healthCheckDescriptor, Result.Status status, String errorMessage) {
- this(healthCheckDescriptor, new Result(status, errorMessage), 0L);
+ ExecutionResult(HealthCheckMetadata metadata, Result.Status status, String errorMessage) {
+ this(metadata, new Result(status, errorMessage), 0L);
}
/**
@@ -63,8 +65,8 @@ public class ExecutionResult implements
* @param status
* @param errorMessage
*/
- ExecutionResult(HealthCheckMetadata healthCheckDescriptor, Result.Status status, String errorMessage, long elapsedTime) {
- this(healthCheckDescriptor, new Result(status, errorMessage), elapsedTime);
+ ExecutionResult(HealthCheckMetadata metadata, Result.Status status, String errorMessage, long elapsedTime) {
+ this(metadata, new Result(status, errorMessage), elapsedTime);
}
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java Fri Jan 10 14:44:31 2014
@@ -46,6 +46,8 @@ import org.apache.sling.commons.threads.
import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
import org.apache.sling.hc.api.execution.HealthCheckExecutor;
+import org.apache.sling.hc.util.HealthCheckFilter;
+import org.apache.sling.hc.util.HealthCheckMetadata;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
@@ -92,7 +94,7 @@ public class HealthCheckExecutorImpl imp
private HealthCheckResultCache healthCheckResultCache = new HealthCheckResultCache();
- private Map<HealthCheckDescriptor, HealthCheckFuture> stillRunningFutures = new ConcurrentHashMap<HealthCheckDescriptor, HealthCheckFuture>();
+ private Map<HealthCheckMetadata, HealthCheckFuture> stillRunningFutures = new ConcurrentHashMap<HealthCheckMetadata, HealthCheckFuture>();
@Reference
private ThreadPoolManager threadPoolManager;
@@ -133,39 +135,45 @@ public class HealthCheckExecutorImpl imp
}
/**
- * @see org.apache.sling.hc.api.execution.HealthCheckExecutor#execute(org.osgi.framework.ServiceReference[])
+ * @see org.apache.sling.hc.api.execution.HealthCheckExecutor#execute(String[])
*/
@Override
- public List<HealthCheckExecutionResult> execute(final ServiceReference... healthCheckReferences) {
- logger.debug("Starting executing all checks... ");
+ public List<HealthCheckExecutionResult> execute(final String... tags) {
+ logger.debug("Starting executing checks for {}", tags == null ? "*" : tags);
- final StopWatch stopWatch = new StopWatch();
- stopWatch.start();
+ final HealthCheckFilter filter = new HealthCheckFilter(this.bundleContext);
+ try {
+ final ServiceReference[] healthCheckReferences = filter.getTaggedHealthCheckServiceReferences(tags);
- final List<HealthCheckExecutionResult> results = new ArrayList<HealthCheckExecutionResult>();
- final List<HealthCheckDescriptor> healthCheckDescriptors = getHealthCheckDescriptors(healthCheckReferences);
+ final StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
- createResultsForDescriptors(healthCheckDescriptors, results);
+ final List<HealthCheckExecutionResult> results = new ArrayList<HealthCheckExecutionResult>();
+ final List<HealthCheckMetadata> healthCheckDescriptors = getHealthCheckDescriptors(healthCheckReferences);
- stopWatch.stop();
- if ( logger.isDebugEnabled() ) {
- logger.debug("Time consumed for all checks: {}", msHumanReadable(stopWatch.getTime()));
- }
-
- // sort result
- Collections.sort(results, new Comparator<HealthCheckExecutionResult>() {
+ createResultsForDescriptors(healthCheckDescriptors, results);
- @Override
- public int compare(final HealthCheckExecutionResult arg0,
- final HealthCheckExecutionResult arg1) {
- return ((ExecutionResult)arg0).compareTo((ExecutionResult)arg1);
+ stopWatch.stop();
+ if ( logger.isDebugEnabled() ) {
+ logger.debug("Time consumed for all checks: {}", msHumanReadable(stopWatch.getTime()));
}
+ // sort result
+ Collections.sort(results, new Comparator<HealthCheckExecutionResult>() {
- });
- return results;
+ @Override
+ public int compare(final HealthCheckExecutionResult arg0,
+ final HealthCheckExecutionResult arg1) {
+ return ((ExecutionResult)arg0).compareTo((ExecutionResult)arg1);
+ }
+
+ });
+ return results;
+ } finally {
+ filter.dispose();
+ }
}
- private void createResultsForDescriptors(final List<HealthCheckDescriptor> healthCheckDescriptors,
+ private void createResultsForDescriptors(final List<HealthCheckMetadata> healthCheckDescriptors,
final Collection<HealthCheckExecutionResult> results) {
// -- All methods below check if they can transform a healthCheckDescriptor into a result
// -- if yes the descriptor is removed from the list and the result added
@@ -183,11 +191,13 @@ public class HealthCheckExecutorImpl imp
healthCheckResultCache.updateWith(results);
}
-
- private List<HealthCheckDescriptor> getHealthCheckDescriptors(final ServiceReference... healthCheckReferences) {
- final List<HealthCheckDescriptor> descriptors = new LinkedList<HealthCheckDescriptor>();
- for (ServiceReference serviceReference : healthCheckReferences) {
- HealthCheckDescriptor descriptor = new HealthCheckDescriptor(serviceReference);
+ /**
+ * Create the health check descriptors
+ */
+ private List<HealthCheckMetadata> getHealthCheckDescriptors(final ServiceReference... healthCheckReferences) {
+ final List<HealthCheckMetadata> descriptors = new LinkedList<HealthCheckMetadata>();
+ for (final ServiceReference serviceReference : healthCheckReferences) {
+ final HealthCheckMetadata descriptor = new HealthCheckMetadata(serviceReference);
descriptors.add(descriptor);
}
@@ -195,10 +205,10 @@ public class HealthCheckExecutorImpl imp
return descriptors;
}
- private List<HealthCheckFuture> createOrReuseFutures(final List<HealthCheckDescriptor> healthCheckDescriptors) {
+ private List<HealthCheckFuture> createOrReuseFutures(final List<HealthCheckMetadata> healthCheckDescriptors) {
List<HealthCheckFuture> futuresForResultOfThisCall = new LinkedList<HealthCheckFuture>();
- for (final HealthCheckDescriptor healthCheckDescriptor : healthCheckDescriptors) {
+ for (final HealthCheckMetadata healthCheckDescriptor : healthCheckDescriptors) {
HealthCheckFuture stillRunningFuture = this.stillRunningFutures.get(healthCheckDescriptor);
HealthCheckFuture resultFuture;
@@ -244,37 +254,37 @@ public class HealthCheckExecutorImpl imp
HealthCheckFuture future = futuresIt.next();
ExecutionResult result;
if (future.isDone()) {
- logger.debug("Health Check is done: {}", future.getHealthCheckDescriptor());
+ logger.debug("Health Check is done: {}", future.getHealthCheckMetadata());
try {
result = future.get();
} catch (Exception e) {
logger.warn("Unexpected Exception during future.get(): " + e, e);
- result = new ExecutionResult(future.getHealthCheckDescriptor().getMetadata(), Result.Status.HEALTH_CHECK_ERROR,
+ result = new ExecutionResult(future.getHealthCheckMetadata(), Result.Status.HEALTH_CHECK_ERROR,
"Unexpected Exception during future.get(): " + e);
}
// if the future came from a previous call remove it from stillRunningFutures
- if (this.stillRunningFutures.containsKey(future.getHealthCheckDescriptor())) {
- this.stillRunningFutures.remove(future.getHealthCheckDescriptor());
+ if (this.stillRunningFutures.containsKey(future.getHealthCheckMetadata())) {
+ this.stillRunningFutures.remove(future.getHealthCheckMetadata());
}
} else {
- logger.debug("Health Check timed out: {}", future.getHealthCheckDescriptor());
+ logger.debug("Health Check timed out: {}", future.getHealthCheckMetadata());
// Futures must not be cancelled as interrupting a health check might could cause a corrupted repository index
// (CrxRoundtripCheck) or ugly messages/stack traces in the log file
- this.stillRunningFutures.put(future.getHealthCheckDescriptor(), future);
+ this.stillRunningFutures.put(future.getHealthCheckMetadata(), future);
// normally we turn the check into WARN (normal timeout), but if the threshold time for CRITICAL is reached for a certain
// future we turn the result CRITICAL
long futureElapsedTimeMs = new Date().getTime() - future.getCreatedTime().getTime();
if (futureElapsedTimeMs < this.longRunningFutureThresholdForRedMs) {
- result = new ExecutionResult(future.getHealthCheckDescriptor().getMetadata(), Result.Status.WARN,
+ result = new ExecutionResult(future.getHealthCheckMetadata(), Result.Status.WARN,
"Timeout: Check still running after " + msHumanReadable(futureElapsedTimeMs), futureElapsedTimeMs);
} else {
- result = new ExecutionResult(future.getHealthCheckDescriptor().getMetadata(), Result.Status.CRITICAL,
+ result = new ExecutionResult(future.getHealthCheckMetadata(), Result.Status.CRITICAL,
"Timeout: Check still running after " + msHumanReadable(futureElapsedTimeMs)
+ " (exceeding the configured threshold for CRITICAL: "
+ msHumanReadable(this.longRunningFutureThresholdForRedMs) + ")", futureElapsedTimeMs);
@@ -318,5 +328,4 @@ public class HealthCheckExecutorImpl imp
final long longRunningFutureThresholdForRedMs) {
this.longRunningFutureThresholdForRedMs = longRunningFutureThresholdForRedMs;
}
-
}
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckFuture.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckFuture.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckFuture.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckFuture.java Fri Jan 10 14:44:31 2014
@@ -25,6 +25,7 @@ import org.apache.commons.lang.StringUti
import org.apache.commons.lang.time.StopWatch;
import org.apache.sling.hc.api.HealthCheck;
import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.util.HealthCheckMetadata;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,29 +37,29 @@ import org.slf4j.LoggerFactory;
class HealthCheckFuture extends FutureTask<ExecutionResult> {
private final static Logger LOG = LoggerFactory.getLogger(HealthCheckFuture.class);
- private final HealthCheckDescriptor healthCheckDescriptor;
+ private final HealthCheckMetadata metadata;
private final Date createdTime;
- HealthCheckFuture(final HealthCheckDescriptor healthCheckDescriptor, final BundleContext bundleContext) {
+ HealthCheckFuture(final HealthCheckMetadata metadata, final BundleContext bundleContext) {
super(new Callable<ExecutionResult>() {
@Override
public ExecutionResult call() throws Exception {
Thread.currentThread().setName(
- "Health-Check-" + StringUtils.substringAfterLast(healthCheckDescriptor.getMetadata().getTitle(), "."));
- LOG.debug("Starting check {}", healthCheckDescriptor);
+ "Health-Check-" + StringUtils.substringAfterLast(metadata.getTitle(), "."));
+ LOG.debug("Starting check {}", metadata);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Result resultFromHealthCheck = null;
ExecutionResult executionResult = null;
- final HealthCheck healthCheck = (HealthCheck) bundleContext.getService(healthCheckDescriptor.getServiceReference());
+ final HealthCheck healthCheck = (HealthCheck) bundleContext.getService(metadata.getServiceReference());
try {
if (healthCheck != null) {
resultFromHealthCheck = healthCheck.execute();
} else {
- throw new IllegalStateException("Service for " + healthCheckDescriptor + " is gone");
+ throw new IllegalStateException("Service for " + metadata + " is gone");
}
} catch (Exception e) {
@@ -66,16 +67,16 @@ class HealthCheckFuture extends FutureTa
// TODO ResultLog should be improved to be able to store exceptions
} finally {
// unget service ref
- bundleContext.ungetService(healthCheckDescriptor.getServiceReference());
+ bundleContext.ungetService(metadata.getServiceReference());
// update result with information about this run
stopWatch.stop();
long elapsedTime = stopWatch.getTime();
if (resultFromHealthCheck != null) {
// wrap the result in an execution result
- executionResult = new ExecutionResult(healthCheckDescriptor.getMetadata(), resultFromHealthCheck, elapsedTime);
+ executionResult = new ExecutionResult(metadata, resultFromHealthCheck, elapsedTime);
}
- LOG.debug("Time consumed for {}: {}", healthCheckDescriptor, HealthCheckExecutorImpl.msHumanReadable(elapsedTime));
+ LOG.debug("Time consumed for {}: {}", metadata, HealthCheckExecutorImpl.msHumanReadable(elapsedTime));
}
Thread.currentThread().setName("Health-Check-idle");
@@ -83,7 +84,7 @@ class HealthCheckFuture extends FutureTa
}
});
this.createdTime = new Date();
- this.healthCheckDescriptor = healthCheckDescriptor;
+ this.metadata = metadata;
}
@@ -91,13 +92,13 @@ class HealthCheckFuture extends FutureTa
return this.createdTime;
}
- public HealthCheckDescriptor getHealthCheckDescriptor() {
- return healthCheckDescriptor;
+ public HealthCheckMetadata getHealthCheckMetadata() {
+ return metadata;
}
@Override
public String toString() {
- return "[Future for " + this.healthCheckDescriptor + ", createdTime=" + this.createdTime + "]";
+ return "[Future for " + this.metadata + ", createdTime=" + this.createdTime + "]";
}
}
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java Fri Jan 10 14:44:31 2014
@@ -27,6 +27,7 @@ import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
+import org.apache.sling.hc.util.HealthCheckMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,15 +53,15 @@ public class HealthCheckResultCache {
}
}
- public void useValidCacheResults(final List<HealthCheckDescriptor> healthCheckDescriptors,
+ public void useValidCacheResults(final List<HealthCheckMetadata> metadatas,
final Collection<HealthCheckExecutionResult> results,
final long resultCacheTtlInMs) {
final Set<HealthCheckExecutionResult> cachedResults = new TreeSet<HealthCheckExecutionResult>();
- final Iterator<HealthCheckDescriptor> checksIt = healthCheckDescriptors.iterator();
+ final Iterator<HealthCheckMetadata> checksIt = metadatas.iterator();
while (checksIt.hasNext()) {
- final HealthCheckDescriptor descriptor = checksIt.next();
+ final HealthCheckMetadata descriptor = checksIt.next();
final HealthCheckExecutionResult result = get(descriptor, resultCacheTtlInMs);
if (result != null) {
cachedResults.add(result);
@@ -71,8 +72,8 @@ public class HealthCheckResultCache {
results.addAll(cachedResults);
}
- private HealthCheckExecutionResult get(final HealthCheckDescriptor healthCheckDescriptor, final long resultCacheTtlInMs) {
- final Long key = healthCheckDescriptor.getMetadata().getServiceId();
+ private HealthCheckExecutionResult get(final HealthCheckMetadata metadata, final long resultCacheTtlInMs) {
+ final Long key = metadata.getServiceId();
final HealthCheckExecutionResult cachedResult = cache.get(key);
if (cachedResult != null) {
Date finishedAt = cachedResult.getFinishedAt();
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java Fri Jan 10 14:44:31 2014
@@ -25,7 +25,6 @@ import org.apache.commons.lang.StringUti
import org.apache.sling.hc.api.HealthCheck;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.component.ComponentConstants;
/**
* This class helps retrieving meta data information about a health check service.
@@ -35,37 +34,76 @@ public class HealthCheckMetadata {
private final String name;
+ private final String mbeanName;
+
private final String title;
private final long serviceId;
private final List<String> tags;
+ private final transient ServiceReference serviceReference;
+
public HealthCheckMetadata(final ServiceReference ref) {
this.serviceId = (Long) ref.getProperty(Constants.SERVICE_ID);
this.name = (String) ref.getProperty(HealthCheck.NAME);
+ this.mbeanName = (String) ref.getProperty(HealthCheck.MBEAN_NAME);
this.title = getHealthCheckTitle(ref);
this.tags = arrayPropertyToListOfStr(ref.getProperty(HealthCheck.TAGS));
-
+ this.serviceReference = ref;
}
+ /**
+ * The name of the health check as defined through the {@link HealthCheck#NAME}
+ * property.
+ * @return The name or <code>null</code>
+ */
public String getName() {
return name;
}
+ /**
+ * The mbean name of the health check as defined through the {@link HealthCheck#MBEAN_NAME}
+ * property.
+ * @return The mbean name or <code>null</code>
+ */
+ public String getMBeanName() {
+ return mbeanName;
+ }
+
+ /**
+ * The title of the health check.
+ * If the health check has a name, this is used as the title.
+ * Otherwise the description, PID and service ID are checked
+ * for values.
+ */
public String getTitle() {
return title;
}
-
+ /**
+ * Return the list of defined tags for this check as set
+ * through {@link HealthCheckMetadata#tags}
+ * @return
+ */
public List<String> getTags() {
return tags;
}
+ /**
+ * Return the service id.
+ */
public long getServiceId() {
return this.serviceId;
}
+ /**
+ * Get the service reference.
+ */
+ public ServiceReference getServiceReference() {
+ return this.serviceReference;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -94,7 +132,10 @@ public class HealthCheckMetadata {
name = (String) ref.getProperty(Constants.SERVICE_DESCRIPTION);
}
if (StringUtils.isBlank(name)) {
- name = (String) ref.getProperty(ComponentConstants.COMPONENT_NAME);
+ name = (String) ref.getProperty(Constants.SERVICE_PID);
+ }
+ if (StringUtils.isBlank(name)) {
+ name = "HealthCheck:" + ref.getProperty(Constants.SERVICE_ID);
}
return name;
}
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImplTest.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImplTest.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImplTest.java Fri Jan 10 14:44:31 2014
@@ -29,17 +29,13 @@ public class HealthCheckExecutorImplTest
private HealthCheckFuture future;
@Mock
- private HealthCheckDescriptor healthCheckDescriptor;
-
- @Mock
private HealthCheckMetadata HealthCheckMetadata;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- when(future.getHealthCheckDescriptor()).thenReturn(healthCheckDescriptor);
- when(healthCheckDescriptor.getMetadata()).thenReturn(this.HealthCheckMetadata);
+ when(future.getHealthCheckMetadata()).thenReturn(HealthCheckMetadata);
when(HealthCheckMetadata.getTitle()).thenReturn("Test Check");
healthCheckExecutorImpl = new HealthCheckExecutorImpl();
@@ -57,7 +53,7 @@ public class HealthCheckExecutorImplTest
Collection<HealthCheckExecutionResult> results = new TreeSet<HealthCheckExecutionResult>();
when(future.isDone()).thenReturn(true);
- ExecutionResult testResult = new ExecutionResult(healthCheckDescriptor.getMetadata(), new Result(Result.Status.OK, "test"), 10L);
+ ExecutionResult testResult = new ExecutionResult(HealthCheckMetadata, new Result(Result.Status.OK, "test"), 10L);
when(future.get()).thenReturn(testResult);
healthCheckExecutorImpl.collectResultsFromFutures(futures, results);
Modified: sling/trunk/bundles/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java?rev=1557138&r1=1557137&r2=1557138&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java Fri Jan 10 14:44:31 2014
@@ -29,9 +29,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
@@ -41,9 +39,6 @@ import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.api.ResultLog;
import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
import org.apache.sling.hc.api.execution.HealthCheckExecutor;
-import org.apache.sling.hc.util.HealthCheckFilter;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
/** Webconsole plugin to execute health check services */
@Component
@@ -68,18 +63,6 @@ public class HealthCheckWebconsolePlugin
@Reference
private HealthCheckExecutor healthCheckExecutor;
- private BundleContext bundleContext;
-
- @Activate
- protected void activate(final BundleContext bc) {
- this.bundleContext = bc;
- }
-
- @Deactivate
- protected void deactivate() {
- this.bundleContext = null;
- }
-
/** Serve static resource if applicable, and return true in that case */
private boolean getStaticResource(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException {
@@ -126,32 +109,26 @@ public class HealthCheckWebconsolePlugin
// Execute health checks only if tags are specified (even if empty)
if (tags != null) {
- final HealthCheckFilter filter = new HealthCheckFilter(this.bundleContext);
- try {
- final ServiceReference[] refs = filter.getTaggedHealthCheckServiceReferences(tags.split(","));
- Collection<HealthCheckExecutionResult> results = healthCheckExecutor.execute(refs);
-
- pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0' width='100%'>");
- int total = 0;
- int failed = 0;
- for (final HealthCheckExecutionResult exR : results) {
-
- final Result r = exR.getHealthCheckResult();
- total++;
- if (!r.isOk()) {
- failed++;
- }
- if (!quiet || !r.isOk()) {
- renderResult(pw, exR, debug);
- }
+ Collection<HealthCheckExecutionResult> results = healthCheckExecutor.execute(tags.split(","));
+ pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0' width='100%'>");
+ int total = 0;
+ int failed = 0;
+ for (final HealthCheckExecutionResult exR : results) {
+
+ final Result r = exR.getHealthCheckResult();
+ total++;
+ if (!r.isOk()) {
+ failed++;
}
- final WebConsoleHelper c = new WebConsoleHelper(resp.getWriter());
- c.titleHtml("Summary", total + " HealthCheck executed, " + failed + " failures");
- pw.println("</table>");
- } finally {
- filter.dispose();
+ if (!quiet || !r.isOk()) {
+ renderResult(pw, exR, debug);
+ }
+
}
+ final WebConsoleHelper c = new WebConsoleHelper(resp.getWriter());
+ c.titleHtml("Summary", total + " HealthCheck executed, " + failed + " failures");
+ pw.println("</table>");
}
}