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/03 17:40:28 UTC

svn commit: r1333510 - in /karaf/cellar/trunk: config/src/main/java/org/apache/karaf/cellar/config/ config/src/main/java/org/apache/karaf/cellar/config/shell/ config/src/main/resources/OSGI-INF/blueprint/ management/src/main/java/org/apache/karaf/cella...

Author: jbonofre
Date: Thu May  3 15:40:27 2012
New Revision: 1333510

URL: http://svn.apache.org/viewvc?rev=1333510&view=rev
Log:
[KARAF-1344] Manager config deletion event

Added:
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
      - copied, changed from r1333437, karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
Modified:
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
    karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
    karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
    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/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java Thu May  3 15:40:27 2012
@@ -21,6 +21,7 @@ import org.apache.karaf.cellar.core.cont
 import org.apache.karaf.cellar.core.event.EventHandler;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -59,24 +60,29 @@ public class ConfigurationEventHandler e
 
         Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
 
-        if (eventSwitch.getStatus().equals(SwitchStatus.ON)) {
-            String pid = event.getId();
-            if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
-                Properties dictionary = configurationTable.get(pid);
-                Configuration conf;
-                try {
-                    conf = configurationAdmin.getConfiguration(pid);
-                    if (conf != null && dictionary != null) {
-                        Dictionary existingConfiguration = conf.getProperties();
-                        if (!equals(dictionary, existingConfiguration)) {
-                            conf.update(dictionary);
+        String pid = event.getId();
+
+        if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
+            Properties remoteDictionary = configurationTable.get(pid);
+            Configuration conf;
+            try {
+                conf = configurationAdmin.getConfiguration(pid);
+                if (conf != null) {
+                    if (event.getType() == ConfigurationEvent.CM_DELETED) {
+                        conf.delete();
+                    } else {
+                        if (remoteDictionary != null) {
+                            Dictionary existingConfiguration = conf.getProperties();
+                            if (!equals(remoteDictionary, existingConfiguration)) {
+                                conf.update(remoteDictionary);
+                            }
                         }
                     }
-                } catch (IOException ex) {
-                    LOGGER.error("CELLAR CONFIG: failed to read remote distributed map", ex);
                 }
-            } else LOGGER.warn("CELLAR CONFIG: configuration with pid {} is marked as BLOCKED INBOUND", pid);
-        }
+            } catch (IOException ex) {
+                LOGGER.error("CELLAR CONFIG: failed to read remote distributed map", ex);
+            }
+        } else LOGGER.warn("CELLAR CONFIG: configuration with pid {} is marked as BLOCKED INBOUND", pid);
     }
 
     /**

Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java Thu May  3 15:40:27 2012
@@ -65,12 +65,18 @@ public class LocalConfigurationListener 
                     Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group.getName());
 
                     try {
-                        Configuration conf = configurationAdmin.getConfiguration(pid);
-                        Properties localDictionary = dictionaryToProperties(conf.getProperties());
-                        Dictionary remoteDictionary = configurationTable.get(pid);
-                        if (!equals(localDictionary, remoteDictionary)) {
-                            // update the distributed map
-                            configurationTable.put(pid, localDictionary);
+                        if (event.getType() == ConfigurationEvent.CM_DELETED) {
+                            configurationTable.remove(pid);
+                            // TODO broadcast the cluster event
+                        } else {
+                            Configuration conf = configurationAdmin.getConfiguration(pid);
+                            Properties localDictionary = dictionaryToProperties(conf.getProperties());
+                            Dictionary remoteDictionary = configurationTable.get(pid);
+                            if (!equals(localDictionary, remoteDictionary)) {
+                                // update the distributed map
+                                configurationTable.put(pid, localDictionary);
+                                // TODO broadcast the cluster event but it creates a loop
+                            }
                         }
                     } catch (Exception e) {
                         LOGGER.error("CELLAR CONFIG: failed to push configuration with PID {} to the distributed map", pid, e);

Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java Thu May  3 15:40:27 2012
@@ -20,8 +20,18 @@ import org.apache.karaf.cellar.core.even
  */
 public class RemoteConfigurationEvent extends Event {
 
+    private int type;
+
     public RemoteConfigurationEvent(String id) {
         super(id);
     }
 
+    public int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
+
 }

Copied: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java (from r1333437, karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java)
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java?p2=karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java&p1=karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java&r1=1333437&r2=1333510&rev=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java Thu May  3 15:40:27 2012
@@ -21,28 +21,20 @@ import org.apache.karaf.cellar.core.cont
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
+import org.osgi.service.cm.ConfigurationEvent;
 
 import java.util.Map;
 import java.util.Properties;
 
-/**
- * Config properties set cluster command.
- */
-@Command(scope = "cluster", name = "config-propset", description = "Sets the a property value for a configuration PID in a cluster group name.")
-public class PropSetCommand extends ConfigCommandSupport {
+@Command(scope = "cluster", name = "config-delete", description = "Delete a configuration from the cluster")
+public class DeleteCommand extends ConfigCommandSupport {
 
-    @Argument(index = 0, name = "group", description = "The cluster group name.", required = true, multiValued = false)
+    @Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
     String groupName;
 
-    @Argument(index = 1, name = "pid", description = "The configuration PID.", required = true, multiValued = false)
+    @Argument(index = 1, name = "pid", description = "The configuration PID", required = true, multiValued = false)
     String pid;
 
-    @Argument(index = 2, name = "key", description = "The property key.", required = true, multiValued = false)
-    String key;
-
-    @Argument(index = 3, name = "value", description = "The property value.", required = true, multiValued = false)
-    String value;
-
     private EventProducer eventProducer;
 
     @Override
@@ -63,29 +55,19 @@ public class PropSetCommand extends Conf
         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();
-            }
-            properties.put(key, value);
-            configurationMap.put(pid, properties);
+            configurationMap.remove(pid);
 
-            // broadcast the cluster event
+            // broadcast a cluster event
             RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
             event.setSourceGroup(group);
+            event.setType(ConfigurationEvent.CM_DELETED);
             eventProducer.produce(event);
+
         } else {
             System.out.println("Configuration distributed map not found for cluster group " + groupName);
         }
-        return null;
-    }
-
-    public EventProducer getEventProducer() {
-        return eventProducer;
-    }
 
-    public void setEventProducer(EventProducer eventProducer) {
-        this.eventProducer = eventProducer;
+        return null;
     }
 
 }

Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java Thu May  3 15:40:27 2012
@@ -22,9 +22,6 @@ import org.apache.karaf.shell.commands.C
 import java.util.Map;
 import java.util.Properties;
 
-/**
- * List cluster config command.
- */
 @Command(scope = "cluster", name = "config-list", description = "List the configuration PIDs assigned to a cluster group.")
 public class ListCommand extends ConfigCommandSupport {
 
@@ -35,27 +32,23 @@ public class ListCommand extends ConfigC
 
     @Override
     protected Object doExecute() throws Exception {
+        // check if the group exists
         Group group = groupManager.findGroupByName(groupName);
         if (group == null) {
-            System.err.println("Cluster group " + groupName + " doesn't exist.");
+            System.err.println("Cluster group " + groupName + " doesn't exist");
             return null;
         }
-        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
-            Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
-
-            if (configurationTable != null && !configurationTable.isEmpty()) {
-                System.out.println(String.format("Configuration PIDs for group " + groupName));
-                System.out.println(String.format(OUTPUT_FORMAT, "PID"));
-                for (String pid : configurationTable.keySet()) {
-                    System.out.println(String.format(OUTPUT_FORMAT, pid));
-                }
-            } else System.err.println("No configuration PID found for group " + groupName);
-        } finally {
-            Thread.currentThread().setContextClassLoader(originalClassLoader);
-        }
+
+        Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+
+        if (configurationTable != null && !configurationTable.isEmpty()) {
+            System.out.println(String.format("Configuration PIDs for group " + groupName));
+            System.out.println(String.format(OUTPUT_FORMAT, "PID"));
+            for (String pid : configurationTable.keySet()) {
+                System.out.println(String.format(OUTPUT_FORMAT, pid));
+            }
+        } else System.err.println("No configuration PID found for group " + groupName);
+
         return null;
     }
 

Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java Thu May  3 15:40:27 2012
@@ -23,9 +23,6 @@ import org.apache.karaf.shell.commands.C
 import java.util.Map;
 import java.util.Properties;
 
-/**
- * Config properties list cluster command.
- */
 @Command(scope = "cluster", name = "config-proplist", description = "List the properties in a configuration PID assigned to a cluster group.")
 public class PropListCommand extends CellarCommandSupport {
 
@@ -42,32 +39,27 @@ public class PropListCommand extends Cel
         // check if the group exist
         Group group = groupManager.findGroupByName(groupName);
         if (group == null) {
-            System.err.println("Cluster group " + groupName + " doesn't exist.");
+            System.err.println("Cluster group " + groupName + " doesn't exist");
             return null;
         }
-        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
-            Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
-
-            if (configurationMap != null && !configurationMap.isEmpty()) {
-                Properties properties = configurationMap.get(pid);
-                if (properties == null || properties.isEmpty()) {
-                    System.err.println("No configuration PID found for group " + groupName);
-                } else {
-                    System.out.println(String.format("Property list for configuration PID " + pid + " for group " + groupName));
-                    System.out.println(String.format(OUTPUT_FORMAT, "Key", "Value"));
-
-                    for (Object key : properties.keySet()) {
-                        String value = properties.getProperty((String) key);
-                        System.out.println(String.format(OUTPUT_FORMAT, key, value));
-                    }
+
+        Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+
+        if (configurationMap != null && !configurationMap.isEmpty()) {
+            Properties properties = configurationMap.get(pid);
+            if (properties == null || properties.isEmpty()) {
+                System.err.println("No configuration PID found for group " + groupName);
+            } else {
+                System.out.println(String.format("Property list for configuration PID " + pid + " for group " + groupName));
+                System.out.println(String.format(OUTPUT_FORMAT, "Key", "Value"));
+
+                for (Object key : properties.keySet()) {
+                    String value = properties.getProperty((String) key);
+                    System.out.println(String.format(OUTPUT_FORMAT, key, value));
                 }
-            } else System.err.println("No configuration PID found for group " + groupName);
-        } finally {
-            Thread.currentThread().setContextClassLoader(originalClassLoader);
-        }
+            }
+        } else System.err.println("No configuration PID found for group " + groupName);
+
         return null;
     }
 

Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java Thu May  3 15:40:27 2012
@@ -25,9 +25,6 @@ import org.apache.karaf.shell.commands.C
 import java.util.Map;
 import java.util.Properties;
 
-/**
- * Config properties set cluster command.
- */
 @Command(scope = "cluster", name = "config-propset", description = "Sets the a property value for a configuration PID in a cluster group name.")
 public class PropSetCommand extends ConfigCommandSupport {
 

Modified: karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml?rev=1333510&r1=1333509&r2=1333510&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (original)
+++ karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml Thu May  3 15:40:27 2012
@@ -45,7 +45,16 @@
                 <ref component-id="allGroupCompleter"/>
             </completers>
         </command>
-
+        <command name="cluster/config-delete">
+            <action class="org.apache.karaf.cellar.config.shell.DeleteCommand">
+                <property name="clusterManager" ref="clusterManager"/>
+                <property name="groupManager" ref="groupManager"/>
+                <property name="eventProducer" ref="eventProducer"/>
+            </action>
+            <completers>
+                <ref component-id="allGroupCompleter"/>
+            </completers>
+        </command>
     </command-bundle>
 
     <bean id="allGroupCompleter" class="org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter">

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=1333510&r1=1333509&r2=1333510&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  3 15:40:27 2012
@@ -21,6 +21,7 @@ import javax.management.openmbean.Tabula
 public interface CellarConfigMBean {
 
     String[] listConfig(String group) throws Exception;
+    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;
 

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=1333510&r1=1333509&r2=1333510&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  3 15:40:27 2012
@@ -14,9 +14,15 @@
 package org.apache.karaf.cellar.management.internal;
 
 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.control.SwitchStatus;
+import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.management.CellarConfigMBean;
+import org.osgi.service.cm.ConfigurationEvent;
 
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
@@ -29,77 +35,132 @@ import java.util.*;
 public class CellarConfigMBeanImpl extends StandardMBean implements CellarConfigMBean {
 
     private ClusterManager clusterManager;
+    private GroupManager groupManager;
+    private EventProducer eventProducer;
 
-    public ClusterManager getClusterManager() {
-        return this.clusterManager;
+    public CellarConfigMBeanImpl() throws NotCompliantMBeanException {
+        super(CellarConfigMBean.class);
     }
 
-    public void setClusterManager(ClusterManager clusterManager) {
-        this.clusterManager = clusterManager;
-    }
+    public String[] listConfig(String groupName) throws Exception {
+        // check if the group exists
+        Group group = groupManager.findGroupByName(groupName);
+        if (group == null) {
+            throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
+        }
 
-    public CellarConfigMBeanImpl() throws NotCompliantMBeanException {
-        super(CellarConfigMBean.class);
+        ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
+        Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
+        return configurationTable.keySet().toArray(new String[configurationTable.keySet().size()]);
     }
 
-    public String[] listConfig(String group) throws Exception {
-        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
-        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-        try {
-            ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
-            Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
-            return configurationTable.keySet().toArray(new String[configurationTable.keySet().size()]);
-        } finally {
-            Thread.currentThread().setContextClassLoader(originalClassLoader);
+    public void deleteConfig(String groupName, String pid) 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");
+        }
+
+        Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (configurationMap != null) {
+            // update the distributed map
+            Properties properties = configurationMap.remove(pid);
+
+            // broadcast the cluster event
+            RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+            event.setSourceGroup(group);
+            event.setType(ConfigurationEvent.CM_DELETED);
+            eventProducer.produce(event);
+        } else {
+            throw new IllegalStateException("Configuration distributed map not found for cluster group " + groupName);
         }
     }
 
     public TabularData listProperties(String group, String pid) throws Exception {
 
         CompositeType compositeType = new CompositeType("Property", "Cellar Config Property",
-                new String[]{ "key", "value" },
-                new String[]{ "Property key", "Property value" },
-                new OpenType[]{ SimpleType.STRING, SimpleType.STRING });
+                new String[]{"key", "value"},
+                new String[]{"Property key", "Property value"},
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING});
         TabularType tableType = new TabularType("Properties", "Table of all properties in the Config PID",
-                compositeType, new String[]{ "key" });
+                compositeType, new String[]{"key"});
         TabularData table = new TabularDataSupport(tableType);
 
-        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
-        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-        try {
-            Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
-            Properties properties = configurationTable.get(pid);
-            if (properties != null) {
-                Enumeration propertyNames = properties.propertyNames();
-                while (propertyNames.hasMoreElements()) {
-                    String key = (String) propertyNames.nextElement();
-                    String value = (String) properties.get(key);
-                    CompositeDataSupport data = new CompositeDataSupport(compositeType,
-                            new String[]{ "key", "value" },
-                            new String[]{ key, value });
-                    table.put(data);
-                }
+        Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
+        Properties properties = configurationTable.get(pid);
+        if (properties != null) {
+            Enumeration propertyNames = properties.propertyNames();
+            while (propertyNames.hasMoreElements()) {
+                String key = (String) propertyNames.nextElement();
+                String value = (String) properties.get(key);
+                CompositeDataSupport data = new CompositeDataSupport(compositeType,
+                        new String[]{"key", "value"},
+                        new String[]{key, value});
+                table.put(data);
             }
-            return table;
-        } finally {
-            Thread.currentThread().setContextClassLoader(originalClassLoader);
         }
+        return table;
     }
 
-    public void setProperty(String group, String pid, String key, String value) throws Exception {
-        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
-        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-        try {
-            Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
-            Properties properties = configurationTable.get(pid);
+    public void setProperty(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");
+        }
+
+        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();
             }
             properties.put(key, value);
-            configurationTable.put(pid, properties);
-        } finally {
-            Thread.currentThread().setContextClassLoader(originalClassLoader);
+
+            configurationMap.put(pid, properties);
+
+            // broadcast the cluster event
+            RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+            event.setSourceGroup(group);
+            eventProducer.produce(event);
+        } else {
+            throw new IllegalStateException("Configuration distributed map not found for cluster group " + groupName);
         }
     }
 
+    public ClusterManager getClusterManager() {
+        return this.clusterManager;
+    }
+
+    public void setClusterManager(ClusterManager clusterManager) {
+        this.clusterManager = clusterManager;
+    }
+
+    public GroupManager getGroupManager() {
+        return groupManager;
+    }
+
+    public void setGroupManager(GroupManager groupManager) {
+        this.groupManager = groupManager;
+    }
+
+    public EventProducer getEventProducer() {
+        return eventProducer;
+    }
+
+    public void setEventProducer(EventProducer eventProducer) {
+        this.eventProducer = eventProducer;
+    }
+
 }

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=1333510&r1=1333509&r2=1333510&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  3 15:40:27 2012
@@ -32,6 +32,8 @@
 
     <bean id="cellarConfigMBean" class="org.apache.karaf.cellar.management.internal.CellarConfigMBeanImpl">
         <property name="clusterManager" ref="clusterManager"/>
+        <property name="groupManager" ref="groupManager"/>
+        <property name="eventProducer" ref="eventProducer"/>
     </bean>
 
     <bean id="cellarFeaturesMBean" class="org.apache.karaf.cellar.management.internal.CellarFeaturesMBeanImpl">