use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier 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.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.
the class AbstractForwardedDataBroker method toBinding.
protected Set<InstanceIdentifier<?>> toBinding(final InstanceIdentifier<?> path, final Set<YangInstanceIdentifier> normalized) {
final Set<InstanceIdentifier<?>> hashSet = new HashSet<>();
for (final YangInstanceIdentifier normalizedPath : normalized) {
try {
final Optional<InstanceIdentifier<? extends DataObject>> potential = getCodec().toBinding(normalizedPath);
if (potential.isPresent()) {
final InstanceIdentifier<? extends DataObject> binding = potential.get();
hashSet.add(binding);
} else if (normalizedPath.getLastPathArgument() instanceof YangInstanceIdentifier.AugmentationIdentifier) {
hashSet.add(path);
}
} catch (final DeserializationException e) {
LOG.warn("Failed to transform {}, omitting it", normalizedPath, e);
}
}
return hashSet;
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testNoChangeOnReplaceWithSameValue.
@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
// We wrote initial state NODE_0_FLOW
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
// We registered DataChangeListener
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
assertFalse(eventFuture.isDone());
final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
secondTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
assertNotNull(event);
// Data change should contains NODE_1 Flow - which was added
assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
// Data change must not containe NODE_0 Flow which was replaced with same value.
assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier 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());
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project openflowplugin by opendaylight.
the class PacketOutConvertor method getPortNumber.
private static PortNumber getPortNumber(final PathArgument pathArgument, final Short ofVersion) {
// FIXME VD P! find InstanceIdentifier helper
InstanceIdentifier.IdentifiableItem<?, ?> item = Arguments.checkInstanceOf(pathArgument, InstanceIdentifier.IdentifiableItem.class);
NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class);
Long port = InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.get(ofVersion), key.getId());
return new PortNumber(port);
}
Aggregations