private final DataBroker dataBroker;
private final HashedWheelTimer hashedWheelTimer;
private final Map<SwitchConnectionDistinguisher, ConnectionContext> auxiliaryConnectionContexts;
- private final TransactionChainManager txChainManager;
+ private final TransactionChainManager transactionChainManager;
private final DeviceFlowRegistry deviceFlowRegistry;
private final DeviceGroupRegistry deviceGroupRegistry;
private final DeviceMeterRegistry deviceMeterRegistry;
@Nonnull final HashedWheelTimer hashedWheelTimer,
@Nonnull final MessageSpy _messageSpy,
@Nonnull final OutboundQueueProvider outboundQueueProvider,
- @Nonnull final TranslatorLibrary translatorLibrary) {
+ @Nonnull final TranslatorLibrary translatorLibrary,
+ @Nonnull final TransactionChainManager transactionChainManager) {
this.primaryConnectionContext = Preconditions.checkNotNull(primaryConnectionContext);
this.deviceState = Preconditions.checkNotNull(deviceState);
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.hashedWheelTimer = Preconditions.checkNotNull(hashedWheelTimer);
this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider);
- txChainManager = new TransactionChainManager(dataBroker, deviceState);
+ this.transactionChainManager = Preconditions.checkNotNull(transactionChainManager);
auxiliaryConnectionContexts = new HashMap<>();
deviceFlowRegistry = new DeviceFlowRegistryImpl();
deviceGroupRegistry = new DeviceGroupRegistryImpl();
* and we are able to set a scheduler for an automatic transaction submitting by time (0,5sec).
*/
void initialSubmitTransaction() {
- txChainManager.initialSubmitWriteTransaction();
+ transactionChainManager.initialSubmitWriteTransaction();
}
@Override
@Override
public <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store,
final InstanceIdentifier<T> path, final T data) {
- txChainManager.writeToTransaction(store, path, data);
+ transactionChainManager.writeToTransaction(store, path, data);
}
@Override
public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) {
- txChainManager.addDeleteOperationTotTxChain(store, path);
+ transactionChainManager.addDeleteOperationTotTxChain(store, path);
}
@Override
public boolean submitTransaction() {
- return txChainManager.submitWriteTransaction();
+ return transactionChainManager.submitWriteTransaction();
}
@Override
deviceContextClosedHandler.onDeviceContextClosed(this);
}
- txChainManager.close();
+ transactionChainManager.close();
}
@Override
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
/**
*
*/
-public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
+public class DeviceManagerImpl implements DeviceManager, AutoCloseable, ReadyForNewTransactionChainHandler {
private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
private final long barrierNanos = TimeUnit.MILLISECONDS.toNanos(500);
private final int maxQueueDepth = 25600;
private final boolean switchFeaturesMandatory;
+ private final DeviceTransactionChainManagerProvider deviceTransactionChainManagerProvider;
public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
@Nonnull final MessageIntelligenceAgency messageIntelligenceAgency,
this.messageIntelligenceAgency = messageIntelligenceAgency;
this.switchFeaturesMandatory = switchFeaturesMandatory;
+ deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider();
}
public void deviceConnected(@CheckForNull final ConnectionContext connectionContext) {
Preconditions.checkArgument(connectionContext != null);
+ TransactionChainManager transactionChainManager = deviceTransactionChainManagerProvider.provideTransactionChainManagerOrWaitForNotification(connectionContext, dataBroker, this);
+ initializeDeviceContextSafely(connectionContext, transactionChainManager);
+ }
+
+ private void initializeDeviceContext(final ConnectionContext connectionContext, final TransactionChainManager transactionChainManager) {
+
// Cache this for clarity
final ConnectionAdapter connectionAdapter = connectionContext.getConnectionAdapter();
connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos);
connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
- final DeviceState deviceState = new DeviceStateImpl(connectionContext.getFeatures(), connectionContext.getNodeId());
+ final NodeId nodeId = connectionContext.getNodeId();
+ final DeviceState deviceState = new DeviceStateImpl(connectionContext.getFeatures(), nodeId);
final DeviceContext deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker,
- hashedWheelTimer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary);
+ hashedWheelTimer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary, transactionChainManager);
deviceContext.setNotificationService(notificationService);
deviceContext.setNotificationPublishService(notificationPublishService);
final NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceState.getNodeId()).setNodeConnector(Collections.<NodeConnector>emptyList());
spyPool = new ScheduledThreadPoolExecutor(1);
spyPool.scheduleAtFixedRate(messageIntelligenceAgency, spyRate, spyRate, TimeUnit.SECONDS);
}
+
+ @Override
+ public void onReadyForNewTransactionChain(final ConnectionContext connectionContext) {
+ TransactionChainManager transactionChainManager = deviceTransactionChainManagerProvider.provideTransactionChainManagerOrWaitForNotification(connectionContext, dataBroker, this);
+ initializeDeviceContextSafely(connectionContext, transactionChainManager);
+ }
+
+ private void initializeDeviceContextSafely(final ConnectionContext connectionContext, final TransactionChainManager transactionChainManager) {
+ if (null != transactionChainManager) {
+ initializeDeviceContext(connectionContext, transactionChainManager);
+ }
+ }
}
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
Preconditions.checkArgument(featuresReply != null);
featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
this.nodeId = Preconditions.checkNotNull(nodeId);
- // FIXME: use builder, as we will be using this identifier often
- nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
+ nodeII = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
version = featuresReply.getVersion();
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.device;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by Martin Bobak <mbobak@cisco.com> on 2.6.2015.
+ */
+public class DeviceTransactionChainManagerProvider {
+
+
+ private static final Logger LOG = LoggerFactory.getLogger(DeviceTransactionChainManagerProvider.class);
+ private static final Map<NodeId, TransactionChainManager> txChManagers = new HashMap<>();
+
+ public TransactionChainManager provideTransactionChainManagerOrWaitForNotification(final ConnectionContext connectionContext,
+ final DataBroker dataBroker,
+ final ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler) {
+ final NodeId nodeId = connectionContext.getNodeId();
+ synchronized (this) {
+ TransactionChainManager transactionChainManager = txChManagers.get(nodeId);
+ if (null == transactionChainManager) {
+ LOG.info("Creating new transaction chain for device {}", nodeId.toString());
+ Registration registration = new Registration() {
+ @Override
+ public void close() throws Exception {
+ txChManagers.remove(nodeId);
+ }
+ };
+ transactionChainManager = new TransactionChainManager(dataBroker, connectionContext, registration);
+ txChManagers.put(nodeId, transactionChainManager);
+ return transactionChainManager;
+ } else {
+ LOG.info("Device {} waits for previous connection's transaction chain to be closed.", nodeId.toString());
+ try {
+ if (!transactionChainManager.attemptToRegisterHandler(readyForNewTransactionChainHandler)) {
+ LOG.info("There already exists one handler for connection described as {}. Will try again.", nodeId);
+ readyForNewTransactionChainHandler.onReadyForNewTransactionChain(connectionContext);
+ }
+ } catch (Exception e) {
+ LOG.info("Transaction closed handler registration for node {} failed because we most probably hit previous transaction chain manager's close process. Will try again.", nodeId);
+ readyForNewTransactionChainHandler.onReadyForNewTransactionChain(connectionContext);
+ }
+ }
+ }
+ return null;
+ }
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.impl.device;
+
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+
+/**
+ * Created by Martin Bobak <mbobak@cisco.com> on 2.6.2015.
+ */
+public interface ReadyForNewTransactionChainHandler {
+
+ void onReadyForNewTransactionChain(ConnectionContext connectionContext);
+}
package org.opendaylight.openflowplugin.impl.device;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import java.util.concurrent.ExecutionException;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Object txLock = new Object();
- private final DeviceState deviceState;
private final DataBroker dataBroker;
private WriteTransaction wTx;
private BindingTransactionChain txChainFactory;
private boolean submitIsEnabled;
-
- TransactionChainManager(@Nonnull final DataBroker dataBroker, @Nonnull final DeviceState deviceState) {
+ private TransactionChainManagerStatus transactionChainManagerStatus;
+ private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
+ private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
+ private final ConnectionContext connectionContext;
+ private Registration managerRegistration;
+
+ TransactionChainManager(@Nonnull final DataBroker dataBroker,
+ @Nonnull final ConnectionContext connectionContext,
+ @Nonnull final Registration managerRegistration) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- this.deviceState = Preconditions.checkNotNull(deviceState);
- checkExistingNode();
- txChainFactory = dataBroker.createTransactionChain(TransactionChainManager.this);
+ this.nodeII = Preconditions.checkNotNull(DeviceStateUtil.createNodeInstanceIdentifier(connectionContext.getNodeId()));
+ this.connectionContext = Preconditions.checkNotNull(connectionContext);
+ this.managerRegistration = Preconditions.checkNotNull(managerRegistration);
+ createTxChain(dataBroker);
LOG.debug("created txChainManager");
}
- /**
- * Creating new TransactionChainManager means we have new Node (HandShake process was successful), but
- * the node existence in OPERATIONAL DataStore indicates some not finished NODE disconnection or some
- * unexpected problem with DataStore.
- * We should not continue with a PostHandShake NODE information collecting in this state.
- */
- private void checkExistingNode() {
- Optional<Node> node = Optional.<Node> absent();
- try {
- node = dataBroker.newReadOnlyTransaction()
- .read(LogicalDatastoreType.OPERATIONAL, deviceState.getNodeInstanceIdentifier()).get();
- }
- catch (InterruptedException | ExecutionException e) {
- LOG.warn("Not able to read node {} in Operation DataStore", deviceState.getNodeId());
- throw new IllegalStateException(e);
- }
- Preconditions.checkArgument((!node.isPresent()), "Node {} is exist, can not add same now!", deviceState.getNodeId());
+ private void createTxChain(final DataBroker dataBroker) {
+ txChainFactory = dataBroker.createTransactionChain(TransactionChainManager.this);
+ this.transactionChainManagerStatus = TransactionChainManagerStatus.WORKING;
}
void initialSubmitWriteTransaction() {
submitWriteTransaction();
}
+ public boolean attemptToRegisterHandler(final ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler) {
+ if (null == this.readyForNewTransactionChainHandler) {
+ synchronized (this) {
+ Preconditions.checkState(null != this.managerRegistration);
+ this.readyForNewTransactionChainHandler = readyForNewTransactionChainHandler;
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
boolean submitWriteTransaction() {
if (!submitIsEnabled) {
LOG.trace("transaction not committed - submit block issued");
return false;
}
- if ( ! deviceState.isValid()) {
- LOG.info("DeviceState is not valid will not submit transaction");
- return false;
- }
+
if (wTx == null) {
LOG.trace("nothing to commit - submit returns true");
return true;
private void recreateTxChain() {
txChainFactory.close();
- txChainFactory = dataBroker.createTransactionChain(TransactionChainManager.this);
+ createTxChain(dataBroker);
synchronized (txLock) {
wTx = null;
}
}
private WriteTransaction getTransactionSafely() {
- if (wTx == null) {
+ if (wTx == null && !TransactionChainManagerStatus.SHUTTING_DOWN.equals(transactionChainManagerStatus)) {
synchronized (txLock) {
if (wTx == null) {
wTx = txChainFactory.newWriteOnlyTransaction();
@Override
public void close() {
- LOG.debug("Removing node {} from operational DS.", deviceState.getNodeId());
+ LOG.debug("Removing node {} from operational DS.", nodeII);
synchronized (txLock) {
final WriteTransaction writeTx = getTransactionSafely();
- writeTx.delete(LogicalDatastoreType.OPERATIONAL, deviceState.getNodeInstanceIdentifier());
- writeTx.submit();
+ this.transactionChainManagerStatus = TransactionChainManagerStatus.SHUTTING_DOWN;
+ writeTx.delete(LogicalDatastoreType.OPERATIONAL, nodeII);
+ CheckedFuture<Void, TransactionCommitFailedException> submitsFuture = writeTx.submit();
+ Futures.addCallback(submitsFuture, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void aVoid) {
+ notifyReadyForNewTransactionChainAndCloseFactory();
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.info("Attempt to close transaction chain factory failed.", throwable);
+ notifyReadyForNewTransactionChainAndCloseFactory();
+ }
+ });
wTx = null;
- txChainFactory.close();
}
}
+
+ private void notifyReadyForNewTransactionChainAndCloseFactory() {
+ synchronized (this) {
+ if (null != readyForNewTransactionChainHandler) {
+ readyForNewTransactionChainHandler.onReadyForNewTransactionChain(connectionContext);
+ }
+ try {
+ managerRegistration.close();
+ } catch (Exception e) {
+ LOG.warn("Failed to close transaction chain manager's registration.", e);
+ }
+ managerRegistration = null;
+ }
+ txChainFactory.close();
+ }
+
+ private enum TransactionChainManagerStatus {
+ WORKING, SHUTTING_DOWN;
+ }
+
}
package org.opendaylight.openflowplugin.impl.util;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 20.4.2015.
deviceState.setQueueStatisticsAvailable(capabilitiesV10.isOFPCQUEUESTATS());
}
+ public static KeyedInstanceIdentifier<Node, NodeKey> createNodeInstanceIdentifier(NodeId nodeId){
+ return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
+ }
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent;
@Mock
TranslatorLibrary translatorLibrary;
+ @Mock
+ Registration registration;
private final AtomicLong atomicLong = new AtomicLong(0);
@Before
public void setUp() {
- final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node> absent());
+ final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
Mockito.when(rTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
Mockito.when(dataBroker.createTransactionChain(Mockito.any(TransactionChainManager.class))).thenReturn(txChainFactory);
Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
- txChainManager = new TransactionChainManager(dataBroker, deviceState);
+ txChainManager = new TransactionChainManager(dataBroker, connectionContext, registration);
final SettableFuture<RpcResult<GetAsyncReply>> settableFuture = SettableFuture.create();
final SettableFuture<RpcResult<MultipartReply>> settableFutureMultiReply = SettableFuture.create();
Mockito.when(requestContext.getFuture()).thenReturn(settableFuture);
Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
- deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary);
+ deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary, txChainManager);
xid = new Xid(atomicLong.incrementAndGet());
xidMulti = new Xid(atomicLong.incrementAndGet());
}
- @Test(expected = NullPointerException.class)
- public void testDeviceContextImplConstructorNullConnectionContext() throws Exception {
- new DeviceContextImpl(null, deviceState, dataBroker, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary).close();
- }
-
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
- new DeviceContextImpl(connectionContext, deviceState, null, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary).close();
+ new DeviceContextImpl(connectionContext, deviceState, null, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary, txChainManager).close();
}
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullDeviceState() throws Exception {
- new DeviceContextImpl(connectionContext, null, dataBroker, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary).close();
+ new DeviceContextImpl(connectionContext, null, dataBroker, timer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary, txChainManager).close();
}
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullTimer() throws Exception {
- new DeviceContextImpl(null, deviceState, dataBroker, null, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary).close();
+ new DeviceContextImpl(null, deviceState, dataBroker, null, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary, txChainManager).close();
}
@Test
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@Mock
private DataBroker dataBroker;
@Mock
- private DeviceState deviceState;
+ private ConnectionContext connectionContext;
@Mock
private BindingTransactionChain txChain;
@Mock
private TransactionChain<?, ?> transactionChain;
@Mock
HashedWheelTimer timer;
+ @Mock
+ Registration registration;
+
@Mock
private KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent;
@Before
public void setUp() throws Exception {
final ReadOnlyTransaction readOnlyTx = Mockito.mock(ReadOnlyTransaction.class);
- final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node> absent());
+ final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
Mockito.when(readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTx);
Mockito.when(dataBroker.createTransactionChain(Matchers.any(TransactionChainListener.class)))
.thenReturn(txChain);
- Mockito.when(deviceState.isValid()).thenReturn(Boolean.TRUE);
- Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
- txChainManager = new TransactionChainManager(dataBroker, deviceState);
+ txChainManager = new TransactionChainManager(dataBroker, connectionContext, registration);
Mockito.when(txChain.newWriteOnlyTransaction()).thenReturn(writeTx);
nodeId = new NodeId("h2g2:42");
/**
* test of {@link TransactionChainManager#enableSubmit()}: no submit - counter is not active
+ *
* @throws Exception
*/
@Test
/**
* test of {@link TransactionChainManager#enableSubmit()}: submit - after counter activated
+ *
* @throws Exception
*/
@Test