Search in sources :

Example 1 with DOMDataBrokerExtension

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

the class DOMDataTreeListenerTest method getDOMDataTreeChangeService.

private DOMDataTreeChangeService getDOMDataTreeChangeService() {
    final DOMDataBrokerExtension extension = domBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
    if (extension == null) {
        return null;
    }
    DOMDataTreeChangeService dataTreeChangeService = null;
    if (extension instanceof DOMDataTreeChangeService) {
        dataTreeChangeService = (DOMDataTreeChangeService) extension;
    }
    return dataTreeChangeService;
}
Also used : DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)

Example 2 with DOMDataBrokerExtension

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

the class CrossBrokerMountPointTest method testMountPoint.

@Test
public void testMountPoint() throws ReadFailedException, TimeoutException {
    final Integer attrIntValue = 500;
    domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI).addService(DOMDataBroker.class, new DOMDataBroker() {

        @Override
        public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMDataWriteTransaction newWriteOnlyTransaction() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMDataReadWriteTransaction newReadWriteTransaction() {
            return new DOMDataReadWriteTransaction() {

                @Override
                public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    if (store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
                        final ContainerNode data = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(AUG_CONT)).withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue)).build();
                        return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>>of(data));
                    }
                    return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
                }

                @Override
                public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Object getIdentifier() {
                    return this;
                }

                @Override
                public boolean cancel() {
                    return false;
                }

                @Override
                public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public CheckedFuture<Void, TransactionCommitFailedException> submit() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        @Override
        public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
            return Collections.emptyMap();
        }
    }).register();
    final Optional<MountPoint> bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
    assertTrue(bindingMountPoint.isPresent());
    final Optional<DataBroker> dataBroker = bindingMountPoint.get().getService(DataBroker.class);
    assertTrue(dataBroker.isPresent());
    final Optional<Cont> data = dataBroker.get().newReadWriteTransaction().read(LogicalDatastoreType.OPERATIONAL, AUG_CONT_ID_BA).checkedGet(5, TimeUnit.SECONDS);
    assertTrue(data.isPresent());
    assertEquals(attrIntValue, data.get().getAttrInt());
}
Also used : DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TimeoutException(java.util.concurrent.TimeoutException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) Cont(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.top.top.level.list.list1.list1._1.Cont) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMDataChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Test(org.junit.Test)

Example 3 with DOMDataBrokerExtension

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

the class AbstractRIBTestSetup method mockedMethods.

@SuppressWarnings("unchecked")
private void mockedMethods() throws Exception {
    MockitoAnnotations.initMocks(this);
    final ReadOnlyTransaction readTx = mock(ReadOnlyTransaction.class);
    doReturn(new listenerRegistration()).when(this.service).registerDataTreeChangeListener(any(DOMDataTreeIdentifier.class), any(ClusteredDOMDataTreeChangeListener.class));
    final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> map = new HashMap<>();
    map.put(DOMDataTreeChangeService.class, this.service);
    doNothing().when(readTx).close();
    final CheckedFuture<Optional<DataObject>, ReadFailedException> readFuture = mock(CheckedFuture.class);
    doNothing().when(this.domTransWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    doNothing().when(this.domTransWrite).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
    doNothing().when(this.domTransWrite).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    doReturn(Optional.absent()).when(readFuture).checkedGet();
    doReturn(readFuture).when(readTx).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
    doNothing().when(this.domChain).close();
    doReturn(this.domTransWrite).when(this.domChain).newWriteOnlyTransaction();
    doNothing().when(getTransaction()).put(eq(LogicalDatastoreType.OPERATIONAL), eq(YangInstanceIdentifier.of(BgpRib.QNAME)), any(NormalizedNode.class));
    doReturn(map).when(this.dom).getSupportedExtensions();
    doReturn(this.domChain).when(this.dom).createTransactionChain(any(BGPPeer.class));
    doReturn(this.transWrite).when(this.chain).newWriteOnlyTransaction();
    doReturn(false).when(this.o).isPresent();
    doReturn(this.o).when(this.future).checkedGet();
    doReturn(this.future).when(this.domTransWrite).submit();
    doNothing().when(this.future).addListener(any(Runnable.class), any(Executor.class));
    doNothing().when(this.transWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
    doNothing().when(this.transWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class));
    doReturn(this.future).when(this.transWrite).submit();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Executor(java.util.concurrent.Executor) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 4 with DOMDataBrokerExtension

use of org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension 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)

Aggregations

DOMDataBrokerExtension (org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)4 Optional (com.google.common.base.Optional)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 ClusteredDOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener)2 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)2 DOMDataTreeIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 HashMap (java.util.HashMap)1 Executor (java.util.concurrent.Executor)1 TimeoutException (java.util.concurrent.TimeoutException)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 MountPoint (org.opendaylight.controller.md.sal.binding.api.MountPoint)1 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)1 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)1 TransactionChainListener (org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMDataBroker (org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)1