Search in sources :

Example 6 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method replaceChildListContainerInTreeTest.

@Test
public void replaceChildListContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH, OUTER_LIST_2);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.SUBTREE_MODIFIED, candidateRoot);
    final DataTreeCandidateNode modifiedChild = candidateRoot.getModifiedChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME));
    assertNotNull(modifiedChild);
    checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 7 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method replaceContainerContainerInTreeTest.

@Test
public void replaceContainerContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.WRITE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 8 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method listEntryChangeNonRootRegistrationTest.

@Test
public void listEntryChangeNonRootRegistrationTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
    final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId1 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
    final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId2 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
    final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId3 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
    final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
    final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
    final MapEntryNode outerListEntry3 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
    final MapNode listAfter = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry2).withChild(outerListEntry3).build();
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId1));
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId2), outerListEntry2);
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId3), outerListEntry3);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(OUTER_LIST, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
    final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1);
    checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate);
    final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2);
    checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate);
    final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3);
    checkChange(null, outerListEntry3, ModificationType.WRITE, entry3Canditate);
    listenerReg.close();
}
Also used : MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) CountDownLatch(java.util.concurrent.CountDownLatch) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 9 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class TracingBroker method getSupportedExtensions.

@Nonnull
@Override
public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
    Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> res = delegate.getSupportedExtensions();
    DOMDataTreeChangeService treeChangeSvc = (DOMDataTreeChangeService) res.get(DOMDataTreeChangeService.class);
    if (treeChangeSvc == null) {
        return res;
    }
    res = new HashMap<>(res);
    res.put(DOMDataTreeChangeService.class, new DOMDataTreeChangeService() {

        @Nonnull
        @Override
        public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DOMDataTreeIdentifier domDataTreeIdentifier, @Nonnull L listener) {
            if (isRegistrationWatched(domDataTreeIdentifier.getRootIdentifier(), domDataTreeIdentifier.getDatastoreType(), DataChangeScope.SUBTREE)) {
                LOG.warn("{} registration (registerDataTreeChangeListener) for {} from {}.", listener instanceof ClusteredDOMDataTreeChangeListener ? "Clustered" : "Non-clustered", toPathString(domDataTreeIdentifier.getRootIdentifier()), getStackSummary());
            }
            return treeChangeSvc.registerDataTreeChangeListener(domDataTreeIdentifier, listener);
        }
    });
    return res;
}
Also used : DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) Nonnull(javax.annotation.Nonnull) DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) Nonnull(javax.annotation.Nonnull)

Example 10 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testDataTreeChangeListener.

@SuppressWarnings("unchecked")
@Test
public void testDataTreeChangeListener() {
    DOMDataTreeChangeService domDTCLService = (DOMDataTreeChangeService) adapter.getSupportedExtensions().get(DOMDataTreeChangeService.class);
    assertNotNull("DOMDataTreeChangeService not found", domDTCLService);
    ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
    ListenerRegistration<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> mockReg = mock(ListenerRegistration.class);
    doNothing().when(mockReg).close();
    doAnswer(invocation -> storeDTCL.getValue()).when(mockReg).getInstance();
    doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeDTCL.capture());
    DOMDataTreeChangeListener brokerDTCL = mock(DOMDataTreeChangeListener.class);
    ListenerRegistration<DOMDataTreeChangeListener> reg = domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerDTCL);
    assertEquals("getInstance", brokerDTCL, reg.getInstance());
    Collection<DataTreeCandidate> changes = Arrays.asList(mock(DataTreeCandidate.class));
    storeDTCL.getValue().onDataTreeChanged(changes);
    verify(brokerDTCL).onDataTreeChanged(changes);
    reg.close();
    verify(mockReg).close();
    // Test ClusteredDOMDataTreeChangeListener
    ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeClusteredDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
    mockReg = mock(ListenerRegistration.class);
    doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeClusteredDTCL.capture());
    final ClusteredDOMDataTreeChangeListener brokerClusteredDTCL = mock(ClusteredDOMDataTreeChangeListener.class);
    domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerClusteredDTCL);
    assertTrue("Expected ClusteredDOMDataTreeChangeListener: " + storeClusteredDTCL.getValue(), storeClusteredDTCL.getValue() instanceof org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener);
    storeClusteredDTCL.getValue().onDataTreeChanged(changes);
    verify(brokerClusteredDTCL).onDataTreeChanged(changes);
}
Also used : DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) Test(org.junit.Test)

Aggregations

DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)11 Test (org.junit.Test)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)6 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)6 ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 Before (org.junit.Before)2 ClusteredDOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener)2 DOMDataBrokerExtension (org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)2 DOMDataTreeIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)2 Optional (com.google.common.base.Optional)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 GlobalEventExecutor (io.netty.util.concurrent.GlobalEventExecutor)1 InetSocketAddress (java.net.InetSocketAddress)1 Executor (java.util.concurrent.Executor)1 TimeUnit (java.util.concurrent.TimeUnit)1