Search in sources :

Example 56 with CommitInfo

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

the class TopologyNodeState method storeNode.

synchronized void storeNode(final InstanceIdentifier<Node1> topologyAugment, final Node1 ta, final PCEPSession session) {
    LOG.trace("Peer data {} set to {}", topologyAugment, ta);
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
    // All set, commit the modifications
    trans.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Node stored {} for session {} updated successfully", topologyAugment, session);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to store node {} for session {}, terminating it", topologyAugment, session, throwable);
            session.close(TerminationReason.UNKNOWN);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 57 with CommitInfo

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

the class TopologyNodeState method putTopologyNode.

private synchronized void putTopologyNode() {
    final Node node = new NodeBuilder().withKey(this.nodeId.getKey()).setNodeId(this.nodeId.getKey().getNodeId()).build();
    final WriteTransaction t = this.chain.newWriteOnlyTransaction();
    LOG.trace("Put topology Node {}, value {}", this.nodeId, node);
    t.merge(LogicalDatastoreType.OPERATIONAL, this.nodeId, node);
    t.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Topology Node stored {}, value {}", TopologyNodeState.this.nodeId, node);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Put topology Node failed {}, value {}", TopologyNodeState.this.nodeId, node, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)

Example 58 with CommitInfo

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

the class AbstractTopologyBuilder method onDataTreeChanged.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void onDataTreeChanged(final Collection<DataTreeModification<T>> changes) {
    if (networkTopologyTransaction) {
        if (this.closed.get()) {
            LOG.trace("Transaction chain was already closed, skipping update.");
            return;
        }
        // check if the transaction chain needed to be restarted due to a previous error
        if (restartTransactionChainOnDemand()) {
            LOG.debug("The data change {} is disregarded due to restart of listener {}", changes, this);
            return;
        }
        final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
        LOG.trace("Received data change {} event with transaction {}", changes, trans.getIdentifier());
        final AtomicBoolean transactionInError = new AtomicBoolean(false);
        for (final DataTreeModification<T> change : changes) {
            try {
                routeChanged(change, trans);
            } catch (final RuntimeException exc) {
                LOG.warn("Data change {} (transaction {}) was not completely propagated to listener {}", change, trans.getIdentifier(), this, exc);
                // trans.cancel() is not supported by PingPongTransactionChain, so we just skip the problematic
                // change.
                // trans.commit() must be called first to unlock the current transaction chain, to make the chain
                // closable so we cannot exit the #onDataTreeChanged() yet
                transactionInError.set(true);
                break;
            }
        }
        trans.commit().addCallback(new FutureCallback<CommitInfo>() {

            @Override
            public void onSuccess(final CommitInfo result) {
                // the data loss will not be able to be recovered. Thus we schedule a listener restart here
                if (transactionInError.get()) {
                    LOG.warn("Transaction {} committed successfully while exception captured. Rescheduling a" + " restart of listener {}", trans.getIdentifier(), AbstractTopologyBuilder.this);
                    scheduleListenerRestart();
                } else {
                    LOG.trace("Transaction {} committed successfully", trans.getIdentifier());
                }
            }

            @Override
            public void onFailure(final Throwable throwable) {
                // we do nothing but print out the log. Transaction chain restart will be done in
                // #onTransactionChainFailed()
                LOG.error("Failed to propagate change (transaction {}) by listener {}", trans.getIdentifier(), AbstractTopologyBuilder.this, throwable);
            }
        }, MoreExecutors.directExecutor());
    } else {
        for (final DataTreeModification<T> change : changes) {
            routeChanged(change, null);
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 59 with CommitInfo

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

the class AbstractTopologyBuilder method initOperationalTopology.

private synchronized void initOperationalTopology() {
    requireNonNull(this.chain, "A valid transaction chain must be provided.");
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    trans.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, this.topology, new TopologyBuilder().withKey(this.topologyKey).setServerProvided(Boolean.TRUE).setTopologyTypes(this.topologyTypes).setLink(Map.of()).setNode(Map.of()).build());
    trans.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Transaction {} committed successfully", trans.getIdentifier());
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to initialize topology {} (transaction {}) by listener {}", AbstractTopologyBuilder.this.topology, trans.getIdentifier(), AbstractTopologyBuilder.this, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) TopologyBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder) 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