Disconnect RestconfDataServiceImpl from streams 04/108804/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 15:38:51 +0000 (16:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 15:46:27 +0000 (16:46 +0100)
The overlap between dataservice and subscription service should not
exist -- what dataservice really wants is to have the operational
datastore populated with information about supported streams.

This patch deals with the first part -- eliminating the primary
dependency.

JIRA: NETCONF-1102
Change-Id: Ie119e8e160eb61d670dc6f6ce3d3051348018064
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java

index d9fe05a4e7ccd87c729e02ceec3eddded7e8cfc2..8c62f743a9b211aebc4cca1fa29ec235f84d85e6 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.MdsalRestconfServer;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl;
@@ -28,27 +27,18 @@ import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.SubscribeToStrea
 
 @Singleton
 public class RestconfApplication extends AbstractRestconfApplication {
-    private RestconfApplication(final DatabindProvider databindProvider, final MdsalRestconfServer server,
-            final DOMMountPointService mountPointService,
-            final RestconfStreamsSubscriptionService streamSubscription, final DOMDataBroker dataBroker,
+    @Inject
+    public RestconfApplication(final DatabindProvider databindProvider, final MdsalRestconfServer server,
+            final DOMMountPointService mountPointService, final DOMDataBroker dataBroker,
             final DOMActionService actionService, final DOMNotificationService notificationService,
             final DOMSchemaService domSchemaService, final SubscribeToStreamUtil streamUtils) {
         super(databindProvider, List.of(
-            streamSubscription,
-            new RestconfDataServiceImpl(databindProvider, server, dataBroker, streamSubscription, actionService),
+            // FIXME: NETCONF:1102: do not instantiate this service
+            new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, streamUtils),
+            new RestconfDataServiceImpl(databindProvider, server, actionService),
             new RestconfInvokeOperationsServiceImpl(databindProvider, server, mountPointService, streamUtils),
             new RestconfOperationsServiceImpl(databindProvider, server),
             new RestconfSchemaServiceImpl(domSchemaService, mountPointService),
             new RestconfImpl(databindProvider)));
     }
-
-    @Inject
-    public RestconfApplication(final DatabindProvider databindProvider, final MdsalRestconfServer server,
-            final DOMMountPointService mountPointService, final DOMDataBroker dataBroker,
-            final DOMActionService actionService, final DOMNotificationService notificationService,
-            final DOMSchemaService domSchemaService, final SubscribeToStreamUtil streamUtils) {
-        this(databindProvider, server, mountPointService,
-            new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, streamUtils),
-            dataBroker, actionService, notificationService, domSchemaService, streamUtils);
-    }
 }
index 1cd54b0dbd17d7f13e55898cbb8c53b1651e5422..cd40c87096b9fe0feaec8e7973c176e097e5d90e 100644 (file)
@@ -8,10 +8,6 @@
 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
 import static java.util.Objects.requireNonNull;
-import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.NOTIFICATION_STREAM;
-import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_ACCESS_PATH_PART;
-import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_LOCATION_PATH_PART;
-import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.FutureCallback;
@@ -24,8 +20,6 @@ import java.time.Clock;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.concurrent.CancellationException;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -50,7 +44,6 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMActionException;
 import org.opendaylight.mdsal.dom.api.DOMActionResult;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
@@ -77,7 +70,6 @@ import org.opendaylight.restconf.nb.rfc8040.databind.XmlResourceBody;
 import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams;
 import org.opendaylight.restconf.nb.rfc8040.legacy.InstanceIdentifierContext;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy.CreateOrReplaceResult;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yangtools.yang.common.Empty;
@@ -108,20 +100,14 @@ public final class RestconfDataServiceImpl {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
     private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss");
 
-    private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
     private final DatabindProvider databindProvider;
     private final DOMActionService actionService;
     private final MdsalRestconfServer server;
-    @Deprecated(forRemoval = true)
-    private final DOMDataBroker dataBroker;
 
     public RestconfDataServiceImpl(final DatabindProvider databindProvider, final MdsalRestconfServer server,
-            final DOMDataBroker dataBroker, final RestconfStreamsSubscriptionService delegRestconfSubscrService,
             final DOMActionService actionService) {
         this.databindProvider = requireNonNull(databindProvider);
         this.server = requireNonNull(server);
-        this.dataBroker = requireNonNull(dataBroker);
-        this.delegRestconfSubscrService = requireNonNull(delegRestconfSubscrService);
         this.actionService = requireNonNull(actionService);
     }
 
@@ -142,7 +128,7 @@ public final class RestconfDataServiceImpl {
     })
     public Response readData(@Context final UriInfo uriInfo) {
         final var readParams = QueryParams.newReadDataParams(uriInfo);
-        return readData(server.bindRequestRoot(databindProvider.currentContext()), readParams).getValue();
+        return readData(server.bindRequestRoot(databindProvider.currentContext()), readParams);
     }
 
     /**
@@ -164,24 +150,10 @@ public final class RestconfDataServiceImpl {
     public Response readData(@Encoded @PathParam("identifier") final String identifier,
             @Context final UriInfo uriInfo) {
         final var readParams = QueryParams.newReadDataParams(uriInfo);
-        final var databind = databindProvider.currentContext();
-        final var reqPath = server.bindRequestPath(databind, identifier);
-
-        final var nodeAndResponse = readData(reqPath, readParams);
-
-        // FIXME: this is utter craziness, refactor it properly!
-        if (identifier != null && identifier.contains(STREAM_PATH) && identifier.contains(STREAM_ACCESS_PATH_PART)
-                && identifier.contains(STREAM_LOCATION_PATH_PART)) {
-            final String value = (String) nodeAndResponse.getKey().body();
-            final String streamName = value.substring(value.indexOf(NOTIFICATION_STREAM + '/'));
-            delegRestconfSubscrService.subscribeToStream(streamName, uriInfo);
-        }
-
-        return nodeAndResponse.getValue();
+        return readData(server.bindRequestPath(databindProvider.currentContext(), identifier), readParams);
     }
 
-    private Entry<NormalizedNode, Response> readData(final InstanceIdentifierContext reqPath,
-            final ReadDataParams readParams) {
+    private Response readData(final InstanceIdentifierContext reqPath, final ReadDataParams readParams) {
         final var queryParams = QueryParams.newQueryParameters(readParams, reqPath);
         final var fieldPaths = queryParams.fieldPaths();
         final var strategy = server.getRestconfStrategy(reqPath.getSchemaContext(), reqPath.getMountPoint());
@@ -199,7 +171,7 @@ public final class RestconfDataServiceImpl {
                     ErrorType.PROTOCOL, ErrorTag.DATA_MISSING);
         }
 
-        return Map.entry(node, switch (readParams.content()) {
+        return switch (readParams.content()) {
             case ALL, CONFIG -> {
                 final QName type = node.name().getNodeType();
                 yield Response.status(Status.OK)
@@ -212,62 +184,9 @@ public final class RestconfDataServiceImpl {
             case NONCONFIG -> Response.status(Status.OK)
                 .entity(new NormalizedNodePayload(reqPath.inference(), node, queryParams))
                 .build();
-        });
+        };
     }
 
-//    private void createAllYangNotificationStreams(final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
-//        final var transaction = dataBroker.newWriteOnlyTransaction();
-//
-//        for (var module : schemaContext.getModuleStatements().values()) {
-//            final var moduleName = module.argument().getLocalName();
-//            // Note: this handles only RFC6020 notifications
-//            module.streamEffectiveSubstatements(NotificationEffectiveStatement.class).forEach(notification -> {
-//                final var notifName = notification.argument();
-//
-//                writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction,
-//                    createYangNotifiStream(moduleName, notifName, NotificationOutputType.XML));
-//                writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction,
-//                    createYangNotifiStream(moduleName, notifName, NotificationOutputType.JSON));
-//            });
-//        }
-//
-//        try {
-//            transaction.commit().get();
-//        } catch (final InterruptedException | ExecutionException e) {
-//            throw new RestconfDocumentedException("Problem while putting data to DS.", e);
-//        }
-//    }
-//
-//    private NotificationListenerAdapter createYangNotifiStream(final String moduleName, final QName notifName,
-//            final NotificationOutputType outputType) {
-//        final var streamName = createNotificationStreamName(moduleName, notifName.getLocalName(), outputType);
-//
-//        final var existing = listenersBroker.notificationListenerFor(streamName);
-//        return existing != null ? existing
-//            : listenersBroker.registerNotificationListener(ImmutableSet.of(notifName), streamName, outputType);
-//    }
-//
-//    private static String createNotificationStreamName(final String moduleName, final String notifName,
-//            final NotificationOutputType outputType) {
-//        final var sb = new StringBuilder()
-//            .append(RestconfStreamsConstants.NOTIFICATION_STREAM)
-//            .append('/').append(moduleName).append(':').append(notifName);
-//        if (outputType != NotificationOutputType.XML) {
-//            sb.append('/').append(outputType.getName());
-//        }
-//        return sb.toString();
-//    }
-//
-//    private void writeNotificationStreamToDatastore(final EffectiveModelContext schemaContext,
-//            final UriInfo uriInfo, final DOMDataTreeWriteOperations tx, final NotificationListenerAdapter listener) {
-//        final URI uri = streamUtils.prepareUriByStreamName(uriInfo, listener.getStreamName());
-//        final MapEntryNode mapToStreams = RestconfStateStreams.notificationStreamEntry(schemaContext,
-//                listener.getSchemaPath().lastNodeIdentifier(), null, listener.getOutputType(), uri);
-//
-//        tx.merge(LogicalDatastoreType.OPERATIONAL,
-//            RestconfStateStreams.restconfStateStreamPath(mapToStreams.name()), mapToStreams);
-//    }
-
     /**
      * Replace the data store.
      *
index 2eecae0103e4d17a2d00cdd9a412a6769e76ee9b..cf4f366816ca8bcb85b221b49c35e2b5564f7d47 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
@@ -48,8 +47,6 @@ public class Netconf799Test extends AbstractInstanceIdentifierTest {
     @Mock
     private DOMMountPointService mountPointService;
     @Mock
-    private RestconfStreamsSubscriptionService restconfStreamSubService;
-    @Mock
     private AsyncResponse asyncResponse;
     @Captor
     private ArgumentCaptor<Response> captor;
@@ -61,8 +58,7 @@ public class Netconf799Test extends AbstractInstanceIdentifierTest {
             .when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
 
         final var dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(IID_SCHEMA),
-            new MdsalRestconfServer(dataBroker, rpcService, mountPointService), dataBroker, restconfStreamSubService,
-            actionService);
+            new MdsalRestconfServer(dataBroker, rpcService, mountPointService), actionService);
 
         doReturn(true).when(asyncResponse).resume(captor.capture());
         dataService.postDataJSON("instance-identifier-module:cont/cont1/reset",
index 16918e06e5d6aff236cd2f56b50d6af71b22fd10..5de287c5191c5063b3be1ac2d1f412dc86166289 100644 (file)
@@ -62,7 +62,6 @@ import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.patch.rev170222.yang.patch.yang.patch.Edit.Operation;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -111,8 +110,6 @@ public class RestconfDataServiceImplTest extends AbstractJukeboxTest {
     @Mock
     private DOMRpcService rpcService;
     @Mock
-    private RestconfStreamsSubscriptionService delegRestconfSubscrService;
-    @Mock
     private MultivaluedMap<String, String> queryParamenters;
     @Mock
     private AsyncResponse asyncResponse;
@@ -133,8 +130,7 @@ public class RestconfDataServiceImplTest extends AbstractJukeboxTest {
         doReturn(readWrite).when(dataBroker).newReadWriteTransaction();
 
         dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(JUKEBOX_SCHEMA),
-            new MdsalRestconfServer(dataBroker, rpcService, mountPointService), dataBroker, delegRestconfSubscrService,
-            actionService);
+            new MdsalRestconfServer(dataBroker, rpcService, mountPointService), actionService);
         doReturn(Optional.of(mountPoint)).when(mountPointService)
                 .getMountPoint(any(YangInstanceIdentifier.class));
         doReturn(Optional.of(FixedDOMSchemaService.of(JUKEBOX_SCHEMA))).when(mountPoint)