Search in sources :

Example 1 with WriteTransactionsOutput

use of org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput in project controller by opendaylight.

the class WriteTransactionsHandler method runSuccessful.

@Override
void runSuccessful(final long allTx) {
    final WriteTransactionsOutput output = new WriteTransactionsOutputBuilder().setAllTx(allTx).setInsertTx(insertTx).setDeleteTx(deleteTx).build();
    completionFuture.set(RpcResultBuilder.<WriteTransactionsOutput>success().withResult(output).build());
}
Also used : WriteTransactionsOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput) WriteTransactionsOutputBuilder(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutputBuilder)

Example 2 with WriteTransactionsOutput

use of org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput in project controller by opendaylight.

the class WriteTransactionsHandler method start.

public static ListenableFuture<RpcResult<WriteTransactionsOutput>> start(final DOMDataBroker domDataBroker, final WriteTransactionsInput input) {
    LOG.debug("Starting write-transactions.");
    final String id = input.getId();
    final MapEntryNode entry = ImmutableNodes.mapEntryBuilder(ID_INT, ID, id).withChild(ImmutableNodes.mapNodeBuilder(ITEM).build()).build();
    final YangInstanceIdentifier idListItem = ID_INT_YID.node(entry.getIdentifier());
    final ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ID_INTS)).withChild(ImmutableNodes.mapNodeBuilder(ID_INT).build()).build();
    DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
    // write only the top list
    tx.merge(LogicalDatastoreType.CONFIGURATION, ID_INTS_YID, containerNode);
    try {
        tx.submit().checkedGet(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (final OptimisticLockFailedException e) {
        // when multiple write-transactions are executed concurrently we need to ignore this.
        // If we get optimistic lock here it means id-ints already exists and we can continue.
        LOG.debug("Got an optimistic lock when writing initial top level list element.", e);
    } catch (final TransactionCommitFailedException | TimeoutException e) {
        LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
        return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    tx = domDataBroker.newWriteOnlyTransaction();
    tx.merge(LogicalDatastoreType.CONFIGURATION, idListItem, entry);
    try {
        tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
        return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    LOG.debug("Filling the item list with initial values.");
    final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ITEM);
    final YangInstanceIdentifier itemListId = idListItem.node(ITEM);
    tx = domDataBroker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, mapBuilder.build());
    try {
        tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.warn("Unable to fill the initial item list.", e);
        return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    final WriteTransactionsHandler handler;
    if (input.isChainedTransactions()) {
        handler = new Chained(domDataBroker, idListItem, input);
    } else {
        handler = new Simple(domDataBroker, idListItem, input);
    }
    handler.doStart();
    return handler.completionFuture;
}
Also used : MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) WriteTransactionsOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ExecutionException(java.util.concurrent.ExecutionException) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

WriteTransactionsOutput (org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)1 WriteTransactionsOutputBuilder (org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutputBuilder)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1