use of org.opendaylight.mdsal.binding.api.TransactionChain 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.binding.api.TransactionChain 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.binding.api.TransactionChain 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());
}
use of org.opendaylight.mdsal.binding.api.TransactionChain in project controller by opendaylight.
the class TxchainBaDelete method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(this);
WriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (int l = 0; l < outerListElem; l++) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey(l));
tx.delete(dsType, iid);
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 chain before closing it
try {
if (writeCnt > 0) {
txSubmitted++;
}
tx.commit().get();
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Transaction failed", e);
}
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.binding.api.TransactionChain in project bgpcep by opendaylight.
the class TopologyStatsProviderImpl method shutdown.
private synchronized void shutdown() throws InterruptedException, ExecutionException {
// Try to get a transaction chain and indicate we are done
final TransactionChain chain = accessChain();
transactionChain = null;
dataBroker = null;
if (chain == null) {
// Belt & suspenders so we do not error out elsewhere
LOG.warn("Cannot acquire transaction chain, skipping cleanup");
return;
}
// Issue deletes for all registered stats
final WriteTransaction wTx = chain.newWriteOnlyTransaction();
for (final KeyedInstanceIdentifier<Node, NodeKey> statId : statsMap.keySet()) {
wTx.delete(LogicalDatastoreType.OPERATIONAL, statId);
}
statsMap.clear();
// Fire the transaction commit ...
final FluentFuture<?> future = wTx.commit();
// ... close the transaction chain ...
chain.close();
// ... and wait for transaction commit to complete
LOG.debug("Awaiting finish of TopologyStatsProvider cleanup");
future.get();
}
Aggregations