package org.opendaylight.openflowplugin.api.openflow.statistics;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
/**
- * Created by Martin Bobak <mbobak@cisco.com> on 26.2.2015.
+ * Manager to start or stop scheduling statistics
*/
public interface StatisticsManager extends DeviceLifecycleSupervisor, DeviceInitializationPhaseHandler,
DeviceTerminationPhaseHandler, AutoCloseable {
- void startScheduling(NodeId nodeId);
- void stopScheduling(NodeId nodeId);
+ void startScheduling(DeviceInfo deviceInfo);
+ void stopScheduling(DeviceInfo deviceInfo);
@Override
void close();
LOG.info("Role change to {} in role context for node {} was successful, starting/stopping services.", newRole, nodeId);
if (OfpRole.BECOMEMASTER.equals(newRole)) {
- statisticsManager.startScheduling(nodeId);
+ statisticsManager.startScheduling(deviceContext.getPrimaryConnectionContext().getDeviceInfo());
} else {
- statisticsManager.stopScheduling(nodeId);
+ statisticsManager.stopScheduling(deviceContext.getPrimaryConnectionContext().getDeviceInfo());
}
final ListenableFuture<Void> onClusterRoleChange = deviceContext.onClusterRoleChange(null, newRole);
import javax.annotation.concurrent.GuardedBy;
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.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.impl.services.RequestContextUtil;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class StatisticsContextImpl implements StatisticsContext {
+class StatisticsContextImpl implements StatisticsContext {
private static final Logger LOG = LoggerFactory.getLogger(StatisticsContextImpl.class);
private static final String CONNECTION_CLOSED = "Connection closed.";
private StatisticsGatheringOnTheFlyService statisticsGatheringOnTheFlyService;
private Timeout pollTimeout;
- private final LifecycleConductor conductor;
private volatile boolean schedulingEnabled;
- public StatisticsContextImpl(@CheckForNull final NodeId nodeId, final boolean shuttingDownStatisticsPolling, final LifecycleConductor lifecycleConductor) {
- this.conductor = lifecycleConductor;
- this.deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(nodeId));
+ StatisticsContextImpl(@CheckForNull final DeviceInfo deviceInfo, final boolean shuttingDownStatisticsPolling, final LifecycleConductor lifecycleConductor) {
+ this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo.getNodeId()));
this.devState = Preconditions.checkNotNull(deviceContext.getDeviceState());
this.shuttingDownStatisticsPolling = shuttingDownStatisticsPolling;
emptyFuture = Futures.immediateFuture(false);
final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo.getNodeId()));
- final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo.getNodeId(), shuttingDownStatisticsPolling, conductor);
+ final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, shuttingDownStatisticsPolling, conductor);
Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
deviceContext.getDeviceState().setDeviceSynchronized(true);
}
@Override
- public void startScheduling(final NodeId nodeId) {
+ public void startScheduling(final DeviceInfo deviceInfo) {
if (shuttingDownStatisticsPolling) {
- LOG.info("Statistics are shut down for device: {}", nodeId);
+ LOG.info("Statistics are shut down for device: {}", deviceInfo.getNodeId());
return;
}
- final StatisticsContext statisticsContext = contexts.get(nodeId);
+ final StatisticsContext statisticsContext = contexts.get(deviceInfo);
if (statisticsContext == null) {
- LOG.warn("Statistics context not found for device: {}", nodeId);
+ LOG.warn("Statistics context not found for device: {}", deviceInfo.getNodeId());
return;
}
if (statisticsContext.isSchedulingEnabled()) {
- LOG.debug("Statistics scheduling is already enabled for device: {}", nodeId);
+ LOG.debug("Statistics scheduling is already enabled for device: {}", deviceInfo.getNodeId());
return;
}
- LOG.info("Scheduling statistics poll for device: {}", nodeId);
- final DeviceContext deviceContext = conductor.getDeviceContext(nodeId);
+ LOG.info("Scheduling statistics poll for device: {}", deviceInfo.getNodeId());
+ final DeviceContext deviceContext = conductor.getDeviceContext(deviceInfo.getNodeId());
if (deviceContext == null) {
- LOG.warn("Device context not found for device: {}", nodeId);
+ LOG.warn("Device context not found for device: {}", deviceInfo.getNodeId());
return;
}
}
@Override
- public void stopScheduling(final NodeId nodeId) {
- LOG.debug("Stopping statistics scheduling for device: {}", nodeId);
- final StatisticsContext statisticsContext = contexts.get(nodeId);
+ public void stopScheduling(final DeviceInfo deviceInfo) {
+ LOG.debug("Stopping statistics scheduling for device: {}", deviceInfo.getNodeId());
+ final StatisticsContext statisticsContext = contexts.get(deviceInfo);
if (statisticsContext == null) {
- LOG.warn("Statistics context not found for device: {}", nodeId);
+ LOG.warn("Statistics context not found for device: {}", deviceInfo.getNodeId());
return;
}
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.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.lifecycle.ServiceChangeListener;
private ListenableFuture<Void> listenableFuture;
@Mock
private StatisticsManager statisticsManager;
+ @Mock
+ private DeviceInfo deviceInfo;
private NodeId nodeId = new NodeId("openflow-junit:1");
private OfpRole ofpRole = OfpRole.NOCHANGE;
lifecycleConductor.setSafelyStatisticsManager(statisticsManager);
when(connectionContext.getFeatures()).thenReturn(featuresReply);
+ when(deviceInfo.getNodeId()).thenReturn(nodeId);
}
when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
when(deviceContext.onClusterRoleChange(null, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
lifecycleConductor.roleChangeOnDevice(nodeId,true,OfpRole.BECOMEMASTER,false);
- verify(statisticsManager).startScheduling(nodeId);
+ verify(statisticsManager).startScheduling(Mockito.<DeviceInfo>any());
}
/**
when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
when(deviceContext.onClusterRoleChange(null, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
lifecycleConductor.roleChangeOnDevice(nodeId,true,OfpRole.BECOMESLAVE,false);
- verify(statisticsManager).stopScheduling(nodeId);
+ verify(statisticsManager).stopScheduling(Mockito.<DeviceInfo>any());
}
/**
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
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.lifecycle.LifecycleConductor;
StatisticsGatheringService mockedStatisticsGatheringService;
StatisticsGatheringOnTheFlyService mockedStatisticsOnFlyGatheringService;
ConnectionContext mockedConnectionContext;
+ DeviceInfo mockedDeviceInfo;
static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
.child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
mockedStatisticsOnFlyGatheringService = mock(StatisticsGatheringOnTheFlyService.class);
mockedConnectionContext = mock(ConnectionContext.class);
mockedDeviceState = mock(DeviceState.class);
+ mockedDeviceInfo = mock(DeviceInfo.class);
final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
public void gatherDynamicDataTest() {
- final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceContext.getDeviceState().getNodeId(), false, mockConductor);
+ final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor);
final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
}
private void initStatisticsContext() {
- statisticsContext = new StatisticsContextImpl(mockedDeviceContext.getDeviceState().getNodeId(), false, mockConductor);
+ statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor);
statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
}
*/
@Test
public void testClose() throws Exception {
- final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceContext.getDeviceState().getNodeId(), false, mockConductor);
+ final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor);
final RequestContext<Object> requestContext = statisticsContext.createRequestContext();
statisticsContext.close();
try {