BUG-6118: making the OFentityListener aware of the InJeopardy() flag 53/40953/5
authorShuva Kar <shuva.jyoti.kar@ericsson.com>
Tue, 28 Jun 2016 15:52:31 +0000 (21:22 +0530)
committerShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Sun, 4 Sep 2016 12:54:52 +0000 (12:54 +0000)
Change-Id: I8e489b9afd7f433b924e009fe8ba64166b7c146e
Signed-off-by: Shuva Kar <shuva.jyoti.kar@ericsson.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/role/OfEntityManager.java

index 4f446b58a1349af89fcfabe17511b2d1ab21c92a..a62ae837eef8bae29f48c7f909d5d25feaadd2d2 100644 (file)
@@ -216,35 +216,50 @@ public class OfEntityManager implements TransactionChainListener{
         final OfpRole newRole;
         final Entity entity = ownershipChange.getEntity();
         SessionContext sessionContext = entsession.get(entity)!=null?entsession.get(entity).getContext():null;
-        if (ownershipChange.isOwner()) {
-            LOG.info("onDeviceOwnershipChanged: Set controller as a MASTER controller because " +
-                    "it's the OWNER of the {}", entity);
-            newRole =  OfpRole.BECOMEMASTER;
-        }
-        else {
-
-            newRole =  OfpRole.BECOMESLAVE;
-            if(sessionContext != null && ownershipChange.hasOwner()) {
-                LOG.info("onDeviceOwnershipChanged: Set controller as a SLAVE controller because " +
-                        "it's not the OWNER of the {}", entity);
-
-                if(ownershipChange.wasOwner()) {
-                    setDeviceOwnershipState(entity,false);
-                    deregisterRoutedRPCForSwitch(entsession.get(entity));
-                    // You don't have to explicitly set role to Slave in this case,
-                    // because other controller will be taking over the master role
-                    // and that will force other controller to become slave.
-                } else {
-                    boolean isOwnershipInitialized = entsession.get(entity).getIsOwnershipInitialized();
-                    setDeviceOwnershipState(entity,false);
-                    if (!isOwnershipInitialized) {
-                        setSlaveRole(sessionContext);
-                        sendNodeAddedNotification(entsession.get(entity));
+        if (!ownershipChange.inJeopardy()) {
+            if (ownershipChange.isOwner()) {
+                LOG.info("onDeviceOwnershipChanged: Set controller as a MASTER controller because " +
+                        "it's the OWNER of the {}", entity);
+                newRole = OfpRole.BECOMEMASTER;
+            } else {
+                newRole = OfpRole.BECOMESLAVE;
+                if (sessionContext != null && ownershipChange.hasOwner()) {
+                    LOG.info("onDeviceOwnershipChanged: Set controller as a SLAVE controller because " +
+                            "it's not the OWNER of the {}", entity);
+
+                    if (ownershipChange.wasOwner()) {
+                        setDeviceOwnershipState(entity, false);
+                        deregisterRoutedRPCForSwitch(entsession.get(entity));
+                        // You don't have to explicitly set role to Slave in this case,
+                        // because other controller will be taking over the master role
+                        // and that will force other controller to become slave.
+                    } else {
+                        boolean isOwnershipInitialized = entsession.get(entity).getIsOwnershipInitialized();
+                        setDeviceOwnershipState(entity, false);
+                        if (!isOwnershipInitialized) {
+                            setSlaveRole(sessionContext);
+                            sendNodeAddedNotification(entsession.get(entity));
+                        }
                     }
                 }
+                return;
             }
-            return;
+        } else {
+            LOG.error("onDeviceOwnershipChanged: inJeopardy{}", ownershipChange.inJeopardy());
+            //if i am the owner at present , i have lost quorum
+            //thus transitioning to slave
+             //if i am not the owner , election will be triggered
+            if(entsession.get(entity).getOfSwitch().isEntityOwner()){
+                newRole = OfpRole.BECOMESLAVE;
+                setSlaveRole(sessionContext);
+                setDeviceOwnershipState(entity, false);
+                deregisterRoutedRPCForSwitch(entsession.get(entity));
+            }else{
+                LOG.error(" owner of the switch {}",entsession.get(entity).getOfSwitch().isEntityOwner());
+            }
+          return;
         }
+
         if (sessionContext != null) {
             //Register the RPC, given *this* controller instance is going to be master owner.
             //If role registration fails for this node, it will deregister as a candidate for
@@ -451,4 +466,4 @@ public class OfEntityManager implements TransactionChainListener{
             this.isOwnershipInitialized.set(ownershipState);
         }
     }
-}
+}
\ No newline at end of file