Search in sources :

Example 6 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.

the class TxchainBaWrite method executeList.

@Override
public void executeList() {
    final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(this);
    final LogicalDatastoreType dsType = getDataStoreType();
    WriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (OuterList element : this.list) {
        InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, element.key());
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, iid, element);
        } else {
            tx.merge(dsType, iid, element);
        }
        writeCnt++;
        if (writeCnt == writesPerTx) {
            txSubmitted++;
            tx.commit().addCallback(new FutureCallback<CommitInfo>() {

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

                @Override
                public void onFailure(final Throwable cause) {
                    LOG.error("Transaction failed", cause);
                    txError++;
                }
            }, MoreExecutors.directExecutor());
            tx = chain.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    // We need to empty the transaction chain before closing it
    try {
        txSubmitted++;
        tx.commit().get();
        txOk++;
    } catch (final InterruptedException | ExecutionException 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 : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) OuterList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) TestExec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class AdjRibInWriter method removeStaleRoutes.

void removeStaleRoutes(final TablesKey tableKey) {
    final TableContext ctx = this.tables.get(tableKey);
    if (ctx == null) {
        LOG.debug("No table for {}, not removing any stale routes", tableKey);
        return;
    }
    final Collection<NodeIdentifierWithPredicates> routeKeys = this.staleRoutesRegistry.get(tableKey);
    if (routeKeys == null || routeKeys.isEmpty()) {
        LOG.debug("No stale routes present in table {}", tableKey);
        return;
    }
    LOG.trace("Removing routes {}", routeKeys);
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    routeKeys.forEach(routeKey -> {
        tx.delete(LogicalDatastoreType.OPERATIONAL, ctx.routePath(routeKey));
    });
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    this.submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Removing routes {}, succeed", routeKeys);
            synchronized (AdjRibInWriter.this.staleRoutesRegistry) {
                staleRoutesRegistry.remove(tableKey);
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Removing routes {}, failed", routeKeys, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 8 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class AdjRibInWriter method updateRoutes.

void updateRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes attributes) {
    final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
    final TableContext ctx = this.tables.get(key);
    if (ctx == null) {
        LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
        return;
    }
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    final Collection<NodeIdentifierWithPredicates> routeKeys = ctx.writeRoutes(tx, nlri, attributes);
    final Collection<NodeIdentifierWithPredicates> staleRoutes = this.staleRoutesRegistry.get(key);
    if (staleRoutes != null) {
        staleRoutes.removeAll(routeKeys);
    }
    LOG.trace("Write routes {}", nlri);
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    this.submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Write routes {}, succeed", nlri);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Write routes failed", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 9 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class AbstractPeer method removePeer.

final synchronized FluentFuture<? extends CommitInfo> removePeer(@Nullable final YangInstanceIdentifier peerPath) {
    if (peerPath == null) {
        return CommitInfo.emptyFluentFuture();
    }
    LOG.info("Closed per Peer {} removed", peerPath);
    final DOMDataTreeWriteTransaction tx = domChain.newWriteOnlyTransaction();
    tx.delete(LogicalDatastoreType.OPERATIONAL, peerPath);
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Peer {} removed", peerPath);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to remove Peer {}", peerPath, throwable);
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 10 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class AbstractTopologyBuilder method destroyOperationalTopology.

/**
 * Destroy the current operational topology data. Note a valid transaction must be provided.
 */
private synchronized FluentFuture<? extends CommitInfo> destroyOperationalTopology() {
    requireNonNull(this.chain, "A valid transaction chain must be provided.");
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    trans.delete(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier());
    final FluentFuture<? extends CommitInfo> future = trans.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Operational topology removed {}", AbstractTopologyBuilder.this.topology);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Unable to reset operational topology {} (transaction {})", AbstractTopologyBuilder.this.topology, trans.getIdentifier(), throwable);
        }
    }, MoreExecutors.directExecutor());
    clearTopology();
    return future;
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Aggregations

CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)59 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)26 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)23 ReadWriteTransaction (org.opendaylight.mdsal.binding.api.ReadWriteTransaction)12 ExecutionException (java.util.concurrent.ExecutionException)10 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)7 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)5 TransactionChain (org.opendaylight.mdsal.binding.api.TransactionChain)4 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)4 FluentFuture (com.google.common.util.concurrent.FluentFuture)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)3 Collection (java.util.Collection)3 Stopwatch (com.google.common.base.Stopwatch)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2