Search in sources :

Example 16 with DOMDataWriteTransaction

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

the class SimpletxDomWrite method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
    long writeCnt = 0;
    for (MapEntryNode element : this.list) {
        YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues()));
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, yid, element);
        } else {
            tx.merge(dsType, yid, element);
        }
        writeCnt++;
        if (writeCnt == writesPerTx) {
            try {
                tx.submit().checkedGet();
                txOk++;
            } catch (final TransactionCommitFailedException e) {
                LOG.error("Transaction failed", e);
                txError++;
            }
            tx = domDataBroker.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    if (writeCnt != 0) {
        try {
            tx.submit().checkedGet();
        } catch (final TransactionCommitFailedException e) {
            LOG.error("Transaction failed", e);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 17 with DOMDataWriteTransaction

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

the class TxchainDomDelete 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();
    final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
    DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (int l = 0; l < outerListElem; l++) {
        YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
        tx.delete(dsType, yid);
        writeCnt++;
        if (writeCnt == writesPerTx) {
            txSubmitted++;
            Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

                @Override
                public void onSuccess(final Void result) {
                    txOk++;
                }

                @Override
                public void onFailure(final Throwable t) {
                    LOG.error("Transaction failed, {}", t);
                    txError++;
                }
            });
            tx = chain.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    // We need to empty the transaction chain before closing it
    try {
        txSubmitted++;
        tx.submit().checkedGet();
        txOk++;
    } catch (final TransactionCommitFailedException e) {
        LOG.error("Transaction failed", e);
        txError++;
    }
    try {
        chain.close();
    } catch (final IllegalStateException e) {
        LOG.error("Transaction close failed,", e);
    }
    LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
}
Also used : DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 18 with DOMDataWriteTransaction

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

the class WriteTransactionsHandler method execWrite.

@Override
ListenableFuture<Void> execWrite(final long txId) {
    final int i = nextInt(MAX_ITEM + 1);
    final YangInstanceIdentifier entryId = idListItem.node(ITEM).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(ITEM, NUMBER, i));
    final DOMDataWriteTransaction tx = createTransaction();
    if (usedValues.contains(i)) {
        LOG.debug("Deleting item: {}", i);
        deleteTx++;
        tx.delete(LogicalDatastoreType.CONFIGURATION, entryId);
        usedValues.remove(i);
    } else {
        LOG.debug("Inserting item: {}", i);
        insertTx++;
        final MapEntryNode entry = ImmutableNodes.mapEntry(ITEM, NUMBER, i);
        tx.put(LogicalDatastoreType.CONFIGURATION, entryId, entry);
        usedValues.add(i);
    }
    return tx.submit();
}
Also used : MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 19 with DOMDataWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction 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();
}
Also used : DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) AtomicReference(java.util.concurrent.atomic.AtomicReference) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DataStoreUnavailableException(org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) 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) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 20 with DOMDataWriteTransaction

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

the class DOMDataTreeListenerTest method deleteContainerContainerInTreeTest.

@Test
public void deleteContainerContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(TEST_CONTAINER, null, ModificationType.DELETE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Aggregations

DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)42 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)14 Test (org.junit.Test)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)9 CountDownLatch (java.util.concurrent.CountDownLatch)7 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)7 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)6 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)5 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)5 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)4 QName (org.opendaylight.yangtools.yang.common.QName)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)3 DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)3 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 InetSocketAddress (java.net.InetSocketAddress)2