CONTROLLER-1809: De-deplicate extraneous ManagedService updates 48/67448/2
authorTom Pantelis <tompantelis@gmail.com>
Mon, 22 Jan 2018 22:43:44 +0000 (17:43 -0500)
committerStephen Kitt <skitt@redhat.com>
Tue, 23 Jan 2018 14:06:28 +0000 (14:06 +0000)
For some strange reason, the ComponentProcessor gets an extraneous
duplicate update from the ConfigAdmin when running the netvirt
integration/CSIT which causes it to restart the container b/c it
thinks there was an update. There is no cfg file so both updates
pass a null Properties. Oddly, I do not see this behavior when
installing the toaster feature from the controller karaf.

I added logic to store the last update and only restart if it
changed. In my testing though, the ConfigAdmin does not notify
unless a change actually occurred.

Change-Id: I692dbd7fcaf921b90f828059d6104138c16a0508
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java

index 97f2fd2b0c92f8bbf59f15d900f8601fd17fc07e..84847a14b1687f87cc7b94bdb58fb4b4eff2f7be 100644 (file)
@@ -12,6 +12,8 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor;
 import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
@@ -133,7 +135,8 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
         // Register a ManagedService so we get updates from the ConfigAdmin when the cfg file corresponding
         // to the persistentId changes.
         final ManagedService managedService = new ManagedService() {
-            private volatile boolean initialUpdate = true;
+            private final AtomicBoolean initialUpdate = new AtomicBoolean(true);
+            private volatile Dictionary<String, ?> previousProperties;
 
             @Override
             public void updated(final Dictionary<String, ?> properties) {
@@ -143,11 +146,11 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
                 // The first update occurs when the service is registered so ignore it as we want subsequent
                 // updates when it changes. The ConfigAdmin will send an update even if the cfg file doesn't
                 // yet exist.
-                if (initialUpdate) {
-                    initialUpdate = false;
-                } else {
+                if (!initialUpdate.compareAndSet(true, false) && !Objects.equals(previousProperties, properties)) {
                     blueprintContainerRestartService.restartContainerAndDependents(bundle);
                 }
+
+                previousProperties = properties;
             }
         };