use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class OpenDaylightToasterTest method testToasterInitOnStartUp.
@Test
public void testToasterInitOnStartUp() throws Exception {
DataBroker broker = getDataBroker();
ReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
Optional<Toaster> optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
assertNotNull(optional);
assertTrue("Operational toaster not present", optional.isPresent());
Toaster toasterData = optional.get();
assertEquals(Toaster.ToasterStatus.Up, toasterData.getToasterStatus());
assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer());
assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber());
Optional<Toaster> configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
assertFalse("Didn't expect config data for toaster.", configToaster.isPresent());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction 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.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.
the class PcepStateUtils method readNodeFromDataStore.
private static Node readNodeFromDataStore(final DataBroker dataBroker, final String topologyId, final String nodeId) {
final InstanceIdentifier<Node> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(new TopologyId(topologyId))).child(Node.class, new NodeKey(new NodeId(nodeId))).build();
final ReadOnlyTransaction rot = dataBroker.newReadOnlyTransaction();
try {
return rot.read(LogicalDatastoreType.OPERATIONAL, topology).get().orNull();
} catch (final InterruptedException | ExecutionException e) {
LOG.warn("Failed to read node {}", nodeId, e);
}
return null;
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.
the class AbstractExtCommunityHandler method loadCommunitySet.
private List<ExtendedCommunities> loadCommunitySet(final String key) throws ExecutionException, InterruptedException {
final ReadOnlyTransaction tr = this.databroker.newReadOnlyTransaction();
final Optional<ExtCommunitySet> result = tr.read(LogicalDatastoreType.CONFIGURATION, EXT_COMMUNITY_SETS_IID.child(ExtCommunitySet.class, new ExtCommunitySetKey(key))).get();
if (!result.isPresent()) {
return Collections.emptyList();
}
return result.get().getExtCommunityMember().stream().map(ge -> new ExtendedCommunitiesBuilder().setExtendedCommunity(ge.getExtendedCommunity()).setTransitive(ge.isTransitive()).build()).collect(Collectors.toList());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.
the class MatchAsPathSetHandler method loadSets.
private AsPathSet loadSets(final String key) throws ExecutionException, InterruptedException {
final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
final Optional<AsPathSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, AS_PATHS_SETS_IID.child(AsPathSet.class, new AsPathSetKey(key))).get();
return result.orNull();
}
Aggregations