incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1490267 - in /sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl: HtmlResultRendererImpl.java JsonResultRendererImpl.java SlingHealthCheckServlet.java SlingHealthCheckWebconsolePlugin.java
Date Thu, 06 Jun 2013 13:16:02 GMT
Author: bdelacretaz
Date: Thu Jun  6 13:16:01 2013
New Revision: 1490267

URL: http://svn.apache.org/r1490267
Log:
SLING-2822 - add 'omit rules which have nothing to report' option

Modified:
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/HtmlResultRendererImpl.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckServlet.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckWebconsolePlugin.java

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/HtmlResultRendererImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/HtmlResultRendererImpl.java?rev=1490267&r1=1490266&r2=1490267&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/HtmlResultRendererImpl.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/HtmlResultRendererImpl.java
Thu Jun  6 13:16:01 2013
@@ -25,10 +25,17 @@ import java.util.Map;
 
 import org.apache.sling.api.request.ResponseUtil;
 import org.apache.sling.hc.api.EvaluationResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Renders a List of EvaluationResult in HTML */
 public class HtmlResultRendererImpl implements SlingHealthCheckServlet.Renderer {
 
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    /** Quiet rendering option - do not show rules which have nothing to report */
+    public static final String OPTION_QUIET = "quiet";
+    
     public String getExtension() {
         return "html";
     }
@@ -37,11 +44,18 @@ public class HtmlResultRendererImpl impl
         return "text/html";
     }
     
-    public void render(List<EvaluationResult> results, Writer output) throws IOException
{
+    public void render(List<EvaluationResult> results, Writer output, Map<String,
String> options) throws IOException {
         final PrintWriter pw = new PrintWriter(output);
         final WebConsoleHelper c = new WebConsoleHelper(pw);
+        final boolean quiet = options == null ? false : Boolean.valueOf(options.get(OPTION_QUIET));

+                
         pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0'
width='100%'>");
         for(EvaluationResult r : results) {
+            if(quiet && !r.anythingToReport()) {
+                log.debug("Ignoring result {}, quiet mode and nothing to report", r);
+                continue;
+            }
+            
             c.titleHtml(r.getRule().toString(), null);
             
             if(!r.getRule().getTags().isEmpty()) {

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java?rev=1490267&r1=1490266&r2=1490267&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
Thu Jun  6 13:16:01 2013
@@ -37,7 +37,7 @@ public class JsonResultRendererImpl impl
         return "application/json";
     }
     
-    public void render(List<EvaluationResult> results, Writer output) throws IOException
{
+    public void render(List<EvaluationResult> results, Writer output, Map<String,
String> options) throws IOException {
         final JSONWriter w = new JSONWriter(output);
         w.setTidy(true);
         try {

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckServlet.java?rev=1490267&r1=1490266&r2=1490267&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckServlet.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckServlet.java
Thu Jun  6 13:16:01 2013
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
@@ -74,7 +75,7 @@ public class SlingHealthCheckServlet ext
     static interface Renderer {
         String getExtension();
         String getContentType();
-        void render(List<EvaluationResult> results, Writer output) throws IOException;
+        void render(List<EvaluationResult> results, Writer output, Map<String, String>
options) throws IOException;
     }
     
     private final Renderer [] renderers = { new JsonResultRendererImpl(), new HtmlResultRendererImpl()
};
@@ -93,10 +94,14 @@ public class SlingHealthCheckServlet ext
     @Override
     protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)

             throws ServletException, IOException {
-        executeRules(request.getResource(), getRuleTagsFromRequest(request), request.getRequestPathInfo().getExtension(),
response);
+        executeRules(request.getResource(), getRuleTagsFromRequest(request), request.getRequestPathInfo().getExtension(),
response, null);
     }
     
-    void executeRules(Resource rulesRoot, String [] tags, String extension, HttpServletResponse
response) 
+    void executeRules(Resource rulesRoot, 
+            String [] tags, 
+            String extension, 
+            HttpServletResponse response,
+            Map<String, String> renderingOptions) 
             throws ServletException, IOException {
         final RulesEngine engine = healthcheck.getNewRulesEngine();
         engine.addRules(parser.parseResource(rulesRoot));
@@ -117,7 +122,7 @@ public class SlingHealthCheckServlet ext
                 new Object[] { rulesRoot.getPath(), filter, renderer });
         response.setContentType(renderer.getContentType());
         response.setCharacterEncoding("UTF-8");
-        renderer.render(engine.evaluateRules(filter), response.getWriter());
+        renderer.render(engine.evaluateRules(filter), response.getWriter(), renderingOptions);
         response.getWriter().flush();
     }
     

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckWebconsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckWebconsolePlugin.java?rev=1490267&r1=1490266&r2=1490267&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckWebconsolePlugin.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/SlingHealthCheckWebconsolePlugin.java
Thu Jun  6 13:16:01 2013
@@ -21,7 +21,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.util.Dictionary;
+import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -93,7 +95,8 @@ public class SlingHealthCheckWebconsoleP
         }
         
         // Send parameters form
-        doForm(req, resp);
+        final boolean quiet = req.getParameter(HtmlResultRendererImpl.OPTION_QUIET) != null;
+        doForm(req, resp, quiet);
         
         // And execute rules if we got a path
         final String path = getParam(req, PARAM_PATH, null);
@@ -103,6 +106,9 @@ public class SlingHealthCheckWebconsoleP
             return;
         }
         
+        final Map<String, String> renderingOptions = new HashMap<String, String>();
+        renderingOptions.put(HtmlResultRendererImpl.OPTION_QUIET, String.valueOf(quiet));
+        
         ResourceResolver resolver = null;
         try {
             resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
@@ -110,7 +116,7 @@ public class SlingHealthCheckWebconsoleP
             if(r == null) {
                 resp.sendError(HttpServletResponse.SC_NOT_FOUND, path);
             }
-            servlet.executeRules(r, tags, "html", resp);
+            servlet.executeRules(r, tags, "html", resp, renderingOptions);
         } catch (LoginException e) {
             throw new ServletException("Unable to get a ResourceResolver", e);
         } finally {
@@ -120,7 +126,7 @@ public class SlingHealthCheckWebconsoleP
         }
     }
     
-    private void doForm(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
+    private void doForm(HttpServletRequest req, HttpServletResponse resp, boolean quiet)
throws IOException {
         final PrintWriter pw = resp.getWriter();
         final WebConsoleHelper c = new WebConsoleHelper(pw);
         pw.print("<form method='get'>");
@@ -148,6 +154,13 @@ public class SlingHealthCheckWebconsoleP
         c.closeTr();
         
         c.tr(); 
+        c.tdLabel("Omit 'nothing to report' results");
+        c.tdContent();
+        pw.println("<input type='checkbox' name='" + HtmlResultRendererImpl.OPTION_QUIET
+ (quiet ? "' checked='true'>" : "'>"));
+        c.closeTd(); 
+        c.closeTr();
+        
+        c.tr(); 
         c.tdContent();
         pw.println("<input type='submit' value='Execute selected rules'/>");
         c.closeTd(); 



Mime
View raw message