Added cluster aware mdsal utils class to net-virt (redo)
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / impl / SouthboundImpl.java
index d65db149a29a319df4a2ff01d52d3bc1d61342f5..a926b93316430b9dd8c0fcfca6d9e1e8d1fe8453 100644 (file)
@@ -16,11 +16,11 @@ import java.util.Map;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.openstack.netvirt.ClusterAwareMdsalUtils;
 import org.opendaylight.ovsdb.openstack.netvirt.MdsalHelper;
 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
@@ -65,7 +65,7 @@ public class SouthboundImpl implements Southbound {
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundImpl.class);
     private final DataBroker databroker;
     private static final String PATCH_PORT_TYPE = "patch";
-    private final MdsalUtils mdsalUtils;
+    private final ClusterAwareMdsalUtils mdsalUtils;
 
     /**
      * Class constructor setting the data broker.
@@ -74,7 +74,7 @@ public class SouthboundImpl implements Southbound {
      */
     public SouthboundImpl(DataBroker dataBroker) {
         this.databroker = dataBroker;
-        mdsalUtils = new MdsalUtils(dataBroker);
+        mdsalUtils = new ClusterAwareMdsalUtils(dataBroker);
     }
 
     public DataBroker getDatabroker() {
@@ -242,6 +242,9 @@ public class SouthboundImpl implements Southbound {
         Node ovsdbNode = node;
         if (extractNodeAugmentation(ovsdbNode) == null) {
             ovsdbNode = readOvsdbNode(node);
+            if (ovsdbNode == null) {
+                return null;
+            }
         }
         Node bridgeNode = null;
         ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
@@ -308,12 +311,8 @@ public class SouthboundImpl implements Southbound {
     }
 
     public String getDatapathId(Node node) {
-        String datapathId = null;
         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
-        if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
-            datapathId = node.getAugmentation(OvsdbBridgeAugmentation.class).getDatapathId().getValue();
-        }
-        return datapathId;
+        return getDatapathId(ovsdbBridgeAugmentation);
     }
 
     public String getDatapathId(OvsdbBridgeAugmentation ovsdbBridgeAugmentation) {
@@ -587,7 +586,9 @@ public class SouthboundImpl implements Southbound {
             OvsdbNodeAugmentation ovsdbNode = extractNodeAugmentation(node);
             if (ovsdbNode == null) {
                 Node nodeFromReadOvsdbNode = readOvsdbNode(node);
-                ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
+                if (nodeFromReadOvsdbNode != null) {
+                    ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
+                }
             }
             if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
                 for (OpenvswitchExternalIds openvswitchExternalIds : ovsdbNode.getOpenvswitchExternalIds()) {
@@ -636,7 +637,9 @@ public class SouthboundImpl implements Southbound {
                 OvsdbNodeAugmentation ovsdbNode = extractNodeAugmentation(node);
                 if (ovsdbNode == null) {
                     Node nodeFromReadOvsdbNode = readOvsdbNode(node);
-                    ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
+                    if (nodeFromReadOvsdbNode != null) {
+                        ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
+                    }
                 }
                 if (ovsdbNode != null && ovsdbNode.getOpenvswitchOtherConfigs() != null) {
                     for (OpenvswitchOtherConfigs openvswitchOtherConfigs : ovsdbNode.getOpenvswitchOtherConfigs()) {