Search in sources :

Example 6 with DOMDataReadOnlyTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadOnlyTransaction.

@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
    final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
    final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(newTransactionIdentifier(), readTxDelegate);
    transactionMap.put(readTxDelegate.getIdentifier(), readTx);
    return readTx;
}
Also used : DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)

Example 7 with DOMDataReadOnlyTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testTransactionChain.

@SuppressWarnings("rawtypes")
@Test
public void testTransactionChain() throws Exception {
    TransactionChainListener mockListener = mock(TransactionChainListener.class);
    doNothing().when(mockListener).onTransactionChainSuccessful(anyObject());
    doNothing().when(mockListener).onTransactionChainFailed(anyObject(), anyObject(), anyObject());
    DOMTransactionChain chain = adapter.createTransactionChain(mockListener);
    // Test read-only tx
    DOMDataReadOnlyTransaction readTx = chain.newReadOnlyTransaction();
    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
    assertEquals("isPresent", true, readOptional.isPresent());
    assertEquals("NormalizedNode", dataNode, readOptional.get());
    // Test write-only tx
    DOMDataWriteTransaction writeTx = chain.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
    submitFuture.get(5, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(mockCommitCohort);
    inOrder.verify(mockCommitCohort).canCommit();
    inOrder.verify(mockCommitCohort).preCommit();
    inOrder.verify(mockCommitCohort).commit();
    // Test read-write tx
    DOMDataReadWriteTransaction readWriteTx = chain.newReadWriteTransaction();
    readFuture = readWriteTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    readOptional = readFuture.get();
    assertEquals("isPresent", true, readOptional.isPresent());
    assertEquals("NormalizedNode", dataNode, readOptional.get());
    chain.close();
    verify(mockListener).onTransactionChainSuccessful(chain);
    // Test failed chain
    doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException("mock", (Throwable) null))).when(mockCommitCohort).canCommit();
    chain = adapter.createTransactionChain(mockListener);
    writeTx = chain.newWriteOnlyTransaction();
    try {
        writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (TransactionCommitFailedException e) {
    // expected
    }
    ArgumentCaptor<AsyncTransaction> failedTx = ArgumentCaptor.forClass(AsyncTransaction.class);
    verify(mockListener).onTransactionChainFailed(eq(chain), failedTx.capture(), any(TransactionCommitFailedException.class));
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InOrder(org.mockito.InOrder) Optional(com.google.common.base.Optional) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 8 with DOMDataReadOnlyTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.

the class MdsalLowLevelTestProvider method unsubscribeDtcl.

@Override
public Future<RpcResult<UnsubscribeDtclOutput>> unsubscribeDtcl() {
    LOG.debug("Received unsubscribe-dtcl");
    if (idIntsListener == null || dtclReg == null) {
        final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Dtcl missing.", "No DataTreeChangeListener registered.");
        return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
    }
    try {
        idIntsListener.tryFinishProcessing().get(120, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport", "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e);
        return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
    }
    dtclReg.close();
    dtclReg = null;
    if (!idIntsListener.hasTriggered()) {
        final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + "any notifications.");
        return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
    }
    final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction();
    try {
        final Optional<NormalizedNode<?, ?>> readResult = rTx.read(CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID).checkedGet();
        if (!readResult.isPresent()) {
            final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Final read empty.", "No data read from id-ints list.");
            return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
        }
        return Futures.immediateFuture(RpcResultBuilder.success(new UnsubscribeDtclOutputBuilder().setCopyMatches(idIntsListener.checkEqual(readResult.get()))).build());
    } catch (final ReadFailedException e) {
        final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed.");
        return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) UnsubscribeDtclOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutput) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ExecutionException(java.util.concurrent.ExecutionException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) UnsubscribeDtclOutputBuilder(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutputBuilder) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 Optional (com.google.common.base.Optional)4 DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)3 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)3 Test (org.junit.Test)2 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)2 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)2 TransactionChainListener (org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)2 DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)2 QName (org.opendaylight.yangtools.yang.common.QName)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 InOrder (org.mockito.InOrder)1