You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:39:50 UTC
[sling-org-apache-sling-hc-support] 03/31: SLING-2987 -
CompositeHealthCheck - execute a set of other HealthChecks selected by tags
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.hc.support-1.0.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hc-support.git
commit 7f238d522acfff04cd56a8a1b45eb2fcedd10645
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Aug 13 10:04:23 2013 +0000
SLING-2987 - CompositeHealthCheck - execute a set of other HealthChecks selected by tags
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/healthcheck/healthchecks@1513416 13f79535-47bb-0310-9956-ffa450edef68
---
.../hc/healthchecks/impl/CompositeHealthCheck.java | 113 +++++++++++++++++++++
.../OSGI-INF/metatype/metatype.properties | 78 ++++++++++++++
2 files changed, 191 insertions(+)
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
new file mode 100644
index 0000000..0b37da7
--- /dev/null
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
@@ -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
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
new file mode 100644
index 0000000..2b2482c
--- /dev/null
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -0,0 +1,78 @@
+#
+# 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.
+#
+
+#
+# This file contains localization strings for configuration labels and
+# descriptions as used in the metatype.xml descriptor generated by the
+# the Sling SCR plugin
+
+org.apache.sling.hc.JmxAttributeHealthCheck.name = JMX Attribute Health Check
+org.apache.sling.hc.JmxAttributeHealthCheck.description = Checks the value of a single JMX attribute.
+
+org.apache.sling.hc.ScriptableHealthCheck.name = Scriptable Health Check
+org.apache.sling.hc.ScriptableHealthCheck.description = Uses scripted expressions to verify multiple JMX \
+ attributes or other values.
+
+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.
+
+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.
+
+attribute.name.name = Attribute name
+attribute.name.description = The name of the MBean attribute to check.
+
+attribute.value.constraint.name = Attribute value constraint
+attribute.value.constraint.description = Constraint on the MBean attribute value.
+
+hc.mbean.name.name = MBean name
+hc.mbean.name.description = Name of the MBean to create for this Health Check.
+
+hc.tags.name = Health Check tags
+hc.tags.description = List of tags for this Health Check service, used to select \
+ subsets of Health Check services for execution.
+
+hc.name.name = Health Check Name
+hc.name.description = Name of this Health Check service, used for example to identify the \
+ corresponding JMX MBean.
+
+expression.name = Expression
+expression.description = The value of this expression must be "true" for the Health Check \
+ to be successful.
+
+language.extension.name = Language extension
+language.extension.description = File extension of the language to use to evaluate the \
+ expression, for example "ecma" or "groovy", asssuming the corresponding script engine \
+ is available.
+
+username.name = Username
+username.description = The username to use to test logins.
+
+password.name = Password
+password.description = The password to use to test logins.
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.