Fix FindBugs violations and enable enforcement in neutronvpn-impl 61/64861/8
authorTom Pantelis <tompantelis@gmail.com>
Mon, 30 Oct 2017 02:22:03 +0000 (22:22 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 15 Nov 2017 03:55:29 +0000 (22:55 -0500)
See in-line comments.

Change-Id: Ie0dce5f21dee80b9c02405b7636e55a4a8347887
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
15 files changed:
.gitignore
vpnservice/neutronvpn/neutronvpn-impl/pom.xml
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronBgpvpnChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronFloatingToFixedIpMappingChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronHostConfigChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronNetworkChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronSubnetChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronSubnetGwMacResolver.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnNatManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/evpn/manager/NeutronEvpnManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GatewayListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GwTransportZoneListener.java

index 9cb68e1bea5ffd921dacb33e84ed7b818eba25c9..a40da0d9144f704ed4c88937b02dbe78fb87b33d 100644 (file)
@@ -34,3 +34,4 @@ maven-metadata-local.xml
 .metadata
 .recommenders
 /.gitignore
+.fbExcludeFilterFile
index e48aefe3088582def838f14efadaf477b8c27387..2fe79c2c418a12f082869f94e9072da94f61c56e 100644 (file)
@@ -130,6 +130,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <groupId>org.apache.aries.blueprint</groupId>
         <artifactId>blueprint-maven-plugin</artifactId>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>findbugs-maven-plugin</artifactId>
+        <configuration>
+          <failOnError>true</failOnError>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
index 92d5b24b2527d54bc5e13e49852f4e706d588880..81a80bd6cf3b4b9ef8b6b161250d75ec3bfee41f 100644 (file)
@@ -123,7 +123,8 @@ public class NeutronBgpvpnChangeListener extends AsyncDataTreeChangeListenerBase
 
             if (rd == null || rd.isEmpty()) {
                 // generate new RD
-                rd = generateNewRD(input.getUuid());
+                // TODO - commented out for now to avoid "Dead store to rd" violation.
+                //rd = generateNewRD(input.getUuid());
             } else {
                 String[] rdParams = rd.get(0).split(":");
                 if (rdParams[0].trim().equals(adminRDValue)) {
@@ -159,18 +160,6 @@ public class NeutronBgpvpnChangeListener extends AsyncDataTreeChangeListenerBase
         }
     }
 
-    private List<String> generateNewRD(Uuid vpn) {
-        if (adminRDValue != null) {
-            Integer rdId = neutronvpnUtils.getUniqueRDId(NeutronConstants.RD_IDPOOL_NAME, vpn.toString());
-            if (rdId != null) {
-                String rd = adminRDValue + ":" + rdId;
-                LOG.debug("Generated RD {} for L3VPN {}", rd, vpn);
-                return Collections.singletonList(rd);
-            }
-        }
-        return Collections.emptyList();
-    }
-
     @Override
     protected void remove(InstanceIdentifier<Bgpvpn> identifier, Bgpvpn input) {
         LOG.trace("Removing Bgpvpn : key: {}, value={}", identifier, input);
index c157442ccfb7488d776418975529f4344b5d2d13..c6f71cee807225b1700d1a6e713a99d7bb73b0df 100644 (file)
@@ -180,7 +180,7 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier,
                 routerPortsBuilder.build());
             LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
-        } catch (Exception e) {
+        } catch (ReadFailedException | RuntimeException e) {
             LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress, e);
         } finally {
             if (isLockAcquired) {
@@ -239,7 +239,7 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
             } else {
                 LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
             }
-        } catch (Exception e) {
+        } catch (RuntimeException | ReadFailedException e) {
             LOG.error("Failed to delete internal-to-external-port-map from FloatingIpInfo DS for fixed Ip {}",
                     fixedIpAddress, e);
         }
index b6f4b8deb72301b4768612c7fef3dadc7d0aef0f..f54b007ed3aecdc00abd070ebc6c6d6a0d949391 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.neutronvpn;
 
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -115,11 +116,11 @@ public class NeutronHostConfigChangeListener
                     // suffix OS_HOST_CONFIG_CONFIG_KEY_PREFIX.length()
                     String hostType = openvswitchExternalIds.getExternalIdKey().substring(
                             OS_HOST_CONFIG_CONFIG_KEY_PREFIX.length());
-                    if (null != hostType && hostType.length() > 0) {
+                    if (hostType.length() > 0) {
                         if (hostType.length() > HOST_TYPE_STR_LEN) {
                             hostType = hostType.substring(0, HOST_TYPE_STR_LEN);
                         }
-                        hostType = "ODL " + hostType.toUpperCase();
+                        hostType = "ODL " + hostType.toUpperCase(Locale.getDefault());
                         if (null != openvswitchExternalIds.getExternalIdValue()) {
                             config.put(hostType, openvswitchExternalIds.getExternalIdValue());
                         }
index 5b69b54d470930612093eaf691423678af6c8245..4cbe0923740b3f023a9205de67ac86271380f35e 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import javax.annotation.Nonnull;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -183,6 +184,7 @@ public class NeutronNetworkChangeListener
         }
     }
 
+    @Nonnull
     private List<ElanSegments> buildSegments(Network input) {
         Long numSegments = NeutronUtils.getNumberSegmentsFromNeutronNetwork(input);
         Long index = 0L;
@@ -238,9 +240,8 @@ public class NeutronNetworkChangeListener
                 elanInstanceBuilder.setPhysicalNetworkName(physicalNetworkName);
             }
         }
-        if (segments != null) {
-            elanInstanceBuilder.setElanSegments(segments);
-        }
+
+        elanInstanceBuilder.setElanSegments(segments);
         elanInstanceBuilder.setExternal(isExternal);
         elanInstanceBuilder.setKey(new ElanInstanceKey(elanInstanceName));
         return elanInstanceBuilder;
index e4fb18ed4ce1e145b97217fe70899b42ce9d88d2..eb63005696cfcd9311c1204b87b2e17a9fd8f99a 100644 (file)
@@ -36,7 +36,6 @@ import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder;
@@ -294,7 +293,6 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
                 createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
                 wrtConfigTxn.submit();
-                PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue());
             } else {
                 LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}"
                     + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(),
@@ -470,10 +468,6 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
         final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
         final List<FixedIps> portupdateIps = portupdate.getFixedIps();
-        LOG.trace("PORT ORIGINAL: {} from network {} with fixed IPs: {}; "
-                    + "PORT UPDATE: {} from network {} with fixed IPs: {}",
-                    portoriginal.getName(), portoriginal.getNetworkId().toString(), portoriginalIps.toString(),
-                    portupdate.getName(), portupdate.getNetworkId().toString(), portupdateIps.toString());
         if (portoriginalIps == null || portoriginalIps.isEmpty()) {
             handleNeutronPortCreated(portupdate);
             return;
index 3c14a8634094944960a84ad5448ef694251cdcfd..794755a72d35d2f18ea7fe41f847c36d1e5834d1 100644 (file)
@@ -15,6 +15,7 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 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.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
@@ -116,7 +117,7 @@ public class NeutronSubnetChangeListener extends AsyncDataTreeChangeListenerBase
         nvpnManager.createSubnetmapNode(subnetId, String.valueOf(subnet.getCidr().getValue()),
                 subnet.getTenantId(), networkId,
                 providerType != null ? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null,
-                segmentationId != null ? Long.valueOf(segmentationId) : 0L);
+                segmentationId != null ? Long.parseLong(segmentationId) : 0L);
         createSubnetToNetworkMapping(subnetId, networkId);
     }
 
@@ -155,7 +156,7 @@ public class NeutronSubnetChangeListener extends AsyncDataTreeChangeListenerBase
                     .build());
             LOG.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(),
                     networkId.getValue());
-        } catch (Exception e) {
+        } catch (ReadFailedException | RuntimeException e) {
             LOG.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
                     networkId.getValue());
         }
@@ -189,7 +190,7 @@ public class NeutronSubnetChangeListener extends AsyncDataTreeChangeListenerBase
             } else {
                 LOG.error("network {} not present for subnet {} ", networkId, subnetId);
             }
-        } catch (Exception e) {
+        } catch (ReadFailedException | RuntimeException e) {
             LOG.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
                     networkId.getValue());
         }
index 0d488cd6fef792af9f7f8afdb7e7f54e0ba94c5d..8f62c06cc570931bd15c962859c13c3211798c23 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.netvirt.neutronvpn;
 
+import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import java.math.BigInteger;
 import java.util.Collections;
@@ -21,6 +22,7 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.arputil.api.ArpConstants;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.vpnmanager.api.ICentralizedSwitchProvider;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -153,7 +155,9 @@ public class NeutronSubnetGwMacResolver {
 
             SendArpRequestInput sendArpRequestInput = new SendArpRequestInputBuilder().setIpaddress(dstIpAddress)
                     .setInterfaceAddress(Collections.singletonList(interfaceAddress)).build();
-            arpUtilService.sendArpRequest(sendArpRequestInput);
+
+            ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(
+                    arpUtilService.sendArpRequest(sendArpRequestInput)), LOG, "Send ARP request");
         } catch (Exception e) {
             LOG.error("Failed to send ARP request to external GW {} from interface {}",
                     dstIpAddress.getIpv4Address().getValue(), interfaceName, e);
index 5019b90ad6b66a6d7b2a09b7eaf16b6184e6c744..2417a174410735b4e15b303ef3e5d6f75d7a6973 100644 (file)
@@ -11,6 +11,7 @@ import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastor
 import static org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional;
 
 import com.google.common.base.Optional;
+import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
@@ -21,10 +22,12 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.Nonnull;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -35,8 +38,8 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.fibmanager.api.FibHelper;
 import org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice;
@@ -111,7 +114,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev15060
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstancesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesBuilder;
@@ -236,7 +238,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
                         subnetMapIdentifier, subnetmapBuilder.build());
             }
-        } catch (Exception e) {
+        } catch (TransactionCommitFailedException | ReadFailedException e) {
             LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
         }
         // check if there are ports to update for already created Subnetmap node
@@ -457,7 +459,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
                         subnetMapIdentifier);
             }
-        } catch (Exception e) {
+        } catch (TransactionCommitFailedException e) {
             LOG.error("Delete subnetMap node failed for subnet : {} ", subnetId.getValue());
         }
     }
@@ -491,8 +493,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void updateVpnInstanceNode(String vpnName, List<String> rd, List<String> irt, List<String> ert,
                                        VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion) {
         VpnInstanceBuilder builder = null;
@@ -565,8 +565,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             VpnInstance newVpn = builder.build();
             isLockAcquired = NeutronUtils.lock(vpnName);
             LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
-        } catch (Exception e) {
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier,
+                    newVpn);
+        } catch (ReadFailedException | TransactionCommitFailedException e) {
             LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
         } finally {
             if (isLockAcquired) {
@@ -575,8 +576,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void deleteVpnMapsNode(Uuid vpnid) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
@@ -585,8 +584,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         LOG.debug("removing vpnMaps node: {} ", vpnid.getValue());
         try {
             isLockAcquired = NeutronUtils.lock(vpnid.getValue());
-            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
-        } catch (Exception e) {
+            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+        } catch (TransactionCommitFailedException e) {
             LOG.error("Delete vpnMaps node failed for vpn : {} ", vpnid.getValue());
         } finally {
             if (isLockAcquired) {
@@ -595,8 +594,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
         VpnMapBuilder builder;
         boolean isLockAcquired = false;
@@ -633,9 +630,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
             isLockAcquired = NeutronUtils.lock(vpnId.getValue());
             LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier,
+                    builder.build());
             LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
-        } catch (Exception e) {
+        } catch (ReadFailedException | TransactionCommitFailedException e) {
             LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
         } finally {
             if (isLockAcquired) {
@@ -644,8 +642,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
@@ -669,8 +665,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         // remove entire node in case of internal VPN
                         isLockAcquired = NeutronUtils.lock(vpnId.getValue());
                         LOG.debug("removing vpnMaps node: {} ", vpnId);
-                        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
-                    } catch (Exception e) {
+                        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                vpnMapIdentifier);
+                    } catch (TransactionCommitFailedException e) {
                         LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
                     } finally {
                         if (isLockAcquired) {
@@ -695,9 +692,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             try {
                 isLockAcquired = NeutronUtils.lock(vpnId.getValue());
                 LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier,
+                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier,
                         vpnMapBuilder.build());
-            } catch (Exception e) {
+            } catch (TransactionCommitFailedException e) {
                 LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
             } finally {
                 if (isLockAcquired) {
@@ -710,8 +707,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void deleteVpnInstance(Uuid vpnId) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
@@ -721,8 +716,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         try {
             isLockAcquired = NeutronUtils.lock(vpnId.getValue());
             LOG.debug("Deleting vpnInstance {}", vpnId.getValue());
-            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
-        } catch (Exception e) {
+            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+        } catch (TransactionCommitFailedException e) {
             LOG.error("Deletion of VPNInstance node failed for VPN {}", vpnId.getValue());
         } finally {
             if (isLockAcquired) {
@@ -763,7 +758,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                     // because router can have IPv4 and IPv6 subnet ports, or can have
                     // more that one IPv4 subnet port or more than one IPv6 subnet port
                     List<Adjacency> erAdjList = getAdjacencyforExtraRoute(vpnId, routeList, ipValue);
-                    if (erAdjList != null && !erAdjList.isEmpty()) {
+                    if (!erAdjList.isEmpty()) {
                         adjList.addAll(erAdjList);
                     }
                 }
@@ -784,7 +779,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     protected void withdrawPortIpFromVpnIface(Uuid vpnId, Port port, Subnetmap sn, WriteTransaction wrtConfigTxn) {
-        boolean isLockAcquired = false;
         String infName = port.getUuid().getValue();
         InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
         Optional<VpnInterface> optionalVpnInterface = null;
@@ -802,10 +796,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         LOG.trace("withdraw adjacencies for Port: {} subnet {}", port.getUuid().getValue(),
                 sn != null ? sn.getSubnetIp() : "null");
         List<Adjacency> vpnAdjsList = optionalVpnInterface.get().getAugmentation(Adjacencies.class).getAdjacency();
-        List<Adjacency> updatedAdjsList = new ArrayList();
+        List<Adjacency> updatedAdjsList = new ArrayList<>();
         boolean isIpFromAnotherSubnet = false;
         for (Adjacency adj : vpnAdjsList) {
-            String adjString = FibHelper.getIpFromPrefix(adj.getIpAddress().toString());
+            String adjString = FibHelper.getIpFromPrefix(adj.getIpAddress());
             if (sn == null || !adj.getSubnetId().equals(sn.getId())) {
                 if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                     isIpFromAnotherSubnet = true;
@@ -821,7 +815,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 if (port.getDeviceOwner()
                     .equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) && sn.getRouterId() != null)  {
                     Router rtr = neutronvpnUtils.getNeutronRouter(sn.getRouterId());
-                    if (rtr == null && rtr.getRoutes() != null) {
+                    if (rtr != null && rtr.getRoutes() != null) {
                         List<Routes> extraRoutesToRemove = new ArrayList<>();
                         for (Routes rt: rtr.getRoutes()) {
                             if (rt.getNexthop().toString().equals(adjString)) {
@@ -1000,7 +994,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
         if (networks != null) {
             List<String> failStrings = associateNetworksToVpn(vpn, networks);
-            if (failStrings != null &&  !failStrings.isEmpty()) {
+            if (!failStrings.isEmpty()) {
                 LOG.error("VPN {} association to networks failed for networks: {}. ",
                         vpn.getValue(), failStrings.toString());
                 throw new Exception(failStrings.toString());
@@ -1393,8 +1387,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             List<Uuid> portList = sn.getPortList();
             if (portList != null) {
                 for (final Uuid portId : portList) {
-                    LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp().toString(),
-                        portId.getValue());
+                    LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
                     final Port port = neutronvpnUtils.getNeutronPort(portId);
                     jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
                         WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
@@ -1480,19 +1473,20 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName))
                     .setInterfaceId(interfaceName).build();
                 if (optRouterInterfaces.isPresent()) {
-                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)),
                             routerInterface);
                 } else {
-                    RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
-                    List<Interfaces> interfaces = new ArrayList<>();
-                    interfaces.add(routerInterface);
                     // TODO Shouldn't we be doing something with builder and interfaces?
-                    MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
+//                    RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
+//                    List<Interfaces> interfaces = new ArrayList<>();
+//                    interfaces.add(routerInterface);
+
+                    SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)),
                             routerInterface);
                 }
-            } catch (ReadFailedException e) {
+            } catch (ReadFailedException | TransactionCommitFailedException e) {
                 LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
             }
         }
@@ -1512,14 +1506,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                     List<Interfaces> interfaces = routerInterfaces.getInterfaces();
                     if (interfaces != null && interfaces.remove(routerInterface)) {
                         if (interfaces.isEmpty()) {
-                            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
+                            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                    routerInterfacesId);
                         } else {
-                            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
                                     routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
                         }
                     }
                 }
-            } catch (ReadFailedException e) {
+            } catch (ReadFailedException | TransactionCommitFailedException e) {
                 LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
             }
         }
@@ -1588,7 +1583,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         new RemoveStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop)
                                 .setVpnInstanceName(vpnName.getValue())
                                 .build();
-                vpnRpcService.removeStaticRoute(rpcInput);
+
+                ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(
+                        vpnRpcService.removeStaticRoute(rpcInput)), LOG, "Remove VPN routes");
             } else {
                 // Any other case is a fault.
                 LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
@@ -1611,6 +1608,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         && interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(nexthop));
     }
 
+    @Nonnull
     protected List<Adjacency> getAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList, String fixedIp) {
         List<Adjacency> adjList = new ArrayList<>();
         Map<String, List<String>> adjMap = new HashMap<>();
@@ -1633,17 +1631,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             }
         }
 
-        for (String destination : adjMap.keySet()) {
+        for (Entry<String, List<String>> entry : adjMap.entrySet()) {
+            final String destination = entry.getKey();
+            final List<String> ipList = entry.getValue();
             Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination)
-                    .setAdjacencyType(AdjacencyType.ExtraRoute).setNextHopIpList(adjMap.get(destination))
+                    .setAdjacencyType(AdjacencyType.ExtraRoute).setNextHopIpList(ipList)
                     .setKey(new AdjacencyKey(destination)).build();
             adjList.add(erAdj);
         }
         return  adjList;
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void updateVpnInterfaceWithExtraRouteAdjacency(Uuid vpnId, List<Routes> routeList) {
         for (Routes route : routeList) {
             if (route == null || route.getNexthop() == null || route.getDestination() == null) {
@@ -1666,8 +1664,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                             .setNextHopIpList(Collections.singletonList(nextHop)).setKey(new AdjacencyKey(destination))
                             .setAdjacencyType(AdjacencyType.ExtraRoute).build();
                         isLockAcquired = NeutronUtils.lock(infName);
-                        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, path, erAdj);
-                    } catch (Exception e) {
+                        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                path, erAdj);
+                    } catch (TransactionCommitFailedException e) {
                         LOG.error("exception in adding extra route with destination: {}, next hop: {}",
                             destination, nextHop, e);
                     } finally {
@@ -1683,8 +1682,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void removeAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList) {
         for (Routes route : routeList) {
             if (route != null && route.getNexthop() != null && route.getDestination() != null) {
@@ -1709,25 +1706,25 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 .child(Adjacency.class, new AdjacencyKey(destination))
                                 .build();
 
-                // Looking for existing prefix in MDSAL database
-                Optional<Adjacency> adjacency = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                        adjacencyIdentifier);
-                boolean updateNextHops = false;
-                List<String> nextHopList = new ArrayList<>();
-                if (adjacency.isPresent()) {
-                    List<String> nhListRead = adjacency.get().getNextHopIpList();
-                    if (nhListRead.size() > 1) { // ECMP case
-                        for (String nextHopRead : nhListRead) {
-                            if (nextHopRead.equals(nextHop)) {
-                                updateNextHops = true;
-                            } else {
-                                nextHopList.add(nextHopRead);
+                try {
+                    // Looking for existing prefix in MDSAL database
+                    Optional<Adjacency> adjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                            LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
+                    boolean updateNextHops = false;
+                    List<String> nextHopList = new ArrayList<>();
+                    if (adjacency.isPresent()) {
+                        List<String> nhListRead = adjacency.get().getNextHopIpList();
+                        if (nhListRead.size() > 1) { // ECMP case
+                            for (String nextHopRead : nhListRead) {
+                                if (nextHopRead.equals(nextHop)) {
+                                    updateNextHops = true;
+                                } else {
+                                    nextHopList.add(nextHopRead);
+                                }
                             }
                         }
                     }
-                }
 
-                try {
                     isLockAcquired = NeutronUtils.lock(infName);
                     if (updateNextHops) {
                         // An update must be done, not including the current next hop
@@ -1741,13 +1738,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 new AdjacenciesBuilder().setAdjacency(Collections.singletonList(newAdj)).build();
                         VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
                                 .addAugmentation(Adjacencies.class, erAdjs).build();
-                        MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
+                        SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                vpnIfIdentifier, vpnIf);
                     } else {
                         // Remove the whole route
-                        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
+                        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                adjacencyIdentifier);
                         LOG.trace("extra route {} deleted successfully", route);
                     }
-                } catch (Exception e) {
+                } catch (TransactionCommitFailedException | ReadFailedException e) {
                     LOG.error("exception in deleting extra route with destination {} for interface {}",
                             destination, infName, e);
                 } finally {
@@ -1790,15 +1789,14 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         updateVpnMaps(vpnId, null, routerId, null, null);
         LOG.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
         List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
-        if (routerSubnets != null) {
-            for (Uuid subnetId : routerSubnets) {
-                Subnetmap sn = updateVpnForSubnet(routerId, vpnId, subnetId, true);
-                if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sn, vpnId)) {
-                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
-                            NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
-                }
+        for (Uuid subnetId : routerSubnets) {
+            Subnetmap sn = updateVpnForSubnet(routerId, vpnId, subnetId, true);
+            if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sn, vpnId)) {
+                neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
+                    NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
             }
         }
+
         try {
             checkAndPublishRouterAssociatedtoVpnNotification(routerId, vpnId);
             LOG.debug("notification upon association of router {} to VPN {} published", routerId.getValue(),
@@ -1824,18 +1822,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
         boolean vpnInstanceIpVersionsRemoved = false;
         IpVersionChoice vpnInstanceIpVersionsToRemove = IpVersionChoice.UNDEFINED;
-        if (routerSubnets != null) {
-            for (Uuid subnetId : routerSubnets) {
-                Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
-                if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
-                    vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils
+        for (Uuid subnetId : routerSubnets) {
+            Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
+            if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
+                vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils
                         .getIpVersionFromString(sn.getSubnetIp()));
-                    vpnInstanceIpVersionsRemoved = true;
-                }
-                LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
-                updateVpnForSubnet(vpnId, routerId, subnetId, false);
+                vpnInstanceIpVersionsRemoved = true;
             }
+            LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
+            updateVpnForSubnet(vpnId, routerId, subnetId, false);
         }
+
         if (vpnInstanceIpVersionsRemoved) {
             neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionsToRemove, false);
         }
@@ -1850,6 +1847,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
+    @Nonnull
     protected List<String> associateNetworksToVpn(Uuid vpn, List<Uuid> networks) {
         List<String> failedNwList = new ArrayList<>();
         List<Uuid> passedNwList = new ArrayList<>();
@@ -1864,6 +1862,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             // process corresponding subnets for VPN
             for (Uuid nw : networks) {
                 Network network = neutronvpnUtils.getNeutronNetwork(nw);
+                if (network == null) {
+                    failedNwList.add(String.format("network %s not found", nw.getValue()));
+                    continue;
+                }
+
                 NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
                 if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
                     LOG.error("MultiSegmented networks not supported in VPN. Failed to associate network {} on vpn {}",
@@ -1874,9 +1877,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
                 try {
                     Uuid vpnId = neutronvpnUtils.getVpnForNetwork(nw);
-                    if (network == null) {
-                        failedNwList.add(String.format("network %s not found", nw.getValue()));
-                    } else if (vpnId != null) {
+                    if (vpnId != null) {
                         failedNwList.add(String.format("network %s already associated to another VPN %s", nw.getValue(),
                                 vpnId.getValue()));
                     } else if (isVpnOfTypeL2(vpnInstance)
@@ -1940,8 +1941,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                             for (Uuid subnet : networkSubnets) {
                                 Subnetmap sn = neutronvpnUtils.getSubnetmap(subnet);
                                 if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpn)) {
-                                    vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils
-                                         .getIpVersionFromString(sn.getSubnetIp()));
+                                    vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(
+                                            NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()));
                                     vpnInstanceIpVersionsRemoved = true;
                                 }
                                 removeSubnetFromVpn(vpn, subnet);
@@ -2276,7 +2277,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     protected List<Uuid> getNetworksForVpn(Uuid vpnId) {
-        return neutronvpnUtils.getNetworksforVpn(vpnId);
+        return neutronvpnUtils.getNetworksForVpn(vpnId);
     }
 
     /**
@@ -2479,9 +2480,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             LOG.error("vpn id or interface is null");
             return;
         }
-        Boolean wrtConfigTxnPresent = true;
+
         if (wrtConfigTxn == null) {
-            wrtConfigTxnPresent = false;
             wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
         }
         InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
index eb0fb80a357b39640c4d1cd382083ce9724bfd56..51ff0f6f9d00200b32f72b772886a3ece7dd8f11 100644 (file)
@@ -11,15 +11,16 @@ import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks;
@@ -160,7 +161,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
             if (newExtGw != null) {
                 return true;
             }
-        } else if (newExtGw == null || origExtGw.isEnableSnat() != newExtGw.isEnableSnat()) {
+        } else if (newExtGw == null || !Objects.equals(origExtGw.isEnableSnat(), newExtGw.isEnableSnat())) {
             return true;
         }
         return false;
@@ -215,8 +216,6 @@ public class NeutronvpnNatManager implements AutoCloseable {
         return false;
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void addExternalNetwork(Network net) {
         Uuid extNetId = net.getUuid();
 
@@ -247,15 +246,14 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Networks networkss = builder.build();
             // Add Networks object to the ExternalNetworks list
             LOG.trace("Creating externalnetworks {}", networkss);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier,
+                    networkss);
             LOG.trace("Wrote externalnetwork successfully to CONFIG Datastore");
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Creation of External Network {} failed", extNetId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void removeExternalNetwork(Network net) {
         Uuid extNetId = net.getUuid();
 
@@ -274,16 +272,14 @@ public class NeutronvpnNatManager implements AutoCloseable {
             }
             // Delete Networks object from the ExternalNetworks list
             LOG.trace("Deleting External Network {}", extNetId.getValue());
-            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
+            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
             LOG.trace("Deleted External Network {} successfully from CONFIG Datastore", extNetId.getValue());
 
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Deletion of External Network {} failed", extNetId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void addExternalNetworkToRouter(Router update) {
         Uuid routerId = update.getUuid();
         Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
@@ -327,16 +323,15 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Networks networkss = builder.build();
             // Add Networks object to the ExternalNetworks list
             LOG.trace("Updating externalnetworks {}", networkss);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier,
+                    networkss);
             LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Creation of externalnetworks failed for {}",
                 extNetId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void removeExternalNetworkFromRouter(Uuid origExtNetId, Router update,
             List<ExternalFixedIps> origExtFixedIps) {
         Uuid routerId = update.getUuid();
@@ -366,18 +361,17 @@ public class NeutronvpnNatManager implements AutoCloseable {
                     rtrList.remove(routerId);
                     builder.setRouterIds(rtrList);
                     Networks networkss = builder.build();
-                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
+                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                            netsIdentifier, networkss);
                     LOG.trace("Removed router {} from externalnetworks {}", routerId, origExtNetId.getValue());
                 }
             }
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Removing externalnetwork {} from router {} failed", origExtNetId.getValue(),
                     routerId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void addExternalNetworkToVpn(Network network, Uuid vpnId) {
         Uuid extNetId = network.getUuid();
 
@@ -401,16 +395,15 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Networks networkss = builder.build();
             // Add Networks object to the ExternalNetworks list
             LOG.trace("Setting VPN-ID for externalnetworks {}", networkss);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier,
+                    networkss);
             LOG.trace("Wrote with VPN-ID successfully to CONFIG Datastore");
 
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Attaching VPN-ID to externalnetwork {} failed", extNetId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void removeExternalNetworkFromVpn(Network network) {
         Uuid extNetId = network.getUuid();
 
@@ -435,16 +428,15 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Networks networkss = builder.build();
             // Add Networks object to the ExternalNetworks list
             LOG.trace("Remove vpn-id for externalnetwork {}", networkss);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier,
+                    networkss);
             LOG.trace("Updated extnetworks successfully to CONFIG Datastore");
 
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Removing VPN-ID from externalnetworks {} failed", extNetId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void addExternalRouter(Router update) {
         Uuid routerId = update.getUuid();
         Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
@@ -493,10 +485,11 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Routers routers = builder.build();
             // Add Routers object to the ExtRouters list
             LOG.trace("Creating extrouters {}", routers);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier,
+                    builder.build());
             LOG.trace("Wrote successfully Routers to CONFIG Datastore");
 
-        } catch (Exception ex) {
+        } catch (ReadFailedException | TransactionCommitFailedException ex) {
             LOG.error("Creation of extrouters failed for router {} failed",
                 routerId.getValue(), ex);
         }
@@ -518,15 +511,15 @@ public class NeutronvpnNatManager implements AutoCloseable {
                 RoutersBuilder builder = new RoutersBuilder(optionalRouters.get());
                 builder.setExternalIps(null);
                 builder.setSubnetIds(null);
-                MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
+                SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                        routersIdentifier);
                 LOG.trace("Removed router {} from extrouters", routerId.getValue());
             }
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Removing extrouter {} from extrouters failed", routerId.getValue(), ex);
         }
     }
 
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void removeRouterFromFloatingIpInfo(Router update, DataBroker broker) {
         Uuid routerId = update.getUuid();
         InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier
@@ -536,9 +529,10 @@ public class NeutronvpnNatManager implements AutoCloseable {
                     SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             routerPortsIdentifierBuilder.build());
             if (optionalRouterPorts.isPresent()) {
-                MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
+                SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.CONFIGURATION,
+                        routerPortsIdentifierBuilder.build());
             }
-        } catch (Exception e) {
+        } catch (ReadFailedException | TransactionCommitFailedException e) {
             LOG.error("Failed to read from FloatingIpInfo DS for routerid {}", routerId, e);
         }
     }
@@ -555,29 +549,26 @@ public class NeutronvpnNatManager implements AutoCloseable {
             LOG.trace("Updating External Fixed IPs Routers node {}", routerId.getValue());
             if (optionalRouters.isPresent()) {
                 RoutersBuilder builder = new RoutersBuilder(optionalRouters.get());
-                if (builder != null) {
-                    ArrayList<ExternalIps> externalIps = new ArrayList<>();
-                    for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
-                        addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
-                    }
-
-                    builder.setExternalIps(externalIps);
+                List<ExternalIps> externalIps = new ArrayList<>();
+                for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
+                    addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
                 }
 
+                builder.setExternalIps(externalIps);
+
                 updateExternalSubnetsForRouter(routerId, update.getExternalGatewayInfo().getExternalNetworkId(),
                         update.getExternalGatewayInfo().getExternalFixedIps());
                 Routers routerss = builder.build();
                 LOG.trace("Updating external fixed ips for router {} with value {}", routerId.getValue(), routerss);
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
+                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier,
+                        routerss);
                 LOG.trace("Added External Fixed IPs successfully for Routers to CONFIG Datastore");
             }
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Updating extfixedips for {} in extrouters failed", routerId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void handleSubnetsForExternalRouter(Uuid routerId) {
         InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
 
@@ -598,16 +589,15 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Routers routerss = builder.build();
             // Add Routers object to the ExtRouters list
             LOG.trace("Updating extrouters {}", routerss);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    routersIdentifier, routerss);
             LOG.trace("Updated successfully Routers to CONFIG Datastore");
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Updation of internal subnets for extrouters failed for router {}",
                 routerId.getValue(), ex);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void handleSnatSettingChangeForRouter(Router update) {
         Uuid routerId = update.getUuid();
 
@@ -629,10 +619,11 @@ public class NeutronvpnNatManager implements AutoCloseable {
             Routers routerss = builder.build();
             // Add Routers object to the ExtRouters list
             LOG.trace("Updating extrouters for snat change {}", routerss);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    routersIdentifier, routerss);
             LOG.trace("Updated successfully Routers to CONFIG Datastore");
 
-        } catch (Exception ex) {
+        } catch (TransactionCommitFailedException | ReadFailedException ex) {
             LOG.error("Updation of snat for extrouters failed for router {}", routerId.getValue(), ex);
         }
     }
index 42f923f70f0ef0fbdf4baeba1d15408569c12fab..b4360c55e6629b13ce6d798e7d7ce05a53bda5be 100644 (file)
@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.StringUtils;
@@ -243,21 +244,23 @@ public class NeutronvpnUtils {
 
     // @param external vpn - true if external vpn being fetched, false for internal vpn
     protected Uuid getVpnForRouter(Uuid routerId, Boolean externalVpn) {
+        if (routerId == null) {
+            return null;
+        }
+
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
         Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
         if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
             List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
-            if (routerId != null) {
-                for (VpnMap vpnMap : allMaps) {
-                    if (routerId.equals(vpnMap.getRouterId())) {
-                        if (externalVpn) {
-                            if (!routerId.equals(vpnMap.getVpnId())) {
-                                return vpnMap.getVpnId();
-                            }
-                        } else {
-                            if (routerId.equals(vpnMap.getVpnId())) {
-                                return vpnMap.getVpnId();
-                            }
+            for (VpnMap vpnMap : allMaps) {
+                if (routerId.equals(vpnMap.getRouterId())) {
+                    if (externalVpn) {
+                        if (!routerId.equals(vpnMap.getVpnId())) {
+                            return vpnMap.getVpnId();
+                        }
+                    } else {
+                        if (routerId.equals(vpnMap.getVpnId())) {
+                            return vpnMap.getVpnId();
                         }
                     }
                 }
@@ -279,7 +282,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
-    protected List<Uuid> getNetworksforVpn(Uuid vpnId) {
+    protected List<Uuid> getNetworksForVpn(Uuid vpnId) {
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
                 new VpnMapKey(vpnId)).build();
         Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
@@ -725,6 +728,7 @@ public class NeutronvpnUtils {
         return subnet;
     }
 
+    @Nonnull
     protected List<Uuid> getNeutronRouterSubnetIds(Uuid routerId) {
         LOG.debug("getNeutronRouterSubnetIds for {}", routerId.getValue());
         List<Uuid> subnetIdList = new ArrayList<>();
@@ -1277,7 +1281,7 @@ public class NeutronvpnUtils {
             if (sn.getSubnetIp() != null) {
                 IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
                 if (rep.choice != ipVers.choice) {
-                    rep.addVersion(ipVers);
+                    rep = rep.addVersion(ipVers);
                 }
                 if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
                     return rep;
@@ -1335,7 +1339,7 @@ public class NeutronvpnUtils {
      */
     public static IpVersionChoice getIpVersionFromString(String ipAddress) {
         IpVersionChoice ipchoice = IpVersionChoice.UNDEFINED;
-        if (ipAddress.indexOf("/") > 0) {
+        if (ipAddress.indexOf("/") >= 0) {
             ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
         }
         try {
index 431a92f99b564ee975d096ffc7931e99a0fd9dbf..c452fa1facc284838cccd4ffcedba635f87fa963 100644 (file)
@@ -69,34 +69,31 @@ public class NeutronEvpnManager {
 
         List<Evpn> vpns = input.getEvpn();
         for (Evpn vpn : vpns) {
-            RpcError error = null;
-            String msg;
-
             if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
-                msg = String.format("Creation of EVPN failed for VPN %s due to absence of RD/iRT/eRT input",
+                String msg = String.format("Creation of EVPN failed for VPN %s due to absence of RD/iRT/eRT input",
                         vpn.getId().getValue());
                 LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
+                RpcError error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
                 errorList.add(error);
                 warningcount++;
                 continue;
             }
             VpnInstance.Type vpnInstanceType = VpnInstance.Type.L2;
             if (vpn.getRouteDistinguisher().size() > 1) {
-                msg = String.format("Creation of EVPN failed for VPN %s due to multiple RD input %s",
+                String msg = String.format("Creation of EVPN failed for VPN %s due to multiple RD input %s",
                         vpn.getId().getValue(), vpn.getRouteDistinguisher());
                 LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
+                RpcError error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
                 errorList.add(error);
                 warningcount++;
                 continue;
             }
             if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
-                msg = String.format("Creation of EVPN failed for VPN %s as another VPN with",
-                        "the same RD %s is already configured",
+                String msg = String.format("Creation of EVPN failed for VPN %s as another VPN with "
+                        "the same RD %s is already configured",
                         vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0));
                 LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
+                RpcError error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
                 errorList.add(error);
                 warningcount++;
                 continue;
@@ -106,9 +103,9 @@ public class NeutronEvpnManager {
                         vpn.getImportRT(), vpn.getExportRT(), null /*router-id*/, null /*network-id*/,
                         vpnInstanceType, 0 /*l2vni*/);
             } catch (Exception ex) {
-                msg = String.format("Creation of EVPN failed for VPN %s", vpn.getId().getValue());
+                String msg = String.format("Creation of EVPN failed for VPN %s", vpn.getId().getValue());
                 LOG.error(msg, ex);
-                error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, msg, ex.getMessage());
+                RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, msg, ex.getMessage());
                 errorList.add(error);
                 failurecount++;
             }
index 5365205734be01acade125750970a04139de24d6..8e91494c8bc50fdfd48a05c1b9d1a2a97a851a12 100644 (file)
@@ -46,14 +46,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev15071
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<L2gateway, L2GatewayListener>
-        implements AutoCloseable {
+public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<L2gateway, L2GatewayListener> {
     private static final Logger LOG = LoggerFactory.getLogger(L2GatewayListener.class);
     private final DataBroker dataBroker;
     private final ItmRpcService itmRpcService;
@@ -210,7 +208,6 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
                     l2GwDevice.removeL2GatewayId(input.getUuid());
                     // Delete ITM tunnels
                     final String hwvtepId = l2GwDevice.getHwvtepNodeId();
-                    InstanceIdentifier<Node> iid = HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(hwvtepId));
 
                     final Set<IpAddress> tunnelIps = l2GwDevice.getTunnelIps();
                     jobCoordinator.enqueueJob(hwvtepId, () -> {
index 0fdc516ee375312f891bae52d4b315964f0f6dec..ea8d02d8efa7c3218cbc6cc9d3ba906d4aaf03f6 100644 (file)
@@ -28,8 +28,7 @@ import org.slf4j.LoggerFactory;
  */
 @Singleton
 public class L2GwTransportZoneListener
-        extends AsyncDataTreeChangeListenerBase<TransportZone, L2GwTransportZoneListener>
-        implements AutoCloseable {
+        extends AsyncDataTreeChangeListenerBase<TransportZone, L2GwTransportZoneListener> {
     private static final Logger LOG = LoggerFactory.getLogger(L2GwTransportZoneListener.class);
     private final DataBroker dataBroker;
     private final ItmRpcService itmRpcService;