Remove DOMDataBrokerHandler 69/96169/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 15:18:28 +0000 (17:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 20:40:37 +0000 (22:40 +0200)
This is a useless indirection over DOMDataBroker, just remove it, making
lifecycle a bit more clearer.

JIRA: NETCONF-773
Change-Id: I349baf5e184c7f18092e41149cf93efc13e72ac1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java

index cfaefa595977bb48409db4738ed8f05750d7c70d..d1be3231b31475163819b70b5c4bb67463c0602c 100644 (file)
@@ -11,10 +11,10 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
@@ -43,14 +43,17 @@ public class Rfc8040RestConfWiring {
     public Rfc8040RestConfWiring(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler,
-            final DOMDataBrokerHandler domDataBrokerHandler, @Reference final DOMRpcService rpcService,
+            // Note: DOMDataBroker is not @Reference, because there is funkiness in the hand-written
+            //       blueprint container.
+            final DOMDataBroker dataBroker,
+            @Reference final DOMRpcService rpcService,
             @Reference final DOMActionService actionService,
             @Reference final DOMNotificationService notificationService,
             final SSEInitializer sseInit,
             final Configuration configuration,
             @Reference final DOMSchemaService domSchemaService) {
         servicesWrapper = ServicesWrapper.newInstance(schemaCtxHandler, domMountPointServiceHandler,
-            transactionChainHandler, domDataBrokerHandler, rpcService, actionService, notificationService,
+            transactionChainHandler, dataBroker, rpcService, actionService, notificationService,
             domSchemaService, configuration);
         servicesNotifWrapper = ServicesNotifWrapper.newInstance(sseInit);
     }
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java
deleted file mode 100644 (file)
index 73623c6..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.handlers;
-
-import static java.util.Objects.requireNonNull;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-
-/**
- * Implementation of {@link DOMDataBrokerHandler}.
- */
-// FIXME: remove this class
-@Singleton
-public class DOMDataBrokerHandler {
-    private final DOMDataBroker broker;
-
-    @Inject
-    public DOMDataBrokerHandler(final DOMDataBroker broker) {
-        this.broker = requireNonNull(broker);
-    }
-
-    public @NonNull DOMDataBroker get() {
-        return broker;
-    }
-}
index 616c6286bfec1fd03c2357fd472d07b723b20bec..5ca0e51e1e36666d698c51dd4ce4458fe368203d 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
@@ -64,10 +63,8 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
     /**
      * Initialize holder of handlers with holders as parameters.
      *
-     * @param domDataBrokerHandler
-     *             handler of {@link DOMDataBroker}
-     * @param notificationService
-     *             handler of {@link DOMNotificationService}
+     * @param dataBroker {@link DOMDataBroker}
+     * @param notificationService {@link DOMNotificationService}
      * @param schemaHandler
      *             handler of {@link SchemaContext}
      * @param transactionChainHandler
@@ -75,10 +72,10 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      * @param configuration
      *             configuration for restconf {@link Configuration}}
      */
-    public RestconfStreamsSubscriptionServiceImpl(final DOMDataBrokerHandler domDataBrokerHandler,
+    public RestconfStreamsSubscriptionServiceImpl(final DOMDataBroker dataBroker,
             final DOMNotificationService notificationService, final SchemaContextHandler schemaHandler,
             final TransactionChainHandler transactionChainHandler, final Configuration configuration) {
-        this.handlersHolder = new HandlersHolder(domDataBrokerHandler, notificationService,
+        this.handlersHolder = new HandlersHolder(dataBroker, notificationService,
                 transactionChainHandler, schemaHandler);
         streamUtils = configuration.isUseSSE() ? SubscribeToStreamUtil.serverSentEvents()
                 : SubscribeToStreamUtil.webSockets();
@@ -143,27 +140,26 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      */
     // FIXME: why do we even need this class?!
     public static final class HandlersHolder {
-        private final DOMDataBrokerHandler domDataBrokerHandler;
+        private final DOMDataBroker dataBroker;
         private final DOMNotificationService notificationService;
         private final TransactionChainHandler transactionChainHandler;
         private final SchemaContextHandler schemaHandler;
 
-        private HandlersHolder(final DOMDataBrokerHandler domDataBrokerHandler,
-                final DOMNotificationService notificationService,
+        private HandlersHolder(final DOMDataBroker dataBroker, final DOMNotificationService notificationService,
                 final TransactionChainHandler transactionChainHandler, final SchemaContextHandler schemaHandler) {
-            this.domDataBrokerHandler = domDataBrokerHandler;
+            this.dataBroker = dataBroker;
             this.notificationService = notificationService;
             this.transactionChainHandler = transactionChainHandler;
             this.schemaHandler = schemaHandler;
         }
 
         /**
-         * Get {@link DOMDataBrokerHandler}.
+         * Get {@link DOMDataBroker}.
          *
-         * @return the domDataBrokerHandler
+         * @return the dataBroker
          */
-        public DOMDataBrokerHandler getDomDataBrokerHandler() {
-            return this.domDataBrokerHandler;
+        public DOMDataBroker getDataBroker() {
+            return this.dataBroker;
         }
 
         /**
index ff02c54e42f6d9cf444715a64e70fc4c3f53b36a..1f8f2fdf59b88916ef61a053175562d01aa97020 100644 (file)
@@ -206,7 +206,7 @@ abstract class SubscribeToStreamUtil {
                 notificationQueryParams.getFilter().orElse(null),
                 false, notificationQueryParams.isSkipNotificationData());
         listener.get().setCloseVars(handlersHolder.getTransactionChainHandler(), handlersHolder.getSchemaHandler());
-        registration(datastoreType, listener.get(), handlersHolder.getDomDataBrokerHandler().get());
+        registration(datastoreType, listener.get(), handlersHolder.getDataBroker());
 
         final URI uri = prepareUriByStreamName(uriInfo, streamName);
         final DOMTransactionChain transactionChain = handlersHolder.getTransactionChainHandler().get();
index 456923d609d252ed0ad1f2895bde4fbb342fda1f..824a0073988b35b927ef91b61da50ec18861645c 100644 (file)
@@ -11,6 +11,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
@@ -19,7 +20,6 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
@@ -71,7 +71,7 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe
 
     public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
-            final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
+            final TransactionChainHandler transactionChainHandler, final DOMDataBroker dataBroker,
             final DOMRpcService rpcService, final DOMActionService actionService,
             final DOMNotificationService notificationService, final DOMSchemaService domSchemaService,
             final Configuration configuration) {
@@ -82,8 +82,7 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe
         RestconfSchemaService restconfSchemaService = new RestconfSchemaServiceImpl(schemaCtxHandler,
             domMountPointServiceHandler, yangTextSourceProvider);
         RestconfStreamsSubscriptionService restconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(
-            domDataBrokerHandler, notificationService, schemaCtxHandler, transactionChainHandler,
-            configuration);
+            dataBroker, notificationService, schemaCtxHandler, transactionChainHandler, configuration);
         RestconfDataService restconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler,
             domMountPointServiceHandler, restconfSubscrService, actionService, configuration);
         RestconfInvokeOperationsService restconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcService,
index 340716b36ce63d1971a3056c924fa5e07684dd83..8a9575071adf596b84637a8d13ed688a59392a2f 100644 (file)
@@ -47,7 +47,6 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.util.SimpleUriInfo;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
@@ -67,7 +66,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
             + "toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE";
 
     @Mock
-    private DOMDataBrokerHandler dataBrokerHandler;
+    private DOMDataBroker dataBroker;
     @Mock
     private UriInfo uriInfo;
     @Mock
@@ -90,7 +89,6 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         when(domTx.newReadWriteTransaction()).thenReturn(rwTx);
         doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit();
 
-        final DOMDataBroker dataBroker = mock(DOMDataBroker.class);
         doReturn(domTx).when(dataBroker).createTransactionChain(any());
 
         transactionHandler = new TransactionChainHandler(dataBroker);
@@ -103,8 +101,6 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         doReturn(ImmutableClassToInstanceMap.of(DOMDataTreeChangeService.class, dataTreeChangeService))
                 .when(dataBroker).getExtensions();
 
-        doReturn(dataBroker).when(this.dataBrokerHandler).get();
-
         final MultivaluedMap<String, String> map = mock(MultivaluedMap.class);
         final Set<Entry<String, List<String>>> set = new HashSet<>();
         when(map.entrySet()).thenReturn(set);
@@ -150,13 +146,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
 
     @Test
     public void testSubscribeToStreamSSE() {
-        final UriBuilder uriBuilder = UriBuilder.fromUri(URI);
         ListenersBroker.getInstance().registerDataChangeListener(
                 IdentifierCodec.deserialize("toaster:toaster/toasterStatus", this.schemaHandler.get()),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationSse);
         final NormalizedNodeContext response = streamsSubscriptionService
                 .subscribeToStream(
@@ -170,13 +165,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
 
     @Test
     public void testSubscribeToStreamWS() {
-        final UriBuilder uriBuilder = UriBuilder.fromUri(URI);
         ListenersBroker.getInstance().registerDataChangeListener(
                 IdentifierCodec.deserialize("toaster:toaster/toasterStatus", this.schemaHandler.get()),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationWs);
         final NormalizedNodeContext response = streamsSubscriptionService
                 .subscribeToStream(
@@ -190,7 +184,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test(expected = RestconfDocumentedException.class)
     public void testSubscribeToStreamMissingDatastoreInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", this.uriInfo);
     }
@@ -198,7 +192,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test(expected = RestconfDocumentedException.class)
     public void testSubscribeToStreamMissingScopeInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL",
                 this.uriInfo);