Search in sources :

Example 11 with ReadWriteTransaction

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());
}
Also used : RootBuilder(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.RootBuilder) Root(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.Root) Fooroot(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.Fooroot) Barroot(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.fooroot.Barroot) ArrayList(java.util.ArrayList) BarrootBuilder(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.fooroot.BarrootBuilder) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) BarrootKey(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.fooroot.BarrootKey) FoorootBuilder(org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.FoorootBuilder)

Example 12 with ReadWriteTransaction

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

Example 13 with ReadWriteTransaction

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

Example 14 with ReadWriteTransaction

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());
}
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 ReadWriteTransaction

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());
}
Also used : HashMap(java.util.HashMap) SupportingNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) HashSet(java.util.HashSet)

Aggregations

ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)67 Optional (com.google.common.base.Optional)21 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)17 Test (org.junit.Test)16 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)13 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 Mockito.doReturn (org.mockito.Mockito.doReturn)11 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)11 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)11 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)9 DataTreeModification (org.opendaylight.controller.md.sal.binding.api.DataTreeModification)8 TestUtils.newInvNodeKey (org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newInvNodeKey)8 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)8 TestUtils.newLink (org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newLink)7 Link (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)7 ArrayList (java.util.ArrayList)6 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)6 NodeBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)6