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 2019/11/15 04:29:43 UTC

[karaf] branch karaf-4.2.x updated: [KARAF-6519] Add append/delete/update properties operations on ConfigMBean

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new 2633871  [KARAF-6519] Add append/delete/update properties operations on ConfigMBean
2633871 is described below

commit 26338712e0a891e1bea5590afcdc59fd426376d0
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Thu Nov 14 14:28:14 2019 +0100

    [KARAF-6519] Add append/delete/update properties operations on ConfigMBean
    
    (cherry picked from commit d63e165723602367d1706d34399f1ec9b2519530)
---
 .../org/apache/karaf/config/core/ConfigMBean.java  | 20 ++++++++++++++++-
 .../karaf/config/core/impl/ConfigMBeanImpl.java    | 26 +++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java b/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
index b0ae0f7..0730116 100644
--- a/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
+++ b/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
@@ -119,7 +119,25 @@ public interface ConfigMBean {
      * @param properties the new properties to set in the configuration.
      * @throws MBeanException in case of MBean failure.
      */
-    void update(String pid, Map<String, String> properties) throws MBeanException;
+    void update(String pid, Map<String, Object> properties) throws MBeanException;
+
+    /**
+     * Add new properties or update existing ones (without removing others) in a given configuration.
+     *
+     * @param pid the configuration PID.
+     * @param properties the properties to add/update.
+     * @throws MBeanException in case of MBean failure.
+     */
+    void append(String pid, Map<String, Object> properties) throws MBeanException;
+
+    /**
+     * Delete properties from a configuration.
+     *
+     * @param pid the configuration PID.
+     * @param properties the properties to delete from the configuration.
+     * @throws MBeanException in case of MBean failure.
+     */
+    void delete(String pid, List<String> properties) throws MBeanException;
 
     String createFactoryConfiguration(String factoryPid) throws MBeanException;
 
diff --git a/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java b/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
index b86a96e..29355c1 100644
--- a/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
+++ b/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
@@ -213,7 +213,18 @@ public class ConfigMBeanImpl extends StandardMBean implements ConfigMBean {
     }
 
     @Override
-    public void update(String pid, Map<String, String> properties) throws MBeanException {
+    public void update(String pid, Map<String, Object> properties) throws MBeanException {
+        try {
+            TypedProperties props = configRepo.getConfig(pid);
+            props.update(properties);
+            configRepo.update(pid, props);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.toString());
+        }
+    }
+
+    @Override
+    public void append(String pid, Map<String, Object> properties) throws MBeanException {
         try {
             TypedProperties props = configRepo.getConfig(pid);
             props.putAll(properties);
@@ -223,6 +234,19 @@ public class ConfigMBeanImpl extends StandardMBean implements ConfigMBean {
         }
     }
 
+    @Override
+    public void delete(String pid, List<String> properties) throws MBeanException {
+        try {
+            TypedProperties props = configRepo.getConfig(pid);
+            for (String property : properties) {
+                props.remove(property);
+            }
+            configRepo.update(pid, props);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.toString());
+        }
+    }
+
 	private Dictionary<String, Object> toDictionary(
 			Map<String, String> properties) {
 		Dictionary<String, Object> dictionary = new Hashtable<>();