Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8809210AE4 for ; Fri, 28 Aug 2015 07:39:36 +0000 (UTC) Received: (qmail 8363 invoked by uid 500); 28 Aug 2015 07:39:36 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 8296 invoked by uid 500); 28 Aug 2015 07:39:36 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 8285 invoked by uid 99); 28 Aug 2015 07:39:36 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2015 07:39:36 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 0A9D5AC009D for ; Fri, 28 Aug 2015 07:39:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@aries.apache.org From: davidb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150828073936.0A9D5AC009D@hades.apache.org> 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 cmTracker; + private final BundleContext ctx; private Map> configurations = new ConcurrentHashMap>(); public ConfigAdminContentHandler(BundleContext ctx) { + this.ctx = ctx; cmTracker = new ServiceTracker( 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 props = new Hashtable(); + 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 blahProps = new Hashtable(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 barTracker = + new ServiceTracker(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 blahTracker = + new ServiceTracker(bundleContext, f2, null); + try { + blahTracker.open(); + String blahSvc = blahTracker.waitForService(2000); + assertEquals("Hello", blahSvc); + } finally { + blahTracker.close(); + } + + stopAndUninstallSubsystemSilently(subsystem); + blahConf.delete(); } }