incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1513157 - in /sling/trunk/contrib/extensions/healthcheck: core/ core/src/main/java/org/apache/sling/hc/api/ core/src/main/java/org/apache/sling/hc/impl/ core/src/main/java/org/apache/sling/hc/util/ it/src/test/java/org/apache/sling/hc/it/c...
Date Mon, 12 Aug 2013 15:07:33 GMT
Author: bdelacretaz
Date: Mon Aug 12 15:07:32 2013
New Revision: 1513157

URL: http://svn.apache.org/r1513157
Log:
SLING-2987 - splitting into several bundles, work in progress

Added:
    sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
    sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java
      - copied, changed from r1513096, sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheckSelector.java
    sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
Removed:
    sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheckSelector.java
    sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/impl/HealthCheckSelectorImpl.java
Modified:
    sling/trunk/contrib/extensions/healthcheck/core/pom.xml
    sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/impl/HealthCheckWebconsolePlugin.java
    sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckSelectorTest.java

Modified: sling/trunk/contrib/extensions/healthcheck/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/core/pom.xml?rev=1513157&r1=1513156&r2=1513157&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/core/pom.xml (original)
+++ sling/trunk/contrib/extensions/healthcheck/core/pom.xml Mon Aug 12 15:07:32 2013
@@ -37,9 +37,6 @@
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
-                        <Export-Package>
-                            org.apache.sling.hc.api,
-                        </Export-Package>
                         <Import-Package>
                             javax.servlet.*;resolution:=optional,
                             org.apache.sling.api.request;resolution:=optional,
@@ -89,6 +86,12 @@
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.scr.annotations</artifactId>
         </dependency>
+      <dependency>
+            <groupId>biz.aQute</groupId>
+            <artifactId>bndlib</artifactId>
+            <version>1.50.0</version>
+            <scope>provided</scope>
+        </dependency>
          <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>

Added: sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java?rev=1513157&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
(added)
+++ sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
Mon Aug 12 15:07:32 2013
@@ -0,0 +1,24 @@
+/*
+ * 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 ASF 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.
+ */
+
+@Version("0.0.2")
+package org.apache.sling.hc.api;
+
+import aQute.bnd.annotation.Version;
+

Modified: sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/impl/HealthCheckWebconsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/impl/HealthCheckWebconsolePlugin.java?rev=1513157&r1=1513156&r2=1513157&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/impl/HealthCheckWebconsolePlugin.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/impl/HealthCheckWebconsolePlugin.java
Mon Aug 12 15:07:32 2013
@@ -28,17 +28,19 @@ 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.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.Constants;
 import org.apache.sling.hc.api.HealthCheck;
-import org.apache.sling.hc.api.HealthCheckSelector;
 import org.apache.sling.hc.api.Result;
 import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.util.HealthCheckSelector;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
 
 /** Webconsole plugin to execute health check services */ 
 @Component(immediate=true)
@@ -61,9 +63,13 @@ public class HealthCheckWebconsolePlugin
     public static final String PARAM_DEBUG = "debug";
     public static final String PARAM_QUIET = "quiet";
     
-    @Reference
-    private HealthCheckSelector selector;
+    private BundleContext bundleContext;
 
+    @Activate
+    protected void activate(ComponentContext ctx) {
+        bundleContext = ctx.getBundleContext();
+    }
+    
     /** 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();
@@ -98,7 +104,7 @@ public class HealthCheckWebconsolePlugin
         
         // Execute health checks only if tags are specified (even if empty)
         if(req.getParameter(PARAM_TAGS) != null) {
-            final List<HealthCheck> checks = selector.getTaggedHealthCheck(tags.split(","));
+            final List<HealthCheck> checks = new HealthCheckSelector(bundleContext).getTaggedHealthCheck(tags.split(","));
             final PrintWriter pw = resp.getWriter();
             pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0'
width='100%'>");
             int total = 0;

Copied: sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java
(from r1513096, sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheckSelector.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java?p2=sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java&p1=sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheckSelector.java&r1=1513096&r2=1513157&rev=1513157&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheckSelector.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java
Mon Aug 12 15:07:32 2013
@@ -15,21 +15,67 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.sling.hc.api;
+package org.apache.sling.hc.util;
 
+import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.sling.hc.api.Constants;
+import org.apache.sling.hc.api.HealthCheck;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /** Select from available {@link HealthCheck} services */
-public interface HealthCheckSelector {
+public class HealthCheckSelector {
+    
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final BundleContext bundleContext;
+    public static final String OMIT_PREFIX = "-";
+    
+    public HealthCheckSelector(BundleContext bc) {
+        bundleContext = bc;
+    }
     
-    /** Retrieve {@link HealthCheck} services that have
-     *  specific tags (declared using the {@link Constants.HC_TAGS}
-     *  service property)
-     *  
-     *  @param tags If not supplied, all available services are
-     *  returned. A tag can be prefixed by a minus sign to omit
-     *  services having that tag. Supplied tags are combined with
-     *  AND to select within available services 
-     */
-    public List<HealthCheck> getTaggedHealthCheck(String ... tags);
+    public List<HealthCheck> getTaggedHealthCheck(String... tags) {
+        
+        // Build service filter
+        final StringBuilder filterBuilder = new StringBuilder();
+        filterBuilder.append("(&(objectClass=").append(HealthCheck.class.getName()).append(")");
+        final int prefixLen = OMIT_PREFIX.length();
+        for(String tag : tags) {
+            tag = tag.trim();
+            if(tag.length() == 0) {
+                continue;
+            }
+            if(tag.startsWith(OMIT_PREFIX)) {
+                filterBuilder.append("(!(").append(Constants.HC_TAGS).append("=").append(tag.substring(prefixLen)).append("))");
+            } else {
+                filterBuilder.append("(").append(Constants.HC_TAGS).append("=").append(tag).append(")");
+            }
+        }
+        filterBuilder.append(")");
+        
+        final List<HealthCheck> result = new ArrayList<HealthCheck>();
+        try {
+            final String filterString = filterBuilder.length() == 0 ? null : filterBuilder.toString();
+            bundleContext.createFilter(filterString); // check syntax early
+            final ServiceReference [] refs = bundleContext.getServiceReferences(HealthCheck.class.getName(),
filterString);
+            if(refs == null) {
+                log.info("Found no HealthCheck services with filter [{}]", filterString);
+            } else {
+                log.info("Found {} HealthCheck services with filter [{}]", refs.length, filterString);
+                for(ServiceReference ref : refs) {
+                    final HealthCheck hc = (HealthCheck)bundleContext.getService(ref);
+                    log.debug("Selected HealthCheck service {}", hc);
+                    result.add(hc);
+                }
+            }
+        } catch(InvalidSyntaxException ise) {
+            throw new IllegalStateException("Invalid OSGi filter syntax in '" + filterBuilder
+ "'", ise);
+        }
+        return result;
+    }
 }

Added: sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java?rev=1513157&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
(added)
+++ sling/trunk/contrib/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
Mon Aug 12 15:07:32 2013
@@ -0,0 +1,24 @@
+/*
+ * 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 ASF 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.
+ */
+
+@Version("0.0.2")
+package org.apache.sling.hc.util;
+
+import aQute.bnd.annotation.Version;
+

Modified: sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckSelectorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckSelectorTest.java?rev=1513157&r1=1513156&r2=1513157&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckSelectorTest.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckSelectorTest.java
Mon Aug 12 15:07:32 2013
@@ -33,8 +33,8 @@ import javax.inject.Inject;
 
 import org.apache.sling.hc.api.Constants;
 import org.apache.sling.hc.api.HealthCheck;
-import org.apache.sling.hc.api.HealthCheckSelector;
 import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.util.HealthCheckSelector;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;



Mime
View raw message