Remove RoleManager and RoleContext 03/47003/2
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Mon, 17 Oct 2016 10:25:32 +0000 (12:25 +0200)
committerJozef Bacigal <jozef.bacigal@pantheon.tech>
Mon, 17 Oct 2016 12:43:02 +0000 (14:43 +0200)
- no more functionality for role manager (after Singleton changes)
- all remain functionality from role-mng and ctx were moved to device-mgn and ctx

Change-Id: I1cc1ef23c45da7b9a4288194caa7f88f7534e409
Signed-off-by: Jozef Bacigal <jozef.bacigal@pantheon.tech>
16 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/LifecycleService.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleContext.java [deleted file]
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleManager.java [deleted file]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java [deleted file]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java [deleted file]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java [deleted file]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java [deleted file]

index 676c21c780ba112cc69264d4d2b192c0b30d58e1..1f8c692b498c33eee73063391192d3eee8c7288c 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import io.netty.util.Timeout;
 import java.math.BigInteger;
 import java.util.List;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
@@ -21,6 +22,9 @@ import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 
 /**
  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
@@ -41,7 +45,8 @@ public interface DeviceContext extends
         AutoCloseable,
         DeviceReplyProcessor,
         TxFacade,
-        DeviceRegistry{
+        DeviceRegistry,
+        RequestContextStack{
 
     /**
      * Method close all auxiliary connections and primary connection.
@@ -132,5 +137,17 @@ public interface DeviceContext extends
     void replaceConnectionContext(ConnectionContext connectionContext);
 
     boolean isSkipTableFeatures();
+
+    /**
+     * Setter for sal role service
+     * @param salRoleService
+     */
+    void setSalRoleService(@Nonnull final SalRoleService salRoleService);
+
+    /**
+     * Make device slave
+     * @return listenable future from sal role service
+     */
+    ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave();
 }
 
index 51f4ee680cf577467bb0068f3dd2a91b3356aa54..c56409a6da4f34c9d6db39d5af61ff30567cecf2 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.openflowplugin.api.openflow.device;
 
+import com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
@@ -39,5 +41,6 @@ public interface DeviceManager extends DeviceConnectedHandler, DeviceDisconnecte
 
     void setBarrierInterval(long barrierTimeoutLimit);
 
+    CheckedFuture<Void, TransactionCommitFailedException> removeDeviceFromOperationalDS(DeviceInfo deviceInfo);
 }
 
index 3084568e3c687cd6d3395b7553afd9fe8e0eafd5..c3e35491c18f09acd05d25939715d2caf2cd24ea 100644 (file)
@@ -13,7 +13,6 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterLifecycleSupervisor;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 
@@ -40,12 +39,6 @@ public interface LifecycleService extends ClusterSingletonService, AutoCloseable
      */
     void setRpcContext(final RpcContext rpcContext);
 
-    /**
-     * Setter for role context
-     * @param roleContext actual role context created per device
-     */
-    void setRoleContext(final RoleContext roleContext);
-
     /**
      * Setter for statistics context
      * @param statContext actual statistics context created per device
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleContext.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleContext.java
deleted file mode 100644 (file)
index 1296d75..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.api.openflow.role;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import javax.annotation.Nonnull;
-import org.opendaylight.openflowplugin.api.openflow.OFPContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-/**
- * Role context for change role on cluster
- */
-public interface RoleContext extends  RequestContextStack, OFPContext {
-
-    /**
-     * Setter for sal role service
-     * @param salRoleService
-     */
-    void setSalRoleService(@Nonnull final SalRoleService salRoleService);
-
-    /**
-     * Make device slave
-     * @return listenable future from sal role service
-     */
-    ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave();
-}
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleManager.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/role/RoleManager.java
deleted file mode 100644 (file)
index 9bc4c88..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.api.openflow.role;
-
-import com.google.common.util.concurrent.CheckedFuture;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-
-/**
- * Manager for role change on device
- */
-public interface RoleManager extends
-        DeviceLifecycleSupervisor,
-        DeviceInitializationPhaseHandler,
-        AutoCloseable,
-        DeviceTerminationPhaseHandler {
-
-    CheckedFuture<Void, TransactionCommitFailedException> removeDeviceFromOperationalDS(final DeviceInfo deviceInfo);
-
-}
index 846cc7cb9170d3c5a342fa5e65b61eae65d4556b..a1799ac79108b3791d32d5b18b81d4d12f35c911 100644 (file)
@@ -38,7 +38,6 @@ import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionPro
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
@@ -48,7 +47,6 @@ import org.opendaylight.openflowplugin.extension.api.OpenFlowPluginExtensionRegi
 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterManager;
 import org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl;
 import org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl;
-import org.opendaylight.openflowplugin.impl.role.RoleManagerImpl;
 import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl;
 import org.opendaylight.openflowplugin.impl.statistics.StatisticsManagerImpl;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
@@ -79,7 +77,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private int barrierCountLimit;
     private long echoReplyTimeout;
     private DeviceManager deviceManager;
-    private RoleManager roleManager;
     private RpcManager rpcManager;
     private RpcProviderRegistry rpcProviderRegistry;
     private StatisticsManager statisticsManager;
@@ -242,7 +239,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
         rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, extensionConverterManager, convertorManager, notificationPublishService);
-        roleManager = new RoleManagerImpl(dataBroker, hashedWheelTimer);
         statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, hashedWheelTimer, convertorManager);
 
         /* Initialization Phase ordering - OFP Device Context suite */
@@ -250,14 +246,12 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         connectionManager.setDeviceConnectedHandler(deviceManager);
         deviceManager.setDeviceInitializationPhaseHandler(statisticsManager);
         statisticsManager.setDeviceInitializationPhaseHandler(rpcManager);
-        rpcManager.setDeviceInitializationPhaseHandler(roleManager);
-        roleManager.setDeviceInitializationPhaseHandler(deviceManager);
+        rpcManager.setDeviceInitializationPhaseHandler(deviceManager);
 
         /* Termination Phase ordering - OFP Device Context suite */
         deviceManager.setDeviceTerminationPhaseHandler(rpcManager);
         rpcManager.setDeviceTerminationPhaseHandler(statisticsManager);
-        statisticsManager.setDeviceTerminationPhaseHandler(roleManager);
-        roleManager.setDeviceTerminationPhaseHandler(deviceManager);
+        statisticsManager.setDeviceTerminationPhaseHandler(deviceManager);
 
         rpcManager.setStatisticsRpcEnabled(isStatisticsRpcEnabled);
 
@@ -337,10 +331,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         rpcManager.close();
         statisticsManager.close();
 
-        // TODO: needs to close org.opendaylight.openflowplugin.impl.role.OpenflowOwnershipListener after RoleContexts are down
-        // TODO: must not be executed prior to all living RoleContexts have been closed (via closing living DeviceContexts)
-        roleManager.close();
-
         // Manually shutdown all remaining running threads in pool
         threadPool.shutdown();
     }
index 1f032d03cc0b5bc9a01f3af1b6be0b218f56f27a..393fe906895555a1c3f74e0244bab58fec7d7716 100644 (file)
@@ -8,18 +8,26 @@
 package org.opendaylight.openflowplugin.impl.device;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
+import com.google.common.util.concurrent.AsyncFunction;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timeout;
+import io.netty.util.TimerTask;
 import java.math.BigInteger;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
@@ -27,6 +35,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
+import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
@@ -62,6 +71,7 @@ import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
 import org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl;
 import org.opendaylight.openflowplugin.impl.registry.meter.DeviceMeterRegistryImpl;
+import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
 import org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtils;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
@@ -92,9 +102,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -108,8 +124,14 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     private static final float LOW_WATERMARK_FACTOR = 0.75f;
     // TODO: high water mark factor should be parametrized
     private static final float HIGH_WATERMARK_FACTOR = 0.95f;
+
+    // Timeout in seconds after what we will give up on propagating role
+    private static final int SET_ROLE_TIMEOUT = 10;
+
     private boolean initialized;
 
+    private SalRoleService salRoleService = null;
+    private final HashedWheelTimer hashedWheelTimer;
     private ConnectionContext primaryConnectionContext;
     private final DeviceState deviceState;
     private final DataBroker dataBroker;
@@ -136,6 +158,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     private final ConvertorExecutor convertorExecutor;
     private volatile CONTEXT_STATE state;
     private ClusterInitializationPhaseHandler clusterInitializationPhaseHandler;
+    private final DeviceManager myManager;
 
     DeviceContextImpl(
             @Nonnull final ConnectionContext primaryConnectionContext,
@@ -144,9 +167,13 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             @Nonnull final TranslatorLibrary translatorLibrary,
             @Nonnull final DeviceManager manager,
             final ConvertorExecutor convertorExecutor,
-            final boolean skipTableFeatures) {
+            final boolean skipTableFeatures,
+            final HashedWheelTimer hashedWheelTimer,
+            final DeviceManager myManager) {
         this.primaryConnectionContext = primaryConnectionContext;
         this.deviceInfo = primaryConnectionContext.getDeviceInfo();
+        this.hashedWheelTimer = hashedWheelTimer;
+        this.myManager = myManager;
         this.deviceState = new DeviceStateImpl();
         this.dataBroker = dataBroker;
         this.auxiliaryConnectionContexts = new HashMap<>();
@@ -549,9 +576,49 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
 
     @Override
     public ListenableFuture<Void> stopClusterServices(boolean deviceDisconnected) {
-        return initialized
-                ? this.transactionChainManager.deactivateTransactionManager()
-                : Futures.immediateFuture(null);
+
+        ListenableFuture<Void> deactivateTxManagerFuture =
+                initialized ? transactionChainManager.deactivateTransactionManager() : Futures.immediateFuture(null);
+
+        if (!deviceDisconnected) {
+            ListenableFuture<Void> makeSlaveFuture = Futures.transform(makeDeviceSlave(), new Function<RpcResult<SetRoleOutput>, Void>() {
+                @Nullable
+                @Override
+                public Void apply(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
+                    return null;
+                }
+            });
+
+            Futures.addCallback(makeSlaveFuture, new FutureCallback<Void>() {
+                @Override
+                public void onSuccess(@Nullable Void aVoid) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getLOGValue());
+                    }
+                }
+
+                @Override
+                public void onFailure(final Throwable throwable) {
+                    LOG.warn("Was not able to set role SLAVE to device on node {} ", deviceInfo.getLOGValue());
+                    LOG.trace("Error occurred on device role setting, probably connection loss: ", throwable);
+                    myManager.removeDeviceFromOperationalDS(deviceInfo);
+                }
+            });
+
+            return Futures.transform(deactivateTxManagerFuture, new AsyncFunction<Void, Void>() {
+                @Override
+                public ListenableFuture<Void> apply(Void aVoid) throws Exception {
+                    return makeSlaveFuture;
+                }
+            });
+        } else {
+            return Futures.transform(deactivateTxManagerFuture, new AsyncFunction<Void, Void>() {
+                @Override
+                public ListenableFuture<Void> apply(Void aVoid) throws Exception {
+                    return myManager.removeDeviceFromOperationalDS(deviceInfo);
+                }
+            });
+        }
     }
 
     @Override
@@ -584,6 +651,11 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         return this.skipTableFeatures;
     }
 
+    @Override
+    public void setSalRoleService(@Nonnull SalRoleService salRoleService) {
+        this.salRoleService = salRoleService;
+    }
+
     @Override
     public void setLifecycleInitializationPhaseHandler(final ClusterInitializationPhaseHandler handler) {
         this.clusterInitializationPhaseHandler = handler;
@@ -610,6 +682,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             return false;
         }
 
+        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new RpcResultFutureCallback());
+
         return this.clusterInitializationPhaseHandler.onContextInstantiateService(getPrimaryConnectionContext());
     }
 
@@ -626,4 +700,58 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             this.initialized = true;
         }
     }
+
+    @Nullable
+    @Override
+    public <T> RequestContext<T> createRequestContext() {
+        return new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
+            @Override
+            public void close() {
+            }
+        };
+
+    }
+
+    ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Sending new role {} to device {}", newRole, deviceInfo.getNodeId());
+        }
+        final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture;
+        if (deviceInfo.getVersion() >= OFConstants.OFP_VERSION_1_3) {
+            final SetRoleInput setRoleInput = (new SetRoleInputBuilder()).setControllerRole(newRole)
+                    .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier())).build();
+            setRoleOutputFuture = this.salRoleService.setRole(setRoleInput);
+            final TimerTask timerTask = timeout -> {
+                if (!setRoleOutputFuture.isDone()) {
+                    LOG.warn("New role {} was not propagated to device {} during {} sec", newRole, deviceInfo.getLOGValue(), SET_ROLE_TIMEOUT);
+                    setRoleOutputFuture.cancel(true);
+                }
+            };
+            hashedWheelTimer.newTimeout(timerTask, SET_ROLE_TIMEOUT, TimeUnit.SECONDS);
+        } else {
+            LOG.info("Device: {} with version: {} does not support role", deviceInfo.getLOGValue(), deviceInfo.getVersion());
+            return Futures.immediateFuture(null);
+        }
+        return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);
+    }
+
+    @Override
+    public ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave() {
+        return sendRoleChangeToDevice(OfpRole.BECOMESLAVE);
+    }
+
+    private class RpcResultFutureCallback implements FutureCallback<RpcResult<SetRoleOutput>> {
+        @Override
+        public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
+            }
+        }
+
+        @Override
+        public void onFailure(final Throwable throwable) {
+            LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
+            shutdownConnection();
+        }
+    }
 }
index a3c51799ce028b92e1f0e06b8a64323063f0c832..964ad0ba6b9fb41f3064361ee2f3d13ae05a34a3 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.impl.device;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterators;
+import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -26,10 +27,12 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
@@ -50,11 +53,14 @@ import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionCon
 import org.opendaylight.openflowplugin.impl.connection.OutboundQueueProviderImpl;
 import org.opendaylight.openflowplugin.impl.device.listener.OpenflowProtocolListenerFullImpl;
 import org.opendaylight.openflowplugin.impl.lifecycle.LifecycleServiceImpl;
+import org.opendaylight.openflowplugin.impl.services.SalRoleServiceImpl;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -186,6 +192,8 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
         connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
 
+        final LifecycleService lifecycleService = new LifecycleServiceImpl();
+
         final DeviceContext deviceContext = new DeviceContextImpl(
                 connectionContext,
                 dataBroker,
@@ -193,16 +201,20 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 translatorLibrary,
                 this,
                 convertorExecutor,
-                skipTableFeatures);
+                skipTableFeatures,
+                hashedWheelTimer,
+                this);
 
+        deviceContext.setSalRoleService(new SalRoleServiceImpl(deviceContext, deviceContext));
         deviceContexts.put(deviceInfo, deviceContext);
 
-        final LifecycleService lifecycleService = new LifecycleServiceImpl();
         lifecycleService.setDeviceContext(deviceContext);
         deviceContext.putLifecycleServiceIntoTxChainManager(lifecycleService);
 
         lifecycleServices.put(deviceInfo, lifecycleService);
 
+        addCallbackToDeviceInitializeToSlave(deviceInfo, deviceContext, lifecycleService);
+
         deviceContext.setSwitchFeaturesMandatory(switchFeaturesMandatory);
 
         ((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
@@ -218,24 +230,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         return ConnectionStatus.MAY_CONTINUE;
     }
 
-    private void updatePacketInRateLimiters() {
-        synchronized (deviceContexts) {
-            final int deviceContextsSize = deviceContexts.size();
-            if (deviceContextsSize > 0) {
-                long freshNotificationLimit = globalNotificationQuota / deviceContextsSize;
-                if (freshNotificationLimit < 100) {
-                    freshNotificationLimit = 100;
-                }
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("fresh notification limit = {}", freshNotificationLimit);
-                }
-                for (final DeviceContext deviceContext : deviceContexts.values()) {
-                    deviceContext.updatePacketInRateLimit(freshNotificationLimit);
-                }
-            }
-        }
-    }
-
     @Override
     public TranslatorLibrary oook() {
         return translatorLibrary;
@@ -387,4 +381,74 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         this.barrierIntervalNanos = TimeUnit.MILLISECONDS.toNanos(barrierTimeoutLimit);
     }
 
+    @Override
+    public CheckedFuture<Void, TransactionCommitFailedException> removeDeviceFromOperationalDS(final DeviceInfo deviceInfo) {
+        final WriteTransaction delWtx = dataBroker.newWriteOnlyTransaction();
+        delWtx.delete(LogicalDatastoreType.OPERATIONAL, deviceInfo.getNodeInstanceIdentifier());
+        final CheckedFuture<Void, TransactionCommitFailedException> delFuture = delWtx.submit();
+
+        Futures.addCallback(delFuture, new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(final Void result) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Delete Node {} was successful", deviceInfo.getLOGValue());
+                }
+            }
+
+            @Override
+            public void onFailure(@Nonnull final Throwable t) {
+                LOG.warn("Delete node {} failed with exception {}", deviceInfo.getLOGValue(), t);
+            }
+        });
+
+        return delFuture;
+    }
+
+
+    private void addCallbackToDeviceInitializeToSlave(final DeviceInfo deviceInfo, final DeviceContext deviceContext, final LifecycleService lifecycleService) {
+        Futures.addCallback(deviceContext.makeDeviceSlave(), new FutureCallback<RpcResult<SetRoleOutput>>() {
+            @Override
+            public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getLOGValue());
+                }
+            }
+
+            @Override
+            public void onFailure(Throwable throwable) {
+                LOG.warn("Was not able to set role SLAVE to device on node {} ",deviceInfo.getLOGValue());
+                lifecycleService.closeConnection();
+            }
+        });
+    }
+
+    private void updatePacketInRateLimiters() {
+        synchronized (deviceContexts) {
+            final int deviceContextsSize = deviceContexts.size();
+            if (deviceContextsSize > 0) {
+                long freshNotificationLimit = globalNotificationQuota / deviceContextsSize;
+                if (freshNotificationLimit < 100) {
+                    freshNotificationLimit = 100;
+                }
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("fresh notification limit = {}", freshNotificationLimit);
+                }
+                for (final DeviceContext deviceContext : deviceContexts.values()) {
+                    deviceContext.updatePacketInRateLimit(freshNotificationLimit);
+                }
+            }
+        }
+    }
+
+    @VisibleForTesting
+    void setDeviceContext(final DeviceInfo deviceInfo, final DeviceContext deviceContext) {
+        this.deviceContexts.putIfAbsent(deviceInfo, deviceContext);
+    }
+
+    @VisibleForTesting
+    int getDeviceContextCount() {
+        return this.deviceContexts.size();
+    }
+
+
 }
index 98a66b83b6ccdd3fe25eee24f60cf3a2778c4ea5..885438df440cd099277c3ab7f47c517c88680ce8 100644 (file)
@@ -24,7 +24,6 @@ import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -38,7 +37,6 @@ public class LifecycleServiceImpl implements LifecycleService {
     private boolean inClosing = false;
     private DeviceContext deviceContext;
     private RpcContext rpcContext;
-    private RoleContext roleContext;
     private StatisticsContext statContext;
     private ClusterSingletonServiceRegistration registration;
     private ClusterInitializationPhaseHandler clusterInitializationPhaseHandler;
@@ -75,7 +73,6 @@ public class LifecycleServiceImpl implements LifecycleService {
 
         // Chain all jobs that will stop our services
         final List<ListenableFuture<Void>> futureList = new ArrayList<>();
-        futureList.add(roleContext.stopClusterServices(connectionInterrupted));
         futureList.add(statContext.stopClusterServices(connectionInterrupted));
         futureList.add(rpcContext.stopClusterServices(connectionInterrupted));
         futureList.add(deviceContext.stopClusterServices(connectionInterrupted));
@@ -116,8 +113,7 @@ public class LifecycleServiceImpl implements LifecycleService {
         this.clusterInitializationPhaseHandler = deviceContext;
         this.deviceContext.setLifecycleInitializationPhaseHandler(this.statContext);
         this.statContext.setLifecycleInitializationPhaseHandler(this.rpcContext);
-        this.rpcContext.setLifecycleInitializationPhaseHandler(this.roleContext);
-        this.roleContext.setLifecycleInitializationPhaseHandler(this);
+        this.rpcContext.setLifecycleInitializationPhaseHandler(this);
         //Set initial submit handler
         this.statContext.setInitialSubmitHandler(this.deviceContext);
         //Register cluster singleton service
@@ -134,11 +130,6 @@ public class LifecycleServiceImpl implements LifecycleService {
         this.rpcContext = rpcContext;
     }
 
-    @Override
-    public void setRoleContext(final RoleContext roleContext) {
-        this.roleContext = roleContext;
-    }
-
     @Override
     public void setStatContext(final StatisticsContext statContext) {
         this.statContext = statContext;
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
deleted file mode 100644 (file)
index 6f5b1c5..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.impl.role;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.TimerTask;
-
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
-import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
-import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Role context try to make change device role on device
- */
-class RoleContextImpl implements RoleContext {
-
-    private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
-
-    // Timeout in seconds after what we will give up on propagating role
-    private static final int SET_ROLE_TIMEOUT = 10;
-
-    private SalRoleService salRoleService = null;
-    private final HashedWheelTimer hashedWheelTimer;
-    private final DeviceInfo deviceInfo;
-    private CONTEXT_STATE state;
-    private final RoleManager myManager;
-    private ClusterInitializationPhaseHandler clusterInitializationPhaseHandler;
-    private final LifecycleService lifecycleService;
-
-    RoleContextImpl(final DeviceInfo deviceInfo,
-                    final HashedWheelTimer hashedWheelTimer,
-                    final RoleManager myManager,
-                    final LifecycleService lifecycleService) {
-        this.deviceInfo = deviceInfo;
-        this.state = CONTEXT_STATE.WORKING;
-        this.myManager = myManager;
-        this.hashedWheelTimer = hashedWheelTimer;
-        this.lifecycleService = lifecycleService;
-    }
-
-    @Nullable
-    @Override
-    public <T> RequestContext<T> createRequestContext() {
-        return new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
-            @Override
-            public void close() {
-            }
-        };
-    }
-
-    @Override
-    public void setSalRoleService(@Nonnull final SalRoleService salRoleService) {
-        Preconditions.checkNotNull(salRoleService);
-        this.salRoleService = salRoleService;
-    }
-
-    @Override
-    public CONTEXT_STATE getState() {
-        return this.state;
-    }
-
-    @Override
-    public void setState(CONTEXT_STATE state) {
-        this.state = state;
-    }
-
-    @Override
-    public ServiceGroupIdentifier getServiceIdentifier() {
-        return this.deviceInfo.getServiceIdentifier();
-    }
-
-    @Override
-    public DeviceInfo getDeviceInfo() {
-        return this.deviceInfo;
-    }
-
-    public void startupClusterServices() throws ExecutionException, InterruptedException {
-        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new RpcResultFutureCallback());
-    }
-
-    @Override
-    public ListenableFuture<Void> stopClusterServices(final boolean deviceDisconnected) {
-
-        if (!deviceDisconnected) {
-            ListenableFuture<Void> future = Futures.transform(makeDeviceSlave(), new Function<RpcResult<SetRoleOutput>, Void>() {
-                @Nullable
-                @Override
-                public Void apply(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
-                    return null;
-                }
-            });
-
-            Futures.addCallback(future, new FutureCallback<Void>() {
-                @Override
-                public void onSuccess(@Nullable Void aVoid) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getLOGValue());
-                    }
-                }
-
-                @Override
-                public void onFailure(final Throwable throwable) {
-                    LOG.warn("Was not able to set role SLAVE to device on node {} ", deviceInfo.getLOGValue());
-                    LOG.trace("Error occurred on device role setting, probably connection loss: ", throwable);
-                    myManager.removeDeviceFromOperationalDS(deviceInfo);
-                }
-            });
-            return future;
-        } else {
-            return myManager.removeDeviceFromOperationalDS(deviceInfo);
-        }
-    }
-
-    @Override
-    public ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave(){
-        return sendRoleChangeToDevice(OfpRole.BECOMESLAVE);
-    }
-
-    @VisibleForTesting
-    ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Sending new role {} to device {}", newRole, deviceInfo.getNodeId());
-        }
-        final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture;
-        if (deviceInfo.getVersion() >= OFConstants.OFP_VERSION_1_3) {
-            final SetRoleInput setRoleInput = (new SetRoleInputBuilder()).setControllerRole(newRole)
-                    .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier())).build();
-            setRoleOutputFuture = this.salRoleService.setRole(setRoleInput);
-            final TimerTask timerTask = timeout -> {
-                if (!setRoleOutputFuture.isDone()) {
-                    LOG.warn("New role {} was not propagated to device {} during {} sec", newRole, deviceInfo.getLOGValue(), SET_ROLE_TIMEOUT);
-                    setRoleOutputFuture.cancel(true);
-                }
-            };
-            hashedWheelTimer.newTimeout(timerTask, SET_ROLE_TIMEOUT, TimeUnit.SECONDS);
-        } else {
-            LOG.info("Device: {} with version: {} does not support role", deviceInfo.getLOGValue(), deviceInfo.getVersion());
-            return Futures.immediateFuture(null);
-        }
-        return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);
-    }
-
-    @Override
-    public void setLifecycleInitializationPhaseHandler(final ClusterInitializationPhaseHandler handler) {
-        this.clusterInitializationPhaseHandler = handler;
-    }
-
-    @Override
-    public boolean onContextInstantiateService(final ConnectionContext connectionContext) {
-
-        if (connectionContext.getConnectionState().equals(ConnectionContext.CONNECTION_STATE.RIP)) {
-            LOG.warn("Connection on device {} was interrupted, will stop starting master services.", deviceInfo.getLOGValue());
-            return false;
-        }
-
-        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new RpcResultFutureCallback());
-        return this.clusterInitializationPhaseHandler.onContextInstantiateService(connectionContext);
-    }
-
-    private class RpcResultFutureCallback implements FutureCallback<RpcResult<SetRoleOutput>> {
-        @Override
-        public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
-            }
-        }
-
-        @Override
-        public void onFailure(final Throwable throwable) {
-            LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
-            lifecycleService.closeConnection();
-        }
-    }
-}
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
deleted file mode 100644 (file)
index 28191b5..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.impl.role;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
-import com.google.common.collect.Iterators;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import io.netty.util.HashedWheelTimer;
-import java.util.Iterator;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
-import org.opendaylight.openflowplugin.impl.services.SalRoleServiceImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Gets invoked from RpcManagerInitial, registers a candidate with EntityOwnershipService.
- * On receipt of the ownership notification, makes an rpc call to SalRoleService.
- *
- * Hands over to StatisticsManager at the end.
- */
-public class RoleManagerImpl implements RoleManager {
-    private static final Logger LOG = LoggerFactory.getLogger(RoleManagerImpl.class);
-
-    // Maximum limit of timeout retries when cleaning DS, to prevent infinite recursive loops
-    private static final int MAX_CLEAN_DS_RETRIES = 3;
-
-    private DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
-    private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
-    private final DataBroker dataBroker;
-    private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
-    private final HashedWheelTimer hashedWheelTimer;
-
-    public RoleManagerImpl(final DataBroker dataBroker, final HashedWheelTimer hashedWheelTimer) {
-        this.dataBroker = Preconditions.checkNotNull(dataBroker);
-        this.hashedWheelTimer = hashedWheelTimer;
-    }
-
-    @Override
-    public void setDeviceInitializationPhaseHandler(final DeviceInitializationPhaseHandler handler) {
-        deviceInitializationPhaseHandler = handler;
-    }
-
-    @Override
-    public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
-        final DeviceContext deviceContext = Preconditions.checkNotNull(lifecycleService.getDeviceContext());
-        final RoleContext roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, this, lifecycleService);
-        roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
-        Verify.verify(contexts.putIfAbsent(deviceInfo, roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getLOGValue());
-        Futures.addCallback(roleContext.makeDeviceSlave(), new FutureCallback<RpcResult<SetRoleOutput>>() {
-                    @Override
-                    public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getLOGValue());
-                        }
-                    }
-
-                    @Override
-                    public void onFailure(Throwable throwable) {
-                        LOG.warn("Was not able to set role SLAVE to device on node {} ",deviceInfo.getLOGValue());
-                        lifecycleService.closeConnection();
-                    }
-                });
-        lifecycleService.setRoleContext(roleContext);
-        deviceInitializationPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-    }
-
-    @Override
-    public void close() {
-        LOG.debug("Close method on role manager was called.");
-        for (final Iterator<RoleContext> iterator = Iterators.consumingIterator(contexts.values().iterator()); iterator.hasNext();) {
-            // got here because last known role is LEADER and DS might need clearing up
-            final RoleContext roleContext = iterator.next();
-            contexts.remove(roleContext.getDeviceInfo());
-            removeDeviceFromOperationalDS(roleContext.getDeviceInfo());
-        }
-    }
-
-    @Override
-    public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
-        contexts.remove(deviceInfo);
-        deviceTerminationPhaseHandler.onDeviceContextLevelDown(deviceInfo);
-    }
-
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> removeDeviceFromOperationalDS(final DeviceInfo deviceInfo) {
-        final WriteTransaction delWtx = dataBroker.newWriteOnlyTransaction();
-        delWtx.delete(LogicalDatastoreType.OPERATIONAL, deviceInfo.getNodeInstanceIdentifier());
-        final CheckedFuture<Void, TransactionCommitFailedException> delFuture = delWtx.submit();
-
-        Futures.addCallback(delFuture, new FutureCallback<Void>() {
-            @Override
-            public void onSuccess(final Void result) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Delete Node {} was successful", deviceInfo.getLOGValue());
-                }
-            }
-
-            @Override
-            public void onFailure(@Nonnull final Throwable t) {
-                LOG.warn("Delete node {} failed with exception {}", deviceInfo.getLOGValue(), t);
-            }
-        });
-
-        return delFuture;
-    }
-
-    @Override
-    public void setDeviceTerminationPhaseHandler(final DeviceTerminationPhaseHandler handler) {
-        deviceTerminationPhaseHandler = handler;
-    }
-
-    @VisibleForTesting
-    RoleContext getRoleContext(final DeviceInfo deviceInfo){
-        return contexts.get(deviceInfo);
-    }
-
-}
index 4e77150fbeceaa19a0d829c770f62cb15c8bde0f..35cc8356db5d030945caf3f975e45be2da011629 100644 (file)
@@ -232,7 +232,7 @@ public class DeviceContextImplTest {
                 translatorLibrary,
                 deviceManager,
                 convertorExecutor,
-                false);
+                false, timer, deviceManager);
         deviceContextSpy = Mockito.spy(deviceContext);
 
         xid = new Xid(atomicLong.incrementAndGet());
@@ -245,12 +245,12 @@ public class DeviceContextImplTest {
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
-        new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor,false).close();
+        new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor,false, timer, deviceManager).close();
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullTimer() throws Exception {
-        new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor,false).close();
+        new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor,false, timer, deviceManager).close();
     }
 
     @Test
index ab12828ef2634fb1a13681fdf0e89650377e1b89..82ee4b06720638465882f5da060dbbd5cc172461 100644 (file)
@@ -31,6 +31,7 @@ import org.mockito.InOrder;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
+import org.mockito.Spy;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
@@ -64,12 +65,15 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorM
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 
 @RunWith(MockitoJUnitRunner.class)
 public class DeviceManagerImplTest {
@@ -109,7 +113,8 @@ public class DeviceManagerImplTest {
     private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     @Mock
     private ConvertorExecutor convertorExecutor;
-
+    @Mock
+    private KeyedInstanceIdentifier<Node, NodeKey> key;
     @Before
     public void setUp() throws Exception {
         OpenflowPortsUtil.init();
index b21f38c6d7226a130e1ebcc7bdffd830c2a683cb..da2340e4f1218c6c02e04d3373bb8f7861a26343 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 
@@ -39,8 +38,6 @@ public class LifecycleServiceImplTest {
     @Mock
     private RpcContext rpcContext;
     @Mock
-    private RoleContext roleContext;
-    @Mock
     private StatisticsContext statContext;
     @Mock
     private ConnectionContext connectionContext;
@@ -62,14 +59,12 @@ public class LifecycleServiceImplTest {
         Mockito.when(deviceInfo.getLOGValue()).thenReturn(TEST_NODE);
 
         Mockito.when(deviceContext.stopClusterServices(Mockito.anyBoolean())).thenReturn(Futures.immediateFuture(null));
-        Mockito.when(roleContext.stopClusterServices(Mockito.anyBoolean())).thenReturn(Futures.immediateFuture(null));
         Mockito.when(statContext.stopClusterServices(Mockito.anyBoolean())).thenReturn(Futures.immediateFuture(null));
         Mockito.when(rpcContext.stopClusterServices(Mockito.anyBoolean())).thenReturn(Futures.immediateFuture(null));
 
         lifecycleService = new LifecycleServiceImpl();
         lifecycleService.setDeviceContext(deviceContext);
         lifecycleService.setRpcContext(rpcContext);
-        lifecycleService.setRoleContext(roleContext);
         lifecycleService.setStatContext(statContext);
         lifecycleService.registerService(clusterSingletonServiceProvider);
     }
@@ -81,7 +76,6 @@ public class LifecycleServiceImplTest {
         Mockito.verify(statContext).setLifecycleInitializationPhaseHandler(Mockito.any());
         Mockito.verify(statContext).setInitialSubmitHandler(Mockito.any());
         Mockito.verify(rpcContext).setLifecycleInitializationPhaseHandler(Mockito.any());
-        Mockito.verify(roleContext).setLifecycleInitializationPhaseHandler(Mockito.any());
     }
 
     @Test
@@ -90,7 +84,6 @@ public class LifecycleServiceImplTest {
         Mockito.verify(statContext).stopClusterServices(false);
         Mockito.verify(deviceContext).stopClusterServices(false);
         Mockito.verify(rpcContext).stopClusterServices(false);
-        Mockito.verify(roleContext).stopClusterServices(false);
     }
 
     @Test
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java
deleted file mode 100644 (file)
index 4234aa9..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.impl.role;
-
-
-import com.google.common.util.concurrent.Futures;
-import io.netty.util.HashedWheelTimer;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
-import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
-import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RoleContextImplTest {
-
-    @Mock
-    HashedWheelTimer hashedWheelTimer;
-    @Mock
-    private DeviceInfo deviceInfo;
-    @Mock
-    private RoleManager roleManager;
-    @Mock
-    private LifecycleService lifecycleService;
-    @Mock
-    private SalRoleService salRoleService;
-
-    private final NodeId nodeId = NodeId.getDefaultInstance("openflow:1");
-    private RoleContext roleContext;
-    private RoleContextImpl roleContextSpy;
-
-    @Before
-    public void setup() throws CandidateAlreadyRegisteredException {
-        roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager, lifecycleService);
-        roleContext.setSalRoleService(salRoleService);
-        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
-        Mockito.when(salRoleService.setRole(Mockito.<SetRoleInput>any())).thenReturn(Futures.immediateFuture(null));
-        Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(DeviceStateUtil.createNodeInstanceIdentifier(nodeId));
-        roleContextSpy = Mockito.spy((RoleContextImpl) roleContext);
-    }
-
-    @Test
-    public void testCreateRequestContext() throws Exception {
-        roleContext.createRequestContext();
-        Mockito.verify(deviceInfo).reserveXidForDeviceMessage();
-    }
-
-    @Test(expected = NullPointerException.class)
-    public void testSetSalRoleService() throws Exception {
-        roleContext.setSalRoleService(null);
-    }
-
-    @Test
-    public void testGetNodeId() throws Exception {
-        Assert.assertTrue(roleContext.getDeviceInfo().getNodeId().equals(nodeId));
-    }
-
-    @Test
-    public void startupClusterServices() throws Exception {
-        roleContextSpy.startupClusterServices();
-        Mockito.verify(roleContextSpy).sendRoleChangeToDevice(OfpRole.BECOMEMASTER);
-    }
-
-    @Test
-    public void startupClusterServicesVersion10() throws Exception {
-        Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
-        roleContextSpy.startupClusterServices();
-        Mockito.verify(roleContextSpy).sendRoleChangeToDevice(OfpRole.BECOMEMASTER);
-    }
-
-    @Test
-    public void startupClusterServicesVersion13() throws Exception {
-        Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
-        roleContextSpy.startupClusterServices();
-        Mockito.verify(roleContextSpy).sendRoleChangeToDevice(OfpRole.BECOMEMASTER);
-    }
-
-    @Test
-    public void stopClusterServicesNotDisconnected() throws Exception {
-        roleContextSpy.stopClusterServices(false);
-        Mockito.verify(roleContextSpy).sendRoleChangeToDevice(OfpRole.BECOMESLAVE);
-        Mockito.verify(roleManager, Mockito.never()).removeDeviceFromOperationalDS(Mockito.<DeviceInfo>any());
-    }
-
-    @Test
-    public void stopClusterServicesDisconnected() throws Exception {
-        roleContextSpy.stopClusterServices(true);
-        Mockito.verify(roleManager, Mockito.atLeastOnce()).removeDeviceFromOperationalDS(Mockito.<DeviceInfo>any());
-    }
-
-    @Test
-    public void makeDeviceSlave() throws Exception {
-        roleContextSpy.makeDeviceSlave();
-        Mockito.verify(roleContextSpy).sendRoleChangeToDevice(OfpRole.BECOMESLAVE);
-    }
-
-}
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java
deleted file mode 100644 (file)
index c1e29b7..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.impl.role;
-
-
-import static org.mockito.Mockito.verify;
-
-import com.google.common.base.VerifyException;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import io.netty.util.HashedWheelTimer;
-import java.math.BigInteger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
-import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
-import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RoleManagerImplTest {
-
-    @Mock
-    DataBroker dataBroker;
-    @Mock
-    DeviceContext deviceContext;
-    @Mock
-    DeviceManager deviceManager;
-    @Mock
-    ConnectionContext connectionContext;
-    @Mock
-    FeaturesReply featuresReply;
-    @Mock
-    DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
-    @Mock
-    DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
-    @Mock
-    WriteTransaction writeTransaction;
-    @Mock
-    DeviceState deviceState;
-    @Mock
-    DeviceInfo deviceInfo;
-    @Mock
-    DeviceInfo deviceInfo2;
-    @Mock
-    MessageSpy messageSpy;
-    @Mock
-    OutboundQueue outboundQueue;
-    @Mock
-    GetFeaturesOutput featuresOutput;
-    @Mock
-    LifecycleService lifecycleService;
-
-    private RoleManagerImpl roleManager;
-    private RoleManagerImpl roleManagerSpy;
-    private RoleContext roleContextSpy;
-    private final NodeId nodeId = NodeId.getDefaultInstance("openflow:1");
-    private final NodeId nodeId2 = NodeId.getDefaultInstance("openflow:2");
-
-    private InOrder inOrder;
-
-    @Before
-    public void setUp() throws Exception {
-        CheckedFuture<Void, TransactionCommitFailedException> future = Futures.immediateCheckedFuture(null);
-        Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
-        Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
-        Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
-        Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
-        Mockito.when(deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider()).thenReturn(outboundQueue);
-        Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply);
-        Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId);
-        Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
-        Mockito.when(deviceInfo.getDatapathId()).thenReturn(new BigInteger("1"));
-        Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
-        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
-        Mockito.doNothing().when(deviceInitializationPhaseHandler).onDeviceContextLevelUp(Mockito.<DeviceInfo>any(), Mockito.<LifecycleService>any());
-        Mockito.doNothing().when(deviceTerminationPhaseHandler).onDeviceContextLevelDown(Mockito.<DeviceInfo>any());
-        Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
-        Mockito.when(writeTransaction.submit()).thenReturn(future);
-        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
-        Mockito.when(deviceInfo2.getNodeId()).thenReturn(nodeId2);
-        Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
-        Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(DeviceStateUtil.createNodeInstanceIdentifier(nodeId));
-        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext);
-        roleManager = new RoleManagerImpl(dataBroker, new HashedWheelTimer());
-        roleManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
-        roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
-        roleManagerSpy = Mockito.spy(roleManager);
-        roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        roleContextSpy = Mockito.spy(roleManager.getRoleContext(deviceInfo));
-        Mockito.when(roleContextSpy.getDeviceInfo()).thenReturn(deviceInfo);
-        Mockito.when(roleContextSpy.getDeviceInfo().getNodeId()).thenReturn(nodeId);
-        inOrder = Mockito.inOrder(roleManagerSpy, roleContextSpy);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-    }
-
-    @Test(expected = VerifyException.class)
-    public void testOnDeviceContextLevelUp() throws Exception {
-        roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        inOrder.verify(roleManagerSpy).onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        inOrder.verifyNoMoreInteractions();
-    }
-
-    @Test
-    public void testCloseMaster() throws Exception {
-        roleManagerSpy.close();
-        inOrder.verify(roleManagerSpy).removeDeviceFromOperationalDS(Mockito.eq(deviceInfo));
-        inOrder.verifyNoMoreInteractions();
-    }
-
-    @Test
-    public void testOnDeviceContextLevelDown() throws Exception {
-        roleManagerSpy.onDeviceContextLevelDown(deviceInfo);
-        inOrder.verify(roleManagerSpy).onDeviceContextLevelDown(deviceInfo);
-        inOrder.verifyNoMoreInteractions();
-    }
-}
\ No newline at end of file