Search in sources :

Example 1 with DOMDataBroker

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

the class DomConcurrentDataBrokerModule method createInstance.

@Override
public AutoCloseable createInstance() {
    // The ConcurrentDOMDataBroker is provided via blueprint so wait for and return it here for
    // backwards compatibility.
    WaitingServiceTracker<DOMDataBroker> tracker = WaitingServiceTracker.create(DOMDataBroker.class, bundleContext, "(type=default)");
    DOMDataBroker delegate = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
    return new ForwardingConcurrentDOMBroker(delegate, tracker);
}
Also used : ForwardingDOMDataBroker(org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataBroker) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)

Example 2 with DOMDataBroker

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

the class BindingAsyncDataBrokerImplModule method createInstance.

@Override
public java.lang.AutoCloseable createInstance() {
    final BindingToNormalizedNodeCodec mappingService = getBindingMappingServiceDependency();
    final DOMDataBroker domDataBroker = getDomAsyncBrokerDependency();
    return new BindingDOMDataBrokerAdapter(domDataBroker, mappingService);
}
Also used : BindingToNormalizedNodeCodec(org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec) BindingDOMDataBrokerAdapter(org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)

Example 3 with DOMDataBroker

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

the class DomBrokerImplModule method createInstance.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public AutoCloseable createInstance() {
    // The services are provided via blueprint so retrieve then from the OSGi service registry for
    // backwards compatibility.
    final List<AutoCloseable> closeables = new ArrayList<>();
    DOMNotificationService domNotificationService = newTracker(DOMNotificationService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
    DOMNotificationPublishService domNotificationPublishService = newTracker(DOMNotificationPublishService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
    DOMRpcService domRpcService = newTracker(DOMRpcService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
    DOMRpcProviderService domRpcProvider = newTracker(DOMRpcProviderService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
    DOMMountPointService mountService = newTracker(DOMMountPointService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
    SchemaService globalSchemaService = newTracker(SchemaService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
    final DOMDataBroker dataBroker = getAsyncDataBrokerDependency();
    final ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create();
    services.putInstance(DOMNotificationService.class, domNotificationService);
    services.putInstance(DOMNotificationPublishService.class, domNotificationPublishService);
    final SchemaService schemaService = getSchemaServiceImpl(globalSchemaService);
    services.putInstance(SchemaService.class, schemaService);
    services.putInstance(DOMDataBroker.class, dataBroker);
    services.putInstance(DOMRpcService.class, domRpcService);
    services.putInstance(DOMRpcProviderService.class, domRpcProvider);
    services.putInstance(DOMMountPointService.class, mountService);
    BrokerImpl broker = new BrokerImpl(domRpcService, domRpcProvider, services);
    broker.setDeactivator(() -> {
        for (AutoCloseable ac : closeables) {
            try {
                ac.close();
            } catch (Exception e) {
                LOG.warn("Exception while closing {}", ac, e);
            }
        }
    });
    return broker;
}
Also used : DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) ArrayList(java.util.ArrayList) DOMMountPointService(org.opendaylight.controller.md.sal.dom.api.DOMMountPointService) DOMRpcProviderService(org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService) DOMNotificationService(org.opendaylight.controller.md.sal.dom.api.DOMNotificationService) BrokerImpl(org.opendaylight.controller.sal.dom.broker.BrokerImpl) SchemaService(org.opendaylight.controller.sal.core.api.model.SchemaService) DOMNotificationPublishService(org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) BrokerService(org.opendaylight.controller.sal.core.api.BrokerService)

Example 4 with DOMDataBroker

use of org.opendaylight.controller.md.sal.dom.api.DOMDataBroker 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 5 with DOMDataBroker

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

the class TracingBrokerTest method testPrintOpenTransactions.

@Test
// Finding resource leaks is the point of this test
@SuppressWarnings({ "resource", "unused" })
public void testPrintOpenTransactions() {
    DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
    Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
    BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
    TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
    DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
    DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
    DOMDataReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    boolean printReturnValue = tracingBroker.printOpenTransactions(ps);
    String output = new String(baos.toByteArray(), UTF_8);
    assertThat(printReturnValue).isTrue();
    // Assert expections about stack trace
    assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
    assertThat(output).doesNotContain(TracingBroker.class.getName());
    String previousLine = "";
    for (String line : output.split("\n")) {
        if (line.contains("(...")) {
            assertThat(previousLine.contains("(...)")).isFalse();
        }
        previousLine = line;
    }
// We don't do any verify/times on the mocks,
// because the main point of the test is just to verify that
// printOpenTransactions runs through without any exceptions
// (e.g. it used to have a ClassCastException).
}
Also used : PrintStream(java.io.PrintStream) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.Config) ConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.ConfigBuilder) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TracingBroker(org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) Test(org.junit.Test)

Aggregations

DOMDataBroker (org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)5 Test (org.junit.Test)2 DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)2 Optional (com.google.common.base.Optional)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 MountPoint (org.opendaylight.controller.md.sal.binding.api.MountPoint)1 BindingDOMDataBrokerAdapter (org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter)1 BindingToNormalizedNodeCodec (org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec)1 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 TransactionChainListener (org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMDataBrokerExtension (org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)1 DOMDataChangeListener (org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener)1 DOMMountPointService (org.opendaylight.controller.md.sal.dom.api.DOMMountPointService)1 DOMNotificationPublishService (org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService)1