Author: cziegeler
Date: Fri Aug 30 09:34:59 2013
New Revision: 1518922
URL: http://svn.apache.org/r1518922
Log:
A little code cleanup of annotations
Modified:
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/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/test/java/org/apache/sling/hc/healthchecks/JmxAttributeHealthCheckTest.java
Modified:
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=1518922&r1=1518921&r2=1518922&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
(original)
+++
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
Fri Aug 30 09:34:59 2013
@@ -23,7 +23,9 @@ import java.util.List;
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.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.hc.api.HealthCheck;
@@ -44,22 +46,21 @@ import org.slf4j.LoggerFactory;
configurationFactory=true,
policy=ConfigurationPolicy.REQUIRE,
metatype=true)
-@Service
+@Properties({
+ @Property(name=HealthCheck.NAME),
+ @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
+ @Property(name=HealthCheck.MBEAN_NAME)
+})
+@Service(value=HealthCheck.class)
public class CompositeHealthCheck implements HealthCheck {
private final Logger log = LoggerFactory.getLogger(getClass());
private BundleContext bundleContext;
- @Property(cardinality=50)
- public static final String PROP_TAGS = HealthCheck.TAGS;
-
- @Property(cardinality=50)
- public static final String PROP_FILTER_TAGS = "filter.tags";
+ @Property(unbounded=PropertyUnbounded.ARRAY)
+ private static final String PROP_FILTER_TAGS = "filter.tags";
private String [] filterTags;
- @Property
- public static final String PROP_MBEAN_NAME = HealthCheck.MBEAN_NAME;
-
@Activate
public void activate(ComponentContext ctx) {
bundleContext = ctx.getBundleContext();
Modified:
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java?rev=1518922&r1=1518921&r2=1518922&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
(original)
+++
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
Fri Aug 30 09:34:59 2013
@@ -28,7 +28,9 @@ import javax.jcr.SimpleCredentials;
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.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
@@ -47,23 +49,20 @@ import org.slf4j.LoggerFactory;
configurationFactory=true,
policy=ConfigurationPolicy.REQUIRE,
metatype=true)
-@Service
+@Properties({
+ @Property(name=HealthCheck.NAME),
+ @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
+ @Property(name=HealthCheck.MBEAN_NAME)
+})
+@Service(value=HealthCheck.class)
public class DefaultLoginsHealthCheck implements HealthCheck {
private final Logger log = LoggerFactory.getLogger(getClass());
- @Property(cardinality=500)
- public static final String PROP_LOGINS = "logins";
- private List<String> logins;
-
- @Property(cardinality=50)
- public static final String PROP_TAGS = HealthCheck.TAGS;
+ @Property(unbounded=PropertyUnbounded.ARRAY)
+ private static final String PROP_LOGINS = "logins";
- @Property
- public static final String PROP_NAME = HealthCheck.NAME;
-
- @Property
- public static final String PROP_MBEAN_NAME = HealthCheck.MBEAN_NAME;
+ private List<String> logins;
@Reference
private SlingRepository repository;
Modified:
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java?rev=1518922&r1=1518921&r2=1518922&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
(original)
+++
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
Fri Aug 30 09:34:59 2013
@@ -18,6 +18,7 @@
package org.apache.sling.hc.healthchecks.impl;
import java.lang.management.ManagementFactory;
+import java.util.Map;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -25,14 +26,15 @@ import javax.management.ObjectName;
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.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.hc.api.HealthCheck;
import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
import org.apache.sling.hc.healthchecks.util.SimpleConstraintChecker;
-import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,7 +44,12 @@ import org.slf4j.LoggerFactory;
configurationFactory=true,
policy=ConfigurationPolicy.REQUIRE,
metatype=true)
-@Service
+@Properties({
+ @Property(name=HealthCheck.NAME),
+ @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
+ @Property(name=HealthCheck.MBEAN_NAME)
+})
+@Service(value=HealthCheck.class)
public class JmxAttributeHealthCheck implements HealthCheck {
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -59,23 +66,14 @@ public class JmxAttributeHealthCheck imp
@Property
public static final String PROP_CONSTRAINT = "attribute.value.constraint";
- @Property(cardinality=50)
- public static final String PROP_TAGS = HealthCheck.TAGS;
-
- @Property
- public static final String PROP_NAME = HealthCheck.NAME;
-
- @Property
- public static final String PROP_MBEAN_NAME = HealthCheck.MBEAN_NAME;
-
@Activate
- public void activate(ComponentContext ctx) {
- mbeanName =
PropertiesUtil.toString(ctx.getProperties().get(PROP_OBJECT_NAME), "");
- attributeName =
PropertiesUtil.toString(ctx.getProperties().get(PROP_ATTRIBUTE_NAME), "");
- constraint =
PropertiesUtil.toString(ctx.getProperties().get(PROP_CONSTRAINT), "");
+ public void activate(final Map<String, Object> properties) {
+ mbeanName = PropertiesUtil.toString(properties.get(PROP_OBJECT_NAME),
"");
+ attributeName =
PropertiesUtil.toString(properties.get(PROP_ATTRIBUTE_NAME), "");
+ constraint = PropertiesUtil.toString(properties.get(PROP_CONSTRAINT),
"");
log.info("Activated with HealthCheck name={}, objectName={},
attribute={}, constraint={}",
- new Object[] { ctx.getProperties().get(HealthCheck.NAME),
mbeanName, attributeName, constraint });
+ new Object[] { properties.get(HealthCheck.NAME), mbeanName,
attributeName, constraint });
}
@Override
Modified:
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java?rev=1518922&r1=1518921&r2=1518922&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
(original)
+++
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
Fri Aug 30 09:34:59 2013
@@ -23,7 +23,9 @@ import javax.script.ScriptEngineManager;
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.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
@@ -41,7 +43,12 @@ import org.slf4j.LoggerFactory;
configurationFactory=true,
policy=ConfigurationPolicy.REQUIRE,
metatype=true)
-@Service
+@Properties({
+ @Property(name=HealthCheck.NAME),
+ @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
+ @Property(name=HealthCheck.MBEAN_NAME)
+})
+@Service(value=HealthCheck.class)
public class ScriptableHealthCheck implements HealthCheck {
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -49,23 +56,14 @@ public class ScriptableHealthCheck imple
private String languageExtension;
private BundleContext bundleContext;
- public static final String DEFAULT_LANGUAGE_EXTENSION = "ecma";
+ private static final String DEFAULT_LANGUAGE_EXTENSION = "ecma";
@Property
public static final String PROP_EXPRESSION = "expression";
- @Property
+ @Property(value=DEFAULT_LANGUAGE_EXTENSION)
public static final String PROP_LANGUAGE_EXTENSION = "language.extension";
- @Property(cardinality=50)
- public static final String PROP_TAGS = HealthCheck.TAGS;
-
- @Property
- public static final String PROP_NAME = HealthCheck.NAME;
-
- @Property
- public static final String PROP_MBEAN_NAME = HealthCheck.MBEAN_NAME;
-
@Reference
private ScriptEngineManager scriptEngineManager;
@@ -75,7 +73,9 @@ public class ScriptableHealthCheck imple
expression =
PropertiesUtil.toString(ctx.getProperties().get(PROP_EXPRESSION), "");
languageExtension =
PropertiesUtil.toString(ctx.getProperties().get(PROP_LANGUAGE_EXTENSION),
DEFAULT_LANGUAGE_EXTENSION);
- log.info("Activated, name={}, languageExtension={}, expression={}",
languageExtension, expression);
+ log.debug("Activated scriptable health check name={},
languageExtension={}, expression={}",
+ new Object[] {ctx.getProperties().get(HealthCheck.NAME),
+ languageExtension, expression});
}
@Override
@@ -84,7 +84,7 @@ public class ScriptableHealthCheck imple
resultLog.debug("Checking expression [{}], language extension=[{}]",
expression, languageExtension);
try {
final ScriptEngine engine =
scriptEngineManager.getEngineByExtension(languageExtension);
- if(engine == null) {
+ if (engine == null) {
resultLog.healthCheckError("No ScriptEngine available for
extension {}", languageExtension);
} else {
// TODO pluggable Bindings? Reuse the Sling bindings providers?
@@ -92,13 +92,13 @@ public class ScriptableHealthCheck imple
b.put("jmx", new JmxScriptBinding(resultLog));
b.put("osgi", new OsgiScriptBinding(bundleContext, resultLog));
final Object value = engine.eval(expression, b);
- if(value!=null && "true".equals(value.toString())) {
+ if(value!=null &&
"true".equals(value.toString().toLowerCase())) {
resultLog.debug("Expression [{}] evaluates to true as
expected", expression);
} else {
resultLog.warn("Expression [{}] does not evaluate to true
as expected, value=[{}]", expression, value);
}
}
- } catch(Exception e) {
+ } catch (final Exception e) {
resultLog.healthCheckError(
"Exception while evaluating expression [{}] with language
extension [{}]: {}",
expression, languageExtension, e);
Modified:
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java?rev=1518922&r1=1518921&r2=1518922&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
(original)
+++
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
Fri Aug 30 09:34:59 2013
@@ -24,7 +24,9 @@ import javax.servlet.http.HttpServletReq
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.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
@@ -44,7 +46,12 @@ import org.slf4j.LoggerFactory;
configurationFactory=true,
policy=ConfigurationPolicy.REQUIRE,
metatype=true)
-@Service
+@Properties({
+ @Property(name=HealthCheck.NAME),
+ @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
+ @Property(name=HealthCheck.MBEAN_NAME)
+})
+@Service(value=HealthCheck.class)
public class SlingRequestStatusHealthCheck implements HealthCheck {
private static final Logger log =
LoggerFactory.getLogger(SlingRequestStatusHealthCheck.class);
@@ -70,17 +77,8 @@ public class SlingRequestStatusHealthChe
}
}
- @Property(cardinality=Integer.MAX_VALUE)
- public static final String PROP_PATH = "path";
-
- @Property(cardinality=50)
- public static final String PROP_TAGS = HealthCheck.TAGS;
-
- @Property
- public static final String PROP_NAME = HealthCheck.NAME;
-
- @Property
- public static final String PROP_MBEAN_NAME = HealthCheck.MBEAN_NAME;
+ @Property(unbounded=PropertyUnbounded.ARRAY)
+ private static final String PROP_PATH = "path";
@Reference
private SlingRequestProcessor requestProcessor;
Modified:
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/test/java/org/apache/sling/hc/healthchecks/JmxAttributeHealthCheckTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/healthchecks/src/test/java/org/apache/sling/hc/healthchecks/JmxAttributeHealthCheckTest.java?rev=1518922&r1=1518921&r2=1518922&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/test/java/org/apache/sling/hc/healthchecks/JmxAttributeHealthCheckTest.java
(original)
+++
sling/trunk/contrib/extensions/healthcheck/healthchecks/src/test/java/org/apache/sling/hc/healthchecks/JmxAttributeHealthCheckTest.java
Fri Aug 30 09:34:59 2013
@@ -19,8 +19,8 @@ package org.apache.sling.hc.healthchecks
import static org.junit.Assert.assertEquals;
-import java.util.Dictionary;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.healthchecks.impl.JmxAttributeHealthCheck;
@@ -29,27 +29,26 @@ import org.mockito.Mockito;
import org.osgi.service.component.ComponentContext;
public class JmxAttributeHealthCheckTest {
-
+
static void assertJmxValue(String objectName, String attributeName, String
constraint, boolean expected) {
final JmxAttributeHealthCheck hc = new JmxAttributeHealthCheck();
-
+
final ComponentContext ctx = Mockito.mock(ComponentContext.class);
- final Dictionary<String, String> props = new Hashtable<String,
String>();
+ final Map<String, Object> props = new HashMap<String, Object>();
props.put(JmxAttributeHealthCheck.PROP_OBJECT_NAME, objectName);
props.put(JmxAttributeHealthCheck.PROP_ATTRIBUTE_NAME, attributeName);
props.put(JmxAttributeHealthCheck.PROP_CONSTRAINT, constraint);
- Mockito.when(ctx.getProperties()).thenReturn(props);
- hc.activate(ctx);
-
+ hc.activate(props);
+
final Result r = hc.execute();
assertEquals("Expected result " + expected, expected, r.isOk());
}
-
+
@Test
public void testJmxAttributeMatch() {
assertJmxValue("java.lang:type=ClassLoading", "LoadedClassCount", ">
10", true);
}
-
+
@Test
public void testJmxAttributeNoMatch() {
assertJmxValue("java.lang:type=ClassLoading", "LoadedClassCount", "<
10", false);