NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / vpnmanager / impl / src / main / java / org / opendaylight / netvirt / vpnmanager / intervpnlink / InterVpnLinkNodeAddTask.java
index 90f8d8b0718cea257ac117f8c4c615c32c88d3e5..bd555d9346b2305c1277235436c14f0f8224249c 100755 (executable)
@@ -7,19 +7,20 @@
  */
 package org.opendaylight.netvirt.vpnmanager.intervpnlink;
 
-import com.google.common.base.Optional;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.Callable;
-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.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.netvirt.vpnmanager.VpnFootprintService;
 import org.opendaylight.netvirt.vpnmanager.VpnUtil;
 import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache;
@@ -30,6 +31,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointStateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointStateBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,7 +42,7 @@ import org.slf4j.LoggerFactory;
  * there are no DPNs connected to controller by the time the InterVpnLink is
  * created.
  */
-public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<Void>>> {
+public class InterVpnLinkNodeAddTask implements Callable<List<? extends ListenableFuture<?>>> {
     private static final Logger LOG = LoggerFactory.getLogger(InterVpnLinkNodeAddTask.class);
     private static final String NBR_OF_DPNS_PROPERTY_NAME = "vpnservice.intervpnlink.number.dpns";
 
@@ -71,8 +74,8 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
         // check if there is any inter-vpn-link in with erroneous state
         int numberOfDpns = Integer.getInteger(NBR_OF_DPNS_PROPERTY_NAME, 1);
 
-        List<BigInteger> firstDpnList = Collections.singletonList(this.dpnId);
-        List<BigInteger> secondDpnList = firstDpnList;
+        List<Uint64> firstDpnList = Collections.singletonList(Uint64.valueOf(this.dpnId));
+        List<Uint64> secondDpnList = firstDpnList;
         interVpnLinkCache.getAllInterVpnLinks().stream()
             .filter(i -> i.isComplete() && !i.isActive()
                         && shouldConfigureLinkIntoDpn(i.getInterVpnLinkState(), numberOfDpns))
@@ -91,8 +94,8 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
             || interVpnLinkState.getSecondEndpointState().getDpId() == null
                     || interVpnLinkState.getSecondEndpointState().getDpId().isEmpty()) {
             return true;
-        } else if (!interVpnLinkState.getFirstEndpointState().getDpId().contains(dpnId)
-            && !interVpnLinkState.getSecondEndpointState().getDpId().contains(dpnId)
+        } else if (!interVpnLinkState.getFirstEndpointState().getDpId().contains(Uint64.valueOf(dpnId))
+            && !interVpnLinkState.getSecondEndpointState().getDpId().contains(Uint64.valueOf(dpnId))
             && interVpnLinkState.getFirstEndpointState().getDpId().size() < numberOfDpns) {
             return true;
         } else {
@@ -101,8 +104,8 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
     }
 
     private ListenableFuture<Void>
-        updateInterVpnLinkState(InterVpnLinkState interVpnLinkState, List<BigInteger> firstDpnList,
-                                List<BigInteger> secondDpnList) {
+        updateInterVpnLinkState(InterVpnLinkState interVpnLinkState, List<Uint64> firstDpnList,
+                                List<Uint64> secondDpnList) {
 
         FirstEndpointState firstEndPointState =
             new FirstEndpointStateBuilder(interVpnLinkState.getFirstEndpointState()).setDpId(firstDpnList).build();
@@ -112,14 +115,13 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
             new InterVpnLinkStateBuilder(interVpnLinkState).setState(InterVpnLinkState.State.Active)
                     .setFirstEndpointState(firstEndPointState).setSecondEndpointState(secondEndPointState)
                     .build();
-        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
-            tx.merge(LogicalDatastoreType.CONFIGURATION,
-                    InterVpnLinkUtil.getInterVpnLinkStateIid(interVpnLinkState.getInterVpnLinkName()),
-                    newInterVpnLinkState, WriteTransaction.CREATE_MISSING_PARENTS));
+        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx ->
+            tx.merge(InterVpnLinkUtil.getInterVpnLinkStateIid(interVpnLinkState.getInterVpnLinkName()),
+                    newInterVpnLinkState, CREATE_MISSING_PARENTS));
     }
 
-    private void installLPortDispatcherTable(InterVpnLinkState interVpnLinkState, List<BigInteger> firstDpnList,
-                                             List<BigInteger> secondDpnList) {
+    private void installLPortDispatcherTable(InterVpnLinkState interVpnLinkState, List<Uint64> firstDpnList,
+                                             List<Uint64> secondDpnList) {
         String ivpnLinkName = interVpnLinkState.key().getInterVpnLinkName();
         Optional<InterVpnLinkDataComposite> optVpnLink = interVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
         if (!optVpnLink.isPresent()) {
@@ -128,14 +130,14 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
         }
 
         InterVpnLinkDataComposite vpnLink = optVpnLink.get();
-        Optional<Long> opt1stEndpointLportTag = vpnLink.getFirstEndpointLportTag();
+        Optional<Uint32> opt1stEndpointLportTag = vpnLink.getFirstEndpointLportTag();
         if (!opt1stEndpointLportTag.isPresent()) {
             LOG.warn("installLPortDispatcherTable: Could not find LPortTag for 1stEnpoint in InterVpnLink {}",
                      ivpnLinkName);
             return;
         }
 
-        Optional<Long> opt2ndEndpointLportTag = vpnLink.getSecondEndpointLportTag();
+        Optional<Uint32> opt2ndEndpointLportTag = vpnLink.getSecondEndpointLportTag();
         if (!opt2ndEndpointLportTag.isPresent()) {
             LOG.warn("installLPortDispatcherTable: Could not find LPortTag for 2ndEnpoint in InterVpnLink {}",
                      ivpnLinkName);
@@ -150,9 +152,9 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
         if (!vpnUtil.isVpnPendingDelete(vpn1PrimaryRd)
                 && !vpnUtil.isVpnPendingDelete(vpn2PrimaryRd)) {
             interVpnLinkUtil.installLPortDispatcherTableFlow(ivpnLinkName, firstDpnList, secondEndpointVpnUuid,
-                    opt2ndEndpointLportTag.get());
+                    opt2ndEndpointLportTag.get().toJava());
             interVpnLinkUtil.installLPortDispatcherTableFlow(ivpnLinkName, secondDpnList, firstEndpointVpnUuid,
-                    opt1stEndpointLportTag.get());
+                    opt1stEndpointLportTag.get().toJava());
             // Update the VPN -> DPNs Map.
             // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2. Why?
             // because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how to reach