use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project controller by opendaylight.
the class Bug2562DeserializedUnkeyedListTest method writeRoot.
private void writeRoot(final LogicalDatastoreType store) {
final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
final Barroot barRoot = new BarrootBuilder().setType(2).setValue(2).setKey(new BarrootKey(2)).build();
final ArrayList<Barroot> barRootList = new ArrayList<>();
barRootList.add(barRoot);
final Fooroot fooRoot = new FoorootBuilder().setBarroot(barRootList).build();
final ArrayList<Fooroot> fooRootList = new ArrayList<>();
fooRootList.add(fooRoot);
final Root root = new RootBuilder().setFooroot(fooRootList).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 mergeTopBarNodeSubtreeListeners.
@Test
public void mergeTopBarNodeSubtreeListeners() {
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.merge(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 controller by opendaylight.
the class ListInsertionDataChangeListenerTest method mergeTopNodeSubtreeListeners.
@Test
public void mergeTopNodeSubtreeListeners() {
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.merge(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
assertCommit(writeTx.submit());
verifyBarOnlyAdded(topListener, allListener, fooListener, barListener);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project controller by opendaylight.
the class ListInsertionDataChangeListenerTest method replaceTopNodeSubtreeListeners.
@Test
public void replaceTopNodeSubtreeListeners() {
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, top(topLevelList(TOP_BAR_KEY)));
assertCommit(writeTx.submit());
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> top = topListener.event();
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> all = allListener.event();
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> foo = fooListener.event();
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> bar = barListener.event();
// Listener for TOP element
assertContains(top.getOriginalData(), TOP, TOP_FOO);
assertContains(top.getCreatedData(), TOP_BAR);
assertContains(top.getUpdatedData(), TOP);
assertContains(top.getRemovedPaths(), TOP_FOO);
/*
* Listener for all list items
*
* Updated should be empty, since no list item was
* updated, items were only removed and added
*/
assertContains(all.getOriginalData(), TOP_FOO);
assertContains(all.getCreatedData(), TOP_BAR);
assertEmpty(all.getUpdatedData());
assertContains(all.getRemovedPaths(), TOP_FOO);
/*
* Listener for all Foo item
*
* This one should see only Foo item removed
*/
assertContains(foo.getOriginalData(), TOP_FOO);
assertEmpty(foo.getCreatedData());
assertEmpty(foo.getUpdatedData());
assertContains(foo.getRemovedPaths(), TOP_FOO);
/*
* Listener for bar list items
*
* Updated should be empty, since no list item was
* updated, items were only removed and added
*/
assertEmpty(bar.getOriginalData());
assertContains(bar.getCreatedData(), TOP_BAR);
assertEmpty(bar.getUpdatedData());
assertEmpty(bar.getRemovedPaths());
}
use of org.opendaylight.controller.md.sal.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);
Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.submit()), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void 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());
}
Aggregations