MRI version bumpup for Aluminium
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / evpn / utils / EvpnUtils.java
index f7474943d9f503cea4f4ac644c30ef0eb82a6ef0..01970cbcbd8bb896e7cd652f6865f917cf2badbf 100644 (file)
@@ -9,13 +9,13 @@ package org.opendaylight.netvirt.elan.evpn.utils;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.function.BiConsumer;
@@ -25,11 +25,6 @@ import java.util.function.Predicate;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-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.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
@@ -47,6 +42,9 @@ import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.SettableFutureCallback;
@@ -132,7 +130,7 @@ public class EvpnUtils {
             return;
         }
         String rd = vpnManager.getVpnRd(broker, evpnName);
-        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orElse(null);
         macEntries.stream().filter(isIpv4PrefixAvailable).forEach(macEntry -> {
             InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(macEntry.getInterface());
             if (interfaceInfo == null) {
@@ -235,7 +233,7 @@ public class EvpnUtils {
         if (l3VpName != null) {
             VpnInstance l3VpnInstance = vpnManager.getVpnInstance(broker, l3VpName);
             l3vni = l3VpnInstance.getL3vni();
-            com.google.common.base.Optional<String> gatewayMac = getGatewayMacAddressForInterface(l3VpName,
+            Optional<String> gatewayMac = getGatewayMacAddressForInterface(l3VpName,
                     interfaceName, prefix);
             gatewayMacAddr = gatewayMac.isPresent() ? gatewayMac.get() : null;
 
@@ -321,11 +319,11 @@ public class EvpnUtils {
         ExternalTunnelList externalTunnelList = null;
         try {
             externalTunnelList = elanUtils.read2(LogicalDatastoreType.CONFIGURATION,
-                    externalTunnelListId).orNull();
-        } catch (ReadFailedException e) {
+                    externalTunnelListId).orElse(null);
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("getExternalTunnelList: unable to read ExternalTunnelList, exception ", e);
         }
-        return Optional.fromNullable(externalTunnelList);
+        return Optional.ofNullable(externalTunnelList);
     }
 
     public static InstanceIdentifier<DcGatewayIpList> getDcGatewayIpListIdentifier() {
@@ -338,11 +336,11 @@ public class EvpnUtils {
         DcGatewayIpList dcGatewayIpListConfig = null;
         try {
             dcGatewayIpListConfig = elanUtils.read2(LogicalDatastoreType.CONFIGURATION,
-                    dcGatewayIpListInstanceIdentifier).orNull();
-        } catch (ReadFailedException e) {
+                    dcGatewayIpListInstanceIdentifier).orElse(null);
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("getDcGatewayTunnelInterfaceNameList: unable to read DcGatewayTunnelList, exception ", e);
         }
-        return Optional.fromNullable(dcGatewayIpListConfig);
+        return Optional.ofNullable(dcGatewayIpListConfig);
     }
 
     public List<String> getDcGatewayTunnelInterfaceNameList() {
@@ -352,14 +350,16 @@ public class EvpnUtils {
             LOG.info("No DC gateways configured while programming the l2vni table.");
             return tunnelInterfaceNameList;
         }
-        List<DcGatewayIp> dcGatewayIps = dcGatewayIpListOptional.get().nonnullDcGatewayIp();
+        List<DcGatewayIp> dcGatewayIps
+                = new ArrayList<DcGatewayIp>(dcGatewayIpListOptional.get().nonnullDcGatewayIp().values());
 
         Optional<ExternalTunnelList> externalTunnelListOptional = getExternalTunnelList();
         if (!externalTunnelListOptional.isPresent()) {
             LOG.info("No External Tunnel Configured while programming the l2vni table.");
             return tunnelInterfaceNameList;
         }
-        List<ExternalTunnel> externalTunnels = externalTunnelListOptional.get().nonnullExternalTunnel();
+        List<ExternalTunnel> externalTunnels
+                = new ArrayList<ExternalTunnel>(externalTunnelListOptional.get().nonnullExternalTunnel().values());
 
         dcGatewayIps.forEach(dcIp -> externalTunnels
                 .stream()
@@ -384,7 +384,7 @@ public class EvpnUtils {
                     NwConstants.ELAN_SERVICE_INDEX, NwConstants.COOKIE_ELAN_INGRESS_TABLE, instructions);
             InstanceIdentifier<BoundServices> bindServiceId = ElanUtils.buildServiceId(interfaceName, elanServiceIndex);
             if (!tx.read(bindServiceId).get().isPresent()) {
-                tx.put(bindServiceId, serviceInfo, WriteTransaction.CREATE_MISSING_PARENTS);
+                tx.mergeParentStructurePut(bindServiceId, serviceInfo);
             }
         }), LOG, "Error binding an ELAN service to an external tunnel");
     }
@@ -417,28 +417,33 @@ public class EvpnUtils {
         Uint32 elanTag = elanInfo.getElanTag();
         List<MatchInfo> mkMatches = new ArrayList<>();
         mkMatches.add(new MatchTunnelId(Uint64.valueOf(ElanUtils.getVxlanSegmentationId(elanInfo).longValue())));
-        NWUtil.getOperativeDPNs(broker).forEach(dpnId -> {
-            LOG.debug("Updating tunnel flow to dpnid {}", dpnId);
-            List<InstructionInfo> instructions = getInstructionsForExtTunnelTable(elanTag);
-            String flowRef = getFlowRef(NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE, elanTag.longValue(), dpnId);
-            FlowEntity flowEntity = MDSALUtil.buildFlowEntity(
-                    dpnId,
-                    NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
-                    flowRef,
-                    5, // prio
-                    elanInfo.getElanInstanceName(), // flowName
-                    0, // idleTimeout
-                    0, // hardTimeout
-                    Uint64.valueOf(ITMConstants.COOKIE_ITM_EXTERNAL.longValue() + elanTag.longValue()),
-                    mkMatches,
-                    instructions);
-            flowHandler.accept(dpnId, flowEntity);
-        });
+        try {
+            NWUtil.getOperativeDPNs(broker).forEach(dpnId -> {
+                LOG.debug("Updating tunnel flow to dpnid {}", dpnId);
+                List<InstructionInfo> instructions = getInstructionsForExtTunnelTable(elanTag);
+                String flowRef = getFlowRef(NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE, elanTag.longValue(), dpnId);
+                FlowEntity flowEntity = MDSALUtil.buildFlowEntity(
+                        dpnId,
+                        NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
+                        flowRef,
+                        5, // prio
+                        elanInfo.getElanInstanceName(), // flowName
+                        0, // idleTimeout
+                        0, // hardTimeout
+                        Uint64.valueOf(ITMConstants.COOKIE_ITM_EXTERNAL.longValue() + elanTag.longValue()),
+                        mkMatches,
+                        instructions);
+                flowHandler.accept(dpnId, flowEntity);
+            });
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("programEvpnL2vniFlow: Exception while programming Evpn L2vni flow for elanInstance {}",
+                    elanInfo, e);
+        }
     }
 
     public void programEvpnL2vniDemuxTable(String elanName, final BiConsumer<String, String> serviceHandler,
                                            BiConsumer<Uint64, FlowEntity> flowHandler) {
-        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orElse(null);
         List<String> tunnelInterfaceNameList = getDcGatewayTunnelInterfaceNameList();
         if (tunnelInterfaceNameList.isEmpty()) {
             LOG.info("No DC gateways tunnels while programming l2vni table for elan {}.", elanName);
@@ -456,7 +461,7 @@ public class EvpnUtils {
             SettableFuture<Optional<T>> settableFuture = SettableFuture.create();
             List futures = Collections.singletonList(settableFuture);
 
-            try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            try (ReadTransaction tx = broker.newReadOnlyTransaction()) {
                 Futures.addCallback(tx.read(datastoreType, iid),
                         new SettableFutureCallback<Optional<T>>(settableFuture) {
                             @Override