Java 8 migration 99/68499/7
authorStephen Kitt <skitt@redhat.com>
Thu, 22 Feb 2018 12:51:18 +0000 (13:51 +0100)
committerSam Hague <shague@redhat.com>
Wed, 4 Apr 2018 15:53:24 +0000 (15:53 +0000)
* Use method references instead of lambda expressions where
  appropriate.
* Use lambda expressions instead of anonymous functions where
  appropriate.
* Use Map::forEach instead of streaming over entry sets and retrieving
  matching values.
* Use Map::computeIfAbsent instead of manually handling missing
  entries.

Change-Id: I815d20d26ad7d7dfdf36b8f11d4d813ebc402457
Signed-off-by: Stephen Kitt <skitt@redhat.com>
29 files changed:
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/AbstractAclServiceImpl.java
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/EgressAclServiceImpl.java
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java
aclservice/shell/src/main/java/org/opendaylight/netvirt/aclservice/shell/DisplayAclDataCaches.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpL2GwUtil.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/listeners/EvpnElanInstanceListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/handlers/NodeCopier.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HAOpNodeListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/ManagerListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/merge/MergeCommandsAggregator.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepPhysicalSwitchListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/L2GatewayConnectionListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/StaleVlanBindingsCleaner.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BaseVrfEntryHandler.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BgpRouteVrfEntryHandler.java
ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/IfMgr.java
ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/utils/Ipv6PeriodicTrQueue.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GatewayListener.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertManager.java
statistics/impl/src/main/java/org/opendaylight/netvirt/statistics/CounterResultDataStructure.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/InterfaceStateChangeListener.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnInterfaceManager.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java

index a717de6d6d67269f83e5542e6f9d89cd14527144..da7768153d973607ae6ca91c385a470c8a6f4c21 100644 (file)
@@ -612,7 +612,7 @@ public abstract class AbstractAclServiceImpl implements AclServiceListener {
                 programAclDispatcherTable(port, NwConstants.ADD_FLOW);
             }
         }
-        Set<BigInteger> dpns = interfaceList.stream().map(port -> port.getDpId()).collect(Collectors.toSet());
+        Set<BigInteger> dpns = interfaceList.stream().map(AclInterface::getDpId).collect(Collectors.toSet());
 
         programRemoteAclTable(aclName, remoteAclsDeleted, dpns, NwConstants.DEL_FLOW);
         programRemoteAclTable(aclName, remoteAclsAdded, dpns, NwConstants.ADD_FLOW);
@@ -625,8 +625,8 @@ public abstract class AbstractAclServiceImpl implements AclServiceListener {
                 continue;
             }
             Set<AllowedAddressPairs> aaps =
-                    remoteAclInterfaces.stream().map(port -> port.getAllowedAddressPairs()).flatMap(List::stream)
-                            .filter(aap -> AclServiceUtils.isNotIpAllNetwork(aap)).collect(Collectors.toSet());
+                    remoteAclInterfaces.stream().map(AclInterface::getAllowedAddressPairs).flatMap(List::stream)
+                            .filter(AclServiceUtils::isNotIpAllNetwork).collect(Collectors.toSet());
 
             Integer aclTag = aclServiceUtils.getAclTag(remoteAclId);
             if (addOrRemove == NwConstants.ADD_FLOW) {
index 1efa1021812cb50df776ff51a3fdab60f8cbbb89..c9b8951f25e4ba07bcb3f3a8499f0a7defd972d0 100644 (file)
@@ -346,7 +346,8 @@ public class EgressAclServiceImpl extends AbstractAclServiceImpl {
         BigInteger dpId = port.getDpId();
         int lportTag = port.getLPortTag();
         List<AllowedAddressPairs> allowedAddresses = port.getAllowedAddressPairs();
-        Set<MacAddress> macs = allowedAddresses.stream().map(aap -> aap.getMacAddress()).collect(Collectors.toSet());
+        Set<MacAddress> macs =
+                allowedAddresses.stream().map(AllowedAddressPairs::getMacAddress).collect(Collectors.toSet());
         for (MacAddress mac : macs) {
             List<MatchInfoBase> matches = new ArrayList<>();
             matches.add(new MatchEthernetSource(mac));
index 5836f80f4ee46793d655792c385b2418f1a47459..3103b32d9b613af8e8dd1947a6edcdbf61e86581 100644 (file)
@@ -1216,7 +1216,7 @@ public final class AclServiceUtils {
             List<PortIds> portIds = new ArrayList<>(aclIpPrefixes.getPortIds());
             // Checking if there are any other ports excluding ignorePorts
             long noOfRemotePorts =
-                    portIds.stream().map(x -> x.getPortId()).filter(y -> !ignorePorts.contains(y)).count();
+                    portIds.stream().map(PortIds::getPortId).filter(y -> !ignorePorts.contains(y)).count();
             if (noOfRemotePorts > 0) {
                 skipDelete = true;
             }
index b38097e99ca3fdb43907adfa7644c101a4b8820e..5beec73aed73cb96602fee704dea767db247b06a 100644 (file)
@@ -42,7 +42,7 @@ public class DisplayAclDataCaches extends OsgiCommandSupport {
     private static final String REM_ID_TAB_FOR = KEY_TAB + REM_ID_TAB;
     private static final String REM_ID_HEAD = String.format(REM_ID_TAB_FOR, "Remote-ACL-ID", "ACL-ID")
             + "\n   -------------------------------------------------------------------------";
-    private static final String ACL_DATA_TAB_FOR = "   %-8s %-8s  ";
+    private static final String ACL_DATA_TAB_FOR = "   %-8s %-8s  %n";
     private static final String ACL_DATA_HEAD = String.format(ACL_DATA_TAB_FOR, "ACL-ID", "ACL-TAG")
             + "\n   -------------------------------------------------------------------------";
     private static final String ACL_HEAD = String.format(ACL_DATA_TAB_FOR, "ACL-ID", "ACL")
@@ -280,7 +280,7 @@ public class DisplayAclDataCaches extends OsgiCommandSupport {
                 session.getConsole().println("No data found");
                 return;
             }
-            session.getConsole().println(ACL_DATA_HEAD);
+            session.getConsole().print(ACL_DATA_HEAD);
             session.getConsole().println(String.format(ACL_DATA_TAB_FOR, key, val));
         } else if (key == null) {
             if (!validateAll()) {
@@ -291,7 +291,7 @@ public class DisplayAclDataCaches extends OsgiCommandSupport {
             if (map.isEmpty()) {
                 session.getConsole().println("No data found");
             } else {
-                session.getConsole().println(ACL_DATA_HEAD);
+                session.getConsole().print(ACL_DATA_HEAD);
                 map.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(entry -> session.getConsole()
                         .println(String.format(ACL_DATA_TAB_FOR, entry.getKey(), entry.getValue())));
             }
@@ -347,8 +347,8 @@ public class DisplayAclDataCaches extends OsgiCommandSupport {
                 session.getConsole().println("No data found");
                 return;
             }
-            session.getConsole().println(ACL_HEAD);
-            session.getConsole().println(String.format(ACL_DATA_TAB_FOR, key, acl));
+            session.getConsole().print(ACL_HEAD);
+            session.getConsole().printf(ACL_DATA_TAB_FOR, key, acl);
         } else if (key == null) {
             if (!validateAll()) {
                 printAclMapHelp();
@@ -358,9 +358,8 @@ public class DisplayAclDataCaches extends OsgiCommandSupport {
             if (map.isEmpty()) {
                 session.getConsole().println("No data found");
             } else {
-                session.getConsole().println(ACL_HEAD);
-                map.entrySet().stream().forEach(entry -> session.getConsole()
-                        .println(String.format(ACL_DATA_TAB_FOR, entry.getKey(), entry.getValue())));
+                session.getConsole().print(ACL_HEAD);
+                map.forEach((string, acl) -> session.getConsole().printf(ACL_DATA_TAB_FOR, string, acl));
             }
         }
     }
index eaa52efbbcce51562c1e412bd0464c80fc2ecb69..a9ca8421bb04c79913fe699f6e017ae4fc1cb660 100644 (file)
@@ -30,13 +30,13 @@ public class DhcpL2GwUtil {
 
     private static final Predicate<List<?>> EMPTY_LIST = (list) -> list == null || list.isEmpty();
 
-    private static final Predicate<Optional<Node>> CONTAINS_GLOBAL_AUGMENTATION = (optionalNode) -> {
-        return optionalNode.isPresent() && optionalNode.get().getAugmentation(HwvtepGlobalAugmentation.class) != null;
-    };
+    private static final Predicate<Optional<Node>> CONTAINS_GLOBAL_AUGMENTATION =
+        (optionalNode) -> optionalNode.isPresent()
+                && optionalNode.get().getAugmentation(HwvtepGlobalAugmentation.class) != null;
 
-    private static final Predicate<Optional<Node>> CONTAINS_SWITCH_AUGMENTATION = (optionalNode) -> {
-        return optionalNode.isPresent() && optionalNode.get().getAugmentation(PhysicalSwitchAugmentation.class) != null;
-    };
+    private static final Predicate<Optional<Node>> CONTAINS_SWITCH_AUGMENTATION =
+        (optionalNode) -> optionalNode.isPresent()
+                && optionalNode.get().getAugmentation(PhysicalSwitchAugmentation.class) != null;
 
     private final DataBroker dataBroker;
     private final L2GatewayCache l2GatewayCache;
index 897e1546c8a9b7f755ccb34f9363a7544ecc6e4d..5ae2ca6fb287273aeee2c408df15f07a290c452a 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.elan.cli.l2gw;
 
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.File;
@@ -23,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.stream.Collectors;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -312,8 +312,8 @@ public class L2GwValidateCli extends OsgiCommandSupport {
                 data2 = cmd.transform(nodeIid1, data2);
             }
             Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
-            data1 = Lists.transform(data1, withoutUuidTransformer);
-            data2 = Lists.transform(data2, withoutUuidTransformer);
+            data1 = data1.stream().map(withoutUuidTransformer).collect(Collectors.toList());
+            data2 = data2.stream().map(withoutUuidTransformer).collect(Collectors.toList());
 
             Map<Identifier<?>, DataObject> map1 = new HashMap<>();
             Map<Identifier<?>, DataObject> map2 = new HashMap<>();
index 7322a80b9cf980660bb7357ce01ee044d42a123e..cdf478f52fc57feb436253e81ffd5ce7e485a572 100644 (file)
@@ -73,13 +73,13 @@ public class EvpnElanInstanceListener extends AsyncDataTreeChangeListenerBase<El
             evpnMacVrfUtils.updateEvpnDmacFlows(original, false);
             evpnUtils.programEvpnL2vniDemuxTable(elanName,
                 (elan, interfaceName) -> evpnUtils.bindElanServiceToExternalTunnel(elanName, interfaceName),
-                (dpnId, flowEntity) -> mdsalManager.installFlow(dpnId, flowEntity));
+                    mdsalManager::installFlow);
         } else if (evpnUtils.isAdvertiseEvpnRT2Routes(original, update)) {
             evpnUtils.advertiseEvpnRT2Routes(update.getAugmentation(EvpnAugmentation.class), elanName);
             evpnMacVrfUtils.updateEvpnDmacFlows(update, true);
             evpnUtils.programEvpnL2vniDemuxTable(elanName,
                 (elan, interfaceName) -> evpnUtils.unbindElanServiceFromExternalTunnel(elanName, interfaceName),
-                (dpnId, flowEntity) -> mdsalManager.removeFlow(dpnId, flowEntity));
+                    mdsalManager::removeFlow);
         }
     }
 
index 415dd536eb871f315f83668b310a01a018e0cd9d..822f2f620567dce1f61e30990f58f15b1c67c21f 100644 (file)
@@ -439,9 +439,7 @@ public class EvpnUtils {
             return;
         }
 
-        tunnelInterfaceNameList.forEach(tunnelInterfaceName -> {
-            serviceHandler.accept(elanName, tunnelInterfaceName);
-        });
+        tunnelInterfaceNameList.forEach(tunnelInterfaceName -> serviceHandler.accept(elanName, tunnelInterfaceName));
         programEvpnL2vniFlow(elanInfo, flowHandler);
     }
 
index 2eecca0685ec559fe6261e789012c3c831f6252e..a1e6496b928e5cfeb0ff37112c989f0684997597 100644 (file)
@@ -123,7 +123,7 @@ public class NodeCopier implements INodeCopier {
             haBuilder.setManagers(HwvtepHAUtil.buildManagersForHANode(srcGlobalNodeOptional.get(),
                     existingDstGlobalNodeOptional));
             //Also update the manager section in config which helps in cluster reboot scenarios
-            haBuilder.getManagers().stream().forEach((manager) -> {
+            haBuilder.getManagers().forEach((manager) -> {
                 InstanceIdentifier<Managers> managerIid = dstPath.augmentation(HwvtepGlobalAugmentation.class)
                         .child(Managers.class, manager.getKey());
                 tx.put(CONFIGURATION, managerIid, manager, true);
index edefaf07fc2161fc9a6024eea40d006325c3570e..05fc5c995d45f1add6ab48f59a4b44ce321731aa 100644 (file)
@@ -215,7 +215,7 @@ public class HAOpNodeListener extends HwvtepNodeBaseListener {
             haOpClusteredListener.getConnectedNodes()
                     .stream()
                     .filter((connectedIid) -> IS_PS_CHILD_TO_GLOBAL_NODE.test(childGlobalNodeId, connectedIid))
-                    .forEach((connectedIid) -> childPsIids.add(connectedIid));
+                    .forEach(childPsIids::add);
         } else {
             hwvtepGlobalAugmentation.getSwitches().forEach(
                 (switches) -> childPsIids.add(switches.getSwitchRef().getValue()));
index f91ddb2dd61a05c20097909c930f29108266567c..0826ef166200b1e0dba56d0349df936fca8772c6 100644 (file)
@@ -65,7 +65,7 @@ public final class ManagerListener extends AsyncClusteredDataTreeChangeListenerB
                 && managers.getManagerOtherConfigs() != null) {
             managers.getManagerOtherConfigs().stream()
                 .filter(otherConfig -> otherConfig.getKey().getOtherConfigKey().contains(HwvtepHAUtil.HA_CHILDREN))
-                .flatMap(otherConfig -> Arrays.asList(otherConfig.getOtherConfigValue().split(",")).stream())
+                .flatMap(otherConfig -> Arrays.stream(otherConfig.getOtherConfigValue().split(",")))
                 .map(HwvtepHAUtil::convertToInstanceIdentifier)
                 .forEach(childIid -> HwvtepHACache.getInstance().addChild(parent, childIid));
         }
index 8e22a4f29eb35a9847280027b33db0e5b03a5213..271829605919e12c2121df2faa74af84301ca239 100644 (file)
@@ -38,10 +38,9 @@ public abstract class MergeCommandsAggregator<BuilderTypeT extends Builder, AugT
 
     protected Map<Class<?>, MergeCommand> commands = new HashMap<>();
 
-    private final BiPredicate<LogicalDatastoreType, Class> skipCopy = (dsType, cmdType) -> {
-        return (dsType == CONFIGURATION ? commands.get(cmdType) instanceof LocalUcastCmd :
-                commands.get(cmdType) instanceof RemoteUcastCmd);
-    };
+    private final BiPredicate<LogicalDatastoreType, Class> skipCopy =
+        (dsType, cmdType) -> (dsType == CONFIGURATION ? commands.get(cmdType) instanceof LocalUcastCmd
+                : commands.get(cmdType) instanceof RemoteUcastCmd);
 
     protected MergeCommandsAggregator() {
     }
index f43258472b1a0c2a6f4a86929e122213f83e6ed3..d2ba464009aea0374bcdef8a397d7b36ff2c9b84 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeLis
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 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.hwvtep.HwvtepAbstractDataTreeChangeListener;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
@@ -72,11 +71,9 @@ public class HwvtepPhysicalSwitchListener
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalSwitchListener.class);
 
     private static final BiPredicate<L2GatewayDevice, InstanceIdentifier<Node>> DEVICE_NOT_CACHED_OR_PARENT_CONNECTED =
-        (l2GatewayDevice, globalIid) -> {
-            return l2GatewayDevice == null || l2GatewayDevice.getHwvtepNodeId() == null
-                    || !Objects.equals(l2GatewayDevice.getHwvtepNodeId(),
-                            globalIid.firstKeyOf(Node.class).getNodeId().getValue());
-        };
+        (l2GatewayDevice, globalIid) -> l2GatewayDevice == null || l2GatewayDevice.getHwvtepNodeId() == null
+                || !Objects.equals(l2GatewayDevice.getHwvtepNodeId(),
+                        globalIid.firstKeyOf(Node.class).getNodeId().getValue());
 
     private static final Predicate<PhysicalSwitchAugmentation> TUNNEL_IP_AVAILABLE =
         phySwitch -> !HwvtepHAUtil.isEmpty(phySwitch.getTunnelIps());
@@ -84,11 +81,9 @@ public class HwvtepPhysicalSwitchListener
     private static final Predicate<PhysicalSwitchAugmentation> TUNNEL_IP_NOT_AVAILABLE = TUNNEL_IP_AVAILABLE.negate();
 
     private static final BiPredicate<PhysicalSwitchAugmentation, L2GatewayDevice> TUNNEL_IP_CHANGED =
-        (phySwitchAfter, existingDevice) -> {
-            return TUNNEL_IP_AVAILABLE.test(phySwitchAfter)
-                    && !Objects.equals(
-                            existingDevice.getTunnelIp(),  phySwitchAfter.getTunnelIps().get(0).getTunnelIpsKey());
-        };
+        (phySwitchAfter, existingDevice) -> TUNNEL_IP_AVAILABLE.test(phySwitchAfter)
+                && !Objects.equals(
+                        existingDevice.getTunnelIp(),  phySwitchAfter.getTunnelIps().get(0).getTunnelIpsKey());
 
     /** The data broker. */
     private final DataBroker dataBroker;
@@ -113,9 +108,7 @@ public class HwvtepPhysicalSwitchListener
         };
 
     private final Predicate<L2GatewayDevice> alreadyHasL2Gwids =
-        (l2GwDevice) -> {
-            return l2GwDevice != null && HwvtepHAUtil.isEmpty(l2GwDevice.getL2GatewayIds());
-        };
+        (l2GwDevice) -> l2GwDevice != null && HwvtepHAUtil.isEmpty(l2GwDevice.getL2GatewayIds());
 
     private final BiPredicate<L2GatewayDevice, InstanceIdentifier<Node>> parentConnectedAfterChild =
         (l2GwDevice, globalIid) -> {
@@ -322,14 +315,8 @@ public class HwvtepPhysicalSwitchListener
             }
 
             handleAdd(l2GwDevice);
-            elanClusterUtils.runOnlyInOwnerNode("Update config tunnels IP ", () -> {
-                try {
-                    updateConfigTunnelIp(identifier, phySwitchAdded);
-                } catch (ReadFailedException e) {
-                    LOG.error("Failed to update tunnel ips {}", identifier);
-                }
-            });
-            return;
+            elanClusterUtils.runOnlyInOwnerNode("Update config tunnels IP ",
+                () -> updateConfigTunnelIp(identifier, phySwitchAdded));
         });
     }
 
@@ -409,7 +396,7 @@ public class HwvtepPhysicalSwitchListener
     }
 
     private void updateConfigTunnelIp(InstanceIdentifier<PhysicalSwitchAugmentation> identifier,
-                                      PhysicalSwitchAugmentation phySwitchAdded) throws ReadFailedException {
+                                      PhysicalSwitchAugmentation phySwitchAdded) {
         if (phySwitchAdded.getTunnelIps() != null) {
             ListenableFutures.addErrorLogging(
                 txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
index a0d2e0d989e76ac1208b11ff662218fe514022cd..4ccf0c2c6d2bb447cd30dc88e7a983699a222519 100644 (file)
@@ -55,21 +55,16 @@ public class L2GatewayConnectionListener extends AsyncClusteredDataTreeChangeLis
     private static final Logger LOG = LoggerFactory.getLogger(L2GatewayConnectionListener.class);
     private static final int MAX_READ_TRIALS = 120;
 
-    private static final Function<Node, InstanceIdentifier<Node>> TO_GLOBAL_PATH = (psNode) -> {
-        return HwvtepHAUtil.getGlobalNodePathFromPSNode(psNode);
-    };
+    private static final Function<Node, InstanceIdentifier<Node>> TO_GLOBAL_PATH =
+            HwvtepHAUtil::getGlobalNodePathFromPSNode;
 
-    private static final Function<Node, InstanceIdentifier<Node>> TO_NODE_PATH = (node) -> {
-        return HwvtepSouthboundUtils.createInstanceIdentifier(node.getNodeId());
-    };
+    private static final Function<Node, InstanceIdentifier<Node>> TO_NODE_PATH =
+        (node) -> HwvtepSouthboundUtils.createInstanceIdentifier(node.getNodeId());
 
-    private static final Function<InstanceIdentifier<Node>, String> GET_DEVICE_NAME = (psIid) -> {
-        return HwvtepHAUtil.getPsName(psIid);
-    };
+    private static final Function<InstanceIdentifier<Node>, String> GET_DEVICE_NAME = HwvtepHAUtil::getPsName;
 
-    private static final Predicate<InstanceIdentifier<Node>> IS_PS_NODE = (psIid) -> {
-        return HwvtepHAUtil.getPsName(psIid) != null;
-    };
+    private static final Predicate<InstanceIdentifier<Node>> IS_PS_NODE = (psIid) ->
+            HwvtepHAUtil.getPsName(psIid) != null;
 
     private static final Predicate<Node> IS_HA_PARENT_NODE = (node) -> {
         HwvtepGlobalAugmentation augmentation = node.getAugmentation(HwvtepGlobalAugmentation.class);
@@ -80,9 +75,8 @@ public class L2GatewayConnectionListener extends AsyncClusteredDataTreeChangeLis
         return false;
     };
 
-    private static final BiPredicate<InstanceIdentifier<Node>, Node> PS_NODE_OF_PARENT_NODE = (psIid, node) -> {
-        return psIid.firstKeyOf(Node.class).getNodeId().getValue().contains(node.getNodeId().getValue());
-    };
+    private static final BiPredicate<InstanceIdentifier<Node>, Node> PS_NODE_OF_PARENT_NODE =
+        (psIid, node) -> psIid.firstKeyOf(Node.class).getNodeId().getValue().contains(node.getNodeId().getValue());
 
     private final DataBroker broker;
     private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
@@ -186,14 +180,10 @@ public class L2GatewayConnectionListener extends AsyncClusteredDataTreeChangeLis
         //Process HA nodes
         allNodes.values().stream()
                 .filter(IS_HA_PARENT_NODE)
-                .forEach(parentNode -> {
-                    allIids.stream()
-                            .filter(IS_PS_NODE)
-                            .filter(psIid -> PS_NODE_OF_PARENT_NODE.test(psIid, parentNode))
-                            .forEach(psIid -> {
-                                addL2DeviceToCache(psIid, parentNode, allNodes.get(psIid));
-                            });
-                });
+                .forEach(parentNode -> allIids.stream()
+                        .filter(IS_PS_NODE)
+                        .filter(psIid -> PS_NODE_OF_PARENT_NODE.test(psIid, parentNode))
+                        .forEach(psIid -> addL2DeviceToCache(psIid, parentNode, allNodes.get(psIid))));
 
         //Process non HA nodes there will be only one ps node iid for each device for non ha nodes
         psNodesByDeviceName.values().stream()
index 74d4881e697a7171690520485c6ac259ac601c08..a525acdce9bed65b4adddc68b3bf52c97f5cadbb 100644 (file)
@@ -537,7 +537,7 @@ public class ElanL2GatewayUtils {
                             if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
                                 macs.addAll(augmentation.getLocalUcastMacs().stream()
                                         .filter(mac -> getLogicalSwitchName(mac).equals(elanName))
-                                        .map(mac -> mac.getMacEntryKey())
+                                        .map(HwvtepMacTableGenericAttributes::getMacEntryKey)
                                         .collect(Collectors.toSet()));
                             }
                             function.apply(macs);
@@ -1096,16 +1096,15 @@ public class ElanL2GatewayUtils {
 
     public void scheduleDeleteLogicalSwitch(final NodeId hwvtepNodeId, final String lsName, final boolean clearUcast) {
         final Pair<NodeId, String> nodeIdLogicalSwitchNamePair = new ImmutablePair<>(hwvtepNodeId, lsName);
-        logicalSwitchDeletedTasks.computeIfAbsent(nodeIdLogicalSwitchNamePair, (key) -> {
-            return scheduler.getScheduledExecutorService().schedule(() -> {
+        logicalSwitchDeletedTasks.computeIfAbsent(nodeIdLogicalSwitchNamePair,
+            (key) -> scheduler.getScheduledExecutorService().schedule(() -> {
                 DeleteLogicalSwitchJob deleteLsJob = new DeleteLogicalSwitchJob(broker,
                         ElanL2GatewayUtils.this, hwvtepNodeId, lsName, clearUcast);
                 jobCoordinator.enqueueJob(deleteLsJob.getJobKey(), deleteLsJob,
                         SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
                 deleteJobs.put(nodeIdLogicalSwitchNamePair, deleteLsJob);
                 logicalSwitchDeletedTasks.remove(nodeIdLogicalSwitchNamePair);
-            }, getLogicalSwitchDeleteDelaySecs(), TimeUnit.SECONDS);
-        });
+            }, getLogicalSwitchDeleteDelaySecs(), TimeUnit.SECONDS));
     }
 
     public void cancelDeleteLogicalSwitch(final NodeId hwvtepNodeId, final String lsName) {
@@ -1157,7 +1156,7 @@ public class ElanL2GatewayUtils {
             if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
                 macs.addAll(augmentation.getLocalUcastMacs().stream()
                         .filter(mac -> getLogicalSwitchName(mac).equals(elanName))
-                        .map(mac -> mac.getMacEntryKey())
+                        .map(HwvtepMacTableGenericAttributes::getMacEntryKey)
                         .collect(Collectors.toSet()));
             }
         }
index c21dbac829b7807c9f6f52b21d86adbf191a4d12..4d59714d90cb42e3f0254685456f635f647b6126 100644 (file)
@@ -382,9 +382,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
                                         return;
                                     }
                                     localUcastMacs.stream()
-                                            .filter((mac) -> {
-                                                return macBelongsToLogicalSwitch(mac, elanName);
-                                            })
+                                            .filter((mac) -> macBelongsToLogicalSwitch(mac, elanName))
                                             .forEach((mac) -> {
                                                 InstanceIdentifier<LocalUcastMacs> macIid = getMacIid(nodeIid, mac);
                                                 localUcastMacListener.added(macIid, mac);
index 4bd8aebbebd37d6070b9bc29b40f2d2d9402e581..620b2ebebc0a9f6106ef297dc7707221d82a8f1c 100644 (file)
@@ -157,11 +157,9 @@ public class StaleVlanBindingsCleaner {
         Map<String, List<InstanceIdentifier<VlanBindings>>> vlans = new HashMap<>();
         ports.stream()
                 .filter(CONTAINS_VLANBINDINGS)
-                .forEach((port) -> {
-                    port.getAugmentation(HwvtepPhysicalPortAugmentation.class)
-                            .getVlanBindings()
-                            .forEach((binding) -> putVlanBindingVsLogicalSwitch(configPsNode, vlans, port, binding));
-                });
+                .forEach((port) -> port.getAugmentation(HwvtepPhysicalPortAugmentation.class)
+                        .getVlanBindings()
+                        .forEach((binding) -> putVlanBindingVsLogicalSwitch(configPsNode, vlans, port, binding)));
         return vlans;
     }
 
index 08cfd155d8fd3c8a737b732522eeaec8e48b9583..6a0b078bfacc546476a9f2f18778b6558845d219 100644 (file)
@@ -161,17 +161,15 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                     prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
                 } else {
                     List<String> prefixIpListLocal = new ArrayList<>();
-                    vpnExtraRoutes.stream().forEach(route -> {
-                        route.getNexthopIpList().stream().forEach(extraRouteIp -> {
-                            String ipPrefix;
-                            if (isIpv4Address(extraRouteIp)) {
-                                ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
-                            } else {
-                                ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
-                            }
-                            prefixIpListLocal.add(ipPrefix);
-                        });
-                    });
+                    vpnExtraRoutes.forEach(route -> route.getNexthopIpList().forEach(extraRouteIp -> {
+                        String ipPrefix;
+                        if (isIpv4Address(extraRouteIp)) {
+                            ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
+                        } else {
+                            ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
+                        }
+                        prefixIpListLocal.add(ipPrefix);
+                    }));
                     prefixIpList = prefixIpListLocal;
                 }
             } else {
index 4e786feaf3f34ec1f1624640cbd34414c5bd8eb1..ffa75d25f880417c1b3316418ccb7868daf554d9 100644 (file)
@@ -250,7 +250,7 @@ public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler
         // ECMP Use case, point to LB group. Move the mpls label accordingly.
         List<String> tunnelList =
                 adjacencyResults.stream()
-                        .map(adjacencyResult -> adjacencyResult.getNextHopIp())
+                        .map(NexthopManager.AdjacencyResult::getNextHopIp)
                         .sorted().collect(toList());
         String lbGroupKey = FibUtil.getGreLbGroupKey(tunnelList);
         long groupId = nexthopManager.createNextHopPointer(lbGroupKey);
index 97d174b188eeb74211b6e2e2eaaefe7afdc111a1..0243bcd49cdccc0bdd395aa0213850fc043fbfc3 100644 (file)
@@ -82,7 +82,7 @@ public class IfMgr implements ElementCache, AutoCloseable {
     private final DataBroker dataBroker;
     private final Ipv6ServiceEosHandler ipv6ServiceEosHandler;
     private final PacketProcessingService packetService;
-    private final Ipv6PeriodicTrQueue ipv6Queue = new Ipv6PeriodicTrQueue(portId -> transmitUnsolicitedRA(portId));
+    private final Ipv6PeriodicTrQueue ipv6Queue = new Ipv6PeriodicTrQueue(this::transmitUnsolicitedRA);
     private final Ipv6TimerWheel timer = new Ipv6TimerWheel();
 
     @Inject
index c79b329157f721d80b7607ba210707020c26fd0c..a17adef3a5811c9e54eb49c5c43e62f857e37636 100644 (file)
@@ -24,7 +24,7 @@ public class Ipv6PeriodicTrQueue implements AutoCloseable {
 
     private final Consumer<Uuid> onMessage;
     private final ConcurrentLinkedQueue<Uuid> ipv6PeriodicQueue = new ConcurrentLinkedQueue<>();
-    private final Thread transmitterThread = new Thread(() -> threadRunLoop());
+    private final Thread transmitterThread = new Thread(this::threadRunLoop);
     private final ReentrantLock queueLock = new ReentrantLock();
     private final Condition queueCondition = queueLock.newCondition();
     private volatile boolean closed;
index 3d3d614fb5cb6978b8a8315eac9f6ca8636082e4..0a9557b3d84ba8cfb4f3b1a7129a4afc5a3a21ba 100644 (file)
@@ -2011,17 +2011,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 nbNextHops++;
                 nextHopList.add(new String(routeTmp.getNexthop().getValue()));
             }
-            final List<String> rdList = new ArrayList();
+            final List<String> rdList = new ArrayList<>();
             if (vpnInstance.getIpv4Family() != null
                     && vpnInstance.getIpv4Family().getRouteDistinguisher() != null) {
-                vpnInstance.getIpv4Family().getRouteDistinguisher().stream().forEach(rd -> {
+                vpnInstance.getIpv4Family().getRouteDistinguisher().forEach(rd -> {
                     if (rd != null) {
                         rdList.add(rd);
                     }
                 });
             }
             if (vpnInstance.getIpv6Family() != null && vpnInstance.getIpv6Family().getRouteDistinguisher() != null) {
-                vpnInstance.getIpv6Family().getRouteDistinguisher().stream().forEach(rd -> {
+                vpnInstance.getIpv6Family().getRouteDistinguisher().forEach(rd -> {
                     if (rd != null && !rdList.contains(rd)) {
                         rdList.add(rd);
                     }
index 50e86c26f7c963b17d8e7eca81b5dcdf6f853b13..4953122d8d5677a33188327ee065e8fcba2fe618 100644 (file)
@@ -130,8 +130,7 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
             return;
         }
         if (original.getDevices() == null) {
-            connections.forEach(
-                (connection) -> l2gwService.addL2GatewayConnection(connection));
+            connections.forEach(l2gwService::addL2GatewayConnection);
             return;
         }
         jobCoordinator.enqueueJob("l2gw.update", () -> {
@@ -150,23 +149,21 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
                                 .stream()
                                 .filter((intf) -> !updatedDeviceInterfaces.containsInterface(
                                         deviceName, intf.getInterfaceName()))
-                                .forEach((intf) -> {
-                                    connections.forEach((connection) -> {
-                                        Integer vlanId = connection.getSegmentId();
-                                        if (intf.getSegmentationIds() != null
-                                                && !intf.getSegmentationIds().isEmpty()) {
-                                            for (Integer vlan : intf.getSegmentationIds()) {
-                                                HwvtepUtils.deleteVlanBinding(transaction,
-                                                        physicalSwitchNodeId, intf.getInterfaceName(), vlan);
-                                            }
-                                        } else {
-                                            LOG.debug("Deleting vlan binding {} {} {}",
-                                                    physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
-                                            HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId,
-                                                    intf.getInterfaceName(), vlanId);
+                                .forEach((intf) -> connections.forEach((connection) -> {
+                                    Integer vlanId = connection.getSegmentId();
+                                    if (intf.getSegmentationIds() != null
+                                            && !intf.getSegmentationIds().isEmpty()) {
+                                        for (Integer vlan : intf.getSegmentationIds()) {
+                                            HwvtepUtils.deleteVlanBinding(transaction,
+                                                    physicalSwitchNodeId, intf.getInterfaceName(), vlan);
                                         }
-                                    });
-                                });
+                                    } else {
+                                        LOG.debug("Deleting vlan binding {} {} {}",
+                                                physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
+                                        HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId,
+                                                intf.getInterfaceName(), vlanId);
+                                    }
+                                }));
                     });
             fts.add(transaction.submit());
             Futures.addCallback(fts.get(0), new FutureCallback<Void>() {
index b92c955e0c6dfb70479054cca41cc77b6fc0d653..b302d29bca69ea5ec1e5dcf94b528610ee288d3c 100644 (file)
@@ -376,7 +376,7 @@ public final class QosAlertManager implements Runnable {
 
     private void initPortStatsData() {
         qosAlertDpnPortNumberMap.values().forEach(portDataMap -> portDataMap.values()
-                .forEach(portData -> portData.initPortData()));
+                .forEach(QosAlertPortData::initPortData));
     }
 
     private static class AlertThresholdSupplier implements Supplier<BigInteger> {
index 3864e22409d09c5899350623a390b1cb56253dca..5e674ab6abb81274a8b82231ac8f80eacf3607f5 100644 (file)
@@ -82,11 +82,7 @@ public class CounterResultDataStructure {
             return;
         }
 
-        if (results.get(id).get(groupName) == null) {
-            results.get(id).put(groupName, new HashMap<>());
-        }
-
-        results.get(id).get(groupName).put(counterName, counterValue);
+        results.get(id).computeIfAbsent(groupName, k -> new HashMap<>()).put(counterName, counterValue);
     }
 
     public Set<String> getGroupCounterNames(String groupName) {
index bbbf3bbbfafce96a550d88a584d18cf0eaedd9eb..792c8ba79705598f3d24989775121296cd11fb7f 100644 (file)
@@ -165,42 +165,40 @@ public class InterfaceStateChangeListener
                 final BigInteger inputDpId = dpId;
                 jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
                     List<ListenableFuture<Void>> futures = new ArrayList<>(3);
-                    ListenableFuture<Void> configFuture = txRunner
-                        .callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
-                            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
-                                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
-                                    VpnInterface cfgVpnInterface =
-                                            VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
-                                    if (cfgVpnInterface == null) {
-                                        LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
-                                        return;
-                                    }
-                                    for (VpnInstanceNames vpnInterfaceVpnInstance :
-                                            cfgVpnInterface.getVpnInstanceNames()) {
-                                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
-                                        Optional<VpnInterfaceOpDataEntry> optVpnInterface =
-                                                VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, ifName, vpnName);
-                                        if (!optVpnInterface.isPresent()) {
-                                            LOG.debug("Interface {} vpn {} is not a vpninterface, or deletion"
-                                                    + " triggered by northbound agent. ignoring.", ifName, vpnName);
-                                            continue;
+                    ListenableFuture<Void> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                        writeConfigTxn -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                            writeOperTxn -> futures.add(
+                                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
+                                        VpnInterface cfgVpnInterface =
+                                                VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
+                                        if (cfgVpnInterface == null) {
+                                            LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
+                                            return;
                                         }
-                                        final VpnInterfaceOpDataEntry vpnInterface = optVpnInterface.get();
-                                        String gwMac = intrf.getPhysAddress() != null ? intrf.getPhysAddress()
-                                                .getValue() : vpnInterface.getGatewayMacAddress();
-                                        BigInteger dpnId = inputDpId;
-                                        if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
-                                            dpnId = vpnInterface.getDpnId();
+                                        for (VpnInstanceNames vpnInterfaceVpnInstance :
+                                                cfgVpnInterface.getVpnInstanceNames()) {
+                                            String vpnName = vpnInterfaceVpnInstance.getVpnName();
+                                            Optional<VpnInterfaceOpDataEntry> optVpnInterface =
+                                                    VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, ifName, vpnName);
+                                            if (!optVpnInterface.isPresent()) {
+                                                LOG.debug("Interface {} vpn {} is not a vpninterface, or deletion"
+                                                        + " triggered by northbound agent. ignoring.", ifName, vpnName);
+                                                continue;
+                                            }
+                                            final VpnInterfaceOpDataEntry vpnInterface = optVpnInterface.get();
+                                            String gwMac = intrf.getPhysAddress() != null ? intrf.getPhysAddress()
+                                                    .getValue() : vpnInterface.getGatewayMacAddress();
+                                            BigInteger dpnId = inputDpId;
+                                            if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
+                                                dpnId = vpnInterface.getDpnId();
+                                            }
+                                            final int ifIndex = intrf.getIfIndex();
+                                            LOG.info("VPN Interface remove event - intfName {} onto vpnName {}"
+                                                    + " running oper-driver", vpnInterface.getName(), vpnName);
+                                            vpnInterfaceManager.processVpnInterfaceDown(dpnId, ifName, ifIndex, gwMac,
+                                                    vpnInterface, false, writeConfigTxn, writeOperTxn, writeInvTxn);
                                         }
-                                        final int ifIndex = intrf.getIfIndex();
-                                        LOG.info("VPN Interface remove event - intfName {} onto vpnName {}"
-                                                + " running oper-driver", vpnInterface.getName(), vpnName);
-                                        vpnInterfaceManager.processVpnInterfaceDown(dpnId, ifName, ifIndex, gwMac,
-                                                vpnInterface, false, writeConfigTxn, writeOperTxn, writeInvTxn);
-                                    }
-                                }));
-                            }));
-                        });
+                                    })))));
                     futures.add(configFuture);
                     Futures.addCallback(configFuture, new PostVpnInterfaceThreadWorker(intrf.getName(), false,
                             "Operational"));
@@ -236,64 +234,66 @@ public class InterfaceStateChangeListener
                         update.getName());
                 jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
                     List<ListenableFuture<Void>> futures = new ArrayList<>(3);
-                    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
-                        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
-                            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
-                                final VpnInterface vpnIf =
-                                        VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
-                                if (vpnIf != null) {
-                                    final int ifIndex = update.getIfIndex();
-                                    BigInteger dpnId = BigInteger.ZERO;
-                                    try {
-                                        dpnId = InterfaceUtils.getDpIdFromInterface(update);
-                                    } catch (Exception e) {
-                                        LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
-                                        return;
-                                    }
-                                    if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
-                                        for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
-                                            String vpnName = vpnInterfaceVpnInstance.getVpnName();
-                                            String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
-                                            if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
-                                                LOG.error("VPN Interface update event - intfName {} onto vpnName {} "
-                                                                + "running oper-driven UP, VpnInstance not ready,"
-                                                        + " holding on", vpnIf.getName(), vpnName);
-                                            } else if (VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
-                                                LOG.error("update: Ignoring UP event for vpnInterface {}, as "
-                                                        + "vpnInstance {} with primaryRd {} is already marked for"
-                                                        + " deletion", vpnIf.getName(), vpnName, primaryRd);
-                                            } else {
-                                                vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd,
-                                                        ifIndex, true, writeConfigTxn, writeOperTxn, writeInvTxn,
-                                                        update, vpnName);
-                                            }
+                    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> futures.add(
+                            txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> futures.add(
+                                txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
+                                    final VpnInterface vpnIf =
+                                            VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
+                                    if (vpnIf != null) {
+                                        final int ifIndex = update.getIfIndex();
+                                        BigInteger dpnId = BigInteger.ZERO;
+                                        try {
+                                            dpnId = InterfaceUtils.getDpIdFromInterface(update);
+                                        } catch (Exception e) {
+                                            LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
+                                            return;
                                         }
-                                    } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
-                                        for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
-                                            String vpnName = vpnInterfaceVpnInstance.getVpnName();
-                                            LOG.info("VPN Interface update event - intfName {} onto vpnName {}"
-                                                   + " running oper-driven DOWN", vpnIf.getName(), vpnName);
-                                            Optional<VpnInterfaceOpDataEntry> optVpnInterface =
-                                                 VpnUtil.getVpnInterfaceOpDataEntry(dataBroker,
-                                                                     vpnIf.getName(), vpnName);
-                                            if (optVpnInterface.isPresent()) {
-                                                VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
-                                                vpnInterfaceManager.processVpnInterfaceDown(dpnId, vpnIf.getName(),
-                                                        ifIndex, update.getPhysAddress().getValue(), vpnOpInterface,
-                                                        true, writeConfigTxn, writeOperTxn, writeInvTxn);
-                                            } else {
-                                                LOG.error("InterfaceStateChangeListener Update DOWN - vpnInterface {}"
-                                                        + " not available, ignoring event", vpnIf.getName());
-                                                continue;
+                                        if (update.getOperStatus().equals(OperStatus.Up)) {
+                                            for (VpnInstanceNames vpnInterfaceVpnInstance :
+                                                    vpnIf.getVpnInstanceNames()) {
+                                                String vpnName = vpnInterfaceVpnInstance.getVpnName();
+                                                String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
+                                                if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
+                                                    LOG.error(
+                                                            "VPN Interface update event - intfName {} onto vpnName {} "
+                                                                    + "running oper-driven UP, VpnInstance not ready,"
+                                                            + " holding on", vpnIf.getName(), vpnName);
+                                                } else if (VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
+                                                    LOG.error("update: Ignoring UP event for vpnInterface {}, as "
+                                                            + "vpnInstance {} with primaryRd {} is already marked for"
+                                                            + " deletion", vpnIf.getName(), vpnName, primaryRd);
+                                                } else {
+                                                    vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd,
+                                                            ifIndex, true, writeConfigTxn, writeOperTxn, writeInvTxn,
+                                                            update, vpnName);
+                                                }
+                                            }
+                                        } else if (update.getOperStatus().equals(OperStatus.Down)) {
+                                            for (VpnInstanceNames vpnInterfaceVpnInstance :
+                                                    vpnIf.getVpnInstanceNames()) {
+                                                String vpnName = vpnInterfaceVpnInstance.getVpnName();
+                                                LOG.info("VPN Interface update event - intfName {} onto vpnName {}"
+                                                       + " running oper-driven DOWN", vpnIf.getName(), vpnName);
+                                                Optional<VpnInterfaceOpDataEntry> optVpnInterface =
+                                                     VpnUtil.getVpnInterfaceOpDataEntry(dataBroker,
+                                                                         vpnIf.getName(), vpnName);
+                                                if (optVpnInterface.isPresent()) {
+                                                    VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
+                                                    vpnInterfaceManager.processVpnInterfaceDown(dpnId, vpnIf.getName(),
+                                                            ifIndex, update.getPhysAddress().getValue(), vpnOpInterface,
+                                                            true, writeConfigTxn, writeOperTxn, writeInvTxn);
+                                                } else {
+                                                    LOG.error(
+                                                            "InterfaceStateChangeListener Update DOWN - vpnInterface {}"
+                                                            + " not available, ignoring event", vpnIf.getName());
+                                                    continue;
+                                                }
                                             }
                                         }
+                                    } else {
+                                        LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
                                     }
-                                } else {
-                                    LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
-                                }
-                            }));
-                        }));
-                    }));
+                                }))))));
                     return futures;
                 });
             }
index 4410dcb2683df440aa66abd91ba93be724017cc9..009bd4386790d62284633f7def00bbd99337d3fe 100755 (executable)
@@ -1211,56 +1211,53 @@ public class VpnInterfaceManager extends AsyncDataTreeChangeListenerBase<VpnInte
         jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName,
             () -> {
                 List<ListenableFuture<Void>> futures = new ArrayList<>(3);
-                ListenableFuture<Void> configFuture = txRunner
-                        .callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
-                            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
-                                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
-                                    LOG.info("remove: - intfName {} onto vpnName {} running config-driven",
-                                            interfaceName, vpnName);
-                                    BigInteger dpId = BigInteger.ZERO;
-                                    int ifIndex = 0;
-                                    String gwMacAddress = null;
-                                    InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
-                                            VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
-                                    final Optional<VpnInterfaceOpDataEntry> optVpnInterface =
-                                            VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, interfaceId);
-                                    if (interfaceState != null) {
-                                        try {
-                                            dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
-                                        } catch (NumberFormatException | IllegalStateException e) {
-                                            LOG.error("remove: Unable to retrieve dpnId from interface operational"
-                                                    + " data store for interface {} on dpn {} for vpn {} Fetching"
-                                                            + " from vpn interface op data store. ", interfaceName,
-                                                    vpnInterface.getDpnId(), vpnName, e);
-                                            dpId = BigInteger.ZERO;
-                                        }
-                                        ifIndex = interfaceState.getIfIndex();
-                                        gwMacAddress = interfaceState.getPhysAddress().getValue();
-                                    } else {
-                                        LOG.info("remove: Interface state not available for {}. Trying to fetch data"
-                                                + " from vpn interface op.", interfaceName);
-                                        if (optVpnInterface.isPresent()) {
-                                            VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
-                                            dpId = vpnOpInterface.getDpnId();
-                                            ifIndex = vpnOpInterface.getLportTag().intValue();
-                                            gwMacAddress = vpnOpInterface.getGatewayMacAddress();
-                                        } else {
-                                            LOG.error("remove: Handling removal of VPN interface {} for vpn {} skipped"
-                                                            + " as interfaceState and vpn interface op is not"
-                                                    + " available", interfaceName, vpnName);
-                                            return;
-                                        }
-                                    }
-                                    processVpnInterfaceDown(dpId, interfaceName, ifIndex, gwMacAddress,
-                                            optVpnInterface.isPresent() ? optVpnInterface.get() : null, false,
-                                            writeConfigTxn, writeOperTxn, writeInvTxn);
-                                    LOG.info(
-                                            "remove: Removal of vpn interface {} on dpn {} for vpn {} processed "
-                                                    + "successfully",
-                                            interfaceName, vpnInterface.getDpnId(), vpnName);
-                                }));
-                            }));
-                        });
+                ListenableFuture<Void> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                    writeConfigTxn -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                        writeOperTxn -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
+                            LOG.info("remove: - intfName {} onto vpnName {} running config-driven",
+                                    interfaceName, vpnName);
+                            BigInteger dpId = BigInteger.ZERO;
+                            int ifIndex = 0;
+                            String gwMacAddress = null;
+                            InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
+                                    VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
+                            final Optional<VpnInterfaceOpDataEntry> optVpnInterface =
+                                    VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, interfaceId);
+                            if (interfaceState != null) {
+                                try {
+                                    dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
+                                } catch (NumberFormatException | IllegalStateException e) {
+                                    LOG.error("remove: Unable to retrieve dpnId from interface operational"
+                                            + " data store for interface {} on dpn {} for vpn {} Fetching"
+                                                    + " from vpn interface op data store. ", interfaceName,
+                                            vpnInterface.getDpnId(), vpnName, e);
+                                    dpId = BigInteger.ZERO;
+                                }
+                                ifIndex = interfaceState.getIfIndex();
+                                gwMacAddress = interfaceState.getPhysAddress().getValue();
+                            } else {
+                                LOG.info("remove: Interface state not available for {}. Trying to fetch data"
+                                        + " from vpn interface op.", interfaceName);
+                                if (optVpnInterface.isPresent()) {
+                                    VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
+                                    dpId = vpnOpInterface.getDpnId();
+                                    ifIndex = vpnOpInterface.getLportTag().intValue();
+                                    gwMacAddress = vpnOpInterface.getGatewayMacAddress();
+                                } else {
+                                    LOG.error("remove: Handling removal of VPN interface {} for vpn {} skipped"
+                                                    + " as interfaceState and vpn interface op is not"
+                                            + " available", interfaceName, vpnName);
+                                    return;
+                                }
+                            }
+                            processVpnInterfaceDown(dpId, interfaceName, ifIndex, gwMacAddress,
+                                    optVpnInterface.isPresent() ? optVpnInterface.get() : null, false,
+                                    writeConfigTxn, writeOperTxn, writeInvTxn);
+                            LOG.info(
+                                    "remove: Removal of vpn interface {} on dpn {} for vpn {} processed "
+                                            + "successfully",
+                                    interfaceName, vpnInterface.getDpnId(), vpnName);
+                        })))));
                 futures.add(configFuture);
                 Futures.addCallback(configFuture, new PostVpnInterfaceWorker(interfaceName, false, "Config"));
                 return futures;
index da306f7e84d05f75c7209f908c88561580c64ff5..6497f8101577dc6390ce5ce689c7e32f0812bcb0 100644 (file)
@@ -530,10 +530,9 @@ public class VpnManagerImpl implements IVpnManager {
             }
 
             final String extIfcFinal = extIfc;
-            ListenableFuture<Void> listenableFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
-                doAddArpResponderFlowsToExternalNetworkIps(
-                        id, fixedIps, macAddress, dpnId, extNetworkId, tx, extIfcFinal);
-            });
+            ListenableFuture<Void> listenableFuture =
+                txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> doAddArpResponderFlowsToExternalNetworkIps(
+                    id, fixedIps, macAddress, dpnId, extNetworkId, tx, extIfcFinal));
             ListenableFutures.addErrorLogging(listenableFuture, LOG,
                     "Error while configuring arp responder for ext. interface");
 
index 081cc5eeef2622c8c0f7c65a31ea0c35159c9277..d33bc79879bf6bdf2d9441e45d92240568011c7e 100755 (executable)
@@ -1524,7 +1524,7 @@ public final class VpnUtil {
         java.util.Optional<String> allocatedRd = VpnExtraRouteHelper
                 .getRdAllocatedForExtraRoute(dataBroker, vpnId, prefix, nextHop);
         if (allocatedRd.isPresent()) {
-            return java.util.Optional.of(allocatedRd.get());
+            return allocatedRd;
         }
 
         //Check if rd is already allocated for this extraroute behind the same CSS. If yes, reuse it