From 018ab358c128db9ef389935fec96cfe752e1cdf0 Mon Sep 17 00:00:00 2001 From: Shuva Kar Date: Tue, 28 Jun 2016 21:22:31 +0530 Subject: [PATCH] BUG-6118: making the OFentityListener aware of the InJeopardy() flag Change-Id: I8e489b9afd7f433b924e009fe8ba64166b7c146e Signed-off-by: Shuva Kar --- .../md/core/role/OfEntityManager.java | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/role/OfEntityManager.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/role/OfEntityManager.java index 4f446b58a1..a62ae837ee 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/role/OfEntityManager.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/role/OfEntityManager.java @@ -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 -- 2.36.6