MD-SAL OVSDB SB - handle update to ovsdb node. 57/15157/8
authorSharad Mishra <sharad.d.mishra@intel.com>
Wed, 11 Feb 2015 18:13:18 +0000 (10:13 -0800)
committerSharad Mishra <sharad.d.mishra@intel.com>
Wed, 25 Feb 2015 16:45:37 +0000 (08:45 -0800)
Patch to handle ovsdb node update.

Change-Id: Ia8a279de1ec17e7149794f4ef6e0b5900e04dccc
Signed-off-by: Sharad Mishra <sharad.d.mishra@intel.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbNodeDataChangeListener.java

index 67c106fbcfde7ab2c9c17b11fa03b11ae877c3ea..26593181c4fb8036e4b3c33e29ed6a5802c8b91f 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -42,37 +43,56 @@ public class OvsdbNodeDataChangeListener implements DataChangeListener, AutoClos
                 .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
                 .child(Node.class)
                 .augmentation(OvsdbNodeAugmentation.class);
-        registration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, path, this, DataChangeScope.ONE);
+        registration =
+                db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, path, this, DataChangeScope.ONE);
 
     }
 
     @Override
     public void onDataChanged(
             AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
-       LOG.info("Received change to ovsdbNode: {}", changes);
-       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((OvsdbNodeAugmentation)created.getValue());
-            } catch (UnknownHostException e) {
-                LOG.warn("Failed to connect to ovsdbNode", e);
+        LOG.info("Received change to ovsdbNode: {}", changes);
+        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((OvsdbNodeAugmentation) created.getValue());
+                } catch (UnknownHostException e) {
+                    LOG.warn("Failed to connect to ovsdbNode", e);
+                }
             }
-           }
-       }
-       // TODO handle case of updates to ovsdb nodes as needed
+        }
 
         Map<InstanceIdentifier<?>, DataObject> originalDataObject = changes.getOriginalData();
         Set<InstanceIdentifier<?>> iID = changes.getRemovedPaths();
         for (InstanceIdentifier instanceIdentifier : iID) {
             if (originalDataObject.get(instanceIdentifier) instanceof OvsdbNodeAugmentation) {
                 try {
-                    cm.disconnect((OvsdbNodeAugmentation)originalDataObject.get(instanceIdentifier));
+                    cm.disconnect((OvsdbNodeAugmentation) originalDataObject.get(instanceIdentifier));
                 } catch (UnknownHostException e) {
                     LOG.warn("Failed to disconnect ovsdbNode", e);
                 }
             }
         }
+
+        for (Entry<InstanceIdentifier<?>, DataObject> updated : changes.getUpdatedData().entrySet()) {
+            if (updated.getValue() instanceof OvsdbNodeAugmentation) {
+                OvsdbNodeAugmentation value = (OvsdbNodeAugmentation) updated.getValue();
+                OvsdbClient client = cm.getClient(value);
+                if (client == null) {
+                    for (Entry<InstanceIdentifier<?>, DataObject> original : changes.getOriginalData().entrySet()) {
+                        if (original.getValue() instanceof OvsdbNodeAugmentation) {
+                            try {
+                                cm.disconnect((OvsdbNodeAugmentation) original.getValue());
+                                cm.connect(value);
+                            } catch (UnknownHostException e) {
+                                LOG.warn("Failed to disconnect to ovsdbNode", e);
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
 
     @Override