incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1511832 - in /sling/branches/SLING-2987-healthcheck-redesign: hc-core/ hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/ hc-core/src/main/resources/OSGI-INF/metatype/ hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/ ...
Date Thu, 08 Aug 2013 15:28:56 GMT
Author: bdelacretaz
Date: Thu Aug  8 15:28:55 2013
New Revision: 1511832

URL: http://svn.apache.org/r1511832
Log:
SLING-2987 - SlingRequestStatusHealthCheck added

Added:
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalRequest.java
      - copied, changed from r1511738, sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalRequest.java
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalResponse.java
      - copied, changed from r1511738, sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalResponse.java
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/SlingRequestStatusHealthCheck.java
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/PathSpecTest.java
    sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.SlingRequestStatusHealthCheck-1.json
Modified:
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/resources/OSGI-INF/metatype/metatype.properties
    sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
    sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.JmxAttributeHealthCheck-1.json
    sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-1.json
    sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-2.json

Modified: sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml?rev=1511832&r1=1511831&r2=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml (original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/pom.xml Thu Aug  8 15:28:55 2013
@@ -108,6 +108,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.engine</artifactId>
+            <version>2.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <version>1.6.2</version>
@@ -132,7 +138,7 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.8.1</version>
+            <version>4.11</version>
             <scope>test</scope>
         </dependency>
         <dependency>

Copied: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalRequest.java
(from r1511738, sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalRequest.java)
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalRequest.java?p2=sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalRequest.java&p1=sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalRequest.java&r1=1511738&r2=1511832&rev=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalRequest.java
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalRequest.java
Thu Aug  8 15:28:55 2013
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.sling.hc.sling.impl.rules;
+package org.apache.sling.hc.impl.healthchecks;
 
 import java.io.BufferedReader;
 import java.io.IOException;

Copied: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalResponse.java
(from r1511738, sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalResponse.java)
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalResponse.java?p2=sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalResponse.java&p1=sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalResponse.java&r1=1511738&r2=1511832&rev=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/rules/InternalResponse.java
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/InternalResponse.java
Thu Aug  8 15:28:55 2013
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.sling.hc.sling.impl.rules;
+package org.apache.sling.hc.impl.healthchecks;
 
 import java.io.IOException;
 import java.io.PrintWriter;

Added: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/SlingRequestStatusHealthCheck.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/SlingRequestStatusHealthCheck.java?rev=1511832&view=auto
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/SlingRequestStatusHealthCheck.java
(added)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/SlingRequestStatusHealthCheck.java
Thu Aug  8 15:28:55 2013
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.hc.impl.healthchecks;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+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.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.engine.SlingRequestProcessor;
+import org.apache.sling.hc.api.Constants;
+import org.apache.sling.hc.api.HealthCheck;
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.api.ResultLog;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** {@link HealthCheck} that checks the HTTP status of Sling requests */
+@Component(
+        name="org.apache.sling.hc.SlingRequestStatusHealthCheck",
+        configurationFactory=true, 
+        policy=ConfigurationPolicy.REQUIRE, 
+        metatype=true)
+@Service
+public class SlingRequestStatusHealthCheck implements HealthCheck {
+
+    private static final Logger log = LoggerFactory.getLogger(SlingRequestStatusHealthCheck.class);
+    private final Map<String, String> info = new HashMap<String, String>();
+    private String [] paths;
+    
+    static class PathSpec {
+        int status;
+        String path;
+        
+        PathSpec(String configuredPath) {
+            path = configuredPath;
+            status = 200;
+            
+            final String [] parts  = configuredPath.split(":");
+            if(parts.length == 2) {
+                try {
+                    status = Integer.valueOf(parts[1].trim());
+                    path = parts[0].trim();
+                } catch(NumberFormatException nfe) {
+                    log.warn("NumberFormatException while parsing [{}], invalid status value?",
configuredPath);
+                }
+            } 
+        }
+    }
+    
+    @Property(cardinality=Integer.MAX_VALUE)
+    public static final String PROP_PATH = "path";
+    
+    @Property(cardinality=50)
+    public static final String PROP_TAGS = Constants.HC_TAGS;
+    
+    @Property
+    public static final String PROP_NAME = Constants.HC_NAME;
+    
+    @Reference
+    private SlingRequestProcessor requestProcessor;
+    
+    @Reference
+    private ResourceResolverFactory resolverFactory;  
+    
+    @Activate
+    public void activate(ComponentContext ctx) {
+        paths = PropertiesUtil.toStringArray(ctx.getProperties().get(PROP_PATH), new String
[] {});
+        
+        info.put(Constants.HC_NAME, PropertiesUtil.toString(ctx.getProperties().get(Constants.HC_NAME),
""));
+        info.put(Constants.HC_TAGS, 
+                Arrays.asList(PropertiesUtil.toStringArray(ctx.getProperties().get(Constants.HC_TAGS),
new String[] {})).toString());
+        
+        log.info("Activated, paths={}", Arrays.asList(paths));
+    }
+    
+    @Override
+    public Result execute(ResultLog log) {
+        final Result result = new Result(this, log);
+        
+        ResourceResolver resolver = null;
+        int checked = 0;
+        int failed = 0;
+        
+        try {
+            resolver = resolverFactory.getAdministrativeResourceResolver(null);
+            for(String p : paths) {
+                final PathSpec ps = new PathSpec(p);
+                final HttpServletRequest request = new InternalRequest(ps.path);
+                final InternalResponse response = new InternalResponse();
+                requestProcessor.processRequest(request, response, resolver);
+                final int status = response.getStatus();
+                if(status != ps.status) {
+                    failed++;
+                    log.warn("[{}] returns status {}, expected {}", new Object[] { ps.path,
status, ps.status });
+                } else {
+                    log.debug("[{}] returns status {} as expected", ps.path, status);
+                }
+                checked++;
+            }
+        } catch(Exception e) {
+            log.warn("Exception while executing request", e);
+        } finally {
+            if(resolver != null) {
+                resolver.close();
+            }
+        }
+        
+        if(checked == 0) {
+            log.warn("No paths checked, empty paths list?");
+        } else {
+            log.debug("{} paths checked, {} failures", checked, failed);
+        }
+        
+        return result;
+    }
+
+    @Override
+    public Map<String, String> getInfo() {
+        return info;
+    }
+}
\ No newline at end of file

Modified: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1511832&r1=1511831&r2=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/resources/OSGI-INF/metatype/metatype.properties
Thu Aug  8 15:28:55 2013
@@ -32,6 +32,9 @@ org.apache.sling.hc.ScriptableHealthChec
 org.apache.sling.hc.DefaultLoginsHealthCheck.name = Default Logins Health Check 
 org.apache.sling.hc.DefaultLoginsHealthCheck.description = Expects default logins to fail,
used to verify \
     that they are disabled on production systems
+    
+org.apache.sling.hc.SlingRequestStatusHealthCheck.name = Sling Request Status Health Check
+org.apache.sling.hc.SlingRequestStatusHealthCheck.description = Checks the HTTP status of
Sling requests.
 
 mbean.name.name = MBean name
 mbean.name.description = The name of the MBean to check.

Added: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/PathSpecTest.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/PathSpecTest.java?rev=1511832&view=auto
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/PathSpecTest.java
(added)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/healthchecks/PathSpecTest.java
Thu Aug  8 15:28:55 2013
@@ -0,0 +1,44 @@
+package org.apache.sling.hc.impl.healthchecks;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class PathSpecTest {
+    private final String pathSpec;
+    private final String expectedPath;
+    private final int expectedStatus;
+    
+    @Parameters(name="{1}")
+    public static List<Object[]> data() {
+        final List<Object[]> result = new ArrayList<Object[]>();
+
+        result.add(new Object[] { "/one.html", "/one.html", 200 } ); 
+        result.add(new Object[] { "/two.html:404", "/two.html", 404 } ); 
+        result.add(new Object[] { "three.html : 404 ", "three.html", 404 } ); 
+        result.add(new Object[] { "four.html:not an integer", "four.html:not an integer",
200 } ); 
+        result.add(new Object[] { "", "", 200 } ); 
+
+        return result;
+    }
+
+    public PathSpecTest(String pathSpec, String expectedPath, int expectedStatus) {
+        this.pathSpec = pathSpec;
+        this.expectedPath = expectedPath;
+        this.expectedStatus = expectedStatus;
+    }
+    
+    @Test
+    public void testParsing() {
+        final SlingRequestStatusHealthCheck.PathSpec ps = new SlingRequestStatusHealthCheck.PathSpec(pathSpec);
+        assertEquals(expectedPath, ps.path);
+        assertEquals(expectedStatus, ps.status);
+    }
+}

Modified: sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json?rev=1511832&r1=1511831&r2=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
Thu Aug  8 15:28:55 2013
@@ -2,6 +2,6 @@
     "jcr:primaryType" : "sling:OsgiConfig",
     "username" : "admin",
     "password" : "admin",
-    "hc.name" : "Default Admin Login Disabled", 
+    "hc.name" : "Admin login fails with default password", 
     "hc.tags" : [security] 
 }

Modified: sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.JmxAttributeHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.JmxAttributeHealthCheck-1.json?rev=1511832&r1=1511831&r2=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.JmxAttributeHealthCheck-1.json
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.JmxAttributeHealthCheck-1.json
Thu Aug  8 15:28:55 2013
@@ -3,6 +3,6 @@
     "mbean.name" : "java.lang:type=ClassLoading", 
     "attribute.name" : "LoadedClassCount", 
     "attribute.value.constraint" : "between 5000 and 50000", 
-    "hc.name" : "JMX LoadedClassCount attribute", 
+    "hc.name" : "LoadedClassCount is in range", 
     "hc.tags" : [jvm, classloading, jmx] 
 }

Modified: sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-1.json?rev=1511832&r1=1511831&r2=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-1.json
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-1.json
Thu Aug  8 15:28:55 2013
@@ -1,7 +1,7 @@
 {
     "jcr:primaryType" : "sling:OsgiConfig",
     "expression" : "jmx.attribute('java.lang:type=ClassLoading', 'LoadedClassCount') >
10 &&  jmx.attribute('java.lang:type=Runtime', 'ManagementSpecVersion') > 1", 
-    "hc.name" : "Check two JMX attributes", 
+    "hc.name" : "LoadedClassCount and ManagementSpecVersion are in range", 
     "language.extension" : "ecma", 
     "hc.tags" : [jvm, script] 
 }

Modified: sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-2.json
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-2.json?rev=1511832&r1=1511831&r2=1511832&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-2.json
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.ScriptableHealthCheck-2.json
Thu Aug  8 15:28:55 2013
@@ -1,7 +1,7 @@
 {
     "jcr:primaryType" : "sling:OsgiConfig",
     "expression" : "osgi.inactiveBundlesCount() == 0 ",
-    "hc.name" : "Check inactive bundles", 
+    "hc.name" : "No inactive bundles", 
     "language.extension" : "ecma", 
     "hc.tags" : [bundles, script] 
 }

Added: sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.SlingRequestStatusHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.SlingRequestStatusHealthCheck-1.json?rev=1511832&view=auto
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.SlingRequestStatusHealthCheck-1.json
(added)
+++ sling/branches/SLING-2987-healthcheck-redesign/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.SlingRequestStatusHealthCheck-1.json
Thu Aug  8 15:28:55 2013
@@ -0,0 +1,11 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "path" : [
+        "index.html",
+        "index.html.json",
+        "apps/hc.tidy.json",
+        "some/non/existent/path:404"
+    ],
+    "hc.name" : "Initial content is present", 
+    "hc.tags" : [request, sling] 
+}



Mime
View raw message