Use SingleTransactionDataBroker to read instead of VpnUtil read() - Part 1 13/72813/11
authoreupakir <kiran.n.upadhyaya@ericsson.com>
Sun, 10 Jun 2018 05:25:27 +0000 (10:55 +0530)
committerKiran Upadhyaya <kiran.n.upadhyaya@ericsson.com>
Mon, 11 Jun 2018 05:40:25 +0000 (05:40 +0000)
of 5

Also replaces MDSALUtil.syncWrite() with SingleTransactionDataBroker
writes in the Vpn engine.
Uses ManagedNewTransactionRunner whereever applicable
Restricts VpnUtil.read() accessibility to within the class

Change-Id: I70432063e235247e1c5d87a0597cd399726c5d02
Signed-off-by: eupakir <kiran.n.upadhyaya@ericsson.com>
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/DpnInVpnChangeListener.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/LearntVpnVipToPortEventProcessor.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/SubnetOpDpnManager.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java

index afb9c54bd99acc700adfaca20211fc0120a630ec..cec76fd9e9a5897f086cee0529b954cc8316b05f 100644 (file)
@@ -17,6 +17,8 @@ import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.netvirt.vpnmanager.api.VpnHelper;
@@ -58,31 +60,35 @@ public class DpnInVpnChangeListener implements OdlL3vpnListener {
         BigInteger dpnId = eventData.getDpnId();
 
         LOG.trace("Remove Dpn Event notification received for rd {} VpnName {} DpnId {}", rd, vpnName, dpnId);
+        try {
+            synchronized (vpnName.intern()) {
+                InstanceIdentifier<VpnInstanceOpDataEntry> id = VpnUtil.getVpnInstanceOpDataIdentifier(rd);
+                Optional<VpnInstanceOpDataEntry> vpnOpValue =
+                        SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
 
-        synchronized (vpnName.intern()) {
-            InstanceIdentifier<VpnInstanceOpDataEntry> id = VpnUtil.getVpnInstanceOpDataIdentifier(rd);
-            Optional<VpnInstanceOpDataEntry> vpnOpValue =
-                VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
-
-            if (vpnOpValue.isPresent()) {
-                VpnInstanceOpDataEntry vpnInstOpData = vpnOpValue.get();
-                List<VpnToDpnList> vpnToDpnList = vpnInstOpData.getVpnToDpnList();
-                boolean flushDpnsOnVpn = true;
-                for (VpnToDpnList dpn : vpnToDpnList) {
-                    if (dpn.getDpnState() == VpnToDpnList.DpnState.Active) {
-                        flushDpnsOnVpn = false;
-                        break;
+                if (vpnOpValue.isPresent()) {
+                    VpnInstanceOpDataEntry vpnInstOpData = vpnOpValue.get();
+                    List<VpnToDpnList> vpnToDpnList = vpnInstOpData.getVpnToDpnList();
+                    boolean flushDpnsOnVpn = true;
+                    for (VpnToDpnList dpn : vpnToDpnList) {
+                        if (dpn.getDpnState() == VpnToDpnList.DpnState.Active) {
+                            flushDpnsOnVpn = false;
+                            break;
+                        }
                     }
-                }
-                if (flushDpnsOnVpn) {
-                    try {
-                        txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> deleteDpn(vpnToDpnList, rd, tx)).get();
-                    } catch (InterruptedException | ExecutionException e) {
-                        LOG.error("Error removing dpnToVpnList for vpn {} ", vpnName);
-                        throw new RuntimeException(e.getMessage(), e);
+                    if (flushDpnsOnVpn) {
+                        try {
+                            txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> deleteDpn(vpnToDpnList, rd, tx))
+                                    .get();
+                        } catch (InterruptedException | ExecutionException e) {
+                            LOG.error("Error removing dpnToVpnList for vpn {} ", vpnName);
+                            throw new RuntimeException(e.getMessage(), e);
+                        }
                     }
                 }
             }
+        } catch (ReadFailedException e) {
+            LOG.error("onRemoveDpnEvent: Failed to read data store for rd {} vpn {} dpn {}", rd, vpnName, dpnId);
         }
     }
 
index 7a0ea4f9252db5f99bd920ceb9a0bf559cbb451c..78c862656606353edaa90029daeddfccdff6566c 100644 (file)
@@ -22,8 +22,11 @@ import javax.inject.Singleton;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.arputil.api.ArpConstants;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
@@ -190,90 +193,103 @@ public class LearntVpnVipToPortEventProcessor
             LOG.trace("Adding {} adjacency to VPN Interface {} ", srcPrefix, vpnInterface);
             InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
             InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
-            synchronized (vpnInterface.intern()) {
-                Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
-                String nextHopIpAddr = null;
-                String nextHopMacAddress = null;
-                String ip = srcPrefix;
-                if (interfaceManager.isExternalInterface(vpnInterface)) {
-                    String subnetId = getSubnetId(vpnInstName, dstPrefix);
-                    if (subnetId == null) {
-                        LOG.trace("Can't find corresponding subnet for src IP {}, src MAC {}, dst IP {},  in VPN {}",
-                                srcPrefix, mipMacAddress, dstPrefix, vpnInstName);
-                        return;
-                    }
-                    ip = VpnUtil.getIpPrefix(ip);
-                    AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip)
-                            .withKey(new AdjacencyKey(ip)).setAdjacencyType(AdjacencyType.PrimaryAdjacency)
-                            .setMacAddress(mipMacAddress).setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);
-
-                    List<Adjacency> adjacencyList = adjacencies.isPresent()
-                            ? adjacencies.get().getAdjacency() : new ArrayList<>();
-
-                    adjacencyList.add(newAdjBuilder.build());
-
-                    Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
-                    Optional<VpnInterface> optionalVpnInterface =
-                            VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
-                    VpnInterface newVpnIntf;
-                    if (optionalVpnInterface.isPresent()) {
-                        newVpnIntf =
-                                new VpnInterfaceBuilder(optionalVpnInterface.get())
-                                        .addAugmentation(Adjacencies.class, aug)
-                                        .build();
-                        VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
-                    }
-                    LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
-                    return;
-                }
-
-                if (adjacencies.isPresent()) {
-                    List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
-                    ip = VpnUtil.getIpPrefix(ip);
-                    for (Adjacency adjacs : adjacencyList) {
-                        if (adjacs.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
-                            if (adjacs.getIpAddress().equals(ip)) {
-                                LOG.error("The MIP {} is already present as a primary adjacency for interface {}"
-                                        + "vpn {} Skipping adjacency addition.", ip, vpnInterface, vpnInstName);
-                                return;
-                            }
-                            nextHopIpAddr = adjacs.getIpAddress();
-                            nextHopMacAddress = adjacs.getMacAddress();
-                            break;
-                        }
-                    }
-                    if (nextHopIpAddr != null) {
-                        String rd = VpnUtil.getVpnRd(dataBroker, vpnInstName);
-                        long label =
-                                VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
-                                        VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnInstName, ip));
-                        if (label == 0) {
-                            LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP adjacency {} "
-                                    + "to vpn interface {} for vpn {}", ip, vpnInterface, vpnInstName);
+            try {
+                synchronized (vpnInterface.intern()) {
+                    Optional<Adjacencies> adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                            LogicalDatastoreType.CONFIGURATION, path);
+                    String nextHopIpAddr = null;
+                    String nextHopMacAddress = null;
+                    String ip = srcPrefix;
+                    if (interfaceManager.isExternalInterface(vpnInterface)) {
+                        String subnetId = getSubnetId(vpnInstName, dstPrefix);
+                        if (subnetId == null) {
+                            LOG.trace("Can't find corresponding subnet for src IP {}, src MAC {}, dst IP {},"
+                                    + "  in VPN {}", srcPrefix, mipMacAddress, dstPrefix, vpnInstName);
                             return;
                         }
-                        String nextHopIp = nextHopIpAddr.split("/")[0];
-                        AdjacencyBuilder newAdjBuilder =
-                                new AdjacencyBuilder().setIpAddress(ip).withKey(new AdjacencyKey(ip)).setNextHopIpList(
-                                        Collections.singletonList(nextHopIp)).setAdjacencyType(AdjacencyType.LearntIp);
-                        if (mipMacAddress != null && !mipMacAddress.equalsIgnoreCase(nextHopMacAddress)) {
-                            newAdjBuilder.setMacAddress(mipMacAddress);
-                        }
+                        ip = VpnUtil.getIpPrefix(ip);
+                        AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip)
+                                .withKey(new AdjacencyKey(ip)).setAdjacencyType(AdjacencyType.PrimaryAdjacency)
+                                .setMacAddress(mipMacAddress).setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);
+
+                        List<Adjacency> adjacencyList = adjacencies.isPresent()
+                                ? adjacencies.get().getAdjacency() : new ArrayList<>();
+
                         adjacencyList.add(newAdjBuilder.build());
+
                         Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
-                        Optional<VpnInterface> optionalVpnInterface =
-                                VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
+                        Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(
+                                dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
                         VpnInterface newVpnIntf;
                         if (optionalVpnInterface.isPresent()) {
                             newVpnIntf =
                                     new VpnInterfaceBuilder(optionalVpnInterface.get())
-                                            .addAugmentation(Adjacencies.class, aug).build();
-                            VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                                    vpnIfId, newVpnIntf);
+                                            .addAugmentation(Adjacencies.class, aug)
+                                            .build();
+                            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                    vpnIfId, newVpnIntf, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
                         }
                         LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
+                        return;
+                    }
+
+                    if (adjacencies.isPresent()) {
+                        List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
+                        ip = VpnUtil.getIpPrefix(ip);
+                        for (Adjacency adjacs : adjacencyList) {
+                            if (adjacs.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
+                                if (adjacs.getIpAddress().equals(ip)) {
+                                    LOG.error("The MIP {} is already present as a primary adjacency for interface {}"
+                                            + "vpn {} Skipping adjacency addition.", ip, vpnInterface, vpnInstName);
+                                    return;
+                                }
+                                nextHopIpAddr = adjacs.getIpAddress();
+                                nextHopMacAddress = adjacs.getMacAddress();
+                                break;
+                            }
+                        }
+                        if (nextHopIpAddr != null) {
+                            String rd = VpnUtil.getVpnRd(dataBroker, vpnInstName);
+                            long label =
+                                    VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
+                                            VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnInstName, ip));
+                            if (label == 0) {
+                                LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP"
+                                        + " adjacency {} to vpn interface {} for vpn {}", ip, vpnInterface,
+                                        vpnInstName);
+                                return;
+                            }
+                            String nextHopIp = nextHopIpAddr.split("/")[0];
+                            AdjacencyBuilder newAdjBuilder =
+                                    new AdjacencyBuilder().setIpAddress(ip).withKey(new AdjacencyKey(ip))
+                                            .setNextHopIpList(Collections.singletonList(nextHopIp))
+                                            .setAdjacencyType(AdjacencyType.LearntIp);
+                            if (mipMacAddress != null && !mipMacAddress.equalsIgnoreCase(nextHopMacAddress)) {
+                                newAdjBuilder.setMacAddress(mipMacAddress);
+                            }
+                            adjacencyList.add(newAdjBuilder.build());
+                            Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
+                            Optional<VpnInterface> optionalVpnInterface =
+                                    SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                                            LogicalDatastoreType.CONFIGURATION, vpnIfId);
+                            VpnInterface newVpnIntf;
+                            if (optionalVpnInterface.isPresent()) {
+                                newVpnIntf =
+                                        new VpnInterfaceBuilder(optionalVpnInterface.get())
+                                                .addAugmentation(Adjacencies.class, aug).build();
+                                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                        vpnIfId, newVpnIntf, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
+                            }
+                            LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
+                        }
                     }
                 }
+            } catch (ReadFailedException e) {
+                LOG.error("addMipAdjacency: Failed to read data store for interface {} vpn {} ip {} mac {}",
+                        vpnInterface, vpnInstName, srcPrefix, mipMacAddress);
+            } catch (TransactionCommitFailedException e) {
+                LOG.error("addMipAdjacency: Failed to commit to data store for interface {} vpn {} ip {} mac {}",
+                        vpnInterface, vpnInstName, srcPrefix, mipMacAddress);
             }
         }
 
index 34536c14b410f8f2669907f98ec80b7da325cc59..d3cb4e9d9b14a194b4716f2d4234ea3a9432436e 100644 (file)
@@ -15,9 +15,9 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.PortOpData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData;
@@ -54,7 +54,8 @@ public class SubnetOpDpnManager {
                     new SubnetOpDataEntryKey(subnetId)).build();
             InstanceIdentifier<SubnetToDpn> dpnOpId =
                 subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
-            Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
+            Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, dpnOpId);
             if (optionalSubDpn.isPresent()) {
                 LOG.error("addDpnToSubnet: Cannot create, SubnetToDpn for subnet {} as DPN {}"
                         + " already seen in datastore", subnetId.getValue(), dpnId);
@@ -64,15 +65,19 @@ public class SubnetOpDpnManager {
             List<VpnInterfaces> vpnIntfList = new ArrayList<>();
             subDpnBuilder.setVpnInterfaces(vpnIntfList);
             SubnetToDpn subDpn = subDpnBuilder.build();
-            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
+            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn,
+                    VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
             LOG.info("addDpnToSubnet: Created SubnetToDpn entry for subnet {} with DPNId {} ", subnetId.getValue(),
                     dpnId);
             return subDpn;
         } catch (TransactionCommitFailedException ex) {
             LOG.error("addDpnToSubnet: Creation of SubnetToDpn for subnet {} with DpnId {} failed",
                     subnetId.getValue(), dpnId, ex);
-            return null;
+        } catch (ReadFailedException e) {
+            LOG.error("addDpnToSubnet: Failed to read data store for subnet {} dpn {}", subnetId.getValue(),
+                    dpnId);
         }
+        return null;
     }
 
     private void removeDpnFromSubnet(Uuid subnetId, BigInteger dpnId) {
@@ -82,7 +87,8 @@ public class SubnetOpDpnManager {
                     new SubnetOpDataEntryKey(subnetId)).build();
             InstanceIdentifier<SubnetToDpn> dpnOpId =
                 subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
-            Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
+            Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, dpnOpId);
             if (!optionalSubDpn.isPresent()) {
                 LOG.warn("removeDpnFromSubnet: Cannot delete, SubnetToDpn for subnet {} DPN {} not available"
                         + " in datastore", subnetId.getValue(), dpnId);
@@ -90,10 +96,13 @@ public class SubnetOpDpnManager {
             }
             LOG.trace("removeDpnFromSubnet: Deleting SubnetToDpn entry for subnet {} with DPNId {}",
                     subnetId.getValue(), dpnId);
-            SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
+            SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId,
+                    VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
         } catch (TransactionCommitFailedException ex) {
             LOG.error("removeDpnFromSubnet: Deletion of SubnetToDpn for subnet {} with DPN {} failed",
                     subnetId.getValue(), dpnId, ex);
+        } catch (ReadFailedException e) {
+            LOG.error("removeDpnFromSubnet: Failed to read data store for subnet {} dpn {}", subnetId, dpnId);
         }
     }
 
@@ -107,7 +116,8 @@ public class SubnetOpDpnManager {
             //Please use a synchronize block here as we donot need a cluster-wide lock
             InstanceIdentifier<SubnetToDpn> dpnOpId =
                 subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
-            Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
+            Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, dpnOpId);
             if (!optionalSubDpn.isPresent()) {
                 // Create a new DPN Entry
                 subDpn = addDpnToSubnet(subnetId, dpnId);
@@ -121,14 +131,16 @@ public class SubnetOpDpnManager {
             vpnIntfList.add(vpnIntfs);
             subDpnBuilder.setVpnInterfaces(vpnIntfList);
             subDpn = subDpnBuilder.build();
-
-            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
+            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn,
+                    VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
             LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}",
                     subnetId.getValue(), dpnId, intfName);
         } catch (TransactionCommitFailedException ex) {
             LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed",
                     intfName, subnetId.getValue(), dpnId, ex);
-            return null;
+        } catch (ReadFailedException e) {
+            LOG.error("addInterfaceToDpn: Failed to read data store for interface {} subnet {} dpn {}", intfName,
+                    subnetId, dpnId);
         }
         return subDpn;
     }
@@ -138,12 +150,11 @@ public class SubnetOpDpnManager {
             // Add to PortOpData as well.
             PortOpDataEntryBuilder portOpBuilder = null;
             PortOpDataEntry portOpEntry = null;
-
             InstanceIdentifier<PortOpDataEntry> portOpIdentifier =
                 InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class,
                     new PortOpDataEntryKey(intfName)).build();
-            Optional<PortOpDataEntry> optionalPortOp =
-                VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
+            Optional<PortOpDataEntry> optionalPortOp = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
             if (!optionalPortOp.isPresent()) {
                 // Create PortOpDataEntry only if not present
                 portOpBuilder =
@@ -167,12 +178,15 @@ public class SubnetOpDpnManager {
             }
             portOpEntry = portOpBuilder.build();
             SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier,
-                portOpEntry);
+                portOpEntry, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
             LOG.info("addPortOpDataEntry: Created PortOpData entry for port {} with DPNId {} subnetId {}",
                      intfName, dpnId, subnetId.getValue());
         } catch (TransactionCommitFailedException ex) {
             LOG.error("addPortOpDataEntry: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed",
                     intfName, subnetId.getValue(), dpnId, ex);
+        } catch (ReadFailedException e) {
+            LOG.error("addPortOpDataEntry: Failed to read from data store for interface {} subnet {} dpn {}",
+                    intfName, subnetId, dpnId);
         }
     }
 
@@ -184,7 +198,8 @@ public class SubnetOpDpnManager {
                     new SubnetOpDataEntryKey(subnetId)).build();
             InstanceIdentifier<SubnetToDpn> dpnOpId =
                 subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
-            Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
+            Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, dpnOpId);
             if (!optionalSubDpn.isPresent()) {
                 LOG.debug("removeInterfaceFromDpn: Cannot delete, SubnetToDpn for intf {} subnet {} DPN {}"
                         + " not available in datastore", intfName, subnetId.getValue(), dpnId);
@@ -203,14 +218,16 @@ public class SubnetOpDpnManager {
             } else {
                 subDpnBuilder.setVpnInterfaces(vpnIntfList);
                 SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId,
-                    subDpnBuilder.build());
+                    subDpnBuilder.build(), VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
             }
             LOG.info("removeInterfaceFromDpn: Removed interface {} from sunbet {} dpn {}",
                     intfName, subnetId.getValue(), dpnId);
         } catch (TransactionCommitFailedException ex) {
             LOG.error("removeInterfaceFromDpn: Deletion of Interface {} for SubnetToDpn on subnet {}"
                     + " with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
-            return false;
+        } catch (ReadFailedException e) {
+            LOG.error("removeInterfaceFromDpn: Failed to read data store for interface {} subnet {} dpn {}",
+                    intfName, subnetId, dpnId);
         }
         return dpnRemoved;
     }
@@ -218,57 +235,64 @@ public class SubnetOpDpnManager {
     public PortOpDataEntry removePortOpDataEntry(String intfName, Uuid subnetId) {
         // Remove PortOpData and return out
         InstanceIdentifier<PortOpDataEntry> portOpIdentifier =
-            InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class,
-                new PortOpDataEntryKey(intfName)).build();
+                InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class,
+                        new PortOpDataEntryKey(intfName)).build();
         PortOpDataEntry portOpEntry = null;
-        Optional<PortOpDataEntry> optionalPortOp =
-            VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
-        if (!optionalPortOp.isPresent()) {
-            LOG.info("removePortOpDataEntry: Cannot delete, portOp for port {} is not available in datastore",
-                    intfName);
-            return null;
-        } else {
-            portOpEntry = optionalPortOp.get();
-            List<Uuid> listSubnet = portOpEntry.getSubnetIds();
-            if (listSubnet == null) {
-                listSubnet = new ArrayList<>();
-            }
-            if (subnetId != null && listSubnet.contains(subnetId)) {
-                listSubnet.remove(subnetId);
-            }
-            if (listSubnet.isEmpty() || subnetId == null) {
-                MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
-                LOG.info("removePortOpDataEntry: Deleted portOpData entry for port {}", intfName);
+        try {
+            Optional<PortOpDataEntry> optionalPortOp = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
+            if (!optionalPortOp.isPresent()) {
+                LOG.info("removePortOpDataEntry: Cannot delete, portOp for port {} is not available in datastore",
+                        intfName);
             } else {
-                try {
+                portOpEntry = optionalPortOp.get();
+                List<Uuid> listSubnet = portOpEntry.getSubnetIds();
+                if (listSubnet == null) {
+                    listSubnet = new ArrayList<>();
+                }
+                if (subnetId != null && listSubnet.contains(subnetId)) {
+                    listSubnet.remove(subnetId);
+                }
+                if (listSubnet.isEmpty() || subnetId == null) {
+                    SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier,
+                            VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
+                    LOG.info("removePortOpDataEntry: Deleted portOpData entry for port {}", intfName);
+                } else {
                     PortOpDataEntryBuilder portOpBuilder = null;
                     portOpBuilder = new PortOpDataEntryBuilder(portOpEntry);
                     portOpBuilder.setSubnetIds(listSubnet);
-                    SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier,
-                        portOpEntry);
-                    LOG.info("removePortOpDataEntry: Updated PortOpData entry for port {} with removing subnetId {}",
-                        intfName, subnetId.getValue());
-                } catch (TransactionCommitFailedException ex) {
-                    LOG.error("removePortOpDataEntry failed: Updated PortOpData entry for port {}"
-                        + " with removing subnetId {}", intfName, subnetId.getValue());
+                    SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL,
+                            portOpIdentifier, portOpEntry, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
+                    LOG.info("removePortOpDataEntry: Updated PortOpData entry for port {} with removing"
+                            + " subnetId {}", intfName, subnetId.getValue());
+                    portOpEntry = null;
                 }
-                return null;
             }
+        } catch (ReadFailedException e) {
+            LOG.error("removePortOpDataEntry: Failed to read data store for interface {} subnet {}", intfName,
+                    subnetId);
+        } catch (TransactionCommitFailedException e) {
+            LOG.error("removePortOpDataEntry: Failed to commit to data store for interface {} subnet {}", intfName,
+                    subnetId);
         }
         return portOpEntry;
     }
 
     public PortOpDataEntry getPortOpDataEntry(String intfName) {
-        // Remove PortOpData and return out
-        InstanceIdentifier<PortOpDataEntry> portOpIdentifier =
-            InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class,
-                new PortOpDataEntryKey(intfName)).build();
-        Optional<PortOpDataEntry> optionalPortOp =
-            VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
-        if (!optionalPortOp.isPresent()) {
-            return null;
+        PortOpDataEntry portOpDataEntry = null;
+        try {
+            // Remove PortOpData and return out
+            InstanceIdentifier<PortOpDataEntry> portOpIdentifier =
+                    InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class,
+                            new PortOpDataEntryKey(intfName)).build();
+            Optional<PortOpDataEntry> optionalPortOp = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
+            if (optionalPortOp.isPresent()) {
+                portOpDataEntry = optionalPortOp.get();
+            }
+        } catch (ReadFailedException e) {
+            LOG.error("getPortOpDataEntry: Failed to read data store for interface {}", intfName);
         }
-        return optionalPortOp.get();
+        return portOpDataEntry;
     }
-
 }
index 3ebf87d815e3da911c1d19bda06541cfbf0a2c02..f7fb5a71417999ef27630d700ee8605a296466ab 100755 (executable)
@@ -234,6 +234,7 @@ import org.slf4j.LoggerFactory;
 public final class VpnUtil {
     private static final Logger LOG = LoggerFactory.getLogger(VpnUtil.class);
     private static final int DEFAULT_PREFIX_LENGTH = 32;
+    static final int SINGLE_TRANSACTION_BROKER_NO_RETRY = 1;
     private static final String PREFIX_SEPARATOR = "/";
 
     /**