Search in sources :

Example 46 with CommitInfo

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

the class ApplicationPeer method onDataTreeChanged.

/**
 * Routes come from application RIB that is identified by (configurable) name.
 * Each route is pushed into AdjRibsInWriter with it's whole context. In this
 * method, it doesn't matter if the routes are removed or added, this will
 * be determined in LocRib.
 */
@Override
public synchronized void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
    final DOMTransactionChain chain = getDomChain();
    if (chain == null) {
        LOG.trace("Skipping data changed called to Application Peer. Change : {}", changes);
        return;
    }
    final DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
    LOG.debug("Received data change to ApplicationRib {}", changes);
    for (final DataTreeCandidate tc : changes) {
        LOG.debug("Modification Type {}", tc.getRootNode().getModificationType());
        final YangInstanceIdentifier path = tc.getRootPath();
        final PathArgument lastArg = path.getLastPathArgument();
        verify(lastArg instanceof NodeIdentifierWithPredicates, "Unexpected type %s in path %s", lastArg.getClass(), path);
        final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) lastArg;
        if (!this.supportedTables.contains(tableKey)) {
            LOG.trace("Skipping received data change for non supported family {}.", tableKey);
            continue;
        }
        for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) {
            final PathArgument childIdentifier = child.getIdentifier();
            final YangInstanceIdentifier tableId = this.adjRibsInId.node(tableKey).node(childIdentifier);
            switch(child.getModificationType()) {
                case DELETE:
                case DISAPPEARED:
                    LOG.trace("App peer -> AdjRibsIn path delete: {}", childIdentifier);
                    tx.delete(LogicalDatastoreType.OPERATIONAL, tableId);
                    break;
                case UNMODIFIED:
                    // No-op
                    break;
                case SUBTREE_MODIFIED:
                    if (ROUTES_NID.equals(childIdentifier)) {
                        processRoutesTable(child, tableId, tx, tableId);
                    } else {
                        processWrite(child, tableId, tx);
                    }
                    break;
                case WRITE:
                case APPEARED:
                    processWrite(child, tableId, tx);
                    break;
                default:
                    break;
            }
        }
    }
    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 : 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) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 47 with CommitInfo

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

the class AbstractPeer method initializeRibOut.

@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void initializeRibOut(final RouteEntryDependenciesContainer entryDep, final List<ActualBestPathRoutes<C, S>> routesToStore) {
    if (ribOutChain == null) {
        LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
        return;
    }
    final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
    final YangInstanceIdentifier tableRibout = getRibOutIId(ribSupport.tablesKey());
    final boolean addPathSupported = supportsAddPathSupported(ribSupport.getTablesKey());
    final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
    for (final ActualBestPathRoutes<C, S> initRoute : routesToStore) {
        if (!supportsLLGR() && initRoute.isDepreferenced()) {
            // Stale Long-lived Graceful Restart routes should not be propagated
            continue;
        }
        final PeerId fromPeerId = initRoute.getFromPeerId();
        if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
            continue;
        }
        final MapEntryNode route = initRoute.getRoute();
        final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
        if (fromPeer == null) {
            LOG.debug("Failed to acquire peer structure for {}, ignoring route {}", fromPeerId, initRoute);
            continue;
        }
        final YangInstanceIdentifier routePath = createRoutePath(ribSupport, tableRibout, initRoute, addPathSupported);
        applyExportPolicy(entryDep, fromPeerId, route, routePath, initRoute.getAttributes()).ifPresent(attributes -> storeRoute(ribSupport, initRoute, route, routePath, attributes, tx));
    }
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

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

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed update commit", trw);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)

Example 48 with CommitInfo

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

the class AbstractPeer method reEvaluateAdvertizement.

@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void reEvaluateAdvertizement(final RouteEntryDependenciesContainer entryDep, final List<ActualBestPathRoutes<C, S>> routesToStore) {
    if (ribOutChain == null) {
        LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
        return;
    }
    final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
    final NodeIdentifierWithPredicates tk = ribSupport.tablesKey();
    final boolean addPathSupported = supportsAddPathSupported(ribSupport.getTablesKey());
    final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
    for (final ActualBestPathRoutes<C, S> actualBestRoute : routesToStore) {
        final PeerId fromPeerId = actualBestRoute.getFromPeerId();
        if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
            continue;
        }
        final YangInstanceIdentifier tableRibout = getRibOutIId(tk);
        // Stale Long-lived Graceful Restart routes should not be propagated
        if (supportsLLGR() || !actualBestRoute.isDepreferenced()) {
            final YangInstanceIdentifier routePath = createRoutePath(ribSupport, tableRibout, actualBestRoute, addPathSupported);
            final MapEntryNode route = actualBestRoute.getRoute();
            final Optional<ContainerNode> effAttr = applyExportPolicy(entryDep, fromPeerId, route, routePath, actualBestRoute.getAttributes());
            if (effAttr.isPresent()) {
                storeRoute(ribSupport, actualBestRoute, route, routePath, effAttr.get(), tx);
                continue;
            }
        }
        deleteRoute(ribSupport, addPathSupported, tableRibout, actualBestRoute, tx);
    }
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

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

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed update commit", trw);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)

Example 49 with CommitInfo

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

the class RIBImpl method closeServiceInstance.

public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
    if (!isServiceInstantiated) {
        LOG.trace("RIB {} already closed", ribId.getValue());
        return CommitInfo.emptyFluentFuture();
    }
    LOG.info("Close RIB {}", ribId.getValue());
    isServiceInstantiated = false;
    setActive(false);
    txChainToLocRibWriter.values().forEach(LocRibWriter::close);
    txChainToLocRibWriter.clear();
    final DOMDataTreeWriteTransaction t = domChain.newWriteOnlyTransaction();
    t.delete(LogicalDatastoreType.OPERATIONAL, getYangRibId());
    final FluentFuture<? extends CommitInfo> cleanFuture = t.commit();
    cleanFuture.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.info("RIB cleaned {}", ribId.getValue());
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to clean RIB {}", ribId.getValue(), throwable);
        }
    }, MoreExecutors.directExecutor());
    domChain.close();
    return cleanFuture;
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 50 with CommitInfo

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

the class AbstractPeer method refreshRibOut.

@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void refreshRibOut(final RouteEntryDependenciesContainer entryDep, final List<StaleBestPathRoute> staleRoutes, final List<AdvertizedRoute<C, S>> newRoutes) {
    if (ribOutChain == null) {
        LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
        return;
    }
    final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
    final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
    deleteRouteRibOut(ribSupport, staleRoutes, tx);
    installRouteRibOut(entryDep, newRoutes, tx);
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

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

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed update commit", trw);
        }
    }, 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