Fix NPE in updateVpnInterfacesForUnProcessAdj 24/73624/3
authorSridhar Gaddam <sgaddam@redhat.com>
Wed, 27 Jun 2018 17:28:37 +0000 (22:58 +0530)
committerAswin Suryanarayanan <asuryana@redhat.com>
Mon, 2 Jul 2018 17:51:10 +0000 (17:51 +0000)
Issue: NETVIRT-1353

Change-Id: I3fe772517f59d02aa92fd7117842a72304205e40
Signed-off-by: Sridhar Gaddam <sgaddam@redhat.com>
(cherry picked from commit 08699284e9398bff2d0eeaca0edc3c55965291d0)

vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnInterfaceManager.java

index 4f0d4260eea6dfbc6ce05694d18138c8076c52cd..ee1c32b0b3d2b38b8a8751c539017d4b3160e64f 100755 (executable)
@@ -2118,29 +2118,33 @@ public class VpnInterfaceManager extends AsyncDataTreeChangeListenerBase<VpnInte
             return;
         }
         LOG.debug("Update the VpnInterfaces for Unprocessed Adjancencies for vpnName:{}", vpnName);
-        vpnToDpnLists.forEach(vpnToDpnList -> vpnToDpnList.getVpnInterfaces().forEach(vpnInterface -> {
-            try {
-                InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId =
-                        VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
-                Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = SingleTransactionDataBroker.syncReadOptional(
-                        dataBroker, LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
-                if (!vpnInterfaceOptional.isPresent()) {
-                    return;
-                }
-                List<Adjacency> configVpnAdjacencies = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker,
-                        vpnInterface.getInterfaceName());
-                if (configVpnAdjacencies == null) {
-                    LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
-                    return;
-                }
-                List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get()
-                        .augmentation(AdjacenciesOp.class).getAdjacency();
-                // Due to insufficient rds,  some of the extra route wont get processed when it is added.
-                // The unprocessed adjacencies will be present in config vpn interface DS but will be missing
-                // in operational DS. These unprocessed adjacencies will be handled below.
-                // To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in operational
-                // DS are retrieved which is used to call addNewAdjToVpnInterface method.
-                configVpnAdjacencies.stream()
+        vpnToDpnLists.forEach(vpnToDpnList -> {
+            if (vpnToDpnList.getVpnInterfaces() == null) {
+                return;
+            }
+            vpnToDpnList.getVpnInterfaces().forEach(vpnInterface -> {
+                try {
+                    InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId =
+                            VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
+                    Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = SingleTransactionDataBroker
+                            .syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
+                    if (!vpnInterfaceOptional.isPresent()) {
+                        return;
+                    }
+                    List<Adjacency> configVpnAdjacencies = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker,
+                            vpnInterface.getInterfaceName());
+                    if (configVpnAdjacencies == null) {
+                        LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
+                        return;
+                    }
+                    List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get()
+                            .augmentation(AdjacenciesOp.class).getAdjacency();
+                    // Due to insufficient rds,  some of the extra route wont get processed when it is added.
+                    // The unprocessed adjacencies will be present in config vpn interface DS but will be missing
+                    // in operational DS. These unprocessed adjacencies will be handled below.
+                    // To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in
+                    // operational DS are retrieved which is used to call addNewAdjToVpnInterface method.
+                    configVpnAdjacencies.stream()
                         .filter(adjacency -> operationVpnAdjacencies.stream()
                                 .noneMatch(operationalAdjacency ->
                                         operationalAdjacency.getIpAddress().equals(adjacency.getIpAddress())))
@@ -2153,21 +2157,22 @@ public class VpnInterfaceManager extends AsyncDataTreeChangeListenerBase<VpnInte
                                     if (VpnUtil.isAdjacencyEligibleToVpn(dataBroker, adjacency, vpnName)) {
                                         List<ListenableFuture<Void>> futures = new ArrayList<>();
                                         futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx ->
-                                                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
-                                                    confTx -> addNewAdjToVpnInterface(existingVpnInterfaceId,
-                                                            primaryRd, adjacency, vpnInterfaceOptional.get()
-                                                                    .getDpnId(), confTx, operTx)))));
+                                            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                                                confTx -> addNewAdjToVpnInterface(existingVpnInterfaceId,
+                                                    primaryRd, adjacency, vpnInterfaceOptional.get()
+                                                        .getDpnId(), confTx, operTx)))));
                                         return futures;
                                     } else {
                                         return Collections.emptyList();
                                     }
                                 });
                         });
-            } catch (ReadFailedException e) {
-                LOG.error("updateVpnInterfacesForUnProcessAdjancencies: Failed to read data store for vpn {} rd {}",
-                        vpnName, primaryRd);
-            }
-        }));
+                } catch (ReadFailedException e) {
+                    LOG.error("updateVpnInterfacesForUnProcessAdjancencies: Failed to read data store for vpn {} rd {}",
+                            vpnName, primaryRd);
+                }
+            });
+        });
     }
 
     private class PostVpnInterfaceWorker implements FutureCallback<Void> {