incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1506464 - in /sling/trunk/contrib/extensions/healthcheck: hc-sling/src/main/java/org/apache/sling/hc/sling/impl/ hc-sling/src/main/resources/OSGI-INF/metatype/ sling-demo/src/main/resources/SLING-CONTENT/apps/hc/install/
Date Wed, 24 Jul 2013 09:32:54 GMT
Author: bdelacretaz
Date: Wed Jul 24 09:32:53 2013
New Revision: 1506464

URL: http://svn.apache.org/r1506464
Log:
SLING-2977 - bean name and rule tags are now configurable

Added:
    sling/trunk/contrib/extensions/healthcheck/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/install/org.apache.sling.hc.sling.impl.RulesMBeans-1.json
      - copied unchanged from r1506421, sling/trunk/contrib/extensions/healthcheck/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/install/org.apache.sling.hc.sling.impl.RulesMBeans.json
Removed:
    sling/trunk/contrib/extensions/healthcheck/sling-demo/src/main/resources/SLING-CONTENT/apps/hc/install/org.apache.sling.hc.sling.impl.RulesMBeans.json
Modified:
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java?rev=1506464&r1=1506463&r2=1506464&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
Wed Jul 24 09:32:53 2013
@@ -39,19 +39,27 @@ import org.apache.sling.hc.api.Rule;
 import org.apache.sling.hc.api.RulesEngine;
 import org.apache.sling.hc.sling.api.RulesResourceParser;
 import org.apache.sling.hc.util.RuleDynamicMBean;
+import org.apache.sling.hc.util.TaggedRuleFilter;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** Registers MBeans for our health check rules */
-@Component(configurationFactory=true, policy=ConfigurationPolicy.REQUIRE,metatype=true)
+@Component(configurationFactory=true, policy=ConfigurationPolicy.REQUIRE, metatype=true)
 public class RulesMBeans {
     private final Logger log = LoggerFactory.getLogger(getClass());
     
     @Property
     public static final String RULES_PATHS_PROP = "rules.path";
     
+    @Property(value=RulesMBeans.DEFAULT_BEAN_NAME)
+    public static final String BEAN_NAME_PROP = "bean.name";
+    public static final String DEFAULT_BEAN_NAME = "rules";
+    
+    @Property(cardinality=20)
+    public static final String RULE_TAGS_PROP = "rules.tags";
+    
     @Reference
     private ResourceResolverFactory resourceResolverFactory;
     
@@ -65,6 +73,8 @@ public class RulesMBeans {
     private RulesEngine engine;
     private List<ServiceRegistration> mBeansRegistrations;
     private ResourceResolver resolver;
+    private String beanName;
+    private String [] rulesTags;
     
     @Activate
     public void activate(ComponentContext ctx) throws Exception {
@@ -73,6 +83,9 @@ public class RulesMBeans {
             throw new IllegalStateException("rulesPath is null, cannot activate");
         }
         
+        beanName = PropertiesUtil.toString(ctx.getProperties().get(BEAN_NAME_PROP), DEFAULT_BEAN_NAME);
+        rulesTags = PropertiesUtil.toStringArray(ctx.getProperties().get(RULE_TAGS_PROP),
new String[] {});
+        
         resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
         final Resource rulesRoot = resolver.getResource(rulesPath);
         if(rulesRoot == null) {
@@ -87,7 +100,12 @@ public class RulesMBeans {
         // And register MBeans for those Rules
         mBeansRegistrations = new ArrayList<ServiceRegistration>();
         final String RESOURCE_PATH_PROP = "sling.resource.path";
+        final TaggedRuleFilter filter = rulesTags.length > 0 ? new TaggedRuleFilter(rulesTags)
: null;
         for(Rule r : rules) {
+            if(filter != null && !filter.accept(r)) {
+                log.debug("{} rejected by {}, ignoring this Rule", r, filter);
+                continue;
+            }
             final Object rulePath = r.getInfo().get(RESOURCE_PATH_PROP);
             if(rulePath == null) {
                 // TODO this happens with scripted rules
@@ -95,7 +113,7 @@ public class RulesMBeans {
                 continue;
             }
             final Dictionary<String, String> mbeanProps = new Hashtable<String,
String>();
-            mbeanProps.put("jmx.objectname", "org.apache.sling.healthcheck:type=rules,service="
+ rulePath);
+            mbeanProps.put("jmx.objectname", "org.apache.sling.healthcheck:type=" + beanName
+ ",service=" + rulePath);
             final RuleDynamicMBean mbean = new RuleDynamicMBean(r);
             mBeansRegistrations.add(ctx.getBundleContext().registerService(DynamicMBean.class.getName(),
mbean, mbeanProps));
             log.debug("Registered {} with properties {}", mbean, mbeanProps);

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1506464&r1=1506463&r2=1506464&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/resources/OSGI-INF/metatype/metatype.properties
Wed Jul 24 09:32:53 2013
@@ -21,4 +21,11 @@ org.apache.sling.hc.sling.impl.RulesMBea
 org.apache.sling.hc.sling.impl.RulesMBeans.description = Creates MBeans for Sling Health
Check Rules
 
 rules.path.name = Rules path
-rules.path.description = MBeans are created for all rules found under this path
\ No newline at end of file
+rules.path.description = MBeans are created for all rules found under this path
+
+bean.name.name = MBean name
+bean.name.description = Name of the MBean generated by this configuration
+
+rules.tags.name = Rule tags
+rules.tags.description = Only rules having all specified tags will be included. \
+  Leave empty to include all rules.
\ No newline at end of file



Mime
View raw message