aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1698272 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/content/ subsystem-itests/src/test/bundles/cmContentBundleZ/org/apache/aries/subsystem/itests/cmcontent/impl/ subsystem-itests/src/test/java/...
Date Fri, 28 Aug 2015 07:39:35 GMT
Author: davidb
Date: Fri Aug 28 07:39:35 2015
New Revision: 1698272

URL: http://svn.apache.org/r1698272
Log:
ARIES-1352 Do not overwrite existing configuration when installing a subsystem

Committing this patch on behalf of Alexandre Roman with many thanks.


Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/content/ConfigAdminContentHandler.java
    aries/trunk/subsystem/subsystem-itests/src/test/bundles/cmContentBundleZ/org/apache/aries/subsystem/itests/cmcontent/impl/BlahManagedService.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ConfigAdminPropsFileContentHandlerTest.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/content/ConfigAdminContentHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/content/ConfigAdminContentHandler.java?rev=1698272&r1=1698271&r2=1698272&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/content/ConfigAdminContentHandler.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/content/ConfigAdminContentHandler.java
Fri Aug 28 07:39:35 2015
@@ -22,6 +22,7 @@ import java.util.concurrent.ConcurrentHa
 
 import org.apache.aries.subsystem.ContentHandler;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.coordinator.Coordination;
@@ -34,9 +35,11 @@ public class ConfigAdminContentHandler i
     public static final String[] CONTENT_TYPES = {PROPERTIES_CONTENT_TYPE, FELIXCM_CONTENT_TYPE};
 
     private final ServiceTracker<ConfigurationAdmin,ConfigurationAdmin> cmTracker;
+    private final BundleContext ctx;
     private Map<String, Dictionary<String, Object>> configurations = new ConcurrentHashMap<String,
Dictionary<String, Object>>();
 
     public ConfigAdminContentHandler(BundleContext ctx) {
+        this.ctx = ctx;
         cmTracker = new ServiceTracker<ConfigurationAdmin, ConfigurationAdmin>(
                 ctx, ConfigurationAdmin.class, null);
         cmTracker.open();
@@ -86,11 +89,20 @@ public class ConfigAdminContentHandler i
                         symbolicName + " to subsystem " + subsystem.getSymbolicName()));
                 return;
             }
-            Configuration conf = cm.getConfiguration(symbolicName, null);
-            conf.update(configuration);
+            Configuration[] matchingConfs = cm.listConfigurations(
+                    ctx.createFilter("(service.pid=" + symbolicName + ")").toString());
+            if(matchingConfs == null || matchingConfs.length == 0) {
+                // No configuration exists: create a new one.
+                Configuration conf = cm.getConfiguration(symbolicName, "?");
+                conf.update(configuration);
+            }
 
             // Update has happened, we can forget the configuration data now
             configurations.remove(symbolicName);
+        } catch(InvalidSyntaxException e) {
+            // Unlikely to happen.
+            coordination.fail(new Exception("Failed to list existing configurations for "
+ symbolicName + " in subsystem " +
+                    subsystem.getSymbolicName(), e));
         } catch (IOException e) {
             coordination.fail(new Exception("Problem applying configuration " + symbolicName
+ " in subsystem " +
                     subsystem.getSymbolicName(), e));

Modified: aries/trunk/subsystem/subsystem-itests/src/test/bundles/cmContentBundleZ/org/apache/aries/subsystem/itests/cmcontent/impl/BlahManagedService.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/bundles/cmContentBundleZ/org/apache/aries/subsystem/itests/cmcontent/impl/BlahManagedService.java?rev=1698272&r1=1698271&r2=1698272&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/bundles/cmContentBundleZ/org/apache/aries/subsystem/itests/cmcontent/impl/BlahManagedService.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/bundles/cmContentBundleZ/org/apache/aries/subsystem/itests/cmcontent/impl/BlahManagedService.java
Fri Aug 28 07:39:35 2015
@@ -23,5 +23,10 @@ public class BlahManagedService implemen
             props.put("test.pid", p.get(Constants.SERVICE_PID));
             bundleContext.registerService(String.class, "Blah!", props);
         }
+        if ("Hello".equals(p.get("configVal"))) {
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put("test.pid", p.get(Constants.SERVICE_PID));
+            bundleContext.registerService(String.class, "Hello", props);
+        }
     }
 }

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ConfigAdminPropsFileContentHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ConfigAdminPropsFileContentHandlerTest.java?rev=1698272&r1=1698271&r2=1698272&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ConfigAdminPropsFileContentHandlerTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ConfigAdminPropsFileContentHandlerTest.java
Fri Aug 28 07:39:35 2015
@@ -17,9 +17,14 @@ import static org.junit.Assert.assertEqu
 
 import org.junit.Test;
 import org.osgi.framework.Filter;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.util.tracker.ServiceTracker;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
 public class ConfigAdminPropsFileContentHandlerTest extends SubsystemTest {
     public ConfigAdminPropsFileContentHandlerTest() {
         installConfigAdmin = true;
@@ -75,5 +80,57 @@ public class ConfigAdminPropsFileContent
         } finally {
             blahTracker.close();
         }
+
+        stopAndUninstallSubsystemSilently(subsystem);
+    }
+
+    @Test
+    public void testAries1352() throws Exception {
+        // Same test than testConfigurationContentHandler, but an existing
+        // configuration exists before the subsystem is installed.
+        // The configuration should not be overwritten by the subsystem
+        // installation.
+
+        ConfigurationAdmin cm = bundleContext.getService(
+                bundleContext.getServiceReference(ConfigurationAdmin.class));
+
+        Configuration blahConf = cm.getConfiguration("com.blah.Blah", "?");
+        Dictionary<String, Object> blahProps = new Hashtable<String, Object>(1);
+        blahProps.put("configVal", "Hello");
+        blahConf.update(blahProps);
+
+        Subsystem subsystem = installSubsystemFromFile("cmContent.esa");
+        subsystem.start();
+
+        // No configuration exists for the service Bar: configuration
+        // values are loaded by the subsystem.
+        Filter f = bundleContext.createFilter(
+                "(&(objectClass=java.lang.String)(test.pid=org.foo.Bar))");
+        ServiceTracker<String, String> barTracker =
+                new ServiceTracker<String, String>(bundleContext, f, null);
+        try {
+            barTracker.open();
+            String blahSvc = barTracker.waitForService(2000);
+            assertEquals("Bar!", blahSvc);
+        } finally {
+            barTracker.close();
+        }
+
+        // A configuration exists for Blah: the subsystem installation should
+        // not overwrite it.
+        Filter f2 = bundleContext.createFilter(
+                "(&(objectClass=java.lang.String)(test.pid=com.blah.Blah))");
+        ServiceTracker<String, String> blahTracker =
+                new ServiceTracker<String, String>(bundleContext, f2, null);
+        try {
+            blahTracker.open();
+            String blahSvc = blahTracker.waitForService(2000);
+            assertEquals("Hello", blahSvc);
+        } finally {
+            blahTracker.close();
+        }
+
+        stopAndUninstallSubsystemSilently(subsystem);
+        blahConf.delete();
     }
 }



Mime
View raw message