Search in sources :

Example 11 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.

the class DsbenchmarkListener method logDataTreeChangeEvent.

private static synchronized void logDataTreeChangeEvent(final int eventNum, final Collection<DataTreeModification<TestExec>> changes) {
    LOG.debug("DsbenchmarkListener-onDataTreeChanged: Event {}", eventNum);
    for (DataTreeModification<TestExec> change : changes) {
        final DataObjectModification<TestExec> rootNode = change.getRootNode();
        final ModificationType modType = rootNode.getModificationType();
        final PathArgument changeId = rootNode.getIdentifier();
        final Collection<DataObjectModification<? extends DataObject>> modifications = rootNode.getModifiedChildren();
        LOG.debug("    changeId {}, modType {}, mods: {}", changeId, modType, modifications.size());
        for (DataObjectModification<? extends DataObject> mod : modifications) {
            LOG.debug("      mod-getDataAfter: {}", mod.getDataAfter());
        }
    }
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ModificationType(org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) TestExec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec) PathArgument(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument)

Example 12 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.

the class Bug1418AugmentationTest method complexAugmentationUpdatedTest.

@Test
public void complexAugmentationUpdatedTest() {
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
    writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
    assertCommit(writeTx.submit());
    final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, AsyncDataBroker.DataChangeScope.SUBTREE);
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY_MOD));
    assertCommit(writeTx.submit());
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
    assertContains(event.getUpdatedData(), COMPLEX_AUGMENT);
    assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY_MOD));
    assertContains(event.getRemovedPaths(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
    assertContains(event.getOriginalData(), COMPLEX_AUGMENT);
    assertContains(event.getOriginalData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ListViaUses(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TopLevelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 13 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.

the class Bug1418AugmentationTest method leafOnlyAugmentationCreatedTest.

@Test
public void leafOnlyAugmentationCreatedTest() {
    final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, AsyncDataBroker.DataChangeScope.SUBTREE, false);
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
    writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
    assertCommit(writeTx.submit());
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
    assertContains(event.getCreatedData(), SIMPLE_AUGMENT);
    assertEmpty(event.getUpdatedData());
    assertEmpty(event.getOriginalData());
    assertEmpty(event.getRemovedPaths());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TopLevelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 14 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject 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());
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 15 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject 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;
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DeserializationException(org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException) HashSet(java.util.HashSet)

Aggregations

DataObject (org.opendaylight.yangtools.yang.binding.DataObject)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)24 Test (org.junit.Test)14 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)10 Optional (com.google.common.base.Optional)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 AbstractDataChangeListenerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)6 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)6 Collection (java.util.Collection)5 Nonnull (javax.annotation.Nonnull)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey)5 DataObjectModification (org.opendaylight.controller.md.sal.binding.api.DataObjectModification)4