use of org.opendaylight.mdsal.binding.api.ReadWriteTransaction in project bgpcep by opendaylight.
the class NodeChangedListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
final ReadWriteTransaction trans = this.dataProvider.newReadWriteTransaction();
final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();
final Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
final Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
final Map<InstanceIdentifier<?>, DataObject> created = new HashMap<>();
for (final DataTreeModification<?> change : changes) {
final InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier();
final DataObjectModification<?> rootNode = change.getRootNode();
handleChangedNode(rootNode, iid, lsps, nodes, original, updated, created);
}
// Now walk all nodes, check for removals/additions and cascade them to LSPs
for (final InstanceIdentifier<Node> iid : nodes) {
enumerateLsps(iid, (Node) original.get(iid), lsps);
enumerateLsps(iid, (Node) updated.get(iid), lsps);
enumerateLsps(iid, (Node) created.get(iid), lsps);
}
// We now have list of all affected LSPs. Walk them create/remove them
updateTransaction(trans, lsps, original, updated, created);
trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Topology change committed successfully");
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Failed to propagate a topology change, target topology became inconsistent", throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.binding.api.ReadWriteTransaction 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());
}
use of org.opendaylight.mdsal.binding.api.ReadWriteTransaction in project bgpcep by opendaylight.
the class AbstractTopologyBuilder method onDataTreeChanged.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void onDataTreeChanged(final Collection<DataTreeModification<T>> changes) {
if (networkTopologyTransaction) {
if (this.closed.get()) {
LOG.trace("Transaction chain was already closed, skipping update.");
return;
}
// check if the transaction chain needed to be restarted due to a previous error
if (restartTransactionChainOnDemand()) {
LOG.debug("The data change {} is disregarded due to restart of listener {}", changes, this);
return;
}
final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
LOG.trace("Received data change {} event with transaction {}", changes, trans.getIdentifier());
final AtomicBoolean transactionInError = new AtomicBoolean(false);
for (final DataTreeModification<T> change : changes) {
try {
routeChanged(change, trans);
} catch (final RuntimeException exc) {
LOG.warn("Data change {} (transaction {}) was not completely propagated to listener {}", change, trans.getIdentifier(), this, exc);
// trans.cancel() is not supported by PingPongTransactionChain, so we just skip the problematic
// change.
// trans.commit() must be called first to unlock the current transaction chain, to make the chain
// closable so we cannot exit the #onDataTreeChanged() yet
transactionInError.set(true);
break;
}
}
trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
// the data loss will not be able to be recovered. Thus we schedule a listener restart here
if (transactionInError.get()) {
LOG.warn("Transaction {} committed successfully while exception captured. Rescheduling a" + " restart of listener {}", trans.getIdentifier(), AbstractTopologyBuilder.this);
scheduleListenerRestart();
} else {
LOG.trace("Transaction {} committed successfully", trans.getIdentifier());
}
}
@Override
public void onFailure(final Throwable throwable) {
// we do nothing but print out the log. Transaction chain restart will be done in
// #onTransactionChainFailed()
LOG.error("Failed to propagate change (transaction {}) by listener {}", trans.getIdentifier(), AbstractTopologyBuilder.this, throwable);
}
}, MoreExecutors.directExecutor());
} else {
for (final DataTreeModification<T> change : changes) {
routeChanged(change, null);
}
}
}
Aggregations