NeutronVPN: Improve txn handling and fix memory leaks - Part 2
[netvirt.git] / neutronvpn / impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronTrunkChangeListener.java
index 6e337932d6820e0fc4571cc95879f8591c4fae09..e80d029949afd8567dd40c98473b0096da713ae6 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
@@ -171,11 +172,11 @@ public class NeutronTrunkChangeListener extends AsyncDataTreeChangeListenerBase<
              * Interface is already created for parent NeutronPort. We're updating parent refs
              * and VLAN Information
              */
-            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
-                CONFIGURATION, tx -> {
-                    tx.merge(interfaceIdentifier, newIface);
-                    LOG.trace("Creating trunk member interface {}", newIface);
-                }));
+            ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                txn -> txn.merge(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, newIface));
+            ListenableFutures.addErrorLogging(future, LOG,
+                    "createSubPortInterface: Failed for portName {}, parentName {}", portName, parentName);
+            futures.add(future);
             return futures;
         });
     }
@@ -186,9 +187,10 @@ public class NeutronTrunkChangeListener extends AsyncDataTreeChangeListenerBase<
                         NeutronvpnUtils.buildVlanInterfaceIdentifier(subPort.getPortId().getValue());
         jobCoordinator.enqueueJob("PORT- " + portName, () -> {
             Interface iface = ifMgr.getInterfaceInfoFromConfigDataStore(portName);
+            List<ListenableFuture<Void>> futures = new ArrayList<>();
             if (iface == null) {
                 LOG.warn("Interface not present for SubPort {}", subPort);
-                return Collections.emptyList();
+                return futures;
             }
             /*
              * We'll reset interface back to way it was? Can IFM handle parentRef delete?
@@ -209,7 +211,6 @@ public class NeutronTrunkChangeListener extends AsyncDataTreeChangeListenerBase<
              * and this being subport delete path, don't expect any significant changes to
              * corresponding Neutron Port. Deletion of NeutronPort should follow soon enough.
              */
-            List<ListenableFuture<Void>> futures = new ArrayList<>();
             futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
                 CONFIGURATION, tx -> {
                     tx.put(interfaceIdentifier, newIface);