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 <mbobak@cisco.com> on 27.3.2015.
+ * Plugin services provider
*/
public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
void setNotificationFlowRemovedOff(boolean isNotificationFlowRemovedOff);
void update(Map<String,Object> props);
+ void setClusteringSingletonServicesProvider(ClusterSingletonServiceProvider singletonServicesProvider);
}
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);
}
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;
void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory);
+ void registerClusterSingletonServices(ClusterSingletonServiceProvider singletonServiceProvider);
+
}
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
/**
* 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;
}
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);
}
boolean unregisterCandidate(final Entity entity);
/**
- * Returns true if we hold both registrations
- * @return
+ * @return true if we hold both registrations
*/
boolean isMaster();
/**
* 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 <mbobak@cisco.com> on 25.2.2015.
@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();
}
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();
<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"/>
<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">
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;
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.");
openflowPluginProvider.setBarrierInterval(providerConfig.getBarrierIntervalTimeoutLimit().getValue());
openflowPluginProvider.setEchoReplyTimeout(providerConfig.getEchoReplyTimeout().getValue());
openflowPluginProvider.setNotificationFlowRemovedOff(providerConfig.isNotificationFlowRemovedOff());
+ openflowPluginProvider.setClusteringSingletonServicesProvider(singletonServiceProvider);
openflowPluginProvider.initialize();
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;
private final LifecycleConductor conductor;
private final ThreadPoolExecutor threadPool;
+ private ClusterSingletonServiceProvider singletonServicesProvider;
public OpenFlowPluginProviderImpl(final long rpcRequestsQuota,
final long globalNotificationQuota,
this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
}
+ public void setClusteringSingletonServicesProvider(ClusterSingletonServiceProvider singletonServicesProvider) {
+ this.singletonServicesProvider = singletonServicesProvider;
+ }
+
@Override
public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
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
barrierCountLimit,
conductor,
isNotificationFlowRemovedOff,
- convertorManager);
+ convertorManager,
+ singletonServicesProvider);
((ExtensionConverterProviderKeeper) conductor).setExtensionConverterProvider(extensionConverterManager);
((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
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);
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;
this.switchFeaturesMandatory = switchFeaturesMandatory;
}
+ @Override
+ public void registerClusterSingletonServices(ClusterSingletonServiceProvider singletonServiceProvider) {
+
+ }
+
@Override
public CONTEXT_STATE getState() {
return this.state;
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;
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;
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;
private ScheduledThreadPoolExecutor spyPool;
private Set<DeviceSynchronizeListener> deviceSynchronizedListeners;
private Set<DeviceValidListener> deviceValidListeners;
+ private final ClusterSingletonServiceProvider singletonServiceProvider;
private final LifecycleConductor conductor;
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;
spyPool = new ScheduledThreadPoolExecutor(1);
this.deviceSynchronizedListeners = new HashSet<>();
this.deviceValidListeners = new HashSet<>();
+ this.singletonServiceProvider = singletonServiceProvider;
}
}
@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
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);
connectionAdapter.setMessageListener(messageListener);
notifyDeviceValidListeners(deviceInfo, true);
- deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo());
+ deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo(), lifecycleServices.get(deviceInfo));
notifyDeviceSynchronizeListeners(deviceInfo, true);
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
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;
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() {
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;
+ }
}
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;
}
@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));
/* 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
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;
public RpcManagerImpl(
final RpcProviderRegistry rpcProviderRegistry,
final int quotaValue,
- ExtensionConverterProvider extensionConverterProvider,
+
final LifecycleConductor lifecycleConductor,
+ ExtensionConverterProvider extensionConverterProvider,
final ConvertorExecutor convertorExecutor) {
this.rpcProviderRegistry = rpcProviderRegistry;
maxRequestsQuota = quotaValue;
}
@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));
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
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;
}
@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
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;
@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;
provider.setNotificationProviderService(notificationService);
provider.setEntityOwnershipService(entityOwnershipService);
provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
+ provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
}
@After
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;
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;
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 {
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);
doThrow(new IllegalStateException("dummy")).when(mockedDeviceContext).initialSubmitTransaction();
}
deviceManager.addDeviceContextToMap(deviceInfo, mockedDeviceContext);
- deviceManager.onDeviceContextLevelUp(deviceInfo);
+ deviceManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
if (withException) {
verify(mockedDeviceContext).close();
} else {
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
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
@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);
}
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;
@Mock
GetFeaturesOutput featuresOutput;
+ @Mock
+ LifecycleService lifecycleService;
+
private RoleManagerImpl roleManager;
private RoleManagerImpl roleManagerSpy;
private RoleContext roleContextSpy;
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);
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);
@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();
}
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;
@Mock
private DeviceInfo deviceInfo;
@Mock
+ private LifecycleService lifecycleService;
+ @Mock
private ExtensionConverterProvider extensionConverterProvider;
@Mock
private ConvertorExecutor convertorExecutor;
@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()
@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
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;
private DeviceInfo deviceInfo;
@Mock
private DataBroker dataBroker;
+ @Mock
+ private LifecycleService lifecycleService;
private RequestContext<List<MultipartReply>> currentRequestContext;
private StatisticsManagerImpl statisticsManager;
.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