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

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


The following commit(s) were added to refs/heads/master by this push:
     new d63e165  [KARAF-6519] Add append/delete/update properties operations 
on ConfigMBean
     new a675e5d  Merge pull request #994 from jbonofre/KARAF-6519
d63e165 is described below

commit d63e165723602367d1706d34399f1ec9b2519530
Author: Jean-Baptiste Onofré <[email protected]>
AuthorDate: Thu Nov 14 14:28:14 2019 +0100

    [KARAF-6519] Add append/delete/update properties operations on ConfigMBean
---
 .../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<>();

Reply via email to