From 32013f8d8fefcb6f5e70f6b809e7ee5291d732a6 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 10 Nov 2022 19:43:28 +0100 Subject: [PATCH] Add DatabindContext and its wiring We are acquiring EffectiveModelContext and codecs left and right. Add DatabindContext, which is an immutable view of these and a service to maintain them in the global view. This allows us to eliminate references to SchemaContextHandler, hence it is no longer a central point. Change-Id: Iab15f628832008b8a818a48746af9e76781958cb Signed-off-by: Robert Varga --- restconf/restconf-nb/pom.xml | 12 ++++ .../rfc8040/AbstractRestconfApplication.java | 20 +++--- .../nb/rfc8040/DataStreamApplication.java | 8 +-- .../nb/rfc8040/RestconfApplication.java | 29 +++++---- .../nb/rfc8040/databind/DatabindContext.java | 46 ++++++++++++++ .../nb/rfc8040/databind/DatabindProvider.java | 23 +++++++ .../databind/mdsal/DOMDatabindProvider.java | 63 +++++++++++++++++++ .../rfc8040/databind/mdsal/package-info.java | 11 ++++ .../nb/rfc8040/databind/package-info.java | 11 ++++ .../handlers/SchemaContextHandler.java | 3 +- .../AbstractNormalizedNodeBodyReader.java | 6 +- .../JsonNormalizedNodeBodyReader.java | 6 +- .../XmlNormalizedNodeBodyReader.java | 6 +- ...sonStreamWriterWithDisabledValidation.java | 14 ++--- .../RestconfDocumentedExceptionMapper.java | 16 ++--- .../StreamWriterWithDisabledValidation.java | 6 +- ...XmlStreamWriterWithDisabledValidation.java | 11 ++-- .../patch/AbstractPatchBodyReader.java | 6 +- .../providers/patch/JsonPatchBodyReader.java | 6 +- .../providers/patch/XmlPatchBodyReader.java | 6 +- .../AbstractIdentifierAwareJaxRsProvider.java | 12 ++-- .../impl/RestconfDataServiceImpl.java | 14 ++--- .../rests/services/impl/RestconfImpl.java | 10 +-- .../impl/RestconfOperationsServiceImpl.java | 21 +++---- .../impl/RestconfSchemaServiceImpl.java | 4 +- ...estconfStreamsSubscriptionServiceImpl.java | 33 +++++----- .../services/impl/SubscribeToStreamUtil.java | 11 ++-- .../listeners/AbstractNotificationsData.java | 10 +-- .../streams/listeners/ListenerAdapter.java | 4 +- .../NotificationListenerAdapter.java | 4 +- .../OSGI-INF/blueprint/restconf-bp.xml | 5 +- .../restconf/nb/rfc8040/TestUtils.java | 19 ------ .../XmlBodyReaderMountPointTest.java | 2 +- ...RestconfDocumentedExceptionMapperTest.java | 10 +-- .../JsonPatchBodyReaderMountPointTest.java | 2 +- .../patch/JsonPatchBodyReaderTest.java | 2 +- .../XmlPatchBodyReaderMountPointTest.java | 2 +- .../patch/XmlPatchBodyReaderTest.java | 2 +- .../test/AbstractBodyReaderTest.java | 11 ++-- .../providers/test/JsonBodyReaderTest.java | 2 +- .../providers/test/XmlBodyReaderTest.java | 2 +- .../rests/services/impl/Netconf799Test.java | 12 ++-- .../impl/RestconfDataServiceImplTest.java | 15 ++--- .../rests/services/impl/RestconfImplTest.java | 8 +-- .../impl/RestconfOperationsServiceTest.java | 7 +-- ...onfStreamsSubscriptionServiceImplTest.java | 35 ++++++----- .../listeners/ListenerAdapterTest.java | 26 ++++---- 47 files changed, 360 insertions(+), 234 deletions(-) create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java diff --git a/restconf/restconf-nb/pom.xml b/restconf/restconf-nb/pom.xml index d083de81dc..d9fab06a2c 100644 --- a/restconf/restconf-nb/pom.xml +++ b/restconf/restconf-nb/pom.xml @@ -54,6 +54,10 @@ true provided + + org.osgi + org.osgi.service.component.annotations + org.opendaylight.netconf @@ -113,6 +117,14 @@ org.opendaylight.yangtools yang-data-impl + + org.opendaylight.yangtools + rfc8528-data-api + + + org.opendaylight.yangtools + rfc8528-data-util + org.opendaylight.yangtools yang-model-api diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java index 2893b4945a..a0c51d1306 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java @@ -14,7 +14,7 @@ import java.util.List; import java.util.Set; import javax.ws.rs.core.Application; import org.opendaylight.mdsal.dom.api.DOMMountPointService; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyWriter; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader; @@ -31,13 +31,13 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlPatchStatu * Abstract Restconf Application. */ abstract class AbstractRestconfApplication extends Application { - private final SchemaContextHandler schemaContextHandler; + private final DatabindProvider databindProvider; private final DOMMountPointService mountPointService; private final List services; - AbstractRestconfApplication(final SchemaContextHandler schemaContextHandler, - final DOMMountPointService mountPointService, final List services) { - this.schemaContextHandler = requireNonNull(schemaContextHandler); + AbstractRestconfApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService, + final List services) { + this.databindProvider = requireNonNull(databindProvider); this.mountPointService = requireNonNull(mountPointService); this.services = requireNonNull(services); } @@ -54,11 +54,11 @@ abstract class AbstractRestconfApplication extends Application { public final Set getSingletons() { return ImmutableSet.builderWithExpectedSize(services.size() + 5) .addAll(services) - .add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService)) - .add(new JsonPatchBodyReader(schemaContextHandler, mountPointService)) - .add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService)) - .add(new XmlPatchBodyReader(schemaContextHandler, mountPointService)) - .add(new RestconfDocumentedExceptionMapper(schemaContextHandler)) + .add(new JsonNormalizedNodeBodyReader(databindProvider, mountPointService)) + .add(new JsonPatchBodyReader(databindProvider, mountPointService)) + .add(new XmlNormalizedNodeBodyReader(databindProvider, mountPointService)) + .add(new XmlPatchBodyReader(databindProvider, mountPointService)) + .add(new RestconfDocumentedExceptionMapper(databindProvider)) .build(); } } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java index deec9d9375..129dfaa633 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java @@ -11,7 +11,7 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; import org.opendaylight.mdsal.dom.api.DOMMountPointService; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataStreamService; /** @@ -20,8 +20,8 @@ import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataStrea @Singleton public class DataStreamApplication extends AbstractRestconfApplication { @Inject - public DataStreamApplication(final SchemaContextHandler schemaContextHandler, - final DOMMountPointService mountPointService, final RestconfDataStreamService dataStreamService) { - super(schemaContextHandler, mountPointService, List.of(dataStreamService)); + public DataStreamApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService, + final RestconfDataStreamService dataStreamService) { + super(databindProvider, mountPointService, List.of(dataStreamService)); } } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java index c869343d98..383926b319 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java @@ -16,7 +16,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; 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.SchemaContextHandler; +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.RestconfDataServiceImpl; import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl; @@ -28,29 +28,28 @@ import org.opendaylight.restconf.nb.rfc8040.streams.Configuration; @Singleton public class RestconfApplication extends AbstractRestconfApplication { - private RestconfApplication(final SchemaContextHandler schemaContextHandler, - final DOMMountPointService mountPointService, final RestconfStreamsSubscriptionService streamSubscription, - final DOMDataBroker dataBroker, final DOMRpcService rpcService, final DOMActionService actionService, + private RestconfApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService, + final RestconfStreamsSubscriptionService streamSubscription, final DOMDataBroker dataBroker, + final DOMRpcService rpcService, final DOMActionService actionService, final DOMNotificationService notificationService, final DOMSchemaService domSchemaService, final Configuration configuration) { - super(schemaContextHandler, mountPointService, List.of( + super(databindProvider, mountPointService, List.of( streamSubscription, - new RestconfDataServiceImpl(schemaContextHandler, dataBroker, mountPointService, streamSubscription, + new RestconfDataServiceImpl(databindProvider, dataBroker, mountPointService, streamSubscription, actionService, configuration), new RestconfInvokeOperationsServiceImpl(rpcService), - new RestconfOperationsServiceImpl(schemaContextHandler, mountPointService), + new RestconfOperationsServiceImpl(databindProvider, mountPointService), new RestconfSchemaServiceImpl(domSchemaService, mountPointService), - new RestconfImpl(schemaContextHandler))); + new RestconfImpl(databindProvider))); } @Inject - public RestconfApplication(final SchemaContextHandler schemaContextHandler, - final DOMMountPointService mountPointService, final DOMDataBroker dataBroker, - final DOMRpcService rpcService, final DOMActionService actionService, - final DOMNotificationService notificationService, - final DOMSchemaService domSchemaService, final Configuration configuration) { - this(schemaContextHandler, mountPointService, - new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, schemaContextHandler, + public RestconfApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService, + final DOMDataBroker dataBroker, final DOMRpcService rpcService, final DOMActionService actionService, + final DOMNotificationService notificationService, final DOMSchemaService domSchemaService, + final Configuration configuration) { + this(databindProvider, mountPointService, + new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, configuration), dataBroker, rpcService, actionService, notificationService, domSchemaService, configuration); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java new file mode 100644 index 0000000000..6ed4fcc5d9 --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.databind; + +import static java.util.Objects.requireNonNull; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext; +import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext; +import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory; +import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier; +import org.opendaylight.yangtools.yang.data.codec.xml.XmlCodecFactory; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; + +/** + * An immutable context holding a consistent view of things related to data bind operations. + */ +public record DatabindContext( + @NonNull MountPointContext mountContext, + @NonNull JSONCodecFactory jsonCodecs, + @NonNull XmlCodecFactory xmlCodecs) { + public DatabindContext { + requireNonNull(mountContext); + requireNonNull(jsonCodecs); + requireNonNull(xmlCodecs); + } + + public static @NonNull DatabindContext ofModel(final EffectiveModelContext modelContext) { + return ofMountPoint(new EmptyMountPointContext(modelContext)); + } + + public static @NonNull DatabindContext ofMountPoint(final MountPointContext mountContext) { + return new DatabindContext(mountContext, + JSONCodecFactorySupplier.RFC7951.getShared(mountContext.getEffectiveModelContext()), + XmlCodecFactory.create(mountContext)); + } + + public @NonNull EffectiveModelContext modelContext() { + return mountContext.getEffectiveModelContext(); + } +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java new file mode 100644 index 0000000000..88cd3a262d --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.databind; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * A service providing access to a {@link DatabindContext}. + */ +@NonNullByDefault +public interface DatabindProvider { + /** + * Acquire current {@link DatabindContext}. + * + * @return Current {@link DatabindContext} + */ + DatabindContext currentContext(); +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java new file mode 100644 index 0000000000..38caf7bd3f --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.databind.mdsal; + +import static com.google.common.base.Verify.verifyNotNull; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; +import org.opendaylight.yangtools.concepts.Registration; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; + +/** + * A {@link DatabindProvider} monitoring a {@link DOMSchemaService}. + */ +@Singleton +@Component(service = DatabindProvider.class) +public final class DOMDatabindProvider implements DatabindProvider, EffectiveModelContextListener, AutoCloseable { + private final Registration reg; + + private volatile DatabindContext currentContext; + + @Inject + @Activate + public DOMDatabindProvider(@Reference final DOMSchemaService schemaService) { + currentContext = DatabindContext.ofModel(schemaService.getGlobalContext()); + reg = schemaService.registerSchemaContextListener(this); + } + + @Override + public DatabindContext currentContext() { + return verifyNotNull(currentContext, "Provider already closed"); + } + + @Override + public void onModelContextUpdated(final EffectiveModelContext newModelContext) { + final var local = currentContext; + if (local != null && local.modelContext() != newModelContext) { + currentContext = DatabindContext.ofModel(newModelContext); + } + } + + @PreDestroy + @Deactivate + @Override + public void close() { + reg.close(); + currentContext = null; + } +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java new file mode 100644 index 0000000000..537fb8911c --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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 holding data binding components implemented on top of MD-SAL APIs. + */ +package org.opendaylight.restconf.nb.rfc8040.databind.mdsal; \ No newline at end of file diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java new file mode 100644 index 0000000000..b21c3f7ee6 --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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 holding concepts related to data binding. + */ +package org.opendaylight.restconf.nb.rfc8040.databind; \ No newline at end of file diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java index 56454db073..b8444132fd 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java @@ -137,7 +137,8 @@ public class SchemaContextHandler implements EffectiveModelContextListener, Auto } } - public EffectiveModelContext get() { + @VisibleForTesting + EffectiveModelContext get() { return schemaContext; } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/AbstractNormalizedNodeBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/AbstractNormalizedNodeBodyReader.java index df32403ee8..72ceafb085 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/AbstractNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/AbstractNormalizedNodeBodyReader.java @@ -11,7 +11,7 @@ import javax.ws.rs.core.Request; import javax.ws.rs.core.UriInfo; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; @@ -19,9 +19,9 @@ import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; * Common superclass for readers producing {@link NormalizedNodePayload}. */ abstract class AbstractNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider { - AbstractNormalizedNodeBodyReader(final SchemaContextHandler schemaContextHandler, + AbstractNormalizedNodeBodyReader(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - super(schemaContextHandler, mountPointService); + super(databindProvider, mountPointService); } public final void injectParams(final UriInfo uriInfo, final Request request) { diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java index 8d42c494db..66962650a5 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java @@ -23,7 +23,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.MediaTypes; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -51,9 +51,9 @@ import org.slf4j.LoggerFactory; public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader { private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class); - public JsonNormalizedNodeBodyReader(final SchemaContextHandler schemaContextHandler, + public JsonNormalizedNodeBodyReader(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - super(schemaContextHandler, mountPointService); + super(databindProvider, mountPointService); } @SuppressWarnings("checkstyle:IllegalCatch") diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java index bc192d7759..49a5498c48 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java @@ -24,7 +24,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.MediaTypes; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.ErrorTag; @@ -57,9 +57,9 @@ import org.xml.sax.SAXException; public class XmlNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader { private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class); - public XmlNormalizedNodeBodyReader(final SchemaContextHandler schemaContextHandler, + public XmlNormalizedNodeBodyReader(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - super(schemaContextHandler, mountPointService); + super(databindProvider, mountPointService); } @SuppressWarnings("checkstyle:IllegalCatch") diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/JsonStreamWriterWithDisabledValidation.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/JsonStreamWriterWithDisabledValidation.java index 982ff3abc9..e5e4d5ce67 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/JsonStreamWriterWithDisabledValidation.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/JsonStreamWriterWithDisabledValidation.java @@ -10,12 +10,11 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors; import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.io.OutputStreamWriter; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Errors; import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier; import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory; @@ -32,15 +31,14 @@ final class JsonStreamWriterWithDisabledValidation extends StreamWriterWithDisab /** * Creation of the custom JSON stream-writer. * - * @param schemaContextHandler Handler that holds actual schema context. - * @param outputWriter Output stream that is used for creation of JSON writers. + * @param databindContext {@link DatabindContext} to use + * @param outputWriter Output stream that is used for creation of JSON writers. */ - JsonStreamWriterWithDisabledValidation(final SchemaContextHandler schemaContextHandler, + JsonStreamWriterWithDisabledValidation(final DatabindContext databindContext, final OutputStreamWriter outputWriter) { jsonWriter = JsonWriterFactory.createJsonWriter(outputWriter, DEFAULT_INDENT_SPACES_NUM); - final var inference = errorsContainerInference(schemaContextHandler); - jsonNodeStreamWriter = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactorySupplier.RFC7951.getShared(inference.getEffectiveModelContext()), + final var inference = errorsContainerInference(databindContext); + jsonNodeStreamWriter = JSONNormalizedNodeStreamWriter.createExclusiveWriter(databindContext.jsonCodecs(), inference, IETF_RESTCONF_URI, jsonWriter); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java index 5823da3cdb..536e163269 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java @@ -8,6 +8,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors; import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.$YangModuleInfoImpl.qnameOf; import com.google.common.annotations.VisibleForTesting; @@ -33,7 +34,7 @@ import org.opendaylight.restconf.common.ErrorTags; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.nb.rfc8040.MediaTypes; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.Errors; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.errors.Error; import org.opendaylight.yangtools.yang.common.QName; @@ -63,17 +64,18 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper< private static final QName ERROR_PATH_QNAME = qnameOf("error-path"); static final QName ERROR_INFO_QNAME = qnameOf("error-info"); + private final DatabindProvider databindProvider; + @Context private HttpHeaders headers; - private final SchemaContextHandler schemaContextHandler; /** * Initialization of the exception mapper. * - * @param schemaContextHandler Handler that provides actual schema context. + * @param databindProvider A {@link DatabindProvider} */ - public RestconfDocumentedExceptionMapper(final SchemaContextHandler schemaContextHandler) { - this.schemaContextHandler = schemaContextHandler; + public RestconfDocumentedExceptionMapper(final DatabindProvider databindProvider) { + this.databindProvider = requireNonNull(databindProvider); } @Override @@ -170,7 +172,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper< OutputStreamWriter streamStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); ) { return writeNormalizedNode(errorsContainer, outputStream, - new JsonStreamWriterWithDisabledValidation(schemaContextHandler, streamStreamWriter)); + new JsonStreamWriterWithDisabledValidation(databindProvider.currentContext(), streamStreamWriter)); } catch (IOException e) { throw new IllegalStateException("Cannot close some of the output JSON writers", e); } @@ -185,7 +187,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper< private String serializeErrorsContainerToXml(final ContainerNode errorsContainer) { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { return writeNormalizedNode(errorsContainer, outputStream, - new XmlStreamWriterWithDisabledValidation(schemaContextHandler, outputStream)); + new XmlStreamWriterWithDisabledValidation(databindProvider.currentContext(), outputStream)); } catch (IOException e) { throw new IllegalStateException("Cannot close some of the output XML writers", e); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/StreamWriterWithDisabledValidation.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/StreamWriterWithDisabledValidation.java index 652a83cb78..8bb1282edf 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/StreamWriterWithDisabledValidation.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/StreamWriterWithDisabledValidation.java @@ -8,7 +8,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors; import java.io.IOException; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Errors; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.stream.ForwardingNormalizedNodeStreamWriter; @@ -76,8 +76,8 @@ abstract class StreamWriterWithDisabledValidation extends ForwardingNormalizedNo */ abstract void endNodeWithDisabledValidation() throws IOException; - static final Inference errorsContainerInference(final SchemaContextHandler schemaContextHandler) { - final var stack = SchemaInferenceStack.of(schemaContextHandler.get()); + static final Inference errorsContainerInference(final DatabindContext databindContext) { + final var stack = SchemaInferenceStack.of(databindContext.modelContext()); stack.enterGrouping(Errors.QNAME); return stack.toInference(); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/XmlStreamWriterWithDisabledValidation.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/XmlStreamWriterWithDisabledValidation.java index fbf2a09a88..dcee7a32d1 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/XmlStreamWriterWithDisabledValidation.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/XmlStreamWriterWithDisabledValidation.java @@ -15,7 +15,7 @@ import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter; @@ -37,11 +37,10 @@ final class XmlStreamWriterWithDisabledValidation extends StreamWriterWithDisabl /** * Creation of the custom XML stream-writer. * - * @param schemaContextHandler Handler that holds actual schema context. - * @param outputStream Output stream that is used for creation of JSON writers. + * @param databindContext {@link DatabindContext} to use + * @param outputStream Output stream that is used for creation of JSON writers. */ - XmlStreamWriterWithDisabledValidation(final SchemaContextHandler schemaContextHandler, - final OutputStream outputStream) { + XmlStreamWriterWithDisabledValidation(final DatabindContext databindContext, final OutputStream outputStream) { try { xmlWriter = XML_FACTORY.createXMLStreamWriter(outputStream, StandardCharsets.UTF_8.name()); } catch (final XMLStreamException | FactoryConfigurationError e) { @@ -49,7 +48,7 @@ final class XmlStreamWriterWithDisabledValidation extends StreamWriterWithDisabl } xmlNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, - errorsContainerInference(schemaContextHandler)); + errorsContainerInference(databindContext)); } @Override diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractPatchBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractPatchBodyReader.java index 3f12e5a3f6..7ea419e28d 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractPatchBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractPatchBodyReader.java @@ -10,7 +10,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.patch.PatchContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider; /** @@ -19,9 +19,9 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentif * @author Robert Varga */ abstract class AbstractPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider { - protected AbstractPatchBodyReader(final SchemaContextHandler schemaContextHandler, + protected AbstractPatchBodyReader(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - super(schemaContextHandler, mountPointService); + super(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java index 95190882a7..aac27e18e8 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java @@ -36,7 +36,7 @@ import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.common.patch.PatchEditOperation; import org.opendaylight.restconf.common.patch.PatchEntity; import org.opendaylight.restconf.nb.rfc8040.MediaTypes; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -62,9 +62,9 @@ import org.slf4j.LoggerFactory; public class JsonPatchBodyReader extends AbstractPatchBodyReader { private static final Logger LOG = LoggerFactory.getLogger(JsonPatchBodyReader.class); - public JsonPatchBodyReader(final SchemaContextHandler schemaContextHandler, + public JsonPatchBodyReader(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - super(schemaContextHandler, mountPointService); + super(databindProvider, mountPointService); } @SuppressWarnings("checkstyle:IllegalCatch") diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java index 109c6a77f0..0059023a61 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java @@ -30,7 +30,7 @@ import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.common.patch.PatchEditOperation; import org.opendaylight.restconf.common.patch.PatchEntity; import org.opendaylight.restconf.nb.rfc8040.MediaTypes; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.ErrorTag; @@ -62,9 +62,9 @@ import org.xml.sax.SAXException; public class XmlPatchBodyReader extends AbstractPatchBodyReader { private static final Logger LOG = LoggerFactory.getLogger(XmlPatchBodyReader.class); - public XmlPatchBodyReader(final SchemaContextHandler schemaContextHandler, + public XmlPatchBodyReader(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - super(schemaContextHandler, mountPointService); + super(databindProvider, mountPointService); } @SuppressWarnings("checkstyle:IllegalCatch") diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java index ebf2774966..369715ab9d 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java @@ -7,6 +7,8 @@ */ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi; +import static java.util.Objects.requireNonNull; + import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; @@ -23,7 +25,7 @@ import javax.ws.rs.core.UriInfo; import javax.ws.rs.ext.MessageBodyReader; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; @@ -35,12 +37,12 @@ public abstract class AbstractIdentifierAwareJaxRsProvider implements Message @Context private Request request; - private final SchemaContextHandler schemaContextHandler; + private final DatabindProvider databindProvider; private final DOMMountPointService mountPointService; - protected AbstractIdentifierAwareJaxRsProvider(final SchemaContextHandler schemaContextHandler, + protected AbstractIdentifierAwareJaxRsProvider(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - this.schemaContextHandler = schemaContextHandler; + this.databindProvider = requireNonNull(databindProvider); this.mountPointService = mountPointService; } @@ -94,7 +96,7 @@ public abstract class AbstractIdentifierAwareJaxRsProvider implements Message } protected EffectiveModelContext getSchemaContext() { - return schemaContextHandler.get(); + return databindProvider.currentContext().modelContext(); } protected DOMMountPointService getMountPointService() { diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 129f45afb8..7c560bc5fd 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -50,8 +50,8 @@ import org.opendaylight.restconf.common.patch.PatchStatusContext; import org.opendaylight.restconf.nb.rfc8040.ReadDataParams; import org.opendaylight.restconf.nb.rfc8040.Rfc8040; import org.opendaylight.restconf.nb.rfc8040.WriteDataParams; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService; @@ -100,18 +100,18 @@ public class RestconfDataServiceImpl implements RestconfDataService { private static final QName NETCONF_BASE_QNAME = SchemaContext.NAME; private final RestconfStreamsSubscriptionService delegRestconfSubscrService; - private final SchemaContextHandler schemaContextHandler; + private final DatabindProvider databindProvider; private final MdsalRestconfStrategy restconfStrategy; private final DOMMountPointService mountPointService; private final SubscribeToStreamUtil streamUtils; private final DOMActionService actionService; private final DOMDataBroker dataBroker; - public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler, + public RestconfDataServiceImpl(final DatabindProvider databindProvider, final DOMDataBroker dataBroker, final DOMMountPointService mountPointService, final RestconfStreamsSubscriptionService delegRestconfSubscrService, final DOMActionService actionService, final Configuration configuration) { - this.schemaContextHandler = requireNonNull(schemaContextHandler); + this.databindProvider = requireNonNull(databindProvider); this.dataBroker = requireNonNull(dataBroker); restconfStrategy = new MdsalRestconfStrategy(dataBroker); this.mountPointService = requireNonNull(mountPointService); @@ -130,7 +130,7 @@ public class RestconfDataServiceImpl implements RestconfDataService { public Response readData(final String identifier, final UriInfo uriInfo) { final ReadDataParams readParams = QueryParams.newReadDataParams(uriInfo); - final EffectiveModelContext schemaContextRef = schemaContextHandler.get(); + final EffectiveModelContext schemaContextRef = databindProvider.currentContext().modelContext(); final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier( identifier, schemaContextRef, Optional.of(mountPointService)); final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint(); @@ -246,8 +246,8 @@ public class RestconfDataServiceImpl implements RestconfDataService { @Override public Response deleteData(final String identifier) { - final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier( - identifier, schemaContextHandler.get(), Optional.of(mountPointService)); + final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, + databindProvider.currentContext().modelContext(), Optional.of(mountPointService)); final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint(); final RestconfStrategy strategy = getRestconfStrategy(mountPoint); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImpl.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImpl.java index d0b58c84ef..3e5b0d02a7 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImpl.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImpl.java @@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull; import javax.ws.rs.Path; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf; @@ -25,15 +25,15 @@ import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; public class RestconfImpl implements RestconfService { private static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern(); - private final SchemaContextHandler schemaContextHandler; + private final DatabindProvider databindProvider; - public RestconfImpl(final SchemaContextHandler schemaContextHandler) { - this.schemaContextHandler = requireNonNull(schemaContextHandler); + public RestconfImpl(final DatabindProvider databindProvider) { + this.databindProvider = requireNonNull(databindProvider); } @Override public NormalizedNodePayload getLibraryVersion() { - final EffectiveModelContext context = schemaContextHandler.get(); + final EffectiveModelContext context = databindProvider.currentContext().modelContext(); final SchemaInferenceStack stack = SchemaInferenceStack.of(context); // FIXME: use rc:data instantiation once the stack supports it diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java index ce95a84fb4..09ce731ed3 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java @@ -24,7 +24,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; @@ -40,7 +40,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,29 +51,29 @@ import org.slf4j.LoggerFactory; public class RestconfOperationsServiceImpl implements RestconfOperationsService { private static final Logger LOG = LoggerFactory.getLogger(RestconfOperationsServiceImpl.class); - private final SchemaContextHandler schemaContextHandler; + private final DatabindProvider databindProvider; private final DOMMountPointService mountPointService; /** - * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}. + * Set {@link DatabindProvider} for getting actual {@link EffectiveModelContext}. * - * @param schemaContextHandler handling schema context - * @param mountPointService handling dom mount point service + * @param databindProvider a {@link DatabindProvider} + * @param mountPointService a {@link DOMMountPointService} */ - public RestconfOperationsServiceImpl(final SchemaContextHandler schemaContextHandler, + public RestconfOperationsServiceImpl(final DatabindProvider databindProvider, final DOMMountPointService mountPointService) { - this.schemaContextHandler = requireNonNull(schemaContextHandler); + this.databindProvider = requireNonNull(databindProvider); this.mountPointService = requireNonNull(mountPointService); } @Override public String getOperationsJSON() { - return OperationsContent.JSON.bodyFor(schemaContextHandler.get()); + return OperationsContent.JSON.bodyFor(databindProvider.currentContext().modelContext()); } @Override public String getOperationsXML() { - return OperationsContent.XML.bodyFor(schemaContextHandler.get()); + return OperationsContent.XML.bodyFor(databindProvider.currentContext().modelContext()); } @Override @@ -88,7 +87,7 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService } final InstanceIdentifierContext mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, - schemaContextHandler.get(), Optional.of(mountPointService)); + databindProvider.currentContext().modelContext(), Optional.of(mountPointService)); final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint(); final var entry = contextForModelContext(modelContext(mountPoint), mountPoint); return NormalizedNodePayload.of(entry.getKey(), entry.getValue()); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceImpl.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceImpl.java index 2e619e3d34..0f15f9f776 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceImpl.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceImpl.java @@ -14,11 +14,9 @@ import javax.ws.rs.Path; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** * Implementation of {@link RestconfSchemaService}. @@ -30,7 +28,7 @@ public class RestconfSchemaServiceImpl implements RestconfSchemaService { private final DOMYangTextSourceProvider sourceProvider; /** - * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}. + * Default constructor. * * @param schemaService a {@link DOMSchemaService} * @param mountPointService a {@link DOMMountPointService} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java index 76504f6417..6a99a52c45 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java @@ -15,15 +15,15 @@ import org.opendaylight.mdsal.dom.api.DOMNotificationService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; 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.utils.RestconfStreamsConstants; import org.opendaylight.restconf.nb.rfc8040.streams.Configuration; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,15 +47,13 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu * * @param dataBroker {@link DOMDataBroker} * @param notificationService {@link DOMNotificationService} - * @param schemaHandler - * handler of {@link SchemaContext} - * @param configuration - * configuration for restconf {@link Configuration}} + * @param databindProvider a {@link DatabindProvider} + * @param configuration configuration for RESTCONF {@link Configuration}} */ public RestconfStreamsSubscriptionServiceImpl(final DOMDataBroker dataBroker, - final DOMNotificationService notificationService, final SchemaContextHandler schemaHandler, + final DOMNotificationService notificationService, final DatabindProvider databindProvider, final Configuration configuration) { - handlersHolder = new HandlersHolder(dataBroker, notificationService, schemaHandler); + handlersHolder = new HandlersHolder(dataBroker, notificationService, databindProvider); streamUtils = configuration.isUseSSE() ? SubscribeToStreamUtil.serverSentEvents() : SubscribeToStreamUtil.webSockets(); } @@ -76,7 +74,8 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu } // prepare node with value of location - return NormalizedNodePayload.ofLocation(prepareIIDSubsStreamOutput(handlersHolder.getSchemaHandler()), + return NormalizedNodePayload.ofLocation( + prepareIIDSubsStreamOutput(handlersHolder.getDatabindProvider().currentContext().modelContext()), LOCATION_NODEID, response); } @@ -86,9 +85,9 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu * @param schemaHandler Schema context handler. * @return InstanceIdentifier of Location leaf. */ - private static InstanceIdentifierContext prepareIIDSubsStreamOutput(final SchemaContextHandler schemaHandler) { + private static InstanceIdentifierContext prepareIIDSubsStreamOutput(final EffectiveModelContext modelContext) { return InstanceIdentifierContext.ofStack( - SchemaInferenceStack.ofDataTreePath(schemaHandler.get(), NOTIFI_QNAME, LOCATION_QNAME)); + SchemaInferenceStack.ofDataTreePath(modelContext, NOTIFI_QNAME, LOCATION_QNAME)); } /** @@ -98,13 +97,13 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu public static final class HandlersHolder { private final DOMDataBroker dataBroker; private final DOMNotificationService notificationService; - private final SchemaContextHandler schemaHandler; + private final DatabindProvider databindProvider; private HandlersHolder(final DOMDataBroker dataBroker, final DOMNotificationService notificationService, - final SchemaContextHandler schemaHandler) { + final DatabindProvider databindProvider) { this.dataBroker = dataBroker; this.notificationService = notificationService; - this.schemaHandler = schemaHandler; + this.databindProvider = databindProvider; } /** @@ -126,12 +125,12 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu } /** - * Get {@link SchemaContextHandler}. + * Get {@link DatabindProvider}. * * @return the schemaHandler */ - public SchemaContextHandler getSchemaHandler() { - return schemaHandler; + public DatabindProvider getDatabindProvider() { + return databindProvider; } } } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java index 2019aff332..acbc80e70b 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java @@ -23,7 +23,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams; import org.opendaylight.restconf.nb.rfc8040.Rfc8040; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder; import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants; import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter; @@ -128,12 +128,13 @@ abstract class SubscribeToStreamUtil { String.format("Stream with name %s was not found.", streamName), ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT)); - final EffectiveModelContext schemaContext = handlersHolder.getSchemaHandler().get(); + final EffectiveModelContext schemaContext = handlersHolder.getDatabindProvider().currentContext() + .modelContext(); final URI uri = prepareUriByStreamName(uriInfo, streamName); notificationListenerAdapter.setQueryParams(notificationQueryParams); notificationListenerAdapter.listen(handlersHolder.getNotificationServiceHandler()); final DOMDataBroker dataBroker = handlersHolder.getDataBroker(); - notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getSchemaHandler()); + notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getDatabindProvider()); final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( notificationListenerAdapter.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), notificationListenerAdapter.getStart(), @@ -181,12 +182,12 @@ abstract class SubscribeToStreamUtil { listener.setQueryParams(notificationQueryParams); final DOMDataBroker dataBroker = handlersHolder.getDataBroker(); - final SchemaContextHandler schemaHandler = handlersHolder.getSchemaHandler(); + final DatabindProvider schemaHandler = handlersHolder.getDatabindProvider(); listener.setCloseVars(dataBroker, schemaHandler); listener.listen(dataBroker, LogicalDatastoreType.valueOf(datastoreParam)); final URI uri = prepareUriByStreamName(uriInfo, streamName); - final EffectiveModelContext schemaContext = schemaHandler.get(); + final EffectiveModelContext schemaContext = schemaHandler.currentContext().modelContext(); final String serializedPath = IdentifierCodec.serialize(listener.getPath(), schemaContext); final MapEntryNode mapToStreams = diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java index 3a2fc930c7..babb221713 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java @@ -24,7 +24,7 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.restconf.nb.rfc8040.Rfc8040; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.QName; import org.slf4j.Logger; @@ -41,7 +41,7 @@ abstract class AbstractNotificationsData { private final String localName; - protected SchemaContextHandler schemaHandler; + protected DatabindProvider databindProvider; private DOMDataBroker dataBroker; AbstractNotificationsData(final QName lastQName) { @@ -52,13 +52,13 @@ abstract class AbstractNotificationsData { * Data broker for delete data in DS on close(). * * @param dataBroker creating new write transaction for delete data on close - * @param schemaHandler for formatting notifications + * @param databindProvider for formatting notifications */ @SuppressWarnings("checkstyle:hiddenField") // FIXME: this is pure lifecycle nightmare just because ... - public void setCloseVars(final DOMDataBroker dataBroker, final SchemaContextHandler schemaHandler) { + public void setCloseVars(final DOMDataBroker dataBroker, final DatabindProvider databindProvider) { this.dataBroker = dataBroker; - this.schemaHandler = schemaHandler; + this.databindProvider = databindProvider; } /** diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java index 4177ca19a6..e4fb25796a 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java @@ -69,8 +69,8 @@ public class ListenerAdapter extends AbstractCommonSubscriber maybeData; try { - maybeData = formatter().eventData(schemaHandler.get(), dataTreeCandidates, now, getLeafNodesOnly(), - isSkipNotificationData()); + maybeData = formatter().eventData(databindProvider.currentContext().modelContext(), dataTreeCandidates, now, + getLeafNodesOnly(), isSkipNotificationData()); } catch (final Exception e) { LOG.error("Failed to process notification {}", dataTreeCandidates.stream().map(Object::toString).collect(Collectors.joining(",")), e); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java index 120ac8d78e..fac2efe5a3 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java @@ -56,8 +56,8 @@ public final class NotificationListenerAdapter extends AbstractCommonSubscriber< final Optional maybeOutput; try { - maybeOutput = formatter().eventData(schemaHandler.get(), notification, now, getLeafNodesOnly(), - isSkipNotificationData()); + maybeOutput = formatter().eventData(databindProvider.currentContext().modelContext(), notification, now, + getLeafNodesOnly(), isSkipNotificationData()); } catch (Exception e) { LOG.error("Failed to process notification {}", notification, e); return; diff --git a/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml b/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml index 8929b4c333..4089f6f904 100644 --- a/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml +++ b/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml @@ -40,12 +40,12 @@ - + - + @@ -75,6 +75,7 @@ + diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java index 1fe3692b49..230dec0a03 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java @@ -10,8 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -36,11 +34,6 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.dom.api.DOMDataBroker; -import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Revision; @@ -250,16 +243,4 @@ public final class TestUtils { "some interface")) .build(); } - - public static SchemaContextHandler newSchemaContextHandler(final EffectiveModelContext schemaContext) { - DOMDataBroker mockDataBroker = mock(DOMDataBroker.class); - DOMDataTreeWriteTransaction mockTx = mock(DOMDataTreeWriteTransaction.class); - doReturn(CommitInfo.emptyFluentFuture()).when(mockTx).commit(); - doReturn(mockTx).when(mockDataBroker).newWriteOnlyTransaction(); - - SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker, - mock(DOMSchemaService.class)); - schemaContextHandler.onModelContextUpdated(schemaContext); - return schemaContextHandler; - } } diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java index 7680495c45..04c9455ab0 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java @@ -51,7 +51,7 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest { public XmlBodyReaderMountPointTest() throws Exception { super(schemaContext); - xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService); + xmlBodyReader = new XmlNormalizedNodeBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java index c537e6cc46..78f64857ea 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java @@ -30,7 +30,7 @@ import org.junit.runners.Parameterized.Parameters; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.nb.rfc8040.MediaTypes; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.QName; @@ -38,7 +38,6 @@ import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.skyscreamer.jsonassert.JSONAssert; @@ -54,13 +53,10 @@ public class RestconfDocumentedExceptionMapperTest { @BeforeClass public static void setupExceptionMapper() { - final SchemaContext schemaContext = YangParserTestUtils.parseYangResources( + final var schemaContext = YangParserTestUtils.parseYangResources( RestconfDocumentedExceptionMapperTest.class, "/restconf/impl/ietf-restconf@2017-01-26.yang", "/instanceidentifier/yang/instance-identifier-patch-module.yang"); - final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class); - doReturn(schemaContext).when(schemaContextHandler).get(); - - exceptionMapper = new RestconfDocumentedExceptionMapper(schemaContextHandler); + exceptionMapper = new RestconfDocumentedExceptionMapper(() -> DatabindContext.ofModel(schemaContext)); } /** diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java index 9673a4b504..28e3f408dd 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java @@ -29,7 +29,7 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest { public JsonPatchBodyReaderMountPointTest() throws Exception { super(schemaContext); - jsonToPatchBodyReader = new JsonPatchBodyReader(schemaContextHandler, mountPointService); + jsonToPatchBodyReader = new JsonPatchBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java index d9f42d9978..7c557b1dd7 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java @@ -29,7 +29,7 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest { public JsonPatchBodyReaderTest() throws Exception { super(schemaContext); - jsonToPatchBodyReader = new JsonPatchBodyReader(schemaContextHandler, mountPointService); + jsonToPatchBodyReader = new JsonPatchBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java index 54a355e421..1ab05af6af 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java @@ -30,7 +30,7 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest { public XmlPatchBodyReaderMountPointTest() throws Exception { super(schemaContext); - xmlToPatchBodyReader = new XmlPatchBodyReader(schemaContextHandler, mountPointService); + xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java index 96e16d71eb..71a7bee0bf 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java @@ -27,7 +27,7 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest { public XmlPatchBodyReaderTest() throws Exception { super(schemaContext); - xmlToPatchBodyReader = new XmlPatchBodyReader(schemaContextHandler, mountPointService); + xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java index fe32b1c69c..f9aa84238d 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java @@ -32,8 +32,8 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.TestUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.yangtools.yang.common.ErrorTag; @@ -43,17 +43,18 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; public abstract class AbstractBodyReaderTest { protected final MediaType mediaType; - protected final SchemaContextHandler schemaContextHandler; + protected final DatabindProvider databindProvider; protected final DOMMountPointService mountPointService; protected AbstractBodyReaderTest(final EffectiveModelContext schemaContext) throws NoSuchFieldException, IllegalAccessException { mediaType = getMediaType(); - schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext); + final var databindContext = DatabindContext.ofModel(schemaContext); + databindProvider = () -> databindContext; mountPointService = mock(DOMMountPointService.class); - final DOMMountPoint mountPoint = mock(DOMMountPoint.class); + final var mountPoint = mock(DOMMountPoint.class); doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class)); doReturn(Optional.of(FixedDOMSchemaService.of(schemaContext))).when(mountPoint) .getService(DOMSchemaService.class); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java index bea7f8d017..5301f659a4 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java @@ -50,7 +50,7 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest { public JsonBodyReaderTest() throws Exception { super(schemaContext); - jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService); + jsonBodyReader = new JsonNormalizedNodeBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java index 90db4c358d..c37274920b 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java @@ -62,7 +62,7 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest { public XmlBodyReaderTest() throws Exception { super(schemaContext); - xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService); + xmlBodyReader = new XmlNormalizedNodeBodyReader(databindProvider, mountPointService); } @Override diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java index 9b362ca00e..e1402a9207 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java @@ -24,11 +24,10 @@ import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.mdsal.dom.api.DOMActionService; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMMountPointService; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +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.restconf.nb.rfc8040.streams.Configuration; @@ -61,18 +60,15 @@ public class Netconf799Test { TestRestconfUtils.loadFiles("/instanceidentifier/yang")); final DOMDataBroker mockDataBroker = mock(DOMDataBroker.class); - final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker, - mock(DOMSchemaService.class)); - schemaContextHandler.onModelContextUpdated(contextRef); final DOMActionService actionService = mock(DOMActionService.class); doReturn(Futures.immediateFuture(new SimpleDOMActionResult( Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build()))) .when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any()); - final RestconfDataServiceImpl dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, - mock(DOMMountPointService.class), mock(RestconfStreamsSubscriptionService.class), - actionService, mock(Configuration.class)); + final RestconfDataServiceImpl dataService = new RestconfDataServiceImpl( + () -> DatabindContext.ofModel(contextRef), mockDataBroker, mock(DOMMountPointService.class), + mock(RestconfStreamsSubscriptionService.class), actionService, mock(Configuration.class)); final var nodeAndStack = DataSchemaContextTree.from(contextRef).enterPath(ACTION_YII).orElseThrow(); final var node = nodeAndStack.node().getDataSchemaNode(); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java index 61897a1b16..5b37353bfd 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java @@ -59,7 +59,7 @@ import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.common.patch.PatchEntity; import org.opendaylight.restconf.common.patch.PatchStatusContext; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +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.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy; @@ -182,23 +182,16 @@ public class RestconfDataServiceImplTest { .node(baseQName) .build(); - contextRef = - YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)); + contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)); - doReturn(CommitInfo.emptyFluentFuture()).when(write).commit(); doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit(); DOMDataBroker mockDataBroker = mock(DOMDataBroker.class); doReturn(read).when(mockDataBroker).newReadOnlyTransaction(); doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction(); - doReturn(write).when(mockDataBroker).newWriteOnlyTransaction(); - final SchemaContextHandler schemaContextHandler = new SchemaContextHandler( - mockDataBroker, mock(DOMSchemaService.class)); - - schemaContextHandler.onModelContextUpdated(contextRef); - dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, mountPointService, - delegRestconfSubscrService, actionService, configuration); + dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(contextRef), mockDataBroker, + mountPointService, delegRestconfSubscrService, actionService, configuration); doReturn(Optional.of(mountPoint)).when(mountPointService) .getMountPoint(any(YangInstanceIdentifier.class)); doReturn(Optional.of(FixedDOMSchemaService.of(contextRef))).when(mountPoint) diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java index 63aa890a82..d980ce819e 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java @@ -12,8 +12,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.TestUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -21,9 +20,8 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfImplTest { @Test public void restImplTest() throws Exception { - final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler( - YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl"))); - final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler); + final var context = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl")); + final RestconfImpl restconfImpl = new RestconfImpl(() -> DatabindContext.ofModel(context)); final NormalizedNodePayload libraryVersion = restconfImpl.getLibraryVersion(); final LeafNode value = (LeafNode) libraryVersion.getData(); assertEquals(IetfYangLibrary.REVISION.toString(), value.body()); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceTest.java index e65a8cdbba..dbf4111207 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceTest.java @@ -16,16 +16,15 @@ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.TestUtils; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class RestconfOperationsServiceTest { @Test public void getOperationsTest() throws IOException { - final var oper = new RestconfOperationsServiceImpl( - TestUtils.newSchemaContextHandler( - YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"))), + final var context = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules")); + final var oper = new RestconfOperationsServiceImpl(() -> DatabindContext.ofModel(context), mock(DOMMountPointService.class)); assertEquals("{\n" diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java index d7d85aed16..6f52bdbdf8 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java @@ -32,10 +32,10 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMNotificationService; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.streams.Configuration; import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter; @@ -49,6 +49,7 @@ import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @RunWith(MockitoJUnitRunner.StrictStubs.class) @@ -67,7 +68,8 @@ public class RestconfStreamsSubscriptionServiceImplTest { private Configuration configurationWs; private Configuration configurationSse; - private SchemaContextHandler schemaHandler; + private EffectiveModelContext modelContext; + private DatabindProvider databindProvider; @Before public void setUp() throws FileNotFoundException, URISyntaxException { @@ -75,8 +77,6 @@ public class RestconfStreamsSubscriptionServiceImplTest { doReturn(wTx).when(dataBroker).newWriteOnlyTransaction(); doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit(); - schemaHandler = new SchemaContextHandler(dataBroker, mock(DOMSchemaService.class)); - DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class); doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService) .registerDataTreeChangeListener(any(), any()); @@ -88,8 +88,9 @@ public class RestconfStreamsSubscriptionServiceImplTest { // FIXME: just mock UriInfo here doReturn(new LocalUriInfo().getBaseUriBuilder()).when(uriInfo).getBaseUriBuilder(); doReturn(new URI("http://127.0.0.1/" + URI)).when(uriInfo).getAbsolutePath(); - schemaHandler.onModelContextUpdated( - YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications"))); + + modelContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")); + databindProvider = () -> DatabindContext.ofModel(modelContext); configurationWs = new Configuration(0, 100, 10, false); configurationSse = new Configuration(0, 100, 10, true); } @@ -112,12 +113,12 @@ public class RestconfStreamsSubscriptionServiceImplTest { @Test public void testSubscribeToStreamSSE() { ListenersBroker.getInstance().registerDataChangeListener( - IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()), + IdentifierCodec.deserialize("toaster:toaster/toasterStatus", modelContext), "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", NotificationOutputType.XML); final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService = - new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, - schemaHandler, configurationSse); + new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, + configurationSse); final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream( "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo); assertEquals("http://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN @@ -129,12 +130,12 @@ public class RestconfStreamsSubscriptionServiceImplTest { @Test public void testSubscribeToStreamWS() { ListenersBroker.getInstance().registerDataChangeListener( - IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()), + IdentifierCodec.deserialize("toaster:toaster/toasterStatus", modelContext), "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", NotificationOutputType.XML); final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService = - new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, - schemaHandler, configurationWs); + new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, + configurationWs); final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream( "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo); assertEquals("ws://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN @@ -145,8 +146,8 @@ public class RestconfStreamsSubscriptionServiceImplTest { @Test public void testSubscribeToStreamMissingDatastoreInPath() { final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService = - new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, - schemaHandler, configurationWs); + new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, + configurationWs); final var errors = assertThrows(RestconfDocumentedException.class, () -> streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", uriInfo)) .getErrors(); @@ -160,8 +161,8 @@ public class RestconfStreamsSubscriptionServiceImplTest { @Test public void testSubscribeToStreamMissingScopeInPath() { final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService = - new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, - schemaHandler, configurationWs); + new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider, + configurationWs); final var errors = assertThrows(RestconfDocumentedException.class, () -> streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL", uriInfo)).getErrors(); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java index 48a33593ad..7f7e0ef8bc 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java @@ -9,7 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040.streams.listeners; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; import com.google.common.util.concurrent.Uninterruptibles; import java.io.IOException; @@ -34,12 +33,12 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.nb.rfc8040.LeafNodesOnlyParam; import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams; import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; import org.opendaylight.restconf.nb.rfc8040.StartTimeParam; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; import org.opendaylight.yang.gen.v1.augment.instance.identifier.patch.module.rev220218.PatchCont1Builder; import org.opendaylight.yang.gen.v1.augment.instance.identifier.patch.module.rev220218.patch.cont.patch.choice1.PatchCase1Builder; import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.PatchCont; @@ -96,12 +95,11 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { private DataBroker dataBroker; private DOMDataBroker domDataBroker; - private SchemaContextHandler schemaContextHandler; + private DatabindProvider databindProvider; @BeforeClass public static void beforeClass() { - SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory( - "/instanceidentifier/yang"); + SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/instanceidentifier/yang"); } @AfterClass @@ -113,9 +111,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void setUp() throws Exception { dataBroker = getDataBroker(); domDataBroker = getDomBroker(); - - schemaContextHandler = new SchemaContextHandler(domDataBroker, mock(DOMSchemaService.class)); - schemaContextHandler.onModelContextUpdated(SCHEMA_CONTEXT); + databindProvider = () -> DatabindContext.ofModel(SCHEMA_CONTEXT); } class ListenerAdapterTester extends ListenerAdapter { @@ -208,7 +204,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void testJsonNotifsLeaves() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON, true, false); - adapter.setCloseVars(domDataBroker, schemaContextHandler); + adapter.setCloseVars(domDataBroker, databindProvider); final DOMDataTreeChangeService changeService = domDataBroker.getExtensions() .getInstance(DOMDataTreeChangeService.class); @@ -256,7 +252,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void testJsonNotifs() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON, false, false); - adapter.setCloseVars(domDataBroker, schemaContextHandler); + adapter.setCloseVars(domDataBroker, databindProvider); final DOMDataTreeChangeService changeService = domDataBroker.getExtensions() .getInstance(DOMDataTreeChangeService.class); @@ -288,7 +284,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void testJsonNotifsWithoutData() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON, false, true); - adapter.setCloseVars(domDataBroker, schemaContextHandler); + adapter.setCloseVars(domDataBroker, databindProvider); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() .getInstance(DOMDataTreeChangeService.class); @@ -318,7 +314,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void testXmlNotifications() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML, false, false); - adapter.setCloseVars(domDataBroker, schemaContextHandler); + adapter.setCloseVars(domDataBroker, databindProvider); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() .getInstance(DOMDataTreeChangeService.class); @@ -348,7 +344,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void testXmlSkipData() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML, false, true); - adapter.setCloseVars(domDataBroker, schemaContextHandler); + adapter.setCloseVars(domDataBroker, databindProvider); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() .getInstance(DOMDataTreeChangeService.class); @@ -378,7 +374,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { public void testXmlLeavesOnly() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML, true, false); - adapter.setCloseVars(domDataBroker, schemaContextHandler); + adapter.setCloseVars(domDataBroker, databindProvider); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() .getInstance(DOMDataTreeChangeService.class); -- 2.36.6