Java Code Examples for com.google.common.util.concurrent.FluentFuture#addCallback()

The following examples show how to use com.google.common.util.concurrent.FluentFuture#addCallback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTopologyBuilder.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Destroy the current operational topology data. Note a valid transaction must be provided.
 */
private synchronized FluentFuture<? extends CommitInfo> destroyOperationalTopology() {
    requireNonNull(this.chain, "A valid transaction chain must be provided.");
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    trans.delete(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier());
    final FluentFuture<? extends CommitInfo> future = trans.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {
        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Operational topology removed {}", AbstractTopologyBuilder.this.topology);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Unable to reset operational topology {} (transaction {})",
                AbstractTopologyBuilder.this.topology, trans.getIdentifier(), throwable);
        }
    }, MoreExecutors.directExecutor());
    clearTopology();
    return future;
}
 
Example 2
Source File: AdjRibInWriter.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
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());
}
 
Example 3
Source File: MdsalUtilsAsync.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Assign a default callback to a {@link FluentFuture}. It will either log
 * a message at DEBUG level if the transaction succeed, or will log at ERROR
 * level and throw an {@link IllegalStateException} if the transaction
 * failed.
 *
 * @param transactionFuture
 *            The transaction to commit.
 * @param operationDesc
 *            A description of the transaction to commit.
 */
void assignDefaultCallback(final FluentFuture<? extends CommitInfo> transactionFuture,
        final String operationDesc) {
    transactionFuture.addCallback(new FutureCallback<CommitInfo>() {
        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Transaction({}) SUCCESSFUL", operationDesc);
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("Transaction({}) FAILED!", operationDesc, ex);
            throw new IllegalStateException("  Transaction(" + operationDesc + ") not committed correctly", ex);
        }
    }, MoreExecutors.directExecutor());
}
 
Example 4
Source File: MdsalUtilsAsync.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Executes read as non blocking transaction and assign a default callback
 * to close the transaction.
 *
 * @param store
 *            {@link LogicalDatastoreType} to read
 * @param path
 *            {@link InstanceIdentifier} for path to read
 * @param <D>
 *            The data object type
 * @return The {@link FluentFuture} object to which you can assign a
 *         callback
 */
public <D extends DataObject> FluentFuture<Optional<D>> read(
                                    final LogicalDatastoreType store,
                                    final InstanceIdentifier<D> path)  {
    final ReadTransaction transaction = databroker.newReadOnlyTransaction();
    final FluentFuture<Optional<D>> future = transaction.read(store, path);
    final FutureCallback<Optional<D>> closeTransactionCallback = new FutureCallback<Optional<D>>() {
        @Override
        public void onSuccess(final Optional<D> result) {
            transaction.close();
        }

        @Override
        public void onFailure(final Throwable ex) {
            transaction.close();
        }
    };
    future.addCallback(closeTransactionCallback, MoreExecutors.directExecutor());
    return future;
}
 
Example 5
Source File: AbstractPeer.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
final synchronized FluentFuture<? extends CommitInfo> removePeer(final @Nullable YangInstanceIdentifier peerPath) {
    if (peerPath == null) {
        return CommitInfo.emptyFluentFuture();
    }
    LOG.info("Closed per Peer {} removed", peerPath);
    final DOMDataTreeWriteTransaction tx = this.domChain.newWriteOnlyTransaction();
    tx.delete(LogicalDatastoreType.OPERATIONAL, peerPath);
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {
        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Peer {} removed", peerPath);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to remove Peer {}", peerPath, throwable);
        }
    }, MoreExecutors.directExecutor());
    return future;
}
 
Example 6
Source File: TransactionInvokerImpl.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private synchronized void executeCommand(final TransactionCommand command) {
    final ReadWriteTransaction transaction = chain.newReadWriteTransaction();
    transactionInFlight = transaction;
    recordPendingTransaction(command, transaction);
    command.execute(transaction);
    FluentFuture<?> ft = transaction.commit();
    command.setTransactionResultFuture(ft);
    ft.addCallback(new FutureCallback<Object>() {
        @Override
        public void onSuccess(final Object result) {
            forgetSuccessfulTransaction(transaction);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            // NOOP - handled by failure of transaction chain
        }
    }, MoreExecutors.directExecutor());
}
 
Example 7
Source File: MdsalUtilsAsyncTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRead() {
    final FluentFuture<? extends CommitInfo> fut =
            mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);

    fut.addCallback(new FutureCallback<CommitInfo>() {
        @Override
        public void onSuccess(final CommitInfo result) {
            final FluentFuture<Optional<Node>> future =
                    mdsalUtilsAsync.read(LogicalDatastoreType.CONFIGURATION, TEST_IID);
            Optional<Node> optNode;
            try {
                optNode = future.get();
                if (optNode.isPresent()) {
                    assertEquals(DATA, optNode.get());
                } else {
                    fail("Couldn't read node");
                }
            } catch (InterruptedException | ExecutionException e) {
                fail(e.getMessage());
            }
        }

        @Override
        public void onFailure(final Throwable ex) {
            fail(ex.getMessage());
        }
    }, MoreExecutors.directExecutor());
}
 
Example 8
Source File: MdsalUtilsAsyncTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMerge() {
    final String operationDesc = "testMerge";
    final SupportingNode supportingNodeBuilder1 = new SupportingNodeBuilder().withKey(
            new SupportingNodeKey(new NodeId("id1"), TOPOLOGY_TEST)).build();
    final SupportingNode supportingNodeBuilder2 = new SupportingNodeBuilder().withKey(
            new SupportingNodeKey(new NodeId("id2"), TOPOLOGY_TEST)).build();

    final Node data1 = new NodeBuilder(DATA).setSupportingNode(
            Collections.singletonList(supportingNodeBuilder1)).build();
    final Node data2 = new NodeBuilder(DATA).setSupportingNode(
            Collections.singletonList(supportingNodeBuilder2)).build();

    mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc, true);
    assertEquals(data1, readDS());

    final FluentFuture<? extends CommitInfo> future =
            mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data2, true);
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            assertEquals(2, readDS().getSupportingNode().size());
        }

        @Override
        public void onFailure(final Throwable ex) {
            fail(ex.getMessage());
        }
    }, MoreExecutors.directExecutor());
}
 
Example 9
Source File: MdsalUtilsAsyncTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testPutWithoutCallback() {
    final String operationDesc = "testPut";
    final SupportingNode supportingNodeBuilder1 = new SupportingNodeBuilder().withKey(
            new SupportingNodeKey(new NodeId("id1"), TOPOLOGY_TEST)).build();
    final SupportingNode supportingNodeBuilder2 = new SupportingNodeBuilder().withKey(
            new SupportingNodeKey(new NodeId("id2"), TOPOLOGY_TEST)).build();

    final Node data1 = new NodeBuilder(DATA).setSupportingNode(
            Collections.singletonList(supportingNodeBuilder1)).build();
    final Node data2 = new NodeBuilder(DATA).setSupportingNode(
            Collections.singletonList(supportingNodeBuilder2)).build();

    mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc);
    assertEquals(data1, readDS());

    final FluentFuture<? extends CommitInfo> future = mdsalUtilsAsync.put(
            LogicalDatastoreType.CONFIGURATION, TEST_IID, data2);
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            assertEquals(1, readDS().getSupportingNode().size());
        }

        @Override
        public void onFailure(final Throwable ex) {
            fail(ex.getMessage());
        }
    }, MoreExecutors.directExecutor());
}
 
Example 10
Source File: ProgrammingServiceImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
    LOG.info("Closing Instruction Queue service {}", this.sgi.getName());

    if (this.reg != null) {
        this.reg.close();
        this.reg = null;
    }
    for (final InstructionImpl instruction : this.insns.values()) {
        instruction.tryCancel(null);
    }
    // Workaround for BUG-2283
    final WriteTransaction wt = this.dataProvider.newWriteOnlyTransaction();
    wt.delete(LogicalDatastoreType.OPERATIONAL, this.qid);

    final FluentFuture<? extends CommitInfo> future = wt.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {
        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Instruction Queue {} removed", ProgrammingServiceImpl.this.qid);
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed to shutdown Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
        }
    }, MoreExecutors.directExecutor());

    return future;
}
 
Example 11
Source File: AbstractPeer.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>,
        R extends Route & ChildOf<? super S> & Identifiable<I>,
        I extends Identifier<R>> void refreshRibOut(final RouteEntryDependenciesContainer entryDep,
        final List<StaleBestPathRoute<C, S, R, I>> staleRoutes, final List<AdvertizedRoute<C, S, R, I>> newRoutes) {
    if (this.bindingChain == null) {
        LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
        return;
    }
    final WriteTransaction tx = this.bindingChain.newWriteOnlyTransaction();
    final RIBSupport<C, S, R, I> ribSupport = entryDep.getRIBSupport();
    deleteRouteRibOut(ribSupport, staleRoutes, tx);
    installRouteRibOut(entryDep, newRoutes, tx);

    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 update commit");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed update commit", trw);
        }
    }, MoreExecutors.directExecutor());
}
 
Example 12
Source File: TransactionInvokerImplTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setTransactionResultFuture(final FluentFuture future) {
    future.addCallback(new FutureCallback<>() {
        @Override
        public void onSuccess(final Object notUsed) {
            ft.set(null);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            ft.setException(throwable);
        }
    }, MoreExecutors.directExecutor());
}
 
Example 13
Source File: ServerSessionManager.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
    if (this.isClosed.getAndSet(true)) {
        LOG.error("Session Manager has already been closed.");
        return CommitInfo.emptyFluentFuture();
    }
    for (final TopologySessionListener node : this.nodes.values()) {
        node.close();
    }
    this.nodes.clear();
    for (final TopologyNodeState topologyNodeState : this.state.values()) {
        topologyNodeState.close();
    }
    this.state.clear();

    final WriteTransaction t = this.dependenciesProvider.getDataBroker().newWriteOnlyTransaction();
    t.delete(LogicalDatastoreType.OPERATIONAL, this.topology);
    final FluentFuture<? extends CommitInfo> future = t.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {
        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Topology {} removed", ServerSessionManager.this.topology);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Failed to remove Topology {}", ServerSessionManager.this.topology, throwable);
        }
    }, MoreExecutors.directExecutor());
    return future;
}
 
Example 14
Source File: RIBImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
    if (!this.isServiceInstantiated) {
        LOG.trace("RIB {} already closed", this.ribId.getValue());
        return CommitInfo.emptyFluentFuture();
    }
    LOG.info("Close RIB {}", this.ribId.getValue());
    this.isServiceInstantiated = false;
    setActive(false);

    this.txChainToLocRibWriter.values().forEach(LocRibWriter::close);
    this.txChainToLocRibWriter.clear();

    final DOMDataTreeWriteTransaction t = this.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 {}", RIBImpl.this.ribId.getValue());
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to clean RIB {}",
                    RIBImpl.this.ribId.getValue(), throwable);
        }
    }, MoreExecutors.directExecutor());
    this.domChain.close();
    return cleanFuture;
}
 
Example 15
Source File: AdjRibInWriter.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
void removeStaleRoutes(final TablesKey tableKey) {
    final TableContext ctx = this.tables.get(tableKey);
    if (ctx == null) {
        LOG.debug("No table for {}, not removing any stale routes", tableKey);
        return;
    }
    final Collection<NodeIdentifierWithPredicates> routeKeys = this.staleRoutesRegistry.get(tableKey);
    if (routeKeys == null || routeKeys.isEmpty()) {
        LOG.debug("No stale routes present in table {}", tableKey);
        return;
    }
    LOG.trace("Removing routes {}", routeKeys);
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    routeKeys.forEach(routeKey -> {
        tx.delete(LogicalDatastoreType.OPERATIONAL, ctx.routePath(routeKey));
    });
    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", routeKeys);
            synchronized (AdjRibInWriter.this.staleRoutesRegistry) {
                staleRoutesRegistry.remove(tableKey);
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Removing routes {}, failed", routeKeys, throwable);
        }
    }, MoreExecutors.directExecutor());
}
 
Example 16
Source File: AdjRibInWriter.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
void updateRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight.params
        .xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes attributes) {
    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;
    }

    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    final Collection<NodeIdentifierWithPredicates> routeKeys = ctx.writeRoutes(tx, nlri, attributes);
    final Collection<NodeIdentifierWithPredicates> staleRoutes = this.staleRoutesRegistry.get(key);
    if (staleRoutes != null) {
        staleRoutes.removeAll(routeKeys);
    }
    LOG.trace("Write routes {}", 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("Write routes {}, succeed", nlri);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Write routes failed", throwable);
        }
    }, MoreExecutors.directExecutor());
}
 
Example 17
Source File: OvsdbConnectionManager.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
private void retryConnection(final InstanceIdentifier<Node> iid, final OvsdbNodeAugmentation ovsdbNode,
                             final ConnectionReconciliationTriggers trigger) {
    final ReconciliationTask task = new ConnectionReconciliationTask(
            reconciliationManager,
            this,
            iid,
            ovsdbNode);

    if (reconciliationManager.isEnqueued(task)) {
        return;
    }
    switch (trigger) {
        case ON_CONTROLLER_INITIATED_CONNECTION_FAILURE:
            reconciliationManager.enqueueForRetry(task);
            break;
        case ON_DISCONNECT: {
            FluentFuture<Boolean> readNodeFuture;
            try (ReadTransaction tx = db.newReadOnlyTransaction()) {
                readNodeFuture = tx.exists(LogicalDatastoreType.CONFIGURATION, iid);
            }
            readNodeFuture.addCallback(new FutureCallback<Boolean>() {
                @Override
                public void onSuccess(final Boolean node) {
                    if (node.booleanValue()) {
                        LOG.info("Disconnected/Failed connection {} was controller initiated, attempting "
                                + "reconnection", ovsdbNode.getConnectionInfo());
                        reconciliationManager.enqueue(task);

                    } else {
                        LOG.debug("Connection {} was switch initiated, no reconciliation is required",
                                iid.firstKeyOf(Node.class).getNodeId());
                    }
                }

                @Override
                public void onFailure(final Throwable throwable) {
                    LOG.warn("Read Config/DS for Node failed! {}", iid, throwable);
                }
            }, MoreExecutors.directExecutor());
            break;
        }
        default:
            break;
    }
}
 
Example 18
Source File: HwvtepConnectionManager.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
private void retryConnection(final InstanceIdentifier<Node> iid, final HwvtepGlobalAugmentation hwvtepNode,
                             ConnectionReconciliationTriggers trigger) {
    if (hwvtepNode == null) {
        //switch initiated connection
        return;
    }
    final ReconciliationTask task = new ConnectionReconciliationTask(
            reconciliationManager,
            this,
            iid,
            hwvtepNode);

    if (reconciliationManager.isEnqueued(task)) {
        return;
    }

    switch (trigger) {
        case ON_CONTROLLER_INITIATED_CONNECTION_FAILURE:
            reconciliationManager.enqueueForRetry(task);
            break;
        case ON_DISCONNECT: {
            ReadTransaction tx = db.newReadOnlyTransaction();
            FluentFuture<Optional<Node>> readNodeFuture =
                    tx.read(LogicalDatastoreType.CONFIGURATION, iid);

            readNodeFuture.addCallback(new FutureCallback<Optional<Node>>() {
                @Override
                public void onSuccess(final Optional<Node> node) {
                    if (node.isPresent()) {
                        HwvtepGlobalAugmentation augmentation = node.get()
                                .augmentation(HwvtepGlobalAugmentation.class);
                        if (augmentation == null || augmentation.getConnectionInfo() == null) {
                            return;
                        }
                        LOG.info(
                            "Disconnected/Failed connection {} was controller initiated, attempting reconnection",
                            hwvtepNode.getConnectionInfo());
                        reconciliationManager.enqueue(task);

                    } else {
                        LOG.debug("Connection {} was switch initiated, no reconciliation is required",
                            iid.firstKeyOf(Node.class).getNodeId());
                    }
                }

                @Override
                public void onFailure(final Throwable ex) {
                    LOG.warn("Read Config/DS for Node failed! {}", iid, ex);
                }
            }, MoreExecutors.directExecutor());
            break;
        }
        default:
            break;
    }
}
 
Example 19
Source File: AbstractPeer.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>,
        R extends Route & ChildOf<? super S> & Identifiable<I>,
        I extends Identifier<R>> void reEvaluateAdvertizement(
        final RouteEntryDependenciesContainer entryDep,
        final List<ActualBestPathRoutes<C, S, R, I>> routesToStore) {
    if (this.bindingChain == null) {
        LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
        return;
    }

    final RIBSupport<C,S,R,I> ribSupport = entryDep.getRIBSupport();
    final TablesKey tk = entryDep.getRIBSupport().getTablesKey();
    final boolean addPathSupported = supportsAddPathSupported(tk);

    final WriteTransaction tx = this.bindingChain.newWriteOnlyTransaction();
    for (final ActualBestPathRoutes<C, S, R, I> actualBestRoute : routesToStore) {
        final PeerId fromPeerId = actualBestRoute.getFromPeerId();
        if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
            continue;
        }

        final R route = actualBestRoute.getRoute();
        final Optional<Attributes> effAttr;
        if (supportsLLGR() || !actualBestRoute.isDepreferenced()) {
            final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
            final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer,
                this, route.getRouteKey(), this.rtCache);
            effAttr = entryDep.getRoutingPolicies()
                    .applyExportPolicies(routeEntry, actualBestRoute.getAttributes(), entryDep.getAfiSafType());
        } else {
            // Stale Long-lived Graceful Restart routes should not be propagated
            effAttr = Optional.empty();
        }

        final KeyedInstanceIdentifier<Tables, TablesKey> tableRibout = getRibOutIId(tk);
        if (effAttr.isPresent()) {
            storeRoute(ribSupport, addPathSupported, tableRibout, actualBestRoute, route, effAttr.get(), tx);
        } else {
            deleteRoute(ribSupport, addPathSupported, tableRibout, actualBestRoute, tx);
        }
    }

    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 update commit");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed update commit", trw);
        }
    }, MoreExecutors.directExecutor());
}
 
Example 20
Source File: EffectiveRibInWriter.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
@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;
    }
}