You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/05/10 08:03:23 UTC

svn commit: r1336488 - in /karaf/cellar/trunk/management/src/main: java/org/apache/karaf/cellar/management/CellarConfigMBean.java java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java resources/OSGI-INF/blueprint/blueprint.xml

Author: jbonofre
Date: Thu May 10 06:03:23 2012
New Revision: 1336488

URL: http://svn.apache.org/viewvc?rev=1336488&view=rev
Log:
[KARAF-1429] CellarConfigMBean now check if pid is allowed outbound

Modified:
    karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java
    karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
    karaf/cellar/trunk/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Modified: karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java?rev=1336488&r1=1336487&r2=1336488&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java Thu May 10 06:03:23 2012
@@ -25,5 +25,6 @@ public interface CellarConfigMBean {
     void deleteConfig(String group, String pid) throws Exception;
     TabularData listProperties(String group, String pid) throws Exception;
     void setProperty(String group, String pid, String key, String value) throws Exception;
+    void appendProperty(String group, String pid, String key, String value) throws Exception;
 
 }

Modified: karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java?rev=1336488&r1=1336487&r2=1336488&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java Thu May 10 06:03:23 2012
@@ -15,13 +15,12 @@ package org.apache.karaf.cellar.manageme
 
 import org.apache.karaf.cellar.config.Constants;
 import org.apache.karaf.cellar.config.RemoteConfigurationEvent;
-import org.apache.karaf.cellar.core.ClusterManager;
-import org.apache.karaf.cellar.core.Configurations;
-import org.apache.karaf.cellar.core.Group;
-import org.apache.karaf.cellar.core.GroupManager;
+import org.apache.karaf.cellar.core.*;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
+import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.cellar.management.CellarConfigMBean;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.cm.ConfigurationEvent;
 
 import javax.management.NotCompliantMBeanException;
@@ -36,6 +35,7 @@ public class CellarConfigMBeanImpl exten
 
     private ClusterManager clusterManager;
     private GroupManager groupManager;
+    private ConfigurationAdmin configurationAdmin;
     private EventProducer eventProducer;
 
     public CellarConfigMBeanImpl() throws NotCompliantMBeanException {
@@ -71,6 +71,15 @@ public class CellarConfigMBeanImpl exten
             throw new IllegalStateException("Cluster event producer is OFF");
         }
 
+        // check if the PID is allowed outbound
+        CellarSupport support = new CellarSupport();
+        support.setClusterManager(this.clusterManager);
+        support.setGroupManager(this.groupManager);
+        support.setConfigurationAdmin(this.configurationAdmin);
+        if (!support.isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
+            throw new IllegalStateException("Configuration PID " + pid + " is blocked outbound");
+        }
+
         Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
         if (configurationMap != null) {
             // update the distributed map
@@ -124,6 +133,15 @@ public class CellarConfigMBeanImpl exten
             throw new IllegalStateException("Cluster event producer is OFF");
         }
 
+        // check if the PID is allowed outbound
+        CellarSupport support = new CellarSupport();
+        support.setClusterManager(this.clusterManager);
+        support.setGroupManager(this.groupManager);
+        support.setConfigurationAdmin(this.configurationAdmin);
+        if (!support.isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
+            throw new IllegalArgumentException("Configuration PID " + pid + " is blocked outbound");
+        }
+
         Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
         if (configurationMap != null) {
             // update the distributed map
@@ -144,6 +162,53 @@ public class CellarConfigMBeanImpl exten
         }
     }
 
+    public void appendProperty(String groupName, String pid, String key, String value) throws Exception {
+        // check if the group exists
+        Group group = groupManager.findGroupByName(groupName);
+        if (group == null) {
+            throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
+        }
+
+        // check if the producer is on
+        if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
+            throw new IllegalStateException("Cluster event producer is off");
+        }
+
+        // check if the pid is allowed outbound
+        CellarSupport support = new CellarSupport();
+        support.setClusterManager(this.clusterManager);
+        support.setGroupManager(this.groupManager);
+        support.setConfigurationAdmin(this.configurationAdmin);
+        if (!support.isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
+            throw new IllegalArgumentException("Configuration PID " + pid + " is blocked outbound");
+        }
+
+        Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (configurationMap != null) {
+            // update the distributed map
+            Properties properties = configurationMap.get(pid);
+            if (properties == null) {
+                properties = new Properties();
+            }
+            Object currentValue = properties.get(key);
+            if (currentValue == null) {
+                properties.put(key, value);
+            } else if (currentValue instanceof String) {
+                properties.put(key, currentValue + value);
+            } else {
+                throw new IllegalStateException("Append failed: current value is not a String");
+            }
+            configurationMap.put(pid, properties);
+
+            // broadcast the cluster event
+            RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+            event.setSourceGroup(group);
+            eventProducer.produce(event);
+        } else {
+            System.out.println("Configuration distributed map not found for cluster group " + groupName);
+        }
+    }
+
     public ClusterManager getClusterManager() {
         return this.clusterManager;
     }
@@ -168,4 +233,12 @@ public class CellarConfigMBeanImpl exten
         this.eventProducer = eventProducer;
     }
 
+    public ConfigurationAdmin getConfigurationAdmin() {
+        return configurationAdmin;
+    }
+
+    public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
+        this.configurationAdmin = configurationAdmin;
+    }
+
 }

Modified: karaf/cellar/trunk/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1336488&r1=1336487&r2=1336488&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/cellar/trunk/management/src/main/resources/OSGI-INF/blueprint/blueprint.xml Thu May 10 06:03:23 2012
@@ -39,6 +39,7 @@
         <property name="clusterManager" ref="clusterManager"/>
         <property name="groupManager" ref="groupManager"/>
         <property name="eventProducer" ref="eventProducer"/>
+        <property name="configurationAdmin" ref="configurationAdmin"/>
     </bean>
 
     <bean id="cellarFeaturesMBean" class="org.apache.karaf.cellar.management.internal.CellarFeaturesMBeanImpl">