Handle cancel txn exception for slaves and device disconnect exception 79/28979/4
authorKamal Rameshan <kramesha@cisco.com>
Mon, 5 Oct 2015 05:16:17 +0000 (22:16 -0700)
committerKamal Rameshan <kramesha@cisco.com>
Wed, 11 Nov 2015 21:20:54 +0000 (13:20 -0800)
During the device initialization process, if its encountered that the role for this node is slave
we cancel the txn which is built during the process.
Now since ping-pong txn does not have a cancel, we drop the txn and recreate it. This throws an exception
Since this is an expected exception, it would be advisable to catch and log it in debug.

Also when a node gets disconected from device, the EntityOwnershipService does send a notification. Which trigers a role change.
A check is made to check if the device is connected before moving ahead with the role change.

Change-Id: I76572f27274f5c5f08117fcfd1590d1042049735
Signed-off-by: Kamal Rameshan <kramesha@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java

index 569c00a82853e4aa190c3a155ce1b74fb4b16dd6..4ae3d1eed9b66dc1d18f50f0de02d2b97c50f154 100644 (file)
@@ -175,8 +175,16 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
             if (deviceContext.getDeviceState().getRole() != OfpRole.BECOMESLAVE) {
                 ((DeviceContextImpl) deviceContext).initialSubmitTransaction();
                 deviceContext.onPublished();
+
             } else {
-                ((DeviceContextImpl) deviceContext).cancelTransaction();
+                //if role = slave
+                try {
+                    ((DeviceContextImpl) deviceContext).cancelTransaction();
+                } catch (Exception e) {
+                    //TODO: how can we avoid it. pingpong does not have cancel
+                    LOG.debug("Expected Exception: Cancel Txn exception thrown for slaves", e);
+                }
+
             }
 
         } catch (final Exception e) {
index fd392cd19f3aaa5ea29c735e1a59173b16cd2625..06305e1879d4957150b7a19338897e2522f0a5b0 100644 (file)
@@ -92,7 +92,12 @@ public class RoleContextImpl implements RoleContext {
     @Override
     public void onRoleChanged(final OfpRole oldRole, final OfpRole newRole) {
 
-        // called notification thread from md-sal
+        if (!isDeviceConnected()) {
+            // this can happen as after the disconnect, we still get a last messsage from EntityOwnershipService.
+            LOG.info("Device {} is disconnected from this node. Hence not attempting a role change.",
+                    deviceContext.getPrimaryConnectionContext().getNodeId());
+            return;
+        }
 
         LOG.debug("Role change received from ownership listener from {} to {} for device:{}", oldRole, newRole,
                 deviceContext.getPrimaryConnectionContext().getNodeId());
index bf0e02e35b34846d91399d51f22c9afc9d468c92..02780493214a3eec9c876d763b487f86f9f71bfe 100644 (file)
@@ -83,6 +83,7 @@ public class RoleContextImplTest {
         when(deviceState.getFeatures()).thenReturn(getFeaturesOutput);
         when(getFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
         when(deviceContext.getPrimaryConnectionContext().getFeatures()).thenReturn(featuresReply);
+        when(deviceContext.getPrimaryConnectionContext().getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
     }
 
     @Test