You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/08/13 12:04:23 UTC
svn commit: r1513416 - in /sling/trunk/contrib/extensions/healthcheck:
healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/
healthchecks/src/main/resources/ healthchecks/src/main/resources/OSGI-INF/
healthchecks/src/main/resources/OSGI-INF...
Author: bdelacretaz
Date: Tue Aug 13 10:04:23 2013
New Revision: 1513416
URL: http://svn.apache.org/r1513416
Log:
SLING-2987 - CompositeHealthCheck - execute a set of other HealthChecks selected by tags
Added:
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/metatype/
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/metatype/metatype.properties
- copied, changed from r1513394, sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/resources/OSGI-INF/metatype/metatype.properties
sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.CompositeHealthCheck-1.json
Removed:
sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/resources/OSGI-INF/
Added: sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java?rev=1513416&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java (added)
+++ sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java Tue Aug 13 10:04:23 2013
@@ -0,0 +1,113 @@
+/*
+ * 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.healthchecks.impl;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+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.Service;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+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.ResultLogEntry;
+import org.apache.sling.hc.util.HealthCheckFilter;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** {@link HealthCheck} that executes a number of other HealthChecks,
+ * selected by their tags, and merges their Results.
+ */
+@Component(
+ name="org.apache.sling.hc.CompositeHealthCheck",
+ configurationFactory=true,
+ policy=ConfigurationPolicy.REQUIRE,
+ metatype=true)
+@Service
+public class CompositeHealthCheck implements HealthCheck {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private Map<String, String> info;
+ private BundleContext bundleContext;
+
+ @Property(cardinality=50)
+ public static final String PROP_TAGS = Constants.HC_TAGS;
+
+ @Property(cardinality=50)
+ public static final String PROP_FILTER_TAGS = "filter.tags";
+ private String [] filterTags;
+
+
+ @Activate
+ public void activate(ComponentContext ctx) {
+ bundleContext = ctx.getBundleContext();
+ info = new HealthCheckInfo(ctx.getProperties());
+ filterTags = PropertiesUtil.toStringArray(ctx.getProperties().get(PROP_FILTER_TAGS), new String[] {});
+ log.info("Activated, will select HealthCheck having tags {}", Arrays.asList(filterTags));
+ }
+
+ @Override
+ public Result execute() {
+ final Result result = new Result(log);
+ final List<HealthCheck> checks = new HealthCheckFilter(bundleContext).getTaggedHealthCheck(filterTags);
+ if(checks.size() == 0) {
+ result.log(ResultLogEntry.LT_WARN, "HealthCheckFilter returns no HealthCheck for tags " + Arrays.asList(filterTags));
+ return result;
+ }
+
+ result.log(ResultLogEntry.LT_DEBUG,
+ "Executing " + checks.size()
+ + " HealthCheck selected by the " + Arrays.asList(filterTags) + " tags");
+ int failures = 0;
+ for(HealthCheck hc : checks) {
+ if(hc == this) {
+ result.log(ResultLogEntry.LT_WARN,
+ "Cowardly forfeiting execution of this HealthCheck in an infinite loop - do not include my tags in the filter tags!");
+ continue;
+ }
+ result.log(ResultLogEntry.LT_DEBUG, "Executing " + hc);
+ final Result sub = hc.execute();
+ if(!sub.isOk()) {
+ failures++;
+ }
+ result.merge(sub);
+ }
+
+ if(failures == 0) {
+ result.log(ResultLogEntry.LT_DEBUG,
+ checks.size() + " HealthCheck executed, all ok");
+ } else {
+ result.log(ResultLogEntry.LT_WARN,
+ checks.size() + " HealthCheck executed, " + failures + " failures");
+ }
+
+ return result;
+ }
+
+ @Override
+ public Map<String, String> getInfo() {
+ return info;
+ }
+}
\ No newline at end of file
Copied: sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/metatype/metatype.properties (from r1513394, sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/resources/OSGI-INF/metatype/metatype.properties)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/metatype/metatype.properties?p2=sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/metatype/metatype.properties&p1=sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/resources/OSGI-INF/metatype/metatype.properties&r1=1513394&r2=1513416&rev=1513416&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/resources/OSGI-INF/metatype/metatype.properties Tue Aug 13 10:04:23 2013
@@ -36,6 +36,12 @@ org.apache.sling.hc.DefaultLoginsHealthC
org.apache.sling.hc.SlingRequestStatusHealthCheck.name = Sling Request Status Health Check
org.apache.sling.hc.SlingRequestStatusHealthCheck.description = Checks the HTTP status of Sling requests.
+org.apache.sling.hc.CompositeHealthCheck.name = Composite Health Check
+org.apache.sling.hc.CompositeHealthCheck.description = Executes a set of Health Checks, selected by tags.
+
+filter.tags.name = Filter tags
+filter.tags.description = Tags used to select Health Checks.
+
mbean.name.name = MBean name
mbean.name.description = The name of the MBean to check.
Added: sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.CompositeHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.CompositeHealthCheck-1.json?rev=1513416&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.CompositeHealthCheck-1.json (added)
+++ sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.CompositeHealthCheck-1.json Tue Aug 13 10:04:23 2013
@@ -0,0 +1,6 @@
+{
+ "jcr:primaryType" : "sling:OsgiConfig",
+ "hc.name" : "CompositeHealthCheck: execute all HealthCheck tagged with 'script'",
+ "hc.tags" : [composite],
+ "filter.tags" : [script]
+}