use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class TopologyNodeState method storeNode.
synchronized void storeNode(final InstanceIdentifier<Node1> topologyAugment, final Node1 ta, final PCEPSession session) {
LOG.trace("Peer data {} set to {}", topologyAugment, ta);
final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
// All set, commit the modifications
trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Node stored {} for session {} updated successfully", topologyAugment, session);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Failed to store node {} for session {}, terminating it", topologyAugment, session, throwable);
session.close(TerminationReason.UNKNOWN);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class TopologyNodeState method putTopologyNode.
private synchronized void putTopologyNode() {
final Node node = new NodeBuilder().withKey(this.nodeId.getKey()).setNodeId(this.nodeId.getKey().getNodeId()).build();
final WriteTransaction t = this.chain.newWriteOnlyTransaction();
LOG.trace("Put topology Node {}, value {}", this.nodeId, node);
t.merge(LogicalDatastoreType.OPERATIONAL, this.nodeId, node);
t.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Topology Node stored {}, value {}", TopologyNodeState.this.nodeId, node);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Put topology Node failed {}, value {}", TopologyNodeState.this.nodeId, node, throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo 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);
}
}
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractTopologyBuilder method initOperationalTopology.
private synchronized void initOperationalTopology() {
requireNonNull(this.chain, "A valid transaction chain must be provided.");
final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
trans.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, this.topology, new TopologyBuilder().withKey(this.topologyKey).setServerProvided(Boolean.TRUE).setTopologyTypes(this.topologyTypes).setLink(Map.of()).setNode(Map.of()).build());
trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Transaction {} committed successfully", trans.getIdentifier());
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Failed to initialize topology {} (transaction {}) by listener {}", AbstractTopologyBuilder.this.topology, trans.getIdentifier(), AbstractTopologyBuilder.this, throwable);
}
}, MoreExecutors.directExecutor());
}
Aggregations