use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project bgpcep by opendaylight.
the class AbstractRIBTestSetup method mockedMethods.
@SuppressWarnings("unchecked")
private void mockedMethods() throws Exception {
MockitoAnnotations.initMocks(this);
final ReadOnlyTransaction readTx = mock(ReadOnlyTransaction.class);
doReturn(new listenerRegistration()).when(this.service).registerDataTreeChangeListener(any(DOMDataTreeIdentifier.class), any(ClusteredDOMDataTreeChangeListener.class));
final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> map = new HashMap<>();
map.put(DOMDataTreeChangeService.class, this.service);
doNothing().when(readTx).close();
final CheckedFuture<Optional<DataObject>, ReadFailedException> readFuture = mock(CheckedFuture.class);
doNothing().when(this.domTransWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doNothing().when(this.domTransWrite).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
doNothing().when(this.domTransWrite).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doReturn(Optional.absent()).when(readFuture).checkedGet();
doReturn(readFuture).when(readTx).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
doNothing().when(this.domChain).close();
doReturn(this.domTransWrite).when(this.domChain).newWriteOnlyTransaction();
doNothing().when(getTransaction()).put(eq(LogicalDatastoreType.OPERATIONAL), eq(YangInstanceIdentifier.of(BgpRib.QNAME)), any(NormalizedNode.class));
doReturn(map).when(this.dom).getSupportedExtensions();
doReturn(this.domChain).when(this.dom).createTransactionChain(any(BGPPeer.class));
doReturn(this.transWrite).when(this.chain).newWriteOnlyTransaction();
doReturn(false).when(this.o).isPresent();
doReturn(this.o).when(this.future).checkedGet();
doReturn(this.future).when(this.domTransWrite).submit();
doNothing().when(this.future).addListener(any(Runnable.class), any(Executor.class));
doNothing().when(this.transWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
doNothing().when(this.transWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class));
doReturn(this.future).when(this.transWrite).submit();
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project openflowplugin by opendaylight.
the class ForwardingRulesManagerImpl method checkNodeInOperationalDataStore.
@Override
public boolean checkNodeInOperationalDataStore(InstanceIdentifier<FlowCapableNode> ident) {
boolean result = false;
InstanceIdentifier<Node> nodeIid = ident.firstIdentifierOf(Node.class);
final ReadOnlyTransaction transaction = dataService.newReadOnlyTransaction();
CheckedFuture<com.google.common.base.Optional<Node>, ReadFailedException> future = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeIid);
try {
com.google.common.base.Optional<Node> optionalDataObject = future.checkedGet();
if (optionalDataObject.isPresent()) {
result = true;
} else {
LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], nodeIid);
}
} catch (ReadFailedException e) {
LOG.warn("Failed to read {} ", nodeIid, e);
}
transaction.close();
return result;
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project openflowplugin by opendaylight.
the class FlowWriterDirectOFRpc method getAllNodes.
private Set<String> getAllNodes() {
Set<String> nodeIds = new HashSet<>();
InstanceIdentifier<Nodes> nodes = InstanceIdentifier.create(Nodes.class);
ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
try {
Optional<Nodes> nodesDataNode = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodes).checkedGet();
if (nodesDataNode.isPresent()) {
List<Node> nodesCollection = nodesDataNode.get().getNode();
if (nodesCollection != null && !nodesCollection.isEmpty()) {
for (Node node : nodesCollection) {
LOG.info("Switch with ID {} discovered !!", node.getId().getValue());
nodeIds.add(node.getId().getValue());
}
} else {
return Collections.emptySet();
}
} else {
return Collections.emptySet();
}
} catch (ReadFailedException rdFailedException) {
LOG.error("Failed to read connected nodes {}", rdFailedException);
}
return nodeIds;
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project openflowplugin by opendaylight.
the class DeviceContextImplTest method setUp.
@Before
public void setUp() throws Exception {
final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
Mockito.when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readTx);
Mockito.when(dataBroker.createTransactionChain(Mockito.any(TransactionChainManager.class))).thenReturn(txChainFactory);
Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.ONE);
final SettableFuture<RpcResult<GetAsyncReply>> settableFuture = SettableFuture.create();
final SettableFuture<RpcResult<MultipartReply>> settableFutureMultiReply = SettableFuture.create();
Mockito.when(requestContext.getFuture()).thenReturn(settableFuture);
Mockito.doAnswer(invocation -> {
settableFuture.set((RpcResult<GetAsyncReply>) invocation.getArguments()[0]);
return null;
}).when(requestContext).setResult(any(RpcResult.class));
Mockito.when(requestContextMultiReply.getFuture()).thenReturn(settableFutureMultiReply);
Mockito.doAnswer(invocation -> {
settableFutureMultiReply.set((RpcResult<MultipartReply>) invocation.getArguments()[0]);
return null;
}).when(requestContextMultiReply).setResult(any(RpcResult.class));
Mockito.when(txChainFactory.newReadWriteTransaction()).thenReturn(writeTx);
Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readTx);
Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
final FeaturesReply mockedFeaturesReply = mock(FeaturesReply.class);
when(connectionContext.getFeatures()).thenReturn(mockedFeaturesReply);
when(connectionContext.getFeatures().getCapabilities()).thenReturn(mock(Capabilities.class));
Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
Mockito.when(featuresOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
Mockito.when(contextChainHolder.getContextChain(deviceInfo)).thenReturn(contextChain);
Mockito.when(contextChain.isMastered(ContextChainMastershipState.CHECK, false)).thenReturn(true);
final PacketReceived packetReceived = new PacketReceivedBuilder().setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder().setInPort(new NodeConnectorId("openflow:1:LOCAL")).build()).build();
Mockito.when(messageTranslatorPacketReceived.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(packetReceived);
Mockito.when(messageTranslatorFlowCapableNodeConnector.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(mock(FlowCapableNodeConnector.class));
Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, PacketIn.class.getName())))).thenReturn(messageTranslatorPacketReceived);
Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, PortGrouping.class.getName())))).thenReturn(messageTranslatorFlowCapableNodeConnector);
Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, FlowRemoved.class.getName())))).thenReturn(messageTranslatorFlowRemoved);
Mockito.when(abstractDeviceInitializer.initialize(any(), anyBoolean(), anyBoolean(), any(), any())).thenReturn(Futures.immediateFuture(null));
final java.util.Optional<AbstractDeviceInitializer> deviceInitializer = java.util.Optional.of(this.abstractDeviceInitializer);
Mockito.when(deviceInitializerProvider.lookup(OFConstants.OFP_VERSION_1_3)).thenReturn(deviceInitializer);
Mockito.when(salRoleService.setRole(any())).thenReturn(Futures.immediateFuture(null));
deviceContext = new DeviceContextImpl(connectionContext, dataBroker, messageSpy, translatorLibrary, convertorExecutor, false, timer, false, deviceInitializerProvider, true, false, contextChainHolder);
((DeviceContextImpl) deviceContext).lazyTransactionManagerInitialization();
deviceContextSpy = Mockito.spy(deviceContext);
xid = new Xid(atomicLong.incrementAndGet());
xidMulti = new Xid(atomicLong.incrementAndGet());
Mockito.doNothing().when(deviceContextSpy).writeToTransaction(any(), any(), any());
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project openflowplugin by opendaylight.
the class DeviceFlowRegistryImpl method fillFromDatastore.
private CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> fillFromDatastore(final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<FlowCapableNode> path) {
// Create new read-only transaction
final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
// Bail out early if transaction is null
if (transaction == null) {
return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read transaction is null"));
}
// Prepare read operation from datastore for path
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> future = transaction.read(logicalDatastoreType, path);
// Bail out early if future is null
if (future == null) {
return Futures.immediateFailedCheckedFuture(new ReadFailedException("Future from read transaction is null"));
}
Futures.addCallback(future, new FutureCallback<Optional<FlowCapableNode>>() {
@Override
public void onSuccess(@Nonnull Optional<FlowCapableNode> result) {
result.asSet().stream().filter(Objects::nonNull).filter(flowCapableNode -> Objects.nonNull(flowCapableNode.getTable())).flatMap(flowCapableNode -> flowCapableNode.getTable().stream()).filter(Objects::nonNull).filter(table -> Objects.nonNull(table.getFlow())).flatMap(table -> table.getFlow().stream()).filter(Objects::nonNull).filter(flow -> Objects.nonNull(flow.getId())).forEach(flowConsumer);
// After we are done with reading from datastore, close the transaction
transaction.close();
}
@Override
public void onFailure(Throwable throwable) {
// Even when read operation failed, close the transaction
transaction.close();
}
}, MoreExecutors.directExecutor());
return future;
}
Aggregations