Merge "Convert OF samples to use DTCL instead of DCL" into stable/boron
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Mon, 19 Sep 2016 12:34:17 +0000 (12:34 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 19 Sep 2016 12:34:17 +0000 (12:34 +0000)
17 files changed:
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedConfigListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedOperationalListener.java
applications/forwardingrules-sync/src/test/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedOperationalListenerTest.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/StatisticsContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/HandshakeListenerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPaxOptionsAssistant.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginFlowTest.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SalIntegrationTest.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/ScenarioFactory.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SimulatorAssistant.java

index 6f86def8a6a9ef71f5a7c00edac2e730759ae36d..0d2e64b1c27f6b54328a791acec75d77b5dd36fe 100644 (file)
@@ -91,6 +91,7 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
                                                   final FlowCapableNode operationalNode) throws InterruptedException {
         NodeId nodeId = PathUtil.digNodeId(nodePath);
         LOG.trace("onNodeAdded {}", nodeId.getValue());
+        LOG.debug("Reconciliation {}: {}", dsType(), nodeId.getValue());
         final SyncupEntry syncupEntry = new SyncupEntry(dataAfter, dsType(), operationalNode, LogicalDatastoreType.OPERATIONAL);
         return reactor.syncup(nodePath, syncupEntry);
     }
index 2f0fc01257e9acd04881443bc554e4ffd9b9e218..c5aaf8def34d70a4d11c88d2b0f3ee3e46154ca9 100644 (file)
@@ -176,7 +176,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         final Optional<FlowCapableNode> nodeConfiguration = configDao.loadByNodeId(nodeId);
 
         if (nodeConfiguration.isPresent()) {
-            LOG.debug("Reconciliation: {}", nodeId.getValue());
+            LOG.debug("Reconciliation {}: {}", dsType(), nodeId.getValue());
             final InstanceIdentifier<FlowCapableNode> nodePath = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, new NodeKey(ModificationUtil.nodeId(modification)))
                     .augmentation(FlowCapableNode.class);
@@ -186,6 +186,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
             return Optional.of(reactor.syncup(nodePath, syncupEntry));
         } else {
             LOG.debug("Config not present for reconciliation: {}", nodeId.getValue());
+            reconciliationRegistry.unregisterIfRegistered(nodeId);
             return skipModification(modification);
         }
     }
index 4eb2e5b9685e7c6fc6d33c789f717af64a2fdebe..0f6a856ad07243590e438b8b5d964010948cd820 100644 (file)
@@ -112,34 +112,11 @@ public class SimplifiedOperationalListenerTest {
     }
 
     @Test
-    public void testOnDataTreeChangeAddSyncup() throws Exception {
-        Mockito.when(reconciliationRegistry.isRegistered(NODE_ID)).thenReturn(true);
+    public void testOnDataTreeChangedAddPhysical() {
         operationalAdd();
-        prepareFreshOperational(true);
-        final SyncupEntry syncupEntry = loadConfigDSAndPrepareSyncupEntry(configNode, configDS, fcOperationalNode, operationalDS);
-
         nodeListenerOperational.onDataTreeChanged(Collections.singleton(dataTreeModification));
-
-        Mockito.verify(deviceMastershipManager).onDeviceConnected(NODE_ID);
-        Mockito.verify(reactor).syncup(fcNodePath, syncupEntry);
-        Mockito.verify(roTx).close();
-    }
-
-    @Test
-    public void testOnDataTreeChangedAddSkip() throws Exception {
-        // Related to bug 5920 -> https://bugs.opendaylight.org/show_bug.cgi?id=5920
-        Mockito.when(reconciliationRegistry.isRegistered(NODE_ID)).thenReturn(true);
-        operationalAdd();
-        prepareFreshOperational(true);
-
-        Mockito.when(roTx.read(LogicalDatastoreType.CONFIGURATION, fcNodePath))
-                .thenReturn(Futures.immediateCheckedFuture(Optional.absent()));
-
-        nodeListenerOperational.onDataTreeChanged(Collections.singleton(dataTreeModification));
-
         Mockito.verify(deviceMastershipManager).onDeviceConnected(NODE_ID);
         Mockito.verifyZeroInteractions(reactor);
-        Mockito.verify(roTx).close();
     }
 
     @Test
@@ -170,8 +147,8 @@ public class SimplifiedOperationalListenerTest {
 
     @Test
     public void testOnDataTreeChangedReconcileNotRegistered() {
-        operationalUpdate();
         Mockito.when(reconciliationRegistry.isRegistered(NODE_ID)).thenReturn(false);
+        operationalUpdate();
 
         nodeListenerOperational.onDataTreeChanged(Collections.singleton(dataTreeModification));
 
@@ -238,6 +215,23 @@ public class SimplifiedOperationalListenerTest {
         Mockito.verify(roTx).close();
     }
 
+    @Test
+    public void testOnDataTreeChangedReconcileAndConfigNotPresent() throws Exception {
+        // Related to bug 5920 -> https://bugs.opendaylight.org/show_bug.cgi?id=5920
+        Mockito.when(reconciliationRegistry.isRegistered(NODE_ID)).thenReturn(true);
+        operationalUpdate();
+        prepareFreshOperational(true);
+
+        Mockito.when(roTx.read(LogicalDatastoreType.CONFIGURATION, fcNodePath))
+                .thenReturn(Futures.immediateCheckedFuture(Optional.absent()));
+
+        nodeListenerOperational.onDataTreeChanged(Collections.singleton(dataTreeModification));
+
+        Mockito.verify(reconciliationRegistry).unregisterIfRegistered(NODE_ID);
+        Mockito.verifyZeroInteractions(reactor);
+        Mockito.verify(roTx).close();
+    }
+
     private void prepareFreshOperational(final boolean afterRegistration) throws ParseException {
         Mockito.when(operationalNode.getAugmentation(FlowCapableStatisticsGatheringStatus.class)).thenReturn(statisticsGatheringStatus);
         Mockito.when(statisticsGatheringStatus.getSnapshotGatheringStatusEnd()).thenReturn(snapshotGatheringStatusEnd);
index 96df0e1455e012199d699cd96b53d1687984c50d..4a954c00fb26d4825ef6bd657e72c9ce73ad3374 100644 (file)
@@ -12,6 +12,8 @@ import com.google.common.util.concurrent.ListenableFuture;
 import io.netty.util.Timeout;
 import java.util.Optional;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
@@ -73,5 +75,20 @@ public interface StatisticsContext extends RequestContextStack, AutoCloseable, O
      */
     boolean isSchedulingEnabled();
 
-    LifecycleService getLifecycleService();
+    /**
+     * Gain device state
+     * @return device state from device context from lifecycle service
+     */
+    DeviceState gainDeviceState();
+
+    /**
+     * Gain device context
+     * @return device context from lifecycle service
+     */
+    DeviceContext gainDeviceContext();
+
+    /**
+     * In case to change mastership to slave or connection interrupted stop the future and release thread
+     */
+    void stopGatheringData();
 }
index e12549da933dec9045318a9ede85383eaa0ee52f..696743f31a744ffa8f3a8576457affd239d35dfd 100644 (file)
@@ -74,7 +74,7 @@ public class HandshakeListenerImpl implements HandshakeListener {
                 try {
                     ConnectionStatus connectionStatusResult = deviceConnectedHandler.deviceConnected(connectionContext);
                     if (!ConnectionStatus.MAY_CONTINUE.equals(connectionStatusResult)) {
-                        connectionContext.closeConnection(ConnectionStatus.ALREADY_CONNECTED.equals(connectionStatusResult));
+                        connectionContext.closeConnection(true);
                     }
                     SessionStatistics.countEvent(connectionContext.getNodeId().toString(),
                             SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
index 4fe9e05b9c66779d538aaaf477d74f2dc2a18f63..9f8bd244a2f3dc9f164fd49b36378109544b6b13 100644 (file)
@@ -653,7 +653,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
 
         LOG.info("Starting device context cluster services for node {}", deviceInfo.getLOGValue());
 
-        lazyTransactionManagerInitialiaztion();
+        lazyTransactionManagerInitialization();
 
         this.transactionChainManager.activateTransactionManager();
 
@@ -668,7 +668,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     }
 
     @VisibleForTesting
-    void lazyTransactionManagerInitialiaztion() {
+    void lazyTransactionManagerInitialization() {
         if (!this.initialized) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Transaction chain manager for node {} created", deviceInfo.getLOGValue());
index 6e201b9dc6dbab371c993a9b2773925cabea3094..39696efd7b8aa5d730d0899f7c11b308026b77cd 100644 (file)
@@ -44,12 +44,9 @@ public class LifecycleServiceImpl implements LifecycleService {
     @Override
     public void instantiateServiceInstance() {
 
-        LOG.info("========== Starting clustering MASTER services for node {} ==========", this.deviceContext.getDeviceInfo().getLOGValue());
+        LOG.info("Starting clustering MASTER services for node {}", this.deviceContext.getDeviceInfo().getLOGValue());
 
-        if (this.clusterInitializationPhaseHandler.onContextInstantiateService(null)) {
-            LOG.info("========== Start-up clustering MASTER services for node {} was SUCCESSFUL ==========", this.deviceContext.getDeviceInfo().getLOGValue());
-        } else {
-            LOG.warn("========== Start-up clustering MASTER services for node {} was UN-SUCCESSFUL ==========", this.deviceContext.getDeviceInfo().getLOGValue());
+        if (!this.clusterInitializationPhaseHandler.onContextInstantiateService(null)) {
             this.closeConnection();
         }
 
@@ -57,9 +54,8 @@ public class LifecycleServiceImpl implements LifecycleService {
 
     @Override
     public ListenableFuture<Void> closeServiceInstance() {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("========== Stopping clustering MASTER services for node {} ==========", this.deviceContext.getDeviceInfo().getLOGValue());
-        }
+
+        LOG.info("Stopping clustering MASTER services for node {}", this.deviceContext.getDeviceInfo().getLOGValue());
 
         final boolean connectionInterrupted =
                 this.deviceContext
@@ -67,17 +63,11 @@ public class LifecycleServiceImpl implements LifecycleService {
                         .getConnectionState()
                         .equals(ConnectionContext.CONNECTION_STATE.RIP);
 
-        LOG.info("Stopping role context cluster services for node {}", getIdentifier());
         roleContext.stopClusterServices(connectionInterrupted);
-
-        LOG.info("Stopping statistics context cluster services for node {}", getIdentifier());
         statContext.stopClusterServices(connectionInterrupted);
-
-        LOG.info("Stopping rpc context cluster services for node {}", getIdentifier());
         rpcContext.stopClusterServices(connectionInterrupted);
-
-        LOG.info("Stopping device context cluster services for node {}", getIdentifier());
         return deviceContext.stopClusterServices(connectionInterrupted);
+
     }
 
     @Override
@@ -170,7 +160,9 @@ public class LifecycleServiceImpl implements LifecycleService {
             @Override
             public void onFailure(Throwable t) {
                 if (deviceFlowRegistryFill.isCancelled()) {
-                    LOG.debug("Cancelled filling flow registry with flows for node: {}", deviceContext.getDeviceInfo().getLOGValue());
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Cancelled filling flow registry with flows for node: {}", deviceContext.getDeviceInfo().getLOGValue());
+                    }
                 } else {
                     LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", deviceContext.getDeviceInfo().getLOGValue(), t);
                 }
@@ -193,7 +185,6 @@ public class LifecycleServiceImpl implements LifecycleService {
             return false;
         }
 
-        LOG.info("Caching flows IDs ...");
         fillDeviceFlowRegistry();
         return true;
     }
index 0af2547c2144b9431dff4dd5d1db59396a0e9d6b..b636c9fb3021aa379c9651fca999c8ff84be70ca 100644 (file)
@@ -48,8 +48,6 @@ import org.slf4j.LoggerFactory;
 class RoleContextImpl implements RoleContext {
 
     private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
-    // Maximum limit of timeout retries when cleaning DS, to prevent infinite recursive loops
-    private static final int MAX_CLEAN_DS_RETRIES = 0;
 
     private SalRoleService salRoleService = null;
     private final HashedWheelTimer hashedWheelTimer;
@@ -64,7 +62,7 @@ class RoleContextImpl implements RoleContext {
                     final RoleManager myManager,
                     final LifecycleService lifecycleService) {
         this.deviceInfo = deviceInfo;
-        state = CONTEXT_STATE.WORKING;
+        this.state = CONTEXT_STATE.WORKING;
         this.myManager = myManager;
         this.hashedWheelTimer = hashedWheelTimer;
         this.lifecycleService = lifecycleService;
@@ -107,20 +105,7 @@ class RoleContextImpl implements RoleContext {
     }
 
     public void startupClusterServices() throws ExecutionException, InterruptedException {
-        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new FutureCallback<RpcResult<SetRoleOutput>>() {
-            @Override
-            public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
-                }
-            }
-
-            @Override
-            public void onFailure(final Throwable throwable) {
-                LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
-                lifecycleService.closeConnection();
-            }
-        });
+        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new RpcResultFutureCallback());
     }
 
     @Override
@@ -198,21 +183,22 @@ class RoleContextImpl implements RoleContext {
             return false;
         }
 
-        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new FutureCallback<RpcResult<SetRoleOutput>>() {
-            @Override
-            public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
-                }
-            }
+        Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new RpcResultFutureCallback());
+        return this.clusterInitializationPhaseHandler.onContextInstantiateService(connectionContext);
+    }
 
-            @Override
-            public void onFailure(final Throwable throwable) {
-                LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
-                lifecycleService.closeConnection();
+    private class RpcResultFutureCallback implements FutureCallback<RpcResult<SetRoleOutput>> {
+        @Override
+        public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
             }
-        });
+        }
 
-        return this.clusterInitializationPhaseHandler.onContextInstantiateService(connectionContext);
+        @Override
+        public void onFailure(final Throwable throwable) {
+            LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
+            lifecycleService.closeConnection();
+        }
     }
 }
index 560481ad862db9922cd759c16f8b63e8db0bfebe..0cf9d6b87ebdd51f8cb2bddc573c1f5eb0b501cb 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -76,10 +77,12 @@ class StatisticsContextImpl implements StatisticsContext {
     private ClusterInitializationPhaseHandler clusterInitializationPhaseHandler;
     private ClusterInitializationPhaseHandler initialSubmitHandler;
 
+    private ListenableFuture<Boolean> lastDataGathering;
+
     StatisticsContextImpl(@Nonnull final DeviceInfo deviceInfo,
                           final boolean shuttingDownStatisticsPolling,
                           @Nonnull final LifecycleService lifecycleService,
-                         @Nonnull final ConvertorExecutor convertorExecutor,
+                          @Nonnull final ConvertorExecutor convertorExecutor,
                           @Nonnull final StatisticsManager myManager) {
         this.lifecycleService = lifecycleService;
         this.deviceContext = lifecycleService.getDeviceContext();
@@ -94,6 +97,7 @@ class StatisticsContextImpl implements StatisticsContext {
         setState(CONTEXT_STATE.INITIALIZATION);
         this.deviceInfo = deviceInfo;
         this.myManager = myManager;
+        this.lastDataGathering = null;
     }
 
     @Override
@@ -136,6 +140,7 @@ class StatisticsContextImpl implements StatisticsContext {
     }
 
     private ListenableFuture<Boolean> gatherDynamicData(final boolean initial) {
+        this.lastDataGathering = null;
         if (shuttingDownStatisticsPolling) {
             LOG.debug("Statistics for device {} is not enabled.", getDeviceInfo().getNodeId().getValue());
             return Futures.immediateFuture(Boolean.TRUE);
@@ -166,6 +171,7 @@ class StatisticsContextImpl implements StatisticsContext {
                     }
                 }
             });
+            this.lastDataGathering = settableStatResultFuture;
             return settableStatResultFuture;
         }
     }
@@ -214,6 +220,7 @@ class StatisticsContextImpl implements StatisticsContext {
                 LOG.debug("Statistics context is already in state TERMINATION.");
             }
         } else {
+            stopGatheringData();
             setState(CONTEXT_STATE.TERMINATION);
             schedulingEnabled = false;
             for (final Iterator<RequestContext<?>> iterator = Iterators.consumingIterator(requestContexts.iterator());
@@ -256,12 +263,12 @@ class StatisticsContextImpl implements StatisticsContext {
         }
         if ( ! iterator.hasNext()) {
             resultFuture.set(Boolean.TRUE);
-            LOG.debug("Stats collection successfully finished for node {}", getDeviceInfo().getNodeId());
+            LOG.debug("Stats collection successfully finished for node {}", getDeviceInfo().getLOGValue());
             return;
         }
 
         final MultipartType nextType = iterator.next();
-        LOG.debug("Stats iterating to next type for node {} of type {}", getDeviceInfo().getNodeId(), nextType);
+        LOG.debug("Stats iterating to next type for node {} of type {}", getDeviceInfo().getLOGValue(), nextType);
 
         final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = chooseStat(nextType, initial);
         Futures.addCallback(deviceStatisticsCollectionFuture, new FutureCallback<Boolean>() {
@@ -420,13 +427,29 @@ class StatisticsContextImpl implements StatisticsContext {
 
     @Override
     public ListenableFuture<Void> stopClusterServices(boolean deviceDisconnected) {
+        stopGatheringData();
         myManager.stopScheduling(deviceInfo);
         return Futures.immediateFuture(null);
     }
 
     @Override
-    public LifecycleService getLifecycleService() {
-        return lifecycleService;
+    public DeviceState gainDeviceState() {
+        return gainDeviceContext().getDeviceState();
+    }
+
+    @Override
+    public DeviceContext gainDeviceContext() {
+        return this.lifecycleService.getDeviceContext();
+    }
+
+    @Override
+    public void stopGatheringData() {
+        if (Objects.nonNull(this.lastDataGathering)) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Stop the running statistics gathering for node {}", this.deviceInfo.getLOGValue());
+            }
+            this.lastDataGathering.cancel(true);
+        }
     }
 
     @Override
index 01cb6d0b14a94a98fcc0531b2712ef4cb21cbd4b..d94a82dac495f2b21369f3f66c763ced36b3b1ad 100644 (file)
@@ -56,7 +56,7 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
     private static final Logger LOG = LoggerFactory.getLogger(StatisticsManagerImpl.class);
 
     private static final long DEFAULT_STATS_TIMEOUT_SEC = 50L;
-    private final ConvertorExecutor convertorExecutor;
+    private final ConvertorExecutor converterExecutor;
 
     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
     private DeviceTerminationPhaseHandler deviceTerminPhaseHandler;
@@ -84,18 +84,29 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
                                  final HashedWheelTimer hashedWheelTimer,
                                  final ConvertorExecutor convertorExecutor) {
         Preconditions.checkArgument(rpcProviderRegistry != null);
-       this.convertorExecutor = convertorExecutor;
-        this.controlServiceRegistration = Preconditions.checkNotNull(rpcProviderRegistry.addRpcImplementation(
-                StatisticsManagerControlService.class, this));
+           this.converterExecutor = convertorExecutor;
+        this.controlServiceRegistration = Preconditions.checkNotNull(
+                rpcProviderRegistry.addRpcImplementation(StatisticsManagerControlService.class, this)
+        );
         this.isStatisticsPollingEnabled = isStatisticsPollingEnabled;
         this.hashedWheelTimer = hashedWheelTimer;
     }
 
     @Override
-    public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
-
-        final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, isStatisticsPollingEnabled, lifecycleService, convertorExecutor, this);
-        Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getLOGValue());
+    public void onDeviceContextLevelUp(final DeviceInfo deviceInfo,
+                                       final LifecycleService lifecycleService) throws Exception {
+
+        final StatisticsContext statisticsContext =
+                new StatisticsContextImpl(
+                        deviceInfo,
+                        isStatisticsPollingEnabled,
+                        lifecycleService,
+                        converterExecutor,
+                        this);
+        Verify.verify(
+                contexts.putIfAbsent(deviceInfo, statisticsContext) == null,
+                "StatisticsCtx still not closed for Node {}", deviceInfo.getLOGValue()
+        );
         lifecycleService.setStatContext(statisticsContext);
         deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
@@ -134,15 +145,10 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
                     LOG.trace("Gathering for node {} failure: ", deviceInfo.getLOGValue(), throwable);
                 }
                 calculateTimerDelay(timeCounter);
-                if (throwable instanceof CancellationException) {
-                    /* This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
-                    contexts.get(deviceInfo).getLifecycleService().closeConnection();
+                if (throwable instanceof IllegalStateException) {
+                    stopScheduling(deviceInfo);
                 } else {
-                    if (throwable instanceof IllegalStateException) {
-                        stopScheduling(deviceInfo);
-                    } else {
-                        scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
-                    }
+                    scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
                 }
             }
         });
@@ -230,10 +236,10 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
                 for (Map.Entry<DeviceInfo, StatisticsContext> entry : contexts.entrySet()) {
                     final DeviceInfo deviceInfo = entry.getKey();
                     final StatisticsContext statisticsContext = entry.getValue();
-                    final DeviceContext deviceContext = statisticsContext.getLifecycleService().getDeviceContext();
+                    final DeviceContext deviceContext = statisticsContext.gainDeviceContext();
                     switch (targetWorkMode) {
                         case COLLECTALL:
-                            scheduleNextPolling(deviceContext.getDeviceState(), deviceInfo, statisticsContext, new TimeCounter());
+                            scheduleNextPolling(statisticsContext.gainDeviceState(), deviceInfo, statisticsContext, new TimeCounter());
                             for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
                                 lifeCycleSource.setItemLifecycleListener(null);
                             }
@@ -285,8 +291,12 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
         LOG.info("Scheduling statistics poll for device: {}", deviceInfo.getNodeId());
 
         statisticsContext.setSchedulingEnabled(true);
-        final DeviceState deviceState = contexts.get(deviceInfo).getLifecycleService().getDeviceContext().getDeviceState();
-        scheduleNextPolling(deviceState, deviceInfo, statisticsContext, new TimeCounter());
+        scheduleNextPolling(
+                statisticsContext.gainDeviceState(),
+                deviceInfo,
+                statisticsContext,
+                new TimeCounter()
+        );
     }
 
     @Override
@@ -300,7 +310,6 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
             LOG.warn("Statistics context not found for device: {}", deviceInfo.getNodeId());
             return;
         }
-
         statisticsContext.setSchedulingEnabled(false);
     }
 
index 3606665575f1219908390ac4250f4bf70ed2ff0b..4e77150fbeceaa19a0d829c770f62cb15c8bde0f 100644 (file)
@@ -237,7 +237,7 @@ public class DeviceContextImplTest {
 
         xid = new Xid(atomicLong.incrementAndGet());
         xidMulti = new Xid(atomicLong.incrementAndGet());
-        ((DeviceContextImpl) deviceContext).lazyTransactionManagerInitialiaztion();
+        ((DeviceContextImpl) deviceContext).lazyTransactionManagerInitialization();
 
         Mockito.doNothing().when(deviceContextSpy).writeToTransaction(Mockito.<LogicalDatastoreType>any(), Mockito.<InstanceIdentifier>any(), any());
 
index ec9270f705e081f00c79c59dfd81b1b654f9f444..0b9c4555591a6334161a9a63d88534919c7c768b 100644 (file)
@@ -85,8 +85,6 @@ public class StatisticsManagerImplTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(StatisticsManagerImplTest.class);
 
-    private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
-    private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
     public static final NodeId NODE_ID = new NodeId("ofp-unit-dummy-node-id");
 
     @Mock
@@ -257,7 +255,8 @@ public class StatisticsManagerImplTest {
         when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
                 Collections.<ItemLifeCycleSource>emptyList());
 
-        when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+        when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+        when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
         when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
@@ -297,7 +296,8 @@ public class StatisticsManagerImplTest {
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
-        when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+        when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+        when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
         when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
 
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
@@ -336,7 +336,8 @@ public class StatisticsManagerImplTest {
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
-        when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+        when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+        when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
         when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
 
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
index 75c7f7ad8bd2521c62254ce562435de3249e7aa3..ba82ec0e661b407e028beacb65216f8a44db4165 100644 (file)
@@ -54,7 +54,7 @@ public abstract class OFPaxOptionsAssistant {
         if (System.getProperty(INSPECT_OSGI) != null) {
             option
             .add(CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address="+DEBUG_PORT))
-            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject()));
+            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject());
         }
 
         return option;
index a9ea510e3a84555952320dcafc52b8a362452b80..866080481dd275fbc4c2f57c83b37738e88f88d0 100644 (file)
@@ -16,12 +16,13 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Deque;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import org.junit.After;
 import org.junit.Assert;
@@ -29,11 +30,12 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
@@ -76,7 +78,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
@@ -155,23 +156,21 @@ public class OFPluginFlowTest {
         }
     }
 
-    final class TriggerTestListener implements DataChangeListener {
+    final class TriggerTestListener implements DataTreeChangeListener<FlowCapableNode> {
 
         public TriggerTestListener() {
             // NOOP
         }
 
         @Override
-        public void onDataChanged(
-                AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg0) {
-            Set<InstanceIdentifier<?>> keySet = arg0.getCreatedData().keySet();
-            if (keySet.size() == 1) {
-                for (InstanceIdentifier<?> key : keySet) {
-                    InstanceIdentifier<FlowCapableNode> neededKey =
-                            key.firstIdentifierOf(FlowCapableNode.class);
-                    if (neededKey != null) {
-                        LOG.info("Node was added (brm) {}", neededKey);
-                        writeFlow(createTestFlow(), neededKey);
+        public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<FlowCapableNode>> modifications) {
+
+            for (DataTreeModification modification : modifications) {
+                if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
+                    InstanceIdentifier<FlowCapableNode> ii = modification.getRootPath().getRootIdentifier();
+                    if (ii != null) {
+                        LOG.info("Node was added (brm) {}", ii);
+                        writeFlow(createTestFlow(), ii);
                         break;
                     }
                 }
@@ -188,8 +187,8 @@ public class OFPluginFlowTest {
         LOG.debug("testFlowMod integration test");
         TriggerTestListener brmListener = new TriggerTestListener();
 
-        dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                getWildcardPath(), brmListener, DataChangeScope.BASE);
+        final DataTreeIdentifier<FlowCapableNode> dataTreeIdentifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, getWildcardPath());
+        dataBroker.registerDataTreeChangeListener(dataTreeIdentifier, brmListener);
 
         switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
index 2eb0a4d16bb23d1603075cf80c25083b43fb13ac..a11fd400c9643fa5b17d55ce9db3ca929fe6d984 100644 (file)
@@ -21,7 +21,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-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.BindingAwareBroker.ConsumerContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
index 4f071cf7fd84cb7ec2295d40b1283526e2b5e8d5..40b6417b17701f9029d1fa9a3ed972c3cde27228 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.openflowplugin.openflow.md.it;
 
 import java.util.ArrayDeque;
 import java.util.Deque;
-
 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
 import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent;
 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
@@ -122,8 +121,6 @@ public abstract class ScenarioFactory {
     /**
      * Attempt to simulate the MLX running 1.0 talking to ODL
      *
-     * @param auxId
-     * @param pluginVersionBitmap
      * @return handshake scenario without switch version bitmap
      */
     public static Deque<ClientEvent> createHandshakeScenarioNoVBM_OF10_TwoHello() {
@@ -240,8 +237,6 @@ public abstract class ScenarioFactory {
     /**
      * Attempt to simulate the MLX running 1.0 talking to ODL
      *
-     * @param auxId
-     * @param pluginVersionBitmap
      * @return handshake scenario without switch version bitmap
      */
     public static Deque<ClientEvent> createHandshakeScenarioNOVBM_OF10_OneHello() {
index 110c4094601410e9cd0208dbefc285acc33b1418..9160491a27923523493c489173ae39b8d454074c 100644 (file)
@@ -11,22 +11,17 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-
 import org.junit.Assert;
 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * 
- */
 public abstract class SimulatorAssistant {
-    
-    private static final Logger LOG = LoggerFactory
-            .getLogger(SimulatorAssistant.class);
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimulatorAssistant.class);
 
     /**
-     * @param switchSim 
+     * @param switchSim
      * @throws InterruptedException
      */
     public static void waitForSwitchSimulatorOn(SimpleClient switchSim) {