use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project controller by opendaylight.
the class Bug3090MultiKeyList method write.
private void write(final LogicalDatastoreType store) {
final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
final List<ListInRoot> listInRoots = new ArrayList<>();
for (int i = 0; i < 10; i++) {
listInRoots.add(new ListInRootBuilder().setLeafA("leaf a" + i).setLeafC("leaf c" + i).setLeafB("leaf b" + i).build());
}
final Root root = new RootBuilder().setListInRoot(listInRoots).build();
readWriteTransaction.put(store, ROOT_PATH, root);
assertCommit(readWriteTransaction.submit());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project controller by opendaylight.
the class ListInsertionDataChangeListenerTest method putTopBarNodeSubtreeListeners.
@Test
public void putTopBarNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.put(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
assertCommit(writeTx.submit());
verifyBarOnlyAdded(topListener, allListener, fooListener, barListener);
}
use of org.opendaylight.controller.md.sal.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 (this.closed) {
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.submit() 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;
}
}
Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void 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());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project netvirt by opendaylight.
the class HwvtepNodeBaseListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
HAJobScheduler.getInstance().submitJob(() -> {
ReadWriteTransaction tx = getTx();
try {
processConnectedNodes(changes, tx);
processUpdatedNodes(changes, tx);
processDisconnectedNodes(changes, tx);
tx.submit().get();
} catch (InterruptedException | ExecutionException | ReadFailedException e) {
LOG.error("Error processing data-tree changes", e);
}
});
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project netvirt by opendaylight.
the class StatisticsImpl method releaseElementCountersRequestHandler.
@Override
public Future<RpcResult<ReleaseElementCountersRequestHandlerOutput>> releaseElementCountersRequestHandler(ReleaseElementCountersRequestHandlerInput input) {
InstanceIdentifier<CounterRequests> ingressPath = InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
InstanceIdentifier<CounterRequests> egressPath = InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
ReadWriteTransaction tx = db.newReadWriteTransaction();
CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
try {
Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
LOG.warn("Couldn't read element counters config data from DB");
StatisticsPluginImplCounters.failed_reading_counter_data_from_config.inc();
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
}
if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
LOG.warn("Handler does not exists");
StatisticsPluginImplCounters.unknown_request_handler.inc();
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
}
String generatedKey = null;
if (ingressRequestData.get().isPresent()) {
handleReleaseTransaction(input, ingressPath, ingressRequestData, iecrcOpt.get().getCounterRequests());
generatedKey = ingressRequestData.get().get().getGeneratedUniqueId();
}
if (egressRequestData.get().isPresent()) {
handleReleaseTransaction(input, egressPath, egressRequestData, eecrcOpt.get().getCounterRequests());
generatedKey = egressRequestData.get().get().getGeneratedUniqueId();
}
releaseId(generatedKey);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
}
return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>success().buildFuture();
}
Aggregations