Bug 5596 Added cluster provider 63/42463/15
authorJozef Bacigal <jbacigal@cisco.com>
Tue, 19 Jul 2016 13:45:12 +0000 (15:45 +0200)
committerShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Mon, 15 Aug 2016 06:44:30 +0000 (06:44 +0000)
Change-Id: I1954b28bfaaf026aebb171fb5c51ef26a6df585c
Signed-off-by: Jozef Bacigal <jbacigal@cisco.com>
24 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProvider.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProviderFactory.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/handlers/DeviceInitializationPhaseHandler.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
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/rpc/RpcManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/StatisticsContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/StatisticsManager.java
openflowplugin-blueprint-config/src/main/resources/org/opendaylight/blueprint/openflowplugin.xml
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java
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/RoleManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.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/RoleManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java

index 8ad73aac1aa0c0d84e9b636f8d875dd2dab3a9cd..132dabed8982a755a7096205812088ea19e1b3f9 100644 (file)
@@ -16,10 +16,11 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 
 /**
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 27.3.2015.
+ * Plugin services provider
  */
 public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
 
@@ -79,4 +80,5 @@ public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
     void setNotificationFlowRemovedOff(boolean isNotificationFlowRemovedOff);
 
     void update(Map<String,Object> props);
+    void setClusteringSingletonServicesProvider(ClusterSingletonServiceProvider singletonServicesProvider);
 }
index d5caf2daaeb4b7047ff9adfd2279a8641bcd8ca8..608537a200f9de5e67de5ed10ff652896285cf97 100644 (file)
@@ -13,18 +13,18 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
 
 /**
  * Factory for creating OpenFlowPluginProvider instances.
- *
- * @author Thomas Pantelis
  */
 public interface OpenFlowPluginProviderFactory {
     OpenFlowPluginProvider newInstance(OpenflowProviderConfig providerConfig, DataBroker dataBroker,
-            RpcProviderRegistry rpcRegistry, NotificationService notificationService,
-            NotificationPublishService notificationPublishService,
-            EntityOwnershipService entityOwnershipService,
-            List<SwitchConnectionProvider> switchConnectionProviders);
+                                       RpcProviderRegistry rpcRegistry, NotificationService notificationService,
+                                       NotificationPublishService notificationPublishService,
+                                       EntityOwnershipService entityOwnershipService,
+                                       List<SwitchConnectionProvider> switchConnectionProviders,
+                                       ClusterSingletonServiceProvider singletonServiceProvider);
 }
index f0d0f0086f67c016bf6361e60cca2c3eac104ea7..871adf3bc707a5aac7f98023cab3363dc91087a3 100644 (file)
@@ -13,6 +13,7 @@ import io.netty.util.Timeout;
 import java.math.BigInteger;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
@@ -129,5 +130,7 @@ public interface DeviceContext extends
 
     void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory);
 
+    void registerClusterSingletonServices(ClusterSingletonServiceProvider singletonServiceProvider);
+
 }
 
index 41884c9d490143c2693f74e715ea2676e8a40479..7c16d3e384bbbf0767736b6adc0ad8e0050e04f4 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.api.openflow.device.handlers;
 import javax.annotation.CheckForNull;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 
 /**
  * openflowplugin-api
@@ -26,8 +27,9 @@ public interface DeviceInitializationPhaseHandler {
     /**
      * Method represents an initialization cycle for {@link DeviceContext} preparation for use.
      *
-     * @param deviceInfo
+     * @param deviceInfo - device
+     * @param lifecycleService - cluster singleton service
      * @throws Exception - needs to be catch in ConnectionHandler implementation
      */
-    void onDeviceContextLevelUp(@CheckForNull DeviceInfo deviceInfo) throws Exception;
+    void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception;
 }
index 72f84dd1eac6d47a13e12f7b77b881de97a34dc9..377be685e26d9c9bc03ab2f3f7f514bc88a307eb 100644 (file)
@@ -8,10 +8,25 @@
 
 package org.opendaylight.openflowplugin.api.openflow.lifecycle;
 
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 
 /**
  * Service for starting or stopping all services in plugin in cluster
  */
-public interface LifecycleService extends ClusterSingletonService {
+public interface LifecycleService extends ClusterSingletonService, AutoCloseable {
+
+    void registerService(ClusterSingletonServiceProvider singletonServiceProvider);
+
+    void setDeviceContext(DeviceContext deviceContext);
+
+    void setRpcContext(RpcContext rpcContext);
+
+    void setRoleContext(RoleContext roleContext);
+
+    void setStatContext(StatisticsContext statContext);
 }
index 263bc51bc34efb9b1c016cabd751ad708dcf31a1..bd56b7b1010294abc04b418b0b1e0676156e8228 100644 (file)
@@ -93,8 +93,7 @@ public interface RoleContext extends  RequestContextStack, AutoCloseable, OFPCon
     boolean unregisterCandidate(final Entity entity);
 
     /**
-     * Returns true if we hold both registrations
-     * @return
+     * @return true if we hold both registrations
      */
     boolean isMaster();
 
index d191527081a47de4551773dedb6da9be8454abd6..25eedcbac1150bef2e5e9bfabeb7c83145d09805 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTermin
 
 /**
  * The RPC Manager will maintain an RPC Context for each online switch. RPC context for device is created when
- * {@link org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler#onDeviceContextLevelUp(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)}
+ * {@link DeviceInitializationPhaseHandler#onDeviceContextLevelUp(DeviceInfo, org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService)}
  * is called.
  * <p>
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
index d681cfde8fe36601b14b516127793cc83ef667c4..9af51e543251ec82809c7bb1fa46710558b51227 100644 (file)
@@ -62,6 +62,15 @@ public interface StatisticsContext extends RequestContextStack, AutoCloseable, O
     @Override
     void close();
 
-    void setSchedulingEnabled(boolean schedulingEnabled);
+    /**
+     * On / Off scheduling
+     * @param schedulingEnabled true if scheduling should be enabled
+     */
+    void setSchedulingEnabled(final boolean schedulingEnabled);
+
+    /**
+     * Check status
+     * @return true if scheduling is enabled
+     */
     boolean isSchedulingEnabled();
 }
index 162a531bfe9f255fa20f7e249e8d03efece29970..5b59a23405273650fb6ee20d271591947638fbbc 100644 (file)
@@ -20,8 +20,18 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTermin
 public interface StatisticsManager extends DeviceLifecycleSupervisor, DeviceInitializationPhaseHandler,
         DeviceTerminationPhaseHandler, AutoCloseable, OFPManager {
 
-    void startScheduling(DeviceInfo deviceInfo);
-    void stopScheduling(DeviceInfo deviceInfo);
+    /**
+     * Start scheduling statistic gathering for given device info
+     * @param deviceInfo for this device should be running statistics gathering
+     */
+    void startScheduling(final DeviceInfo deviceInfo);
+
+    /**
+     * Stop scheduling statistic gathering for given device info
+     * @param deviceInfo for this device should be stopped statistics gathering
+     */
+
+    void stopScheduling(final DeviceInfo deviceInfo);
 
     @Override
     void close();
index 0eb0866c219da741602d73816b187bd1f727daed..78cf24e7d21553e2c8ab9d77e5f275e82db1e19a 100644 (file)
@@ -9,6 +9,7 @@
   <reference id="notificationService" interface="org.opendaylight.controller.md.sal.binding.api.NotificationService"/>
   <reference id="notificationPublishService" interface="org.opendaylight.controller.md.sal.binding.api.NotificationPublishService"/>
   <reference id="entityOwnershipService" interface="org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService"/>
+  <reference id="clusterSingletonServiceProvider" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
 
   <reference id="switchConnProviderFactory"
           interface="org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderFactory"/>
@@ -77,6 +78,7 @@
     <cm:managed-properties persistent-id="org.opendaylight.openflowplugin"
                            update-strategy="component-managed"
                            update-method="update"/>
+    <argument ref="clusterSingletonServiceProvider"/>
   </bean>
 
   <service ref="openflowPluginProvider" odl:type="openflow-plugin-provider-impl">
index c216e439b7d7a8b84e848229152da23aa39b7b0b..8538bb6ebca97a551871377a0c2c49e8c87295d5 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProviderFactory;
@@ -30,11 +31,14 @@ public class OpenFlowPluginProviderFactoryImpl implements OpenFlowPluginProvider
     private static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderFactoryImpl.class);
 
     @Override
-    public OpenFlowPluginProvider newInstance(OpenflowProviderConfig providerConfig, DataBroker dataBroker,
-            RpcProviderRegistry rpcRegistry, NotificationService notificationService,
-            NotificationPublishService notificationPublishService,
-            EntityOwnershipService entityOwnershipService,
-            List<SwitchConnectionProvider> switchConnectionProviders) {
+    public OpenFlowPluginProvider newInstance(OpenflowProviderConfig providerConfig,
+                                              DataBroker dataBroker,
+                                              RpcProviderRegistry rpcRegistry,
+                                              NotificationService notificationService,
+                                              NotificationPublishService notificationPublishService,
+                                              EntityOwnershipService entityOwnershipService,
+                                              List<SwitchConnectionProvider> switchConnectionProviders,
+                                              ClusterSingletonServiceProvider singletonServiceProvider) {
 
         LOG.info("Initializing new OFP southbound.");
 
@@ -59,6 +63,7 @@ public class OpenFlowPluginProviderFactoryImpl implements OpenFlowPluginProvider
         openflowPluginProvider.setBarrierInterval(providerConfig.getBarrierIntervalTimeoutLimit().getValue());
         openflowPluginProvider.setEchoReplyTimeout(providerConfig.getEchoReplyTimeout().getValue());
         openflowPluginProvider.setNotificationFlowRemovedOff(providerConfig.isNotificationFlowRemovedOff());
+        openflowPluginProvider.setClusteringSingletonServicesProvider(singletonServiceProvider);
 
         openflowPluginProvider.initialize();
 
index 657a06509435ef777d1ded1370addea320aff281..ba8f806c083633de38305fc5cef8122a4c72df37 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager;
@@ -96,6 +97,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
 
     private final LifecycleConductor conductor;
     private final ThreadPoolExecutor threadPool;
+    private ClusterSingletonServiceProvider singletonServicesProvider;
 
     public OpenFlowPluginProviderImpl(final long rpcRequestsQuota,
                                       final long globalNotificationQuota,
@@ -182,6 +184,10 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
     }
 
+    public void setClusteringSingletonServicesProvider(ClusterSingletonServiceProvider singletonServicesProvider) {
+        this.singletonServicesProvider = singletonServicesProvider;
+    }
+
 
     @Override
     public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
@@ -212,6 +218,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         Preconditions.checkNotNull(dataBroker, "missing data broker");
         Preconditions.checkNotNull(rpcProviderRegistry, "missing RPC provider registry");
         Preconditions.checkNotNull(notificationProviderService, "missing notification provider service");
+        Preconditions.checkNotNull(singletonServicesProvider, "missing singleton services provider");
 
         extensionConverterManager = new ExtensionConverterManagerImpl();
         // TODO: copied from OpenFlowPluginProvider (Helium) misusesing the old way of distributing extension converters
@@ -229,7 +236,8 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
                 barrierCountLimit,
                 conductor,
                 isNotificationFlowRemovedOff,
-                convertorManager);
+                convertorManager,
+                singletonServicesProvider);
         ((ExtensionConverterProviderKeeper) conductor).setExtensionConverterProvider(extensionConverterManager);
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
@@ -240,7 +248,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, conductor, convertorManager);
         conductor.setSafelyManager(statisticsManager);
 
-        rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, extensionConverterManager, conductor, convertorManager);
+        rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, conductor, extensionConverterManager, convertorManager);
         conductor.setSafelyManager(rpcManager);
 
         roleManager.addRoleChangeListener((RoleChangeListener) conductor);
index 80cb770d653747541416feaf0aff3a8d5e55b039..5d68cc981e874828cf6ed778f82f06d3b3212510 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
@@ -537,6 +538,11 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         this.switchFeaturesMandatory = switchFeaturesMandatory;
     }
 
+    @Override
+    public void registerClusterSingletonServices(ClusterSingletonServiceProvider singletonServiceProvider) {
+
+    }
+
     @Override
     public CONTEXT_STATE getState() {
         return this.state;
index 34142de5675b5d839e3641bc6cc5a0301f90fb49..8d5b50625413b86037c52ac0f191afed5e9d910b 100644 (file)
@@ -31,6 +31,7 @@ import javax.annotation.Nonnull;
 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.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
@@ -46,11 +47,13 @@ import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
 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.util.DeviceInitializationUtils;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -81,6 +84,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private DeviceTerminationPhaseHandler deviceTerminPhaseHandler;
 
     private final ConcurrentMap<DeviceInfo, DeviceContext> deviceContexts = new ConcurrentHashMap<>();
+    private final ConcurrentMap<DeviceInfo, LifecycleService> lifecycleServices = new ConcurrentHashMap<>();
 
     private final long barrierIntervalNanos;
     private final int barrierCountLimit;
@@ -88,6 +92,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private ScheduledThreadPoolExecutor spyPool;
     private Set<DeviceSynchronizeListener> deviceSynchronizedListeners;
     private Set<DeviceValidListener> deviceValidListeners;
+    private final ClusterSingletonServiceProvider singletonServiceProvider;
 
     private final LifecycleConductor conductor;
 
@@ -98,7 +103,8 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                              final int barrierCountLimit,
                              final LifecycleConductor lifecycleConductor,
                              boolean isNotificationFlowRemovedOff,
-                            final ConvertorExecutor convertorExecutor) {
+                            final ConvertorExecutor convertorExecutor,
+                            final ClusterSingletonServiceProvider singletonServiceProvider) {
         this.switchFeaturesMandatory = switchFeaturesMandatory;
         this.globalNotificationQuota = globalNotificationQuota;
         this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
@@ -124,6 +130,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         spyPool = new ScheduledThreadPoolExecutor(1);
         this.deviceSynchronizedListeners = new HashSet<>();
         this.deviceValidListeners = new HashSet<>();
+        this.singletonServiceProvider = singletonServiceProvider;
     }
 
 
@@ -133,11 +140,12 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     }
 
     @Override
-    public void onDeviceContextLevelUp(@CheckForNull DeviceInfo deviceInfo) throws Exception {
+    public void onDeviceContextLevelUp(@CheckForNull DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
         // final phase - we have to add new Device to MD-SAL DataStore
         LOG.debug("Final phase of DeviceContextLevelUp for Node: {} ", deviceInfo.getNodeId());
         DeviceContext deviceContext = Preconditions.checkNotNull(deviceContexts.get(deviceInfo));
         deviceContext.onPublished();
+        lifecycleService.registerService(this.singletonServiceProvider);
     }
 
     @Override
@@ -187,7 +195,11 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 connectionContext.getDeviceInfo(),
                 convertorExecutor);
 
+        final LifecycleService lifecycleService = new LifecycleServiceImpl();
+        lifecycleService.setDeviceContext(deviceContext);
+
         Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
+        lifecycleServices.putIfAbsent(deviceInfo, lifecycleService);
 
         deviceContext.setSwitchFeaturesMandatory(switchFeaturesMandatory);
 
@@ -201,7 +213,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         connectionAdapter.setMessageListener(messageListener);
         notifyDeviceValidListeners(deviceInfo, true);
 
-        deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo());
+        deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo(), lifecycleServices.get(deviceInfo));
 
         notifyDeviceSynchronizeListeners(deviceInfo, true);
 
@@ -255,6 +267,12 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         LOG.debug("onDeviceContextClosed for Node {}", deviceInfo.getNodeId());
         deviceContexts.remove(deviceInfo);
         updatePacketInRateLimiters();
+        LifecycleService lifecycleService = lifecycleServices.remove(deviceInfo);
+        try {
+            lifecycleService.close();
+        } catch (Exception e) {
+            LOG.warn("Closing service for node {} was unsuccessful ", deviceInfo.getNodeId().getValue(), e);
+        }
     }
 
     @Override
index b804f3128bea20f68c02a7178e3a6d8589fdcd06..77ea3e975340452c5a772884b7fcb320dbf58366 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.openflowplugin.impl.lifecycle;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
@@ -18,25 +20,16 @@ import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class LifecycleServiceImpl implements LifecycleService {
+public class LifecycleServiceImpl implements LifecycleService {
 
     private static final Logger LOG = LoggerFactory.getLogger(LifecycleServiceImpl.class);
 
-    private final DeviceContext deviceContext;
-    private final RpcContext rpcContext;
-    private final RoleContext roleContext;
-    private final StatisticsContext statContext;
+    private DeviceContext deviceContext;
+    private RpcContext rpcContext;
+    private RoleContext roleContext;
+    private StatisticsContext statContext;
+    private ClusterSingletonServiceRegistration registration;
 
-    LifecycleServiceImpl(
-            final DeviceContext deviceContext,
-            final RpcContext rpcContext,
-            final RoleContext roleContext,
-            final StatisticsContext statContext) {
-        this.deviceContext = deviceContext;
-        this.rpcContext = rpcContext;
-        this.roleContext = roleContext;
-        this.statContext = statContext;
-    }
 
     @Override
     public void instantiateServiceInstance() {
@@ -70,4 +63,38 @@ class LifecycleServiceImpl implements LifecycleService {
     public ServiceGroupIdentifier getIdentifier() {
         return deviceContext.getServiceIdentifier();
     }
+
+
+    @Override
+    public void close() throws Exception {
+        if (registration != null) {
+            registration.close();
+            registration = null;
+        }
+    }
+
+    @Override
+    public void registerService(final ClusterSingletonServiceProvider singletonServiceProvider) {
+        this.registration = singletonServiceProvider.registerClusterSingletonService(this);
+    }
+
+    @Override
+    public void setDeviceContext(final DeviceContext deviceContext) {
+        this.deviceContext = deviceContext;
+    }
+
+    @Override
+    public void setRpcContext(final RpcContext rpcContext) {
+        this.rpcContext = rpcContext;
+    }
+
+    @Override
+    public void setRoleContext(final RoleContext roleContext) {
+        this.roleContext = roleContext;
+    }
+
+    @Override
+    public void setStatContext(final StatisticsContext statContext) {
+        this.statContext = statContext;
+    }
 }
index 716a9b38db51703378414e955d81d5611589b1ba..acea122efa9e2e3f3c673313caab2bc3be2395f9 100644 (file)
@@ -44,6 +44,7 @@ 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ServiceChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
@@ -99,7 +100,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     }
 
     @Override
-    public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo) throws Exception {
+    public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
         final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
         final RoleContext roleContext = new RoleContextImpl(deviceInfo, entityOwnershipService, makeEntity(deviceInfo.getNodeId()), makeTxEntity(deviceInfo.getNodeId()), conductor);
         roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
@@ -108,7 +109,8 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
         /* First start to watch entity so we don't miss any notification, and then try to register in EOS */
         watchingEntities.put(roleContext.getEntity(), roleContext);
         notifyListenersRoleInitializationDone(roleContext.getDeviceInfo(), roleContext.initialization());
-        deviceInitializationPhaseHandler.onDeviceContextLevelUp(deviceInfo);
+        lifecycleService.setRoleContext(roleContext);
+        deviceInitializationPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Override
index 7849fc76874676aef32a7b0619f41efb2a56381b..c9c6e18c2d2b1b6f2a0c048af638130ccb2da1f7 100644 (file)
@@ -21,6 +21,7 @@ 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
@@ -44,8 +45,9 @@ public class RpcManagerImpl implements RpcManager {
     public RpcManagerImpl(
             final RpcProviderRegistry rpcProviderRegistry,
             final int quotaValue,
-            ExtensionConverterProvider extensionConverterProvider,
+            
             final LifecycleConductor lifecycleConductor,
+           ExtensionConverterProvider extensionConverterProvider,
             final ConvertorExecutor convertorExecutor) {
         this.rpcProviderRegistry = rpcProviderRegistry;
         maxRequestsQuota = quotaValue;
@@ -60,7 +62,7 @@ public class RpcManagerImpl implements RpcManager {
     }
 
     @Override
-    public void onDeviceContextLevelUp(final DeviceInfo deviceInfo) throws Exception {
+    public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
 
         final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
 
@@ -76,11 +78,11 @@ public class RpcManagerImpl implements RpcManager {
                 convertorExecutor);
 
         Verify.verify(contexts.putIfAbsent(deviceInfo, rpcContext) == null, "RpcCtx still not closed for node {}", deviceInfo.getNodeId());
-
+        lifecycleService.setRpcContext(rpcContext);
         rpcContext.setStatisticsRpcEnabled(isStatisticsRpcEnabled);
 
         // finish device initialization cycle back to DeviceManager
-        deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo);
+        deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Override
index 4602217b7a6d21f374921e0a5dd88c8c7b6a600f..8255e35adb9ec27957c7b1e78d6c068c4ef1e73a 100644 (file)
@@ -31,12 +31,12 @@ import javax.annotation.Nonnull;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
@@ -93,12 +93,12 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
     }
 
     @Override
-    public void onDeviceContextLevelUp(final DeviceInfo deviceInfo) throws Exception {
+    public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, LifecycleService lifecycleService) throws Exception {
 
         final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, shuttingDownStatisticsPolling, conductor, convertorExecutor);
         Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
-
-        deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo);
+        lifecycleService.setStatContext(statisticsContext);
+        deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @VisibleForTesting
index cb7c958b5c239f34926e5eb6fb5b54e112c69183..40d973976695730fa70ab32493b91ca28dd19009 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipL
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
 
@@ -59,6 +60,9 @@ public class OpenFlowPluginProviderImplTest {
     @Mock
     SwitchConnectionProvider switchConnectionProvider;
 
+    @Mock
+    ClusterSingletonServiceProvider clusterSingletonServiceProvider;
+
     private static final long RPC_REQUESTS_QUOTA = 500;
     private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
     private static final int THREAD_POOL_MIN_THREADS = 1;
@@ -87,6 +91,7 @@ public class OpenFlowPluginProviderImplTest {
         provider.setNotificationProviderService(notificationService);
         provider.setEntityOwnershipService(entityOwnershipService);
         provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
+        provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
     }
 
     @After
index bb073cd91d77aa8fd95730a09f0de16fd1322bb6..702a5f6ca54848706f0c2249b0e1c30337be3b09 100644 (file)
@@ -40,6 +40,8 @@ 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.TransactionChainListener;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandler;
@@ -55,8 +57,10 @@ import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
@@ -102,6 +106,12 @@ public class DeviceManagerImplTest {
     private MessageIntelligenceAgency messageIntelligenceAgency;
     @Mock
     private DeviceInfo deviceInfo;
+    @Mock
+    private LifecycleService lifecycleService;
+    @Mock
+    private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
+    @Mock
+    private ConvertorExecutor convertorExecutor;
 
     @Before
     public void setUp() throws Exception {
@@ -145,9 +155,16 @@ public class DeviceManagerImplTest {
 
         when(mockedWriteTransaction.submit()).thenReturn(mockedFuture);
 
-        final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
-        final DeviceManagerImpl deviceManager = new DeviceManagerImpl(mockedDataBroker,
-                TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA, false, barrierIntervalNanos, barrierCountLimit, lifecycleConductor, true, convertorManager);
+        final DeviceManagerImpl deviceManager = new DeviceManagerImpl(
+                mockedDataBroker,
+                TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA,
+                false,
+                barrierIntervalNanos,
+                barrierCountLimit,
+                lifecycleConductor,
+                true,
+                convertorExecutor,
+                clusterSingletonServiceProvider);
 
         deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler);
         deviceManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
@@ -164,7 +181,7 @@ public class DeviceManagerImplTest {
             doThrow(new IllegalStateException("dummy")).when(mockedDeviceContext).initialSubmitTransaction();
         }
         deviceManager.addDeviceContextToMap(deviceInfo, mockedDeviceContext);
-        deviceManager.onDeviceContextLevelUp(deviceInfo);
+        deviceManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
         if (withException) {
             verify(mockedDeviceContext).close();
         } else {
@@ -184,7 +201,7 @@ public class DeviceManagerImplTest {
         order.verify(mockConnectionContext).setOutboundQueueProvider(any(OutboundQueueProvider.class));
         order.verify(mockConnectionContext).setOutboundQueueHandleRegistration(
                 Mockito.<OutboundQueueHandlerRegistration<OutboundQueueProvider>>any());
-        verify(deviceInitPhaseHandler).onDeviceContextLevelUp(Matchers.<DeviceInfo>any());
+        verify(deviceInitPhaseHandler).onDeviceContextLevelUp(Matchers.<DeviceInfo>any(), Mockito.<LifecycleService>any());
     }
 
     @Test
@@ -207,7 +224,7 @@ public class DeviceManagerImplTest {
         order.verify(mockConnectionContext).setOutboundQueueProvider(any(OutboundQueueProvider.class));
         order.verify(mockConnectionContext).setOutboundQueueHandleRegistration(
                 Mockito.<OutboundQueueHandlerRegistration<OutboundQueueProvider>>any());
-        verify(deviceInitPhaseHandler).onDeviceContextLevelUp(Matchers.<DeviceInfo>any());
+        verify(deviceInitPhaseHandler).onDeviceContextLevelUp(Matchers.<DeviceInfo>any(), Mockito.<LifecycleService>any());
     }
 
     @Test
index 7388fcb596a63490d4d2640b81e8f90593299654..4c978e4d1ad7fb40822119894bdea2c5284589c7 100644 (file)
@@ -40,7 +40,11 @@ public class LifecycleServiceImplTest {
 
     @Before
     public void setUp() {
-        lifecycleService = new LifecycleServiceImpl(deviceContext, rpcContext, roleContext, statContext);
+        lifecycleService = new LifecycleServiceImpl();
+        lifecycleService.setDeviceContext(deviceContext);
+        lifecycleService.setRpcContext(rpcContext);
+        lifecycleService.setRoleContext(roleContext);
+        lifecycleService.setStatContext(statContext);
         Mockito.when(deviceInfo.getServiceIdentifier()).thenReturn(SERVICE_GROUP_IDENTIFIER);
     }
 
index a29a2553d6ea37eb1856dc621f82c9506a8f5fa2..c2cd5dd30e42e6cea139a0832ff781fbc6fb149b 100644 (file)
@@ -44,6 +44,7 @@ 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
@@ -112,6 +113,9 @@ public class RoleManagerImplTest {
     @Mock
     GetFeaturesOutput featuresOutput;
 
+    @Mock
+    LifecycleService lifecycleService;
+
     private RoleManagerImpl roleManager;
     private RoleManagerImpl roleManagerSpy;
     private RoleContext roleContextSpy;
@@ -143,7 +147,7 @@ public class RoleManagerImplTest {
         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.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);
@@ -155,7 +159,7 @@ public class RoleManagerImplTest {
         roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
         Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
         roleManagerSpy = Mockito.spy(roleManager);
-        roleManagerSpy.onDeviceContextLevelUp(deviceInfo);
+        roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService);
         Mockito.doNothing().when(roleManagerSpy).makeDeviceRoleChange(Mockito.<OfpRole>any(), Mockito.<RoleContext>any(), Mockito.anyBoolean());
         roleContextSpy = Mockito.spy(roleManager.getRoleContext(deviceInfo));
         Mockito.when(roleContextSpy.getDeviceInfo()).thenReturn(deviceInfo);
@@ -169,8 +173,8 @@ public class RoleManagerImplTest {
 
     @Test(expected = VerifyException.class)
     public void testOnDeviceContextLevelUp() throws Exception {
-        roleManagerSpy.onDeviceContextLevelUp(deviceInfo);
-        inOrder.verify(roleManagerSpy).onDeviceContextLevelUp(deviceInfo);
+        roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+        inOrder.verify(roleManagerSpy).onDeviceContextLevelUp(deviceInfo, lifecycleService);
         inOrder.verifyNoMoreInteractions();
     }
 
index 0918e4e43159a52f82353b6ce19bd0f22a23603d..1b8235064b0269d38fa282813720aa1e6761eb41 100644 (file)
@@ -33,6 +33,7 @@ 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.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
@@ -83,6 +84,8 @@ public class RpcManagerImplTest {
     @Mock
     private DeviceInfo deviceInfo;
     @Mock
+    private LifecycleService lifecycleService;
+    @Mock
     private ExtensionConverterProvider extensionConverterProvider;
     @Mock
     private ConvertorExecutor convertorExecutor;
@@ -97,7 +100,7 @@ public class RpcManagerImplTest {
     @Before
     public void setUp() {
         final NodeKey nodeKey = new NodeKey(nodeId);
-        rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, extensionConverterProvider, conductor, convertorExecutor);
+        rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, conductor, extensionConverterProvider, convertorExecutor);
         rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
 
         GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder()
@@ -128,33 +131,33 @@ public class RpcManagerImplTest {
 
     @Test
     public void onDeviceContextLevelUp() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
         verify(conductor).getDeviceContext(deviceInfo);
     }
 
     @Test
     public void onDeviceContextLevelUpTwice() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
         expectedException.expect(VerifyException.class);
-        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Test
     public void testOnDeviceContextLevelUpMaster() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo);
+        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Test
     public void testOnDeviceContextLevelUpSlave() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo);
+        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Test
     public void testOnDeviceContextLevelUpOther() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo);
+        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Test
index 6c4229e10fa6cfd280560c3a654eb24f2adf7acc..37eb28c5a4eaad1f862a481661441b91b4f7edd7 100644 (file)
@@ -52,6 +52,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitia
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
@@ -137,6 +138,8 @@ public class StatisticsManagerImplTest {
     private DeviceInfo deviceInfo;
     @Mock
     private DataBroker dataBroker;
+    @Mock
+    private LifecycleService lifecycleService;
 
     private RequestContext<List<MultipartReply>> currentRequestContext;
     private StatisticsManagerImpl statisticsManager;
@@ -205,8 +208,8 @@ public class StatisticsManagerImplTest {
                 .commitEntry(Matchers.anyLong(), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
 
         statisticsManager.setDeviceInitializationPhaseHandler(mockedDevicePhaseHandler);
-        statisticsManager.onDeviceContextLevelUp(deviceInfo);
-        verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo);
+        statisticsManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+        verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Test