use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class EventSourceTopic method notifyExistingNodes.
private void notifyExistingNodes(final EventSourceTopology eventSourceTopology) {
LOG.debug("Notify existing nodes");
final Pattern nodeRegex = this.nodeIdPattern;
final ReadOnlyTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction();
final ListenableFuture<Optional<Topology>> future = tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
Futures.addCallback(future, new FutureCallback<Optional<Topology>>() {
@Override
public void onSuccess(@Nonnull final Optional<Topology> data) {
if (data.isPresent()) {
final List<Node> nodes = data.get().getNode();
if (nodes != null) {
for (final Node node : nodes) {
if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, node.getKey()));
}
}
}
}
tx.close();
}
@Override
public void onFailure(final Throwable ex) {
LOG.error("Can not notify existing nodes", ex);
tx.close();
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class DataStoreAppConfigMetadata method readInitialAppConfig.
private void readInitialAppConfig(final DataBroker dataBroker) {
final ReadOnlyTransaction readOnlyTx = dataBroker.newReadOnlyTransaction();
ListenableFuture<Optional<DataObject>> future = readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, bindingContext.appConfigPath);
Futures.addCallback(future, new FutureCallback<Optional<DataObject>>() {
@Override
public void onSuccess(final Optional<DataObject> possibleAppConfig) {
LOG.debug("{}: Read of app config {} succeeded: {}", logName(), bindingContext.appConfigBindingClass.getName(), possibleAppConfig);
readOnlyTx.close();
setInitialAppConfig(possibleAppConfig);
}
@Override
public void onFailure(final Throwable failure) {
readOnlyTx.close();
// We may have gotten the app config via the data tree change listener so only retry if not.
if (readingInitialAppConfig.get()) {
LOG.warn("{}: Read of app config {} failed - retrying", logName(), bindingContext.appConfigBindingClass.getName(), failure);
readInitialAppConfig(dataBroker);
}
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class SimpletxBaRead method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
for (long l = 0; l < outerListElem; l++) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l));
Optional<OuterList> optionalDataObject;
CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
try {
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 WriteTransactionTest method testPutCreateParentsSuccess.
@Test
public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE, true);
writeTx.submit().checkedGet();
ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
assertTrue("Top node must exists after commit", topNode.isPresent());
Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
assertTrue("List node must exists after commit", listNode.isPresent());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project controller by opendaylight.
the class WriteTransactionTest method testMergeCreateParentsSuccess.
@Test
public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE, true);
writeTx.submit().checkedGet();
ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
assertTrue("Top node must exists after commit", topNode.isPresent());
Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
assertTrue("List node must exists after commit", listNode.isPresent());
}
Aggregations