Search in sources :

Example 51 with CommitInfo

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

the class EffectiveRibInWriter method onDataTreeChanged.

@Override
public synchronized void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
    if (this.chain == null) {
        LOG.trace("Chain closed. Ignoring Changes : {}", changes);
        return;
    }
    LOG.trace("Data changed called to effective RIB. Change : {}", changes);
    DOMDataTreeWriteTransaction tx = null;
    for (final DataTreeCandidate tc : changes) {
        final YangInstanceIdentifier rootPath = tc.getRootPath();
        final DataTreeCandidateNode root = tc.getRootNode();
        for (final DataTreeCandidateNode table : root.getChildNodes()) {
            if (tx == null) {
                tx = this.chain.newWriteOnlyTransaction();
            }
            changeDataTree(tx, rootPath, root, table);
        }
    }
    if (tx != null) {
        final FluentFuture<? extends CommitInfo> future = tx.commit();
        this.submitted = future;
        future.addCallback(new FutureCallback<CommitInfo>() {

            @Override
            public void onSuccess(final CommitInfo result) {
                LOG.trace("Successful commit");
            }

            @Override
            public void onFailure(final Throwable trw) {
                LOG.error("Failed commit", trw);
            }
        }, MoreExecutors.directExecutor());
    }
    // Refresh VPN Table if RT Memberships were updated
    if (this.rtMembershipsUpdated) {
        this.vpnTableRefresher.refreshTable(IVP4_VPN_TABLE_KEY, this.peerImportParameters.getFromPeerId());
        this.vpnTableRefresher.refreshTable(IVP6_VPN_TABLE_KEY, this.peerImportParameters.getFromPeerId());
        this.rtMembershipsUpdated = false;
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 52 with CommitInfo

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

the class LocRibWriter method init.

private synchronized void init() {
    final DOMDataTreeWriteTransaction tx = this.chain.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, this.locRibTableIID.node(ATTRIBUTES_NID).node(UPTODATE_NID), RIBNormalizedNodes.ATTRIBUTES_UPTODATE_TRUE);
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Successful commit");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed commit", trw);
        }
    }, MoreExecutors.directExecutor());
    this.reg = this.dataBroker.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, ribIId.node(PEER_NID).node(PEER_NID).node(EFFRIBIN_NID).node(TABLES_NID).node(locRibTableIID.getLastPathArgument())), this);
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 53 with CommitInfo

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

the class LocRibWriter method onDataTreeChanged.

/**
 * We use two-stage processing here in hopes that we avoid duplicate
 * calculations when multiple peers have changed a particular entry.
 *
 * @param changes on supported table
 */
@Override
@SuppressWarnings("checkstyle:illegalCatch")
public synchronized void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
    if (this.chain == null) {
        LOG.trace("Chain closed, ignoring received data change {} to LocRib {}", changes, this);
        return;
    }
    LOG.trace("Received data change {} to LocRib {}", changes, this);
    final DOMDataTreeWriteTransaction tx = this.chain.newWriteOnlyTransaction();
    try {
        final Map<RouteUpdateKey, RouteEntry<C, S>> toUpdate = update(tx, changes);
        if (!toUpdate.isEmpty()) {
            walkThrough(tx, toUpdate.entrySet());
        }
    } catch (final Exception e) {
        LOG.error("Failed to completely propagate updates {}, state is undefined", changes, e);
    } finally {
        tx.commit().addCallback(new FutureCallback<CommitInfo>() {

            @Override
            public void onSuccess(final CommitInfo result) {
                LOG.trace("Successful commit");
            }

            @Override
            public void onFailure(final Throwable trw) {
                LOG.error("Failed commit", trw);
            }
        }, MoreExecutors.directExecutor());
    }
}
Also used : RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 54 with CommitInfo

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

the class TopologyDataChangeCounter method putCount.

private void putCount(final long totalCount) {
    final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction();
    final Counter counter = new CounterBuilder().setId(this.counterId).setCount(Uint32.valueOf(totalCount)).build();
    wTx.put(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId, counter);
    wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Data change count update stored");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed to store Data change count");
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Counter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter) DataChangeCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.DataChangeCounter) CounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.CounterBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 55 with CommitInfo

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

the class StateProviderImpl method close.

@Deactivate
@PreDestroy
@Override
public synchronized void close() {
    if (closed.compareAndSet(false, true)) {
        this.scheduleTask.cancel(true);
        if (!this.instanceIdentifiersCache.isEmpty()) {
            final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction();
            this.instanceIdentifiersCache.values().forEach(bgpIID -> wTx.delete(LogicalDatastoreType.OPERATIONAL, bgpIID));
            this.instanceIdentifiersCache.clear();
            wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

                @Override
                public void onSuccess(final CommitInfo result) {
                    LOG.trace("Successfully operational stats removed.");
                }

                @Override
                public void onFailure(final Throwable throwable) {
                    LOG.error("Failed to clean up operational stats", throwable);
                }
            }, MoreExecutors.directExecutor());
        }
        this.transactionChain.close();
        this.scheduler.shutdown();
    }
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) PreDestroy(javax.annotation.PreDestroy) Deactivate(org.osgi.service.component.annotations.Deactivate)

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