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.ConnectionException;
+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;
private final ConvertorExecutor converterExecutor;
private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
- private DeviceTerminationPhaseHandler deviceTerminPhaseHandler;
+ private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
private final ConcurrentMap<DeviceInfo, StatisticsContext> contexts = new ConcurrentHashMap<>();
- private static final long basicTimerDelay = 3000;
- private static long currentTimerDelay = basicTimerDelay;
- private static final long maximumTimerDelay = 900000; //wait max 15 minutes for next statistics
+ private static long basicTimerDelay;
+ private static long currentTimerDelay;
+ private static long maximumTimerDelay; //wait time for next statistics
private StatisticsWorkMode workMode = StatisticsWorkMode.COLLECTALL;
private final Semaphore workModeGuard = new Semaphore(1, true);
- private boolean isStatisticsPollingEnabled;
+ private boolean isStatisticsPollingOn;
private BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
private final HashedWheelTimer hashedWheelTimer;
}
public StatisticsManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
- final boolean isStatisticsPollingEnabled,
+ final boolean isStatisticsPollingOn,
final HashedWheelTimer hashedWheelTimer,
- final ConvertorExecutor convertorExecutor) {
+ final ConvertorExecutor convertorExecutor,
+ final long basicTimerDelay,
+ final long maximumTimerDelay) {
Preconditions.checkArgument(rpcProviderRegistry != null);
this.converterExecutor = convertorExecutor;
this.controlServiceRegistration = Preconditions.checkNotNull(
rpcProviderRegistry.addRpcImplementation(StatisticsManagerControlService.class, this)
);
- this.isStatisticsPollingEnabled = isStatisticsPollingEnabled;
+ this.isStatisticsPollingOn = isStatisticsPollingOn;
+ this.basicTimerDelay = basicTimerDelay;
+ this.currentTimerDelay = basicTimerDelay;
+ this.maximumTimerDelay = maximumTimerDelay;
this.hashedWheelTimer = hashedWheelTimer;
}
final StatisticsContext statisticsContext =
new StatisticsContextImpl(
deviceInfo,
- isStatisticsPollingEnabled,
+ isStatisticsPollingOn,
lifecycleService,
converterExecutor,
this);
+
Verify.verify(
contexts.putIfAbsent(deviceInfo, statisticsContext) == null,
"StatisticsCtx still not closed for Node {}", deviceInfo.getLOGValue()
);
+
lifecycleService.setStatContext(statisticsContext);
+ lifecycleService.registerDeviceRemovedHandler(this);
deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
}
if (LOG.isDebugEnabled()) {
LOG.debug("POLLING ALL STATISTICS for device: {}", deviceInfo.getNodeId());
}
+
timeCounter.markStart();
final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = statisticsContext.gatherDynamicData();
Futures.addCallback(deviceStatisticsCollectionFuture, new FutureCallback<Boolean>() {
@Override
public void onFailure(@Nonnull final Throwable throwable) {
timeCounter.addTimeMark();
- LOG.warn("Statistics gathering for single node {} was not successful: ", deviceInfo.getLOGValue(), throwable.getMessage());
+ LOG.warn("Statistics gathering for single node {} was not successful: {}", deviceInfo.getLOGValue(),
+ throwable.getMessage());
if (LOG.isTraceEnabled()) {
LOG.trace("Gathering for node {} failure: ", deviceInfo.getLOGValue(), throwable);
}
calculateTimerDelay(timeCounter);
- if (throwable instanceof IllegalStateException) {
+ if (throwable instanceof ConnectionException) {
+ // ConnectionException is raised by StatisticsContextImpl class when the connections
+ // move to RIP state. In this particular case, there is no need to reschedule
+ // because this statistics manager should be closed soon
+ LOG.warn("Node {} is no more connected, stopping the statistics collection",
+ deviceInfo.getLOGValue(),throwable);
stopScheduling(deviceInfo);
} else {
+ if (!(throwable instanceof CancellationException)) {
+ LOG.warn("Unexpected error occurred during statistics collection for node {}, rescheduling " +
+ "statistics collections", deviceInfo.getLOGValue(),throwable);
+ }
scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
}
}
});
final long averageTime = TimeUnit.MILLISECONDS.toSeconds(timeCounter.getAverageTimeBetweenMarks());
- final long STATS_TIMEOUT_SEC = averageTime > 0 ? 3 * averageTime : DEFAULT_STATS_TIMEOUT_SEC;
+ final long statsTimeoutSec = averageTime > 0 ? 3 * averageTime : DEFAULT_STATS_TIMEOUT_SEC;
final TimerTask timerTask = timeout -> {
if (!deviceStatisticsCollectionFuture.isDone()) {
- LOG.info("Statistics collection for node {} still in progress even after {} secs", deviceInfo.getLOGValue(), STATS_TIMEOUT_SEC);
+ LOG.info("Statistics collection for node {} still in progress even after {} secs", deviceInfo.getLOGValue(), statsTimeoutSec);
deviceStatisticsCollectionFuture.cancel(true);
}
};
- hashedWheelTimer.newTimeout(timerTask, STATS_TIMEOUT_SEC, TimeUnit.SECONDS);
+ hashedWheelTimer.newTimeout(timerTask, statsTimeoutSec, TimeUnit.SECONDS);
}
private void scheduleNextPolling(final DeviceState deviceState,
if (LOG.isDebugEnabled()) {
LOG.debug("SCHEDULING NEXT STATISTICS POLLING for device: {}", deviceInfo.getNodeId());
}
- if (!isStatisticsPollingEnabled) {
+ if (isStatisticsPollingOn) {
final Timeout pollTimeout = hashedWheelTimer.newTimeout(
timeout -> pollStatistics(
deviceState,
@Override
public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
- final StatisticsContext statisticsContext = contexts.remove(deviceInfo);
- if (null != statisticsContext) {
- LOG.debug("Removing device context from stack. No more statistics gathering for device: {}", deviceInfo.getLOGValue());
- statisticsContext.close();
- }
- deviceTerminPhaseHandler.onDeviceContextLevelDown(deviceInfo);
+ Optional.ofNullable(contexts.get(deviceInfo)).ifPresent(OFPContext::close);
+ deviceTerminationPhaseHandler.onDeviceContextLevelDown(deviceInfo);
}
@Override
if (workModeGuard.tryAcquire()) {
final StatisticsWorkMode targetWorkMode = input.getMode();
if (!workMode.equals(targetWorkMode)) {
- isStatisticsPollingEnabled = StatisticsWorkMode.FULLYDISABLED.equals(targetWorkMode);
+ isStatisticsPollingOn = !(StatisticsWorkMode.FULLYDISABLED.equals(targetWorkMode));
// iterate through stats-ctx: propagate mode
for (Map.Entry<DeviceInfo, StatisticsContext> entry : contexts.entrySet()) {
final DeviceInfo deviceInfo = entry.getKey();
@Override
public void startScheduling(final DeviceInfo deviceInfo) {
- if (isStatisticsPollingEnabled) {
+ if (!isStatisticsPollingOn) {
LOG.info("Statistics are shutdown for device: {}", deviceInfo.getNodeId());
return;
}
if (LOG.isDebugEnabled()) {
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: {}", deviceInfo.getNodeId());
return;
}
+
statisticsContext.setSchedulingEnabled(false);
}
controlServiceRegistration.close();
controlServiceRegistration = null;
}
+
for (final Iterator<StatisticsContext> iterator = Iterators.consumingIterator(contexts.values().iterator());
iterator.hasNext();) {
iterator.next().close();
@Override
public void setDeviceTerminationPhaseHandler(final DeviceTerminationPhaseHandler handler) {
- this.deviceTerminPhaseHandler = handler;
+ this.deviceTerminationPhaseHandler = handler;
+ }
+
+ @Override
+ public void setIsStatisticsPollingOn(boolean isStatisticsPollingOn){
+ this.isStatisticsPollingOn = isStatisticsPollingOn;
}
+ public void onDeviceRemoved(DeviceInfo deviceInfo) {
+ contexts.remove(deviceInfo);
+ LOG.debug("Statistics context removed for node {}", deviceInfo.getLOGValue());
+ }
+
+ @Override
+ public void setBasicTimerDelay(final long basicTimerDelay) {
+ this.basicTimerDelay = basicTimerDelay;
+ }
+
+ @Override
+ public void setMaximumTimerDelay(final long maximumTimerDelay) {
+ this.maximumTimerDelay = maximumTimerDelay;
+ }
}