Handling NPE 61/72161/3
authorxcheara <chetan.arakere@altencalsoftlabs.com>
Tue, 22 May 2018 12:09:46 +0000 (17:39 +0530)
committerSam Hague <shague@redhat.com>
Wed, 30 May 2018 16:39:05 +0000 (16:39 +0000)
Issue : NETVIRT-1276

Change-Id: If34422444e26facae0374523935f5f33c083f006
Signed-off-by: xcheara <chetan.arakere@altencalsoftlabs.com>
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java

index 40f8ee30a2a547e58ad8012fbd157f59de95046e..22b9d3419d9263d7bb2ccaa4b8c75700823edf4f 100644 (file)
@@ -63,9 +63,11 @@ public class SnatCentralizedSwitchChangeListener
     protected void remove(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
         LOG.debug("Deleting {}", routerToNaptSwitch);
         BigInteger primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
-        Routers router =   natDataUtil.getRouter(routerToNaptSwitch.getRouterName());
-        snatServiceManger.notify(router, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
-        natDataUtil.removeFromRouterMap(router);
+        Routers router = natDataUtil.getRouter(routerToNaptSwitch.getRouterName());
+        if (router != null) {
+            snatServiceManger.notify(router, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
+            natDataUtil.removeFromRouterMap(router);
+        }
     }
 
     @Override
@@ -74,14 +76,18 @@ public class SnatCentralizedSwitchChangeListener
         LOG.debug("Updating old {} new {}", origRouterToNaptSwitch, updatedRouterToNaptSwitch);
         BigInteger origPrimarySwitchId = origRouterToNaptSwitch.getPrimarySwitchId();
         Routers origRouter = NatUtil.getRoutersFromConfigDS(dataBroker, origRouterToNaptSwitch.getRouterName());
-        snatServiceManger.notify(origRouter, origPrimarySwitchId, null,
-                SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
-        natDataUtil.removeFromRouterMap(origRouter);
+        if (origRouter != null) {
+            snatServiceManger.notify(origRouter, origPrimarySwitchId, null,
+                    SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
+            natDataUtil.removeFromRouterMap(origRouter);
+        }
         BigInteger updatedPrimarySwitchId = updatedRouterToNaptSwitch.getPrimarySwitchId();
         Routers updatedRouter = NatUtil.getRoutersFromConfigDS(dataBroker, updatedRouterToNaptSwitch.getRouterName());
-        natDataUtil.updateRouterMap(updatedRouter);
-        snatServiceManger.notify(updatedRouter, updatedPrimarySwitchId, null,
-                SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
+        if (updatedRouter != null) {
+            natDataUtil.updateRouterMap(updatedRouter);
+            snatServiceManger.notify(updatedRouter, updatedPrimarySwitchId, null,
+                    SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
+        }
     }
 
     @Override
@@ -89,8 +95,10 @@ public class SnatCentralizedSwitchChangeListener
         LOG.debug("Adding {}", routerToNaptSwitch);
         BigInteger primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
         Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerToNaptSwitch.getRouterName());
-        natDataUtil.addtoRouterMap(router);
-        snatServiceManger.notify(router, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
+        if (router != null) {
+            natDataUtil.addtoRouterMap(router);
+            snatServiceManger.notify(router, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
+        }
     }
 
     @Override