Search in sources :

Example 16 with CommitInfo

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

the class ConnectedGraphServer method initOperationalGraphModel.

/**
 * Initialize GraphModel tree at Data Store top-level.
 */
private synchronized void initOperationalGraphModel() {
    requireNonNull(this.chain, "A valid transaction chain must be provided.");
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    LOG.info("Create Graph Model at top level in Operational DataStore: {}", GRAPH_TOPOLOGY_IDENTIFIER);
    trans.put(LogicalDatastoreType.OPERATIONAL, GRAPH_TOPOLOGY_IDENTIFIER, new GraphTopologyBuilder().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 GraphModel {} (transaction {}) by listener {}", GRAPH_TOPOLOGY_IDENTIFIER, trans.getIdentifier(), ConnectedGraphServer.this, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) GraphTopologyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.GraphTopologyBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 17 with CommitInfo

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

the class ConnectedGraphServer method updateToDataStore.

/**
 * Update Graph components (Vertex, Edge or Prefix ) to the Data Store. Old value identified by its Instance ID
 * will be remove first before adding the new value.
 *
 * @param <T>   As a generic method, T must be a Vertex, Edge or Prefix.
 * @param id    Instance Identifier of the Data Object
 * @param data  Data Object (Vertex, Edge or Prefix)
 * @param old   Instance Identifier of the previous version of the Data Object
 * @param info  Information to be logged
 */
private synchronized <T extends DataObject> void updateToDataStore(final InstanceIdentifier<T> id, final T data, final InstanceIdentifier<T> old, final String info) {
    final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
    if (old != null) {
        trans.delete(LogicalDatastoreType.OPERATIONAL, old);
    }
    trans.put(LogicalDatastoreType.OPERATIONAL, id, data);
    trans.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.info("GraphModel: {} has been published in operational datastore ", info);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("GrahModel: Cannot write {} to the operational datastore (transaction: {})", info, trans.getIdentifier());
        }
    }, MoreExecutors.directExecutor());
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 18 with CommitInfo

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

the class AbstractTopologySessionListener method updatePccState.

synchronized void updatePccState(final PccSyncState pccSyncState) {
    if (this.nodeState == null) {
        LOG.info("Server Session Manager is closed.");
        AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
        return;
    }
    final MessageContext ctx = new MessageContext(this.nodeState.getChain().newWriteOnlyTransaction());
    updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(pccSyncState).build());
    if (pccSyncState != PccSyncState.Synchronized) {
        this.synced.set(false);
        this.triggeredResyncInProcess = true;
    }
    // All set, commit the modifications
    ctx.trans.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Pcc Internal state for session {} updated successfully", AbstractTopologySessionListener.this.session);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to update Pcc internal state for session {}", AbstractTopologySessionListener.this.session, throwable);
            AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
        }
    }, MoreExecutors.directExecutor());
}
Also used : PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.PathComputationClientBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 19 with CommitInfo

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

the class TopologyStatsProviderImpl method updateStats.

@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void updateStats() {
    final TransactionChain chain = accessChain();
    if (chain == null) {
        // Already closed, do not bother
        return;
    }
    final WriteTransaction tx = chain.newWriteOnlyTransaction();
    try {
        for (Entry<KeyedInstanceIdentifier<Node, NodeKey>, PcepSessionState> entry : statsMap.entrySet()) {
            if (!statsPendingDelete.contains(entry.getKey())) {
                tx.put(LogicalDatastoreType.OPERATIONAL, entry.getKey().augmentation(PcepTopologyNodeStatsAug.class), new PcepTopologyNodeStatsAugBuilder().setPcepSessionState(new PcepSessionStateBuilder(entry.getValue()).build()).build());
            }
        }
    } catch (Exception e) {
        LOG.warn("Failed to prepare Tx for PCEP stats update", e);
        tx.cancel();
        return;
    }
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Successfully committed Topology stats update");
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("Failed to commit Topology stats update", ex);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) PcepSessionState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.PcepSessionState) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) ExecutionException(java.util.concurrent.ExecutionException) PcepTopologyNodeStatsAugBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAugBuilder) PcepTopologyNodeStatsAug(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAug) PcepSessionStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.grouping.PcepSessionStateBuilder) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 20 with CommitInfo

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

the class TopologyStatsProviderImpl method unbind.

@Override
public synchronized void unbind(final KeyedInstanceIdentifier<Node, NodeKey> nodeId) {
    final TransactionChain chain = accessChain();
    if (chain == null) {
        // Already closed, do not bother
        LOG.debug("Ignoring unbind of Pcep Node {}", nodeId);
        return;
    }
    final PcepSessionState node = statsMap.remove(nodeId);
    if (node == null) {
        LOG.debug("Ignoring duplicate unbind of Pcep Node {}", nodeId);
        return;
    }
    statsPendingDelete.add(nodeId);
    final WriteTransaction wTx = chain.newWriteOnlyTransaction();
    wTx.delete(LogicalDatastoreType.OPERATIONAL, nodeId);
    wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Successfully removed Pcep Node stats {}.", nodeId.getKey().getNodeId());
            statsPendingDelete.remove(nodeId);
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.warn("Failed to remove Pcep Node stats {}.", nodeId.getKey().getNodeId(), ex);
            statsPendingDelete.remove(nodeId);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) PcepSessionState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.PcepSessionState) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) 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