X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Frole%2FRoleManagerImpl.java;h=716a9b38db51703378414e955d81d5611589b1ba;hb=867da8f64fbc12f407db3d41e96b216f7f62eb5b;hp=07c74c30e26e54a23c0fe1363fdd2af12bc406f7;hpb=e56afa21626eb9578c0d5d953f6660aaedd0db63;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java index 07c74c30e2..716a9b38db 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java @@ -20,6 +20,7 @@ import io.netty.util.TimerTask; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Future; @@ -122,26 +123,26 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se watchingEntities.remove(roleContext.getTxEntity()); contexts.remove(roleContext.getDeviceInfo()); if (roleContext.isTxCandidateRegistered()) { - LOG.info("Node {} was holder txEntity, so trying to remove device from operational DS."); + LOG.info("Node {} was holder txEntity, so trying to remove device from operational DS.", roleContext.getDeviceInfo().getNodeId().getValue()); removeDeviceFromOperationalDS(roleContext.getDeviceInfo(), MAX_CLEAN_DS_RETRIES); - } else { - roleContext.close(); } + roleContext.close(); } } @Override public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) { LOG.trace("onDeviceContextLevelDown for node {}", deviceInfo.getNodeId()); - final RoleContext roleContext = contexts.get(deviceInfo); + final RoleContext roleContext = contexts.remove(deviceInfo); if (roleContext != null) { LOG.debug("Found roleContext associated to deviceContext: {}, now trying close the roleContext", deviceInfo.getNodeId()); - if (roleContext.isMainCandidateRegistered()) { - roleContext.unregisterCandidate(roleContext.getEntity()); - } else { - contexts.remove(deviceInfo.getNodeId(), roleContext); - roleContext.close(); + roleContext.setState(OFPContext.CONTEXT_STATE.TERMINATION); + roleContext.unregisterCandidate(roleContext.getEntity()); + if (roleContext.isTxCandidateRegistered()) { + LOG.info("Node {} was holder txEntity, so trying to remove device from operational DS.", deviceInfo.getNodeId().getValue()); + removeDeviceFromOperationalDS(roleContext.getDeviceInfo(), MAX_CLEAN_DS_RETRIES); } + roleContext.close(); } deviceTerminationPhaseHandler.onDeviceContextLevelDown(deviceInfo); } @@ -162,19 +163,24 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se Preconditions.checkArgument(ownershipChange != null); final RoleContext roleContext = watchingEntities.get(ownershipChange.getEntity()); - LOG.debug("Received EOS message: wasOwner:{} isOwner:{} hasOwner:{} inJeopardy:{} for entity type {} and node {}", - ownershipChange.wasOwner(), ownershipChange.isOwner(), ownershipChange.hasOwner(), ownershipChange.inJeopardy(), - ownershipChange.getEntity().getType(), - roleContext != null ? roleContext.getDeviceInfo().getNodeId() : "-> no watching entity, disregarding notification <-"); + if (Objects.nonNull(roleContext) && !roleContext.getState().equals(OFPContext.CONTEXT_STATE.TERMINATION)) { + + LOG.debug("Received EOS message: wasOwner:{} isOwner:{} hasOwner:{} inJeopardy:{} for entity type {} and node {}", + ownershipChange.wasOwner(), ownershipChange.isOwner(), ownershipChange.hasOwner(), ownershipChange.inJeopardy(), + ownershipChange.getEntity().getType(), + roleContext.getDeviceInfo().getNodeId()); - if (roleContext != null) { if (ownershipChange.getEntity().equals(roleContext.getEntity())) { changeOwnershipForMainEntity(ownershipChange, roleContext); } else { changeOwnershipForTxEntity(ownershipChange, roleContext); } + } else { - LOG.debug("OwnershipChange {}", ownershipChange); + + LOG.debug("Role context for entity type {} is in state closing, disregarding ownership change notification.", ownershipChange.getEntity().getType()); + watchingEntities.remove(ownershipChange.getEntity()); + } } @@ -247,7 +253,6 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se LOG.debug("Trying to remove from operational node: {}", roleContext.getDeviceInfo().getNodeId()); removeDeviceFromOperationalDS(roleContext.getDeviceInfo(), MAX_CLEAN_DS_RETRIES); } else { - final NodeId nodeId = roleContext.getDeviceInfo().getNodeId(); contexts.remove(roleContext.getDeviceInfo(), roleContext); roleContext.close(); conductor.closeConnection(roleContext.getDeviceInfo()); @@ -270,13 +275,15 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se @Override public void onSuccess(@Nullable final RpcResult setRoleOutputRpcResult) { LOG.info("Role {} successfully set on device {}", role, roleContext.getDeviceInfo().getNodeId()); - notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo(), true, role, init); + if (!init) { + notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo(), role); + } } @Override public void onFailure(@Nonnull final Throwable throwable) { LOG.warn("Unable to set role {} on device {}", role, roleContext.getDeviceInfo().getNodeId()); - notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo(), false, role, init); + conductor.closeConnection(roleContext.getDeviceInfo()); } }); } @@ -400,20 +407,18 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se * Notifies registered listener on role change. Role is the new role on device * If initialization phase is true, we may skip service starting * @param deviceInfo - * @param success true if role change on device done ok, false otherwise * @param role new role meant to be set on device - * @param initializationPhase if true, then skipp services start */ @VisibleForTesting - void notifyListenersRoleChangeOnDevice(final DeviceInfo deviceInfo, final boolean success, final OfpRole role, final boolean initializationPhase){ + void notifyListenersRoleChangeOnDevice(final DeviceInfo deviceInfo, final OfpRole role){ LOG.debug("Notifying registered listeners for role change, no. of listeners {}", listeners.size()); for (final RoleChangeListener listener : listeners) { - listener.roleChangeOnDevice(deviceInfo, success, role, initializationPhase); + listener.roleChangeOnDevice(deviceInfo, role); } } @Override - public T gainContext(DeviceInfo deviceInfo) { + public T gainContext(final DeviceInfo deviceInfo) { return (T) contexts.get(deviceInfo); } }