Search in sources :

Example 41 with CommitInfo

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

the class ConnectedGraphServer method removeFromDataStore.

/**
 * Remove Graph or Graph components to the Data Store.
 *
 * @param <T>  As a generic method, T must be a Graph, Vertex, Edge or Prefix.
 * @param id   Instance Identifier of the Data Object
 * @param info Information to be logged
 */
private synchronized <T extends DataObject> void removeFromDataStore(final InstanceIdentifier<T> id, final String info) {
    final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
    trans.delete(LogicalDatastoreType.OPERATIONAL, id);
    trans.commit().addCallback(new FutureCallback<CommitInfo>() {

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

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("GraphModel: Cannot delete {} 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 42 with CommitInfo

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

the class ConnectedGraphServer method destroyOperationalGraphModel.

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

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

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Unable to reset operational GraphModel {} (transaction {})", GRAPH_TOPOLOGY_IDENTIFIER, trans.getIdentifier(), throwable);
        }
    }, MoreExecutors.directExecutor());
    /* Clear Connected Graph */
    for (ConnectedGraph graph : graphs.values()) {
        ((ConnectedGraphImpl) graph).clear();
    }
    return future;
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) ConnectedGraph(org.opendaylight.graph.ConnectedGraph) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 43 with CommitInfo

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

the class AdjRibInWriter method removeRoutes.

void removeRoutes(final MpUnreachNlri nlri) {
    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;
    }
    LOG.trace("Removing routes {}", nlri);
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    ctx.removeRoutes(tx, 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("Removing routes {}, succeed", nlri);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Removing 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)

Example 44 with CommitInfo

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

the class AdjRibInWriter method transform.

AdjRibInWriter transform(final PeerId newPeerId, final YangInstanceIdentifier peerPath, final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes, final Map<TablesKey, SendReceive> addPathTablesType, @Nullable final RegisterAppPeerListener registerAppPeerListener) {
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    createEmptyPeerStructure(newPeerId, peerPath, tx);
    final ImmutableMap<TablesKey, TableContext> tb = createNewTableInstances(peerPath, registry, tableTypes, addPathTablesType, tx);
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            if (registerAppPeerListener != null) {
                LOG.trace("Application Peer Listener registered");
                registerAppPeerListener.register();
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            if (registerAppPeerListener != null) {
                LOG.error("Failed to create Empty Structure, Application Peer Listener won't be registered", throwable);
            } else {
                LOG.error("Failed to create Empty Structure", throwable);
            }
        }
    }, MoreExecutors.directExecutor());
    return new AdjRibInWriter(this.ribPath, this.chain, this.role, tb);
}
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)

Example 45 with CommitInfo

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

the class AdjRibInWriter method markTableUptodate.

void markTableUptodate(final TablesKey tableTypes) {
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    final TableContext ctx = this.tables.get(tableTypes);
    tx.merge(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().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("Write Attributes uptodate, succeed");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Write Attributes uptodate failed", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) 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