use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testReadOnlyTransaction.
@Test
public void testReadOnlyTransaction() throws Exception {
DOMDataReadOnlyTransaction tx = adapter.newReadOnlyTransaction();
// Test successful read
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
// Test successful exists
CheckedFuture<Boolean, ReadFailedException> existsFuture = tx.exists(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
assertEquals("exists", Boolean.TRUE, existsFuture.get());
// Test failed read
String errorMsg = "mock read error";
Throwable cause = new RuntimeException();
doReturn(Futures.immediateFailedCheckedFuture(new org.opendaylight.mdsal.common.api.ReadFailedException(errorMsg, cause))).when(mockReadTx).read(TestModel.TEST_PATH);
try {
tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH).checkedGet();
fail("Expected ReadFailedException");
} catch (ReadFailedException e) {
assertEquals("getMessage", errorMsg, e.getMessage());
assertEquals("getCause", cause, e.getCause());
}
// Test close
tx.close();
verify(mockReadTx).close();
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class SimpletxDomRead method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
for (int l = 0; l < outerListElem; l++) {
YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
try {
Optional<NormalizedNode<?, ?>> optionalDataObject = submitFuture.checkedGet();
if (optionalDataObject != null && optionalDataObject.isPresent()) {
NormalizedNode<?, ?> ret = optionalDataObject.get();
LOG.trace("optionalDataObject is {}", ret);
txOk++;
} else {
txError++;
LOG.warn("optionalDataObject is either null or .isPresent is false");
}
} catch (final ReadFailedException e) {
LOG.warn("failed to ....", e);
txError++;
}
}
}
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class TxchainDomRead method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
for (int l = 0; l < outerListElem; l++) {
YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
Optional<NormalizedNode<?, ?>> optionalDataObject;
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
try {
optionalDataObject = submitFuture.checkedGet();
if (optionalDataObject != null && optionalDataObject.isPresent()) {
txOk++;
}
} catch (final ReadFailedException e) {
LOG.warn("failed to ....", e);
txError++;
}
}
}
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapter method createTransactionChain.
@Override
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
AtomicReference<DOMTransactionChain> legacyChain = new AtomicReference<>();
org.opendaylight.mdsal.common.api.TransactionChainListener delegateListener = new org.opendaylight.mdsal.common.api.TransactionChainListener() {
@SuppressWarnings("rawtypes")
@Override
public void onTransactionChainFailed(final org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain, final org.opendaylight.mdsal.common.api.AsyncTransaction<?, ?> transaction, final Throwable cause) {
listener.onTransactionChainFailed(legacyChain.get(), (AsyncTransaction) () -> transaction.getIdentifier(), cause instanceof Exception ? SUBMIT_EX_MAPPER.apply((Exception) cause) : cause);
}
@Override
public void onTransactionChainSuccessful(org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain) {
listener.onTransactionChainSuccessful(legacyChain.get());
}
};
final org.opendaylight.mdsal.dom.api.DOMTransactionChain delegateChain = delegate().createTransactionChain(delegateListener);
legacyChain.set(new DOMTransactionChain() {
@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
return new DOMDataReadOnlyTransactionAdapter(delegateChain.newReadOnlyTransaction());
}
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
return new DOMDataTransactionAdapter(delegateChain.newReadWriteTransaction());
}
@Override
public DOMDataWriteTransaction newWriteOnlyTransaction() {
return new DOMDataTransactionAdapter(delegateChain.newWriteOnlyTransaction());
}
@Override
public void close() {
delegateChain.close();
}
});
return legacyChain.get();
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadWriteTransaction.
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
final Object readWriteTxId = newTransactionIdentifier();
final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(readWriteTxId, readTxDelegate);
final DOMDataTreeWriteTransaction writeTxDelegate = txChainDelegate.newWriteOnlyTransaction();
final DOMDataWriteTransaction writeTx = new ShardedDOMDataBrokerDelegatingWriteTransaction(readWriteTxId, writeTxDelegate);
final DOMDataReadWriteTransaction readWriteTx = new ShardedDOMDataBrokerDelegatingReadWriteTransaction(readWriteTxId, schemaContext, readTx, writeTx);
transactionMap.put(readTxDelegate.getIdentifier(), readWriteTx);
transactionMap.put(writeTxDelegate.getIdentifier(), readWriteTx);
return readWriteTx;
}
Aggregations