BUG-2600 Proper reset caching of notifications upon disconnect 29/15529/4
authorMaros Marsalek <mmarsale@cisco.com>
Fri, 20 Feb 2015 09:40:12 +0000 (10:40 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Mon, 23 Feb 2015 10:45:08 +0000 (11:45 +0100)
Change-Id: I9269aef2fee21138b30552ffb0762d73ba98d4be
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java

index 9a5b239024c5bb0cbca3798de58ccc102a994224..281f82ba2aa04d9085d9127e4aeb7ad10cb8d400 100644 (file)
@@ -223,6 +223,8 @@ public final class NetconfDevice implements RemoteDevice<NetconfSessionPreferenc
 
     @Override
     public void onRemoteSessionDown() {
+        notificationHandler.onRemoteSchemaDown();
+
         salFacade.onDeviceDisconnected();
         for (final SchemaSourceRegistration<? extends SchemaSourceRepresentation> sourceRegistration : sourceRegistrations) {
             sourceRegistration.close();
@@ -314,6 +316,7 @@ public final class NetconfDevice implements RemoteDevice<NetconfSessionPreferenc
                 logger.warn("{}: Netconf device provides additional yang models not reported in hello message capabilities: {}",
                         id, providedSourcesNotRequired);
                 logger.warn("{}: Adding provided but not required sources as required to prevent failures", id);
+                logger.debug("{}: Netconf device reported in hello: {}", id, requiredSources);
                 requiredSources.addAll(providedSourcesNotRequired);
             }
 
index 80451a1027713174d66a90ead14bd184ee4a3721..d340e4c1adf1b28f90600c0f320004dbede0f79c 100644 (file)
@@ -42,7 +42,7 @@ final class NotificationHandler {
 
     synchronized void handleNotification(final NetconfMessage notification) {
         if(passNotifications) {
-            passNotification(messageTransformer.toNotification(notification));
+            passNotification(transformNotification(notification));
         } else {
             queueNotification(notification);
         }
@@ -55,15 +55,18 @@ final class NotificationHandler {
         passNotifications = true;
 
         for (final NetconfMessage cachedNotification : queue) {
-            final CompositeNode parsedNotification = messageTransformer.toNotification(cachedNotification);
-            // TODO possible race condition here, because this exception is thrown occasionally
-            Preconditions.checkNotNull(parsedNotification, "Unable to parse received notification %s", cachedNotification);
-            passNotification(parsedNotification);
+            passNotification(transformNotification(cachedNotification));
         }
 
         queue.clear();
     }
 
+    private CompositeNode transformNotification(final NetconfMessage cachedNotification) {
+        final CompositeNode parsedNotification = messageTransformer.toNotification(cachedNotification);
+        Preconditions.checkNotNull(parsedNotification, "{}: Unable to parse received notification %s", id, cachedNotification);
+        return parsedNotification;
+    }
+
     private void queueNotification(final NetconfMessage notification) {
         Preconditions.checkState(passNotifications == false);
 
@@ -87,6 +90,10 @@ final class NotificationHandler {
         this.filter = filter;
     }
 
+    synchronized void onRemoteSchemaDown() {
+        passNotifications = false;
+    }
+
     static interface NotificationFilter {
 
         Optional<CompositeNode> filterNotification(CompositeNode notification);