From 5437aabe5766d929a735d9fcadfe1e261772519d Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Thu, 14 Sep 2017 09:16:05 +0200 Subject: [PATCH] Terminate SLAVE task before sending role change - Terminate SLAVE task in role context when role change is requested and not after role change is finished. - Do not send notification about role failed to set to mastership service in case future was cancelled See also: bug 9089 Change-Id: Ia784d3b682b8991fe7a471bbfc7462aebfa6d4ef Signed-off-by: Tomas Slusny --- .../impl/role/RoleContextImpl.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java index a17b540356..88b87527d8 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java @@ -19,6 +19,7 @@ import io.netty.util.TimerTask; import java.util.Collection; import java.util.HashSet; import java.util.Objects; +import java.util.concurrent.CancellationException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -86,7 +87,6 @@ public class RoleContextImpl implements RoleContext { @Override public void close() { - slaveTask.cancel(); changeLastRoleFuture(null); requestContexts.forEach(requestContext -> RequestContextUtil .closeRequestContextWithRpcError(requestContext, "Connection closed.")); @@ -126,6 +126,7 @@ public class RoleContextImpl implements RoleContext { } private void changeLastRoleFuture(final ListenableFuture> newFuture) { + slaveTask.cancel(); lastRoleFuture.getAndUpdate(lastFuture -> { if (Objects.nonNull(lastFuture) && !lastFuture.isCancelled() && !lastFuture.isDone()) { lastFuture.cancel(true); @@ -172,7 +173,6 @@ public class RoleContextImpl implements RoleContext { private final class MasterRoleCallback implements FutureCallback> { @Override public void onSuccess(@Nullable RpcResult setRoleOutputRpcResult) { - slaveTask.cancel(); contextChainMastershipWatcher.onMasterRoleAcquired( deviceInfo, ContextChainMastershipState.MASTER_ON_DEVICE); @@ -181,26 +181,27 @@ public class RoleContextImpl implements RoleContext { @Override public void onFailure(@Nonnull final Throwable throwable) { - slaveTask.cancel(); - contextChainMastershipWatcher.onNotAbleToStartMastershipMandatory( - deviceInfo, - "Was not able to propagate MASTER role on device. Error: " + throwable.toString()); + if (!(throwable instanceof CancellationException)) { + contextChainMastershipWatcher.onNotAbleToStartMastershipMandatory( + deviceInfo, + "Was not able to propagate MASTER role on device. Error: " + throwable.toString()); + } } } private final class SlaveRoleCallback implements FutureCallback> { @Override public void onSuccess(@Nullable final RpcResult result) { - slaveTask.cancel(); contextChainMastershipWatcher.onSlaveRoleAcquired(deviceInfo); LOG.debug("Role SLAVE was successfully set on device, node {}", deviceInfo); } @Override public void onFailure(@Nonnull final Throwable throwable) { - slaveTask.cancel(); - contextChainMastershipWatcher.onSlaveRoleNotAcquired(deviceInfo, - "Was not able to propagate SLAVE role on device. Error: " + throwable.toString()); + if (!(throwable instanceof CancellationException)) { + contextChainMastershipWatcher.onSlaveRoleNotAcquired(deviceInfo, + "Was not able to propagate SLAVE role on device. Error: " + throwable.toString()); + } } } } \ No newline at end of file -- 2.36.6