This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.hc.webconsole-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hc-webconsole.git
commit d4075954ea8be52c056a2ccf02ae33db0473f2e5 Author: Carsten Ziegeler <[email protected]> AuthorDate: Tue Dec 31 10:35:13 2013 +0000 SLING-3278 : Provide a HealthCheckExecutor service. Move executor into separate package, reuse Result from HC git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/healthcheck/webconsole@1554396 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/HealthCheckWebconsolePlugin.java | 69 +++++++++++++++------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java b/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java index bb12065..c5f83bb 100644 --- a/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java +++ b/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java @@ -28,16 +28,21 @@ 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; import org.apache.felix.scr.annotations.Service; import org.apache.sling.api.request.ResponseUtil; -import org.apache.sling.hc.api.HealthCheckExecutor; -import org.apache.sling.hc.api.HealthCheckResult; 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 @@ -62,6 +67,18 @@ public class HealthCheckWebconsolePlugin extends HttpServlet { @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(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String pathInfo = req.getPathInfo(); @@ -96,36 +113,44 @@ public class HealthCheckWebconsolePlugin extends HttpServlet { // Execute health checks only if tags are specified (even if empty) if(req.getParameter(PARAM_TAGS) != null) { - Collection<HealthCheckResult> results = healthCheckExecutor.executeAllForTags(tags.split(",")); - - final PrintWriter pw = resp.getWriter(); - pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0' width='100%'>"); - int total = 0; - int failed = 0; - for (final HealthCheckResult r : results) { + final HealthCheckFilter filter = new HealthCheckFilter(this.bundleContext); + try { + final ServiceReference[] refs = filter.getTaggedHealthCheckServiceReferences(tags.split(",")); + Collection<HealthCheckExecutionResult> results = healthCheckExecutor.execute(refs); + + final PrintWriter pw = resp.getWriter(); + 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(resp, exR, debug); + } - total++; - if (!r.isOk()) { - failed++; } - if (!quiet || !r.isOk()) { - renderResult(resp, r, debug); - } - + final WebConsoleHelper c = new WebConsoleHelper(resp.getWriter()); + c.titleHtml("Summary", total + " HealthCheck executed, " + failed + " failures"); + pw.println("</table>"); + } finally { + filter.dispose(); } - final WebConsoleHelper c = new WebConsoleHelper(resp.getWriter()); - c.titleHtml("Summary", total + " HealthCheck executed, " + failed + " failures"); - pw.println("</table>"); } } - private void renderResult(HttpServletResponse resp, HealthCheckResult result, boolean debug) throws IOException { + private void renderResult(HttpServletResponse resp, HealthCheckExecutionResult exResult, boolean debug) throws IOException { + final Result result = exResult.getHealthCheckResult(); final WebConsoleHelper c = new WebConsoleHelper(resp.getWriter()); final StringBuilder status = new StringBuilder(); - status.append("Tags: ").append(result.getHealthCheckTags()); - c.titleHtml(result.getHealthCheckName(), null); + status.append("Tags: ").append(exResult.getHealthCheckTags()); + c.titleHtml(exResult.getHealthCheckName(), null); c.tr(); c.tdContent(); -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
