Exception Handling in UpgradeStateListener 19/74619/2
authorxcheara <chetan.arakere@altencalsoftlabs.com>
Sun, 29 Jul 2018 10:23:15 +0000 (15:53 +0530)
committerxcheara <chetan.arakere@altencalsoftlabs.com>
Sun, 29 Jul 2018 11:04:49 +0000 (16:34 +0530)
Change-Id: I8bf268e8392b9f7b3902de318833729f3dfca4f4
Signed-off-by: xcheara <chetan.arakere@altencalsoftlabs.com>
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/UpgradeStateListener.java

index dc28ae022a57c33c0616c0038352f9c2fa00424b..49d54141cf17146a4dda94ffe1a1315a9a0cb03f 100644 (file)
@@ -2156,12 +2156,11 @@ public final class NatUtil {
     public static void removeSNATFromDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager,
             IdManagerService idManager, NaptSwitchHA naptSwitchHA, BigInteger dpnId,
             String routerName, long routerId, long routerVpnId,
-            ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> confTx) {
+            ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> confTx)
+                    throws ExecutionException, InterruptedException {
         //irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
         //remove miss entry to NAPT switch
         //if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
-
-        Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
         if (extNwProvType == null) {
             return;
         }
@@ -2177,77 +2176,74 @@ public final class NatUtil {
             LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
             return;
         }
-        try {
-            boolean naptStatus =
-                naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId,
-                        externalIpCache, confTx);
-            if (!naptStatus) {
-                LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}",
-                    dpnId, routerName);
-                long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
-                FlowEntity flowEntity = null;
-                try {
-                    flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId,
-                        NatConstants.DEL_FLOW);
-                    if (flowEntity == null) {
-                        LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
-                                + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
-                        return;
-                    }
-                    LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
-                    mdsalManager.removeFlow(confTx, flowEntity);
-
-                } catch (Exception ex) {
-                    LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
-                        flowEntity, ex);
-                    return;
-                }
-                LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}",
-                    dpnId, routerName);
-
-                //remove group
-                GroupEntity groupEntity = null;
-                try {
-                    groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
-                        GroupTypes.GroupAll, Collections.emptyList() /*listBucketInfo*/);
-                    LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
-                    mdsalManager.removeGroup(groupEntity);
-                } catch (Exception ex) {
-                    LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
+        Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
+        boolean naptStatus =
+            naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId,
+                    externalIpCache, confTx);
+        if (!naptStatus) {
+            LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}",
+                dpnId, routerName);
+            long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
+            FlowEntity flowEntity = null;
+            try {
+                flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId,
+                    NatConstants.DEL_FLOW);
+                if (flowEntity == null) {
+                    LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
+                            + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
                     return;
                 }
-                LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}",
-                    dpnId, routerName);
-            } else {
-                naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch,
-                        externalIpLabel, confTx);
-                //remove table 26 flow ppointing to table46
-                FlowEntity flowEntity = null;
-                try {
-                    flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId,
-                        NatConstants.DEL_FLOW);
-                    if (flowEntity == null) {
-                        LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}",
-                                routerName, dpnId);
-                        return;
-                    }
-                    LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with "
-                        + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
-                    mdsalManager.removeFlow(confTx, flowEntity);
+                LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
+                mdsalManager.removeFlow(confTx, flowEntity);
 
-                } catch (Exception ex) {
-                    LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
-                        flowEntity, ex);
+            } catch (Exception ex) {
+                LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
+                    flowEntity, ex);
+                return;
+            }
+            LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}",
+                dpnId, routerName);
+
+            //remove group
+            GroupEntity groupEntity = null;
+            try {
+                groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
+                    GroupTypes.GroupAll, Collections.emptyList() /*listBucketInfo*/);
+                LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
+                mdsalManager.removeGroup(groupEntity);
+            } catch (Exception ex) {
+                LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
+                return;
+            }
+            LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}",
+                dpnId, routerName);
+        } else {
+            naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch,
+                    externalIpLabel, confTx);
+            //remove table 26 flow ppointing to table46
+            FlowEntity flowEntity = null;
+            try {
+                flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId,
+                    NatConstants.DEL_FLOW);
+                if (flowEntity == null) {
+                    LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}",
+                            routerName, dpnId);
                     return;
                 }
-                LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}",
-                    dpnId, routerName);
+                LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with "
+                    + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
+                mdsalManager.removeFlow(confTx, flowEntity);
 
-                //best effort to check IntExt model
-                naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, confTx);
+            } catch (Exception ex) {
+                LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
+                    flowEntity, ex);
+                return;
             }
-        } catch (Exception ex) {
-            LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, ex);
+            LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}",
+                dpnId, routerName);
+
+            //best effort to check IntExt model
+            naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, confTx);
         }
     }
 
index 712be49a653d9ef2832a4a13f4a49b5e061d2e0a..a82dac312b0da640263d2a3219110bb7e3b401ea 100644 (file)
@@ -15,6 +15,8 @@ import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -143,7 +145,7 @@ public class UpgradeStateListener extends AbstractClusteredSyncDataTreeChangeLis
     }
 
     private void reElectNewNaptSwitch(String routerName, BigInteger primaryNaptDpnId,
-            TypedReadWriteTransaction<Configuration> confTx) {
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
         // Check if this is externalRouter else ignore
         InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
         Optional<Routers> routerData =