use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class ConnectedGraphServer method initOperationalGraphModel.
/**
* Initialize GraphModel tree at Data Store top-level.
*/
private synchronized void initOperationalGraphModel() {
requireNonNull(this.chain, "A valid transaction chain must be provided.");
final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
LOG.info("Create Graph Model at top level in Operational DataStore: {}", GRAPH_TOPOLOGY_IDENTIFIER);
trans.put(LogicalDatastoreType.OPERATIONAL, GRAPH_TOPOLOGY_IDENTIFIER, new GraphTopologyBuilder().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 GraphModel {} (transaction {}) by listener {}", GRAPH_TOPOLOGY_IDENTIFIER, trans.getIdentifier(), ConnectedGraphServer.this, throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class ConnectedGraphServer method updateToDataStore.
/**
* Update Graph components (Vertex, Edge or Prefix ) to the Data Store. Old value identified by its Instance ID
* will be remove first before adding the new value.
*
* @param <T> As a generic method, T must be a Vertex, Edge or Prefix.
* @param id Instance Identifier of the Data Object
* @param data Data Object (Vertex, Edge or Prefix)
* @param old Instance Identifier of the previous version of the Data Object
* @param info Information to be logged
*/
private synchronized <T extends DataObject> void updateToDataStore(final InstanceIdentifier<T> id, final T data, final InstanceIdentifier<T> old, final String info) {
final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
if (old != null) {
trans.delete(LogicalDatastoreType.OPERATIONAL, old);
}
trans.put(LogicalDatastoreType.OPERATIONAL, id, data);
trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("GraphModel: {} has been published in operational datastore ", info);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("GrahModel: Cannot write {} to the operational datastore (transaction: {})", info, trans.getIdentifier());
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractTopologySessionListener method updatePccState.
synchronized void updatePccState(final PccSyncState pccSyncState) {
if (this.nodeState == null) {
LOG.info("Server Session Manager is closed.");
AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
return;
}
final MessageContext ctx = new MessageContext(this.nodeState.getChain().newWriteOnlyTransaction());
updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(pccSyncState).build());
if (pccSyncState != PccSyncState.Synchronized) {
this.synced.set(false);
this.triggeredResyncInProcess = true;
}
// All set, commit the modifications
ctx.trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Pcc Internal state for session {} updated successfully", AbstractTopologySessionListener.this.session);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Failed to update Pcc internal state for session {}", AbstractTopologySessionListener.this.session, throwable);
AbstractTopologySessionListener.this.session.close(TerminationReason.UNKNOWN);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class TopologyStatsProviderImpl method updateStats.
@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void updateStats() {
final TransactionChain chain = accessChain();
if (chain == null) {
// Already closed, do not bother
return;
}
final WriteTransaction tx = chain.newWriteOnlyTransaction();
try {
for (Entry<KeyedInstanceIdentifier<Node, NodeKey>, PcepSessionState> entry : statsMap.entrySet()) {
if (!statsPendingDelete.contains(entry.getKey())) {
tx.put(LogicalDatastoreType.OPERATIONAL, entry.getKey().augmentation(PcepTopologyNodeStatsAug.class), new PcepTopologyNodeStatsAugBuilder().setPcepSessionState(new PcepSessionStateBuilder(entry.getValue()).build()).build());
}
}
} catch (Exception e) {
LOG.warn("Failed to prepare Tx for PCEP stats update", e);
tx.cancel();
return;
}
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.debug("Successfully committed Topology stats update");
}
@Override
public void onFailure(final Throwable ex) {
LOG.error("Failed to commit Topology stats update", ex);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class TopologyStatsProviderImpl method unbind.
@Override
public synchronized void unbind(final KeyedInstanceIdentifier<Node, NodeKey> nodeId) {
final TransactionChain chain = accessChain();
if (chain == null) {
// Already closed, do not bother
LOG.debug("Ignoring unbind of Pcep Node {}", nodeId);
return;
}
final PcepSessionState node = statsMap.remove(nodeId);
if (node == null) {
LOG.debug("Ignoring duplicate unbind of Pcep Node {}", nodeId);
return;
}
statsPendingDelete.add(nodeId);
final WriteTransaction wTx = chain.newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, nodeId);
wTx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.debug("Successfully removed Pcep Node stats {}.", nodeId.getKey().getNodeId());
statsPendingDelete.remove(nodeId);
}
@Override
public void onFailure(final Throwable ex) {
LOG.warn("Failed to remove Pcep Node stats {}.", nodeId.getKey().getNodeId(), ex);
statsPendingDelete.remove(nodeId);
}
}, MoreExecutors.directExecutor());
}
Aggregations