Optional clean-up
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / utils / ElanL2GatewayUtils.java
index 42a7b8ae3515dd33946cecbd25691cc13038aa76..c7f96bd9f949e81ff3f08719d2e3adffddd9783f 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.genius.utils.SystemPropertyReader;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
+import org.opendaylight.netvirt.elan.ElanException;
 import org.opendaylight.netvirt.elan.l2gw.jobs.DeleteL2GwDeviceMacsFromElanJob;
 import org.opendaylight.netvirt.elan.l2gw.jobs.DeleteLogicalSwitchJob;
 import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepTerminationPointListener;
@@ -106,7 +107,7 @@ public class ElanL2GatewayUtils {
 
     private final DataStoreJobCoordinator dataStoreJobCoordinator = DataStoreJobCoordinator.getInstance();
     private static Timer LogicalSwitchDeleteJobTimer = new Timer();
-    private static final int LOGICAL_SWITCH_DELETE_DELAY = 120000;
+    private static final int LOGICAL_SWITCH_DELETE_DELAY = 20000;
     private final ConcurrentMap<Pair<NodeId, String>, TimerTask> logicalSwitchDeletedTasks = new ConcurrentHashMap<>();
 
     public ElanL2GatewayUtils(DataBroker broker, ItmRpcService itmRpcService, ElanUtils elanUtils,
@@ -305,9 +306,10 @@ public class ElanL2GatewayUtils {
      *            the elan
      * @param interfaceName
      *            the interface name
+     * @throws ElanException in case of issues creating the flow objects
      */
     public void installL2gwDeviceMacsInDpn(BigInteger dpnId, NodeId l2gwDeviceNodeId, ElanInstance elan,
-            String interfaceName) {
+            String interfaceName) throws ElanException {
         L2GatewayDevice l2gwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elan.getElanInstanceName(),
                 l2gwDeviceNodeId.getValue());
         if (l2gwDevice == null) {
@@ -329,9 +331,10 @@ public class ElanL2GatewayUtils {
      *            the elan
      * @param interfaceName
      *            the interface name
+     * @throws ElanException in case of issues creating the flow objects
      */
     public void installDmacFlowsOnDpn(BigInteger dpnId, L2GatewayDevice l2gwDevice, ElanInstance elan,
-            String interfaceName) {
+            String interfaceName) throws ElanException {
         String elanName = elan.getElanInstanceName();
 
         List<LocalUcastMacs> l2gwDeviceLocalMacs = l2gwDevice.getUcastLocalMacs();
@@ -355,8 +358,10 @@ public class ElanL2GatewayUtils {
      *            the elan
      * @param interfaceName
      *            the interface name
+     * @throws ElanException in case of issues creating the flow objects
      */
-    public void installElanL2gwDevicesLocalMacsInDpn(BigInteger dpnId, ElanInstance elan, String interfaceName) {
+    public void installElanL2gwDevicesLocalMacsInDpn(BigInteger dpnId, ElanInstance elan, String interfaceName)
+            throws ElanException {
         ConcurrentMap<String, L2GatewayDevice> elanL2GwDevicesFromCache = ElanL2GwCacheUtils
                 .getInvolvedL2GwDevices(elan.getElanInstanceName());
         if (elanL2GwDevicesFromCache != null) {
@@ -455,9 +460,8 @@ public class ElanL2GatewayUtils {
      * @return true, if successful
      */
     private static boolean doesLocalUcastMacExistsInCache(L2GatewayDevice elanL2GwDevice, String macAddress) {
-        java.util.Optional<LocalUcastMacs> macExistsInCache = elanL2GwDevice.getUcastLocalMacs().stream()
-                .filter(mac -> mac.getMacEntryKey().getValue().equalsIgnoreCase(macAddress)).findFirst();
-        return macExistsInCache.isPresent();
+        return elanL2GwDevice.getUcastLocalMacs().stream()
+                .anyMatch(mac -> mac.getMacEntryKey().getValue().equalsIgnoreCase(macAddress));
     }
 
     /**
@@ -605,7 +609,7 @@ public class ElanL2GatewayUtils {
         });
 
         if (LOG.isDebugEnabled()) {
-            List<String> elanMacs = lstElanMacs.stream().map(mac -> mac.getValue()).collect(Collectors.toList());
+            List<String> elanMacs = lstElanMacs.stream().map(MacAddress::getValue).collect(Collectors.toList());
             LOG.debug("Deleting elan [{}] macs from node [{}]. Deleted macs = {}", elanName, hwvtepNodeId, elanMacs);
         }
         return future;
@@ -863,8 +867,7 @@ public class ElanL2GatewayUtils {
 
         WriteTransaction transaction = broker.newWriteOnlyTransaction();
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
-                .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice
-                .getInterfaces()) {
+                 .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
             NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId,
                     hwVtepDevice.getDeviceName());
             TerminationPoint portTerminationPoint = HwvtepUtils.getPhysicalPortTerminationPoint(broker,
@@ -937,7 +940,7 @@ public class ElanL2GatewayUtils {
 
         WriteTransaction transaction = broker.newWriteOnlyTransaction();
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
-                .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
+                 .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
             String phyPortName = deviceInterface.getInterfaceName();
             if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
                 for (Integer vlanId : deviceInterface.getSegmentationIds()) {
@@ -1003,13 +1006,7 @@ public class ElanL2GatewayUtils {
 
     public static Interface getInterfaceFromConfigDS(InterfaceKey interfaceKey, DataBroker dataBroker) {
         InstanceIdentifier<Interface> interfaceId = getInterfaceIdentifier(interfaceKey);
-        Optional<Interface> interfaceOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfaceId,
-                dataBroker);
-        if (!interfaceOptional.isPresent()) {
-            return null;
-        }
-
-        return interfaceOptional.get();
+        return IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfaceId, dataBroker).orNull();
     }
 
     /**