use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.
the class TxchainBaWrite method executeList.
@Override
public void executeList() {
final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(this);
final LogicalDatastoreType dsType = getDataStoreType();
WriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (OuterList element : this.list) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, element.key());
if (oper == StartTestInput.Operation.PUT) {
tx.put(dsType, iid, element);
} else {
tx.merge(dsType, iid, element);
}
writeCnt++;
if (writeCnt == writesPerTx) {
txSubmitted++;
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
txOk++;
}
@Override
public void onFailure(final Throwable cause) {
LOG.error("Transaction failed", cause);
txError++;
}
}, MoreExecutors.directExecutor());
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
// We need to empty the transaction chain before closing it
try {
txSubmitted++;
tx.commit().get();
txOk++;
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Transaction failed", e);
txError++;
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed,", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AdjRibInWriter method removeStaleRoutes.
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());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AdjRibInWriter method updateRoutes.
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());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractPeer method removePeer.
final synchronized FluentFuture<? extends CommitInfo> removePeer(@Nullable final YangInstanceIdentifier peerPath) {
if (peerPath == null) {
return CommitInfo.emptyFluentFuture();
}
LOG.info("Closed per Peer {} removed", peerPath);
final DOMDataTreeWriteTransaction tx = 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;
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractTopologyBuilder method destroyOperationalTopology.
/**
* 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;
}
Aggregations