Merge "Add getTerminationPointOfBridge method to SouthboundUtils"
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / HwvtepDataChangeListener.java
index 0da5f37cb26f28be55e74f35d26712f89b6098f5..5cca754d4b009ab573164316b20c812ae5e8c2a5 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.ovsdb.hwvtepsouthbound;
 
+import java.net.ConnectException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -133,9 +134,9 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
                                         + "to same device, hence dropping the request {}", connection, hwvtepGlobal);
                     } else {
                         try {
-                            hcm.connect(HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId()), hwvtepGlobal);
-                        } catch (UnknownHostException e) {
-                            LOG.warn("Failed to connect to OVSDB node", e);
+                            OvsdbClient client = hcm.connect(key, hwvtepGlobal);
+                        } catch (UnknownHostException | ConnectException e) {
+                            LOG.warn("Failed to connect to HWVTEP node", e);
                         }
                     }
                 }
@@ -159,9 +160,13 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
                     if (client == null) {
                         try {
                             hcm.disconnect(hgOriginal);
-                            hcm.connect(HwvtepSouthboundMapper.createInstanceIdentifier(original.getNodeId()), hgUpdated);
-                        } catch (UnknownHostException e) {
-                            LOG.warn("Failed to update connection on OVSDB Node", e);
+                            hcm.stopConnectionReconciliationIfActive(key, hgOriginal);
+                            OvsdbClient newClient = hcm.connect(key, hgUpdated);
+                            if (newClient == null) {
+                                hcm.reconcileConnection(key, hgUpdated);
+                            }
+                        } catch (UnknownHostException | ConnectException e) {
+                            LOG.warn("Failed to update connection on HWVTEP Node", e);
                         }
                     }
                 }
@@ -170,7 +175,7 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
     }
 
     private void updateData(Collection<DataTreeModification<Node>> changes) {
-        /* TODO: 
+        /* TODO:
          * Get connection instances for each change
          * Update data for each connection
          * Requires Command patterns. TBD.
@@ -193,8 +198,9 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
                 if (hgDeleted != null) {
                     try {
                         hcm.disconnect(hgDeleted);
+                        hcm.stopConnectionReconciliationIfActive(key, hgDeleted);
                     } catch (UnknownHostException e) {
-                        LOG.warn("Failed to disconnect OVSDB Node", e);
+                        LOG.warn("Failed to disconnect HWVTEP Node", e);
                     }
                 }
             }