NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / vpnmanager / impl / src / main / java / org / opendaylight / netvirt / vpnmanager / iplearn / IpMonitorStopTask.java
index 0c764c80b333227f8054d48c7e290547ab717d52..023bc0dd41819652ee43a72bc87e4f16aff4805f 100644 (file)
@@ -12,6 +12,11 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.Callable;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.netvirt.vpnmanager.VpnUtil;
 import org.opendaylight.netvirt.vpnmanager.iplearn.model.MacEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
@@ -19,19 +24,23 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class IpMonitorStopTask implements Callable<List<ListenableFuture<Void>>> {
+public class IpMonitorStopTask implements Callable<List<? extends ListenableFuture<?>>> {
     private static final Logger LOG = LoggerFactory.getLogger(IpMonitorStopTask.class);
     private MacEntry macEntry;
+    private DataBroker dataBroker;
     private final AlivenessMonitorUtils alivenessMonitorUtils;
     private boolean isRemoveMipAdjAndLearntIp;
     private final VpnUtil vpnUtil;
+    private final ManagedNewTransactionRunner txRunner;
 
-    public IpMonitorStopTask(MacEntry macEntry, boolean removeMipAdjAndLearntIp, VpnUtil vpnUtil,
-                              AlivenessMonitorUtils alivenessMonitorUtils) {
+    public IpMonitorStopTask(MacEntry macEntry, DataBroker dataBroker, boolean removeMipAdjAndLearntIp, VpnUtil vpnUtil,
+                             AlivenessMonitorUtils alivenessMonitorUtils) {
         this.macEntry = macEntry;
+        this.dataBroker = dataBroker;
         this.alivenessMonitorUtils = alivenessMonitorUtils;
         this.isRemoveMipAdjAndLearntIp = removeMipAdjAndLearntIp;
         this.vpnUtil = vpnUtil;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
     }
 
     @Override
@@ -54,13 +63,20 @@ public class IpMonitorStopTask implements Callable<List<ListenableFuture<Void>>>
                         + "Ignoring this remove event.", learntIp, vpnName);
                 return futures;
             }
-            vpnUtil.removeMipAdjAndLearntIp(vpnName, macEntry.getInterfaceName(), learntIp);
+            vpnUtil.removeLearntVpnVipToPort(macEntry.getVpnName(),
+                    macEntry.getIpAddress().getHostAddress(), null);
+            vpnUtil.removeVpnPortFixedIpToPort(dataBroker, macEntry.getVpnName(),
+                    macEntry.getIpAddress().getHostAddress(), null);
+
+            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                    Datastore.CONFIGURATION, tx -> vpnUtil.removeMipAdjacency(macEntry.getVpnName(),
+                            macEntry.getInterfaceName(), macEntry.getIpAddress().getHostAddress(), tx)),
+                    LOG, "ArpMonitorStopTask: Error writing to datastore for Vpn {} IP  {}",
+                    macEntry.getVpnName(), macEntry.getIpAddress().getHostAddress());
         } else {
             // Delete only MIP adjacency
             vpnUtil.removeMipAdjacency(macEntry.getInterfaceName(), learntIp);
         }
         return futures;
     }
-
-
 }