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/11/05 14:58:09 UTC

svn commit: r1405794 - in /karaf/cellar/branches/cellar-2.3.x: config/src/main/java/org/apache/karaf/cellar/config/shell/ config/src/main/resources/OSGI-INF/blueprint/ management/src/main/java/org/apache/karaf/cellar/management/ management/src/main/jav...

Author: jbonofre
Date: Mon Nov  5 13:58:09 2012
New Revision: 1405794

URL: http://svn.apache.org/viewvc?rev=1405794&view=rev
Log:
[KARAF-1484] Add cluster:config-propdel command (and corresponding operation in the CellarConfigMBean)

Added:
    karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
Modified:
    karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
    karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java
    karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java

Added: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java?rev=1405794&view=auto
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java (added)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java Mon Nov  5 13:58:09 2012
@@ -0,0 +1,91 @@
+/*
+ * Licensed 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.karaf.cellar.config.shell;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.cellar.config.Constants;
+import org.apache.karaf.cellar.config.RemoteConfigurationEvent;
+import org.apache.karaf.cellar.core.Configurations;
+import org.apache.karaf.cellar.core.Group;
+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 java.util.Map;
+import java.util.Properties;
+
+@Command(scope = "cluster", name = "config-propdel", description = "Delete a property from a configuration PID assigned to a cluster group")
+public class PropDelCommand extends ConfigCommandSupport {
+
+    @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)
+    String pid;
+
+    @Argument(index = 2, name = "key", description = "The property key to delete", required = true, multiValued = false)
+    String key;
+
+    private EventProducer eventProducer;
+
+    @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");
+            return null;
+        }
+
+        // check if the event producer is ON
+        if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
+            System.err.println("Cluster event producer is OFF");
+            return null;
+        }
+
+        // check if the configuration PID is allowed
+        if (!isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
+            System.err.println("Configuration PID " + pid + " is blocked outbound");
+            return null;
+        }
+
+        Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (distributedConfigurations != null) {
+            // update the distributed map
+            Properties distributedDictionary = distributedConfigurations.get(pid);
+            if (distributedDictionary != null) {
+                distributedDictionary.remove(key);
+                distributedConfigurations.put(pid, distributedDictionary);
+                // broadcast the cluster event
+                RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+                event.setSourceGroup(group);
+                eventProducer.produce(event);
+            }
+        } else {
+            System.out.println("Configuration distributed map is not found for cluster group " + groupName);
+        }
+
+        return null;
+    }
+
+    public EventProducer getEventProducer() {
+        return eventProducer;
+    }
+
+    public void setEventProducer(EventProducer eventProducer) {
+        this.eventProducer = eventProducer;
+    }
+
+}

Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml?rev=1405794&r1=1405793&r2=1405794&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml Mon Nov  5 13:58:09 2012
@@ -57,6 +57,17 @@
                 <ref component-id="allGroupCompleter"/>
             </completers>
         </command>
+        <command name="cluster/config-propdel">
+            <action class="org.apache.karaf.cellar.config.shell.PropDelCommand">
+                <property name="clusterManager" ref="clusterManager"/>
+                <property name="groupManager" ref="groupManager"/>
+                <property name="eventProducer" ref="eventProducer"/>
+                <property name="configurationAdmin" ref="configurationAdmin"/>
+            </action>
+            <completers>
+                <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"/>

Modified: karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java?rev=1405794&r1=1405793&r2=1405794&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/CellarConfigMBean.java Mon Nov  5 13:58:09 2012
@@ -26,5 +26,6 @@ public interface CellarConfigMBean {
     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;
+    void deleteProperty(String group, String pid, String key) throws Exception;
 
 }

Modified: karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java?rev=1405794&r1=1405793&r2=1405794&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java Mon Nov  5 13:58:09 2012
@@ -42,7 +42,6 @@ public class CellarConfigMBeanImpl exten
         super(CellarConfigMBean.class);
     }
 
-
     public List<String> listConfig(String groupName) throws Exception {
         // check if the group exists
         Group group = groupManager.findGroupByName(groupName);
@@ -52,8 +51,8 @@ public class CellarConfigMBeanImpl exten
 
         List<String> result = new ArrayList<String>();
 
-        Map<String, Properties> config = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
-        for (String pid : config.keySet()) {
+        Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        for (String pid : distributedConfigurations.keySet()) {
             result.add(pid);
         }
 
@@ -81,10 +80,10 @@ public class CellarConfigMBeanImpl exten
             throw new IllegalStateException("Configuration PID " + pid + " is blocked outbound");
         }
 
-        Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
-        if (configurationMap != null) {
+        Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (distributedConfigurations != null) {
             // update the distributed map
-            Properties properties = configurationMap.remove(pid);
+            Properties properties = distributedConfigurations.remove(pid);
 
             // broadcast the cluster event
             RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
@@ -92,7 +91,7 @@ public class CellarConfigMBeanImpl exten
             event.setType(ConfigurationEvent.CM_DELETED);
             eventProducer.produce(event);
         } else {
-            throw new IllegalStateException("Configuration distributed map not found for cluster group " + groupName);
+            throw new IllegalArgumentException("Configuration distributed map not found for cluster group " + groupName);
         }
     }
 
@@ -101,12 +100,12 @@ public class CellarConfigMBeanImpl exten
                 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",
+        TabularType tableType = new TabularType("Properties", "Table of all properties in the configuration PID",
                 compositeType, new String[]{"key"});
         TabularData table = new TabularDataSupport(tableType);
 
-        Map<String, Properties> config = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
-        Properties properties = config.get(pid);
+        Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group);
+        Properties properties = distributedConfigurations.get(pid);
         if (properties != null) {
             Enumeration propertyNames = properties.propertyNames();
             while (propertyNames.hasMoreElements()) {
@@ -139,25 +138,25 @@ public class CellarConfigMBeanImpl exten
         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");
+            throw new IllegalStateException("Configuration PID " + pid + " is blocked outbound");
         }
 
-        Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
-        if (configurationMap != null) {
+        Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (distributedConfigurations != null) {
             // update the distributed map
-            Properties properties = configurationMap.get(pid);
+            Properties properties = distributedConfigurations.get(pid);
             if (properties == null) {
                 properties = new Properties();
             }
             properties.put(key, value);
-            configurationMap.put(pid, properties);
+            distributedConfigurations.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);
+            throw new IllegalArgumentException("Configuration distributed map not found for cluster group " + groupName);
         }
     }
 
@@ -179,13 +178,13 @@ public class CellarConfigMBeanImpl exten
         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");
+            throw new IllegalStateException("Configuration PID " + pid + " is blocked outbound");
         }
 
-        Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
-        if (configurationMap != null) {
+        Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (distributedConfigurations != null) {
             // update the distributed map
-            Properties properties = configurationMap.get(pid);
+            Properties properties = distributedConfigurations.get(pid);
             if (properties == null) {
                 properties = new Properties();
             }
@@ -197,14 +196,52 @@ public class CellarConfigMBeanImpl exten
             } else {
                 throw new IllegalStateException("Append failed: current value is not a String");
             }
-            configurationMap.put(pid, properties);
+            distributedConfigurations.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);
+            throw new IllegalArgumentException("Configuration distributed map not found for cluster group " + groupName);
+        }
+    }
+
+    public void deleteProperty(String groupName, String pid, String key) 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 event 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> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+        if (distributedConfigurations != null) {
+            // update the distributed map
+            Properties distributedDictionary = distributedConfigurations.get(pid);
+            if (distributedDictionary != null) {
+                distributedDictionary.remove(key);
+                distributedConfigurations.put(pid, distributedDictionary);
+                // broadcast the cluster event
+                RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+                event.setSourceGroup(group);
+                eventProducer.produce(event);
+            }
+        } else {
+            throw new IllegalArgumentException("Configuration distributed map not found for cluster group " + groupName);
         }
     }