use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class TxchainBaRead method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
for (long l = 0; l < outerListElem; l++) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l));
CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
try {
Optional<OuterList> optionalDataObject = submitFuture.checkedGet();
if (optionalDataObject != null && optionalDataObject.isPresent()) {
OuterList outerList = optionalDataObject.get();
String[] objectsArray = new String[outerList.getInnerList().size()];
for (InnerList innerList : outerList.getInnerList()) {
if (objectsArray[innerList.getName()] != null) {
LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue());
}
objectsArray[innerList.getName()] = innerList.getValue();
}
for (int i = 0; i < outerList.getInnerList().size(); i++) {
String itemStr = objectsArray[i];
if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
LOG.error("innerList: name: {}, value: {}", i, itemStr);
break;
}
}
txOk++;
} else {
txError++;
}
} catch (final ReadFailedException e) {
LOG.warn("failed to ....", e);
txError++;
}
}
}
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class EventSourceTopicTest method setUp.
@Before
public void setUp() throws Exception {
final NotificationPattern notificationPattern = new NotificationPattern("value1");
eventSourceServiceMock = mock(EventSourceService.class);
doReturn(RpcResultBuilder.success(new JoinTopicOutputBuilder().setStatus(JoinTopicStatus.Up).build()).buildFuture()).when(eventSourceServiceMock).joinTopic(any(JoinTopicInput.class));
eventSourceTopologyMock = mock(EventSourceTopology.class);
dataBrokerMock = mock(DataBroker.class);
doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService();
doReturn(dataBrokerMock).when(eventSourceTopologyMock).getDataBroker();
WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
CheckedFuture checkedFutureWriteMock = mock(CheckedFuture.class);
doReturn(checkedFutureWriteMock).when(writeTransactionMock).submit();
ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
CheckedFuture checkedFutureReadMock = mock(CheckedFuture.class);
doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class EventSourceTopologyTest method topicTestHelper.
private void topicTestHelper() throws Exception {
constructorTestHelper();
createTopicInputMock = mock(CreateTopicInput.class);
eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock);
NotificationPattern notificationPattern = new NotificationPattern("value1");
doReturn(notificationPattern).when(createTopicInputMock).getNotificationPattern();
Pattern pattern = new Pattern("valuePattern1");
doReturn(pattern).when(createTopicInputMock).getNodeIdPattern();
listenerRegistrationMock = mock(ListenerRegistration.class);
doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener(any(DataTreeIdentifier.class), any(EventSourceTopic.class));
ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
doReturn(checkedFutureMock).when(readOnlyTransactionMock).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
Optional optionalMock = mock(Optional.class);
doReturn(optionalMock).when(checkedFutureMock).checkedGet();
doReturn(true).when(optionalMock).isPresent();
Topology topologyMock = mock(Topology.class);
doReturn(topologyMock).when(optionalMock).get();
Node nodeMock = mock(Node.class);
List<Node> nodeList = new ArrayList<>();
nodeList.add(nodeMock);
doReturn(nodeList).when(topologyMock).getNode();
NodeId nodeId = new NodeId("nodeIdValue1");
doReturn(nodeId).when(nodeMock).getNodeId();
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.
the class MatchBgpNeighborSetHandler method loadRoleSets.
private List<PeerId> loadRoleSets(final String key) throws ExecutionException, InterruptedException {
final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
final Optional<NeighborSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, NEIGHBOR_SET_IID.child(NeighborSet.class, new NeighborSetKey(key))).get();
if (!result.isPresent()) {
return Collections.emptyList();
}
return result.get().getNeighbor().stream().map(nei -> RouterIds.createPeerId(nei.getAddress())).collect(Collectors.toList());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.
the class MatchClusterIdSetHandler method loadSets.
private ClusterIdSet loadSets(final String key) throws ExecutionException, InterruptedException {
final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
final Optional<ClusterIdSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, CLUSTERS_ID_SETS_IID.child(ClusterIdSet.class, new ClusterIdSetKey(key))).get();
return result.orNull();
}
Aggregations