Bug 3989 -- Fix the original patch. Original patch can break 59/27459/3
authorAnil Vishnoi <vishnoianil@gmail.com>
Fri, 25 Sep 2015 17:34:02 +0000 (23:04 +0530)
committerAnil Vishnoi <vishnoianil@gmail.com>
Fri, 25 Sep 2015 19:27:53 +0000 (00:57 +0530)
the functioning if there are more then one data change and
the first data change is OvsdbNodeAugmentation for which connection
already exist. It will return out of OnDataChanged() when it see
that connection already exist, without processing rest of the
data

Change-Id: Icec9fdcc241fb9f1b823d73cbe2dfdd1f5c3def7
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbDataChangeListener.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbDataChangeListenerTest.java

index 434ef04aa42af97f87eb0ce48f634cc59fb355da..34eb3d9671d45aa75e18205d490009db0099fff5 100644 (file)
@@ -71,19 +71,6 @@ public class OvsdbDataChangeListener implements DataChangeListener, AutoCloseabl
     public void onDataChanged(
             AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
         LOG.trace("onDataChanged: {}", changes);
-        for (Entry<InstanceIdentifier<?>, DataObject> created : changes.getCreatedData().entrySet()) {
-            // TODO validate we have the correct kind of InstanceIdentifier
-            if (created.getValue() instanceof OvsdbNodeAugmentation) {
-                OvsdbNodeAugmentation ovsdbNode = (OvsdbNodeAugmentation)created.getValue();
-                ConnectionInfo key = ovsdbNode.getConnectionInfo();
-                InstanceIdentifier<Node> iid = cm.getInstanceIdentifier(key);
-                if ( iid != null) {
-                    LOG.warn("Connection to device {} already exists. Plugin does not allow multiple connections "
-                              + "to same device, hence dropping the request {}", key, ovsdbNode);
-                    return;
-                }
-            }
-        }
         // Connect first if we have to:
         connect(changes);
 
@@ -156,11 +143,19 @@ public class OvsdbDataChangeListener implements DataChangeListener, AutoCloseabl
         for (Entry<InstanceIdentifier<?>, DataObject> created : changes.getCreatedData().entrySet()) {
             // TODO validate we have the correct kind of InstanceIdentifier
             if (created.getValue() instanceof OvsdbNodeAugmentation) {
-                try {
-                    cm.connect((InstanceIdentifier<Node>) created.getKey(),
-                            (OvsdbNodeAugmentation) created.getValue());
-                } catch (UnknownHostException e) {
-                    LOG.warn("Failed to connect to ovsdbNode", e);
+                OvsdbNodeAugmentation ovsdbNode = (OvsdbNodeAugmentation)created.getValue();
+                ConnectionInfo key = ovsdbNode.getConnectionInfo();
+                InstanceIdentifier<Node> iid = cm.getInstanceIdentifier(key);
+                if ( iid != null) {
+                    LOG.warn("Connection to device {} already exists. Plugin does not allow multiple connections "
+                              + "to same device, hence dropping the request {}", key, ovsdbNode);
+                } else {
+                    try {
+                        cm.connect((InstanceIdentifier<Node>) created.getKey(),
+                                (OvsdbNodeAugmentation) created.getValue());
+                    } catch (UnknownHostException e) {
+                        LOG.warn("Failed to connect to ovsdbNode", e);
+                    }
                 }
             }
         }
index 0df6b30712b659333ebf3eb68b69400ef446b341..9760b103abbf4ea26a8af437572083548c5af431 100644 (file)
@@ -86,16 +86,6 @@ public class OvsdbDataChangeListenerTest {
         MemberModifier.suppress(MemberMatcher.method(OvsdbDataChangeListener.class, "disconnect", AsyncDataChangeEvent.class));
         MemberModifier.suppress(MemberMatcher.method(OvsdbDataChangeListener.class, "init", AsyncDataChangeEvent.class));
 
-        //iid not null case
-        InstanceIdentifier<Node> iid = mock(InstanceIdentifier.class);
-        when(cm.getInstanceIdentifier(any(ConnectionInfo.class))).thenReturn(iid);
-
-        ovsdbDataChangeListener.onDataChanged(changes);
-        verify(changes).getCreatedData();
-        verify(ovsdbNode).getConnectionInfo();
-        verify(cm).getInstanceIdentifier(any(ConnectionInfo.class));
-        PowerMockito.verifyPrivate(ovsdbDataChangeListener, times(0)).invoke("connect", any(AsyncDataChangeEvent.class));
-
         //iid null case
         when(cm.getInstanceIdentifier(any(ConnectionInfo.class))).thenReturn(null);
         ovsdbDataChangeListener.onDataChanged(changes);