Merge "Support for patch command"
authorTomas Cere <cerko2@gmail.com>
Thu, 30 Nov 2017 14:59:46 +0000 (14:59 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 30 Nov 2017 14:59:46 +0000 (14:59 +0000)
32 files changed:
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/schema/SchemaExportContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYangBodyWriter.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/schema/SchemaExportContentYangBodyWriter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfDataService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfInvokeOperationsService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfStreamsSubscriptionService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/SubscribeToStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfOperationsService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfSchemaService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/UpdateHandlers.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfSchemaServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapperImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java
restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProviderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040ImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfSchemaServiceTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java

index 7f634e203d09c09d9dfa90cdc436eceee9613985..ac2d9c3e64895e198b43d9954eaade30762dbb0b 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.restconf.common.schema;
 
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -14,10 +15,13 @@ public class SchemaExportContext {
 
     private final SchemaContext schemaContext;
     private final Module module;
+    private final DOMYangTextSourceProvider sourceProvider;
 
-    public SchemaExportContext(final SchemaContext ctx, final Module module) {
+    public SchemaExportContext(final SchemaContext ctx, final Module module,
+                               final DOMYangTextSourceProvider sourceProvider) {
         schemaContext = ctx;
         this.module = module;
+        this.sourceProvider = sourceProvider;
     }
 
     public SchemaContext getSchemaContext() {
@@ -28,4 +32,7 @@ public class SchemaExportContext {
         return module;
     }
 
+    public DOMYangTextSourceProvider getSourceProvider() {
+        return sourceProvider;
+    }
 }
index 182224fb05a4220f0fdc7f210600c7976579b1c4..4826405496ce17653e41e02f50b070e4adc177fb 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netconf.md.sal.rest.schema;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import javax.ws.rs.Produces;
@@ -19,6 +18,9 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
 @Provider
 @Produces({ SchemaRetrievalService.YANG_MEDIA_TYPE })
@@ -41,8 +43,14 @@ public class SchemaExportContentYangBodyWriter implements MessageBodyWriter<Sche
             final Annotation[] annotations, final MediaType mediaType,
             final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
             WebApplicationException {
-        final PrintWriter writer = new PrintWriter(entityStream);
-        writer.write(context.getModule().getSource());
-
+        final RevisionSourceIdentifier sourceId = RevisionSourceIdentifier.create(context.getModule().getName(),
+                context.getModule().getQNameModule().getFormattedRevision());
+        final YangTextSchemaSource yangTextSchemaSource;
+        try {
+            yangTextSchemaSource = context.getSourceProvider().getSource(sourceId).checkedGet();
+        } catch (SchemaSourceException e) {
+            throw new WebApplicationException("Unable to retrieve source from SourceProvider.", e);
+        }
+        yangTextSchemaSource.copyTo(entityStream);
     }
 }
index bdfdec7cec2e654b2c89d6c4ea08437b6040bfce..7282d03b1a7b8b27ed48fb499ddacfbd077c9db5 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.collect.Iterables;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.Iterator;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -67,16 +68,20 @@ public class SchemaRetrievalServiceImpl implements SchemaRetrievalService {
         RestconfValidationUtils.checkDocumentedError(componentIter.hasNext(),
                 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, "Revision date must be supplied.");
         final String revisionString = componentIter.next();
-        return getExportUsingNameAndRevision(schemaContext, moduleName, revisionString);
+        return getExportUsingNameAndRevision(schemaContext, moduleName, revisionString,
+                salContext.getYangTextSourceProvider());
     }
 
     private static SchemaExportContext getExportUsingNameAndRevision(final SchemaContext schemaContext,
-            final String moduleName, final String revisionStr) {
+             final String moduleName, final String revisionStr,
+             final DOMYangTextSourceProvider yangTextSourceProvider) {
         try {
             final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse(revisionStr);
             final Module module = schemaContext.findModuleByName(moduleName, revision);
+
             return new SchemaExportContext(
-                    schemaContext, RestconfValidationUtils.checkNotNullDocumented(module, moduleName));
+                    schemaContext, RestconfValidationUtils.checkNotNullDocumented(module, moduleName),
+                    yangTextSourceProvider);
         } catch (final ParseException e) {
             throw new RestconfDocumentedException("Supplied revision is not in expected date format YYYY-mm-dd", e);
         }
index 6890b0d175092a6bb47ba73340b73bfd1c2f767b..a99495cc052b5db7a059e20e7867c970c8651db5 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizat
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -94,6 +95,7 @@ public class ControllerContext implements SchemaContextListener {
     // FIXME; these three should be final
     private volatile SchemaContext globalSchema;
     private volatile DOMMountPointService mountService;
+    private volatile DOMYangTextSourceProvider yangTextSourceProvider;
     private DataNormalizer dataNormalizer;
 
 
@@ -106,6 +108,14 @@ public class ControllerContext implements SchemaContextListener {
         this.mountService = mountService;
     }
 
+    public DOMYangTextSourceProvider getYangTextSourceProvider() {
+        return yangTextSourceProvider;
+    }
+
+    public void setYangTextSourceProvider(DOMYangTextSourceProvider yangTextSourceProvider) {
+        this.yangTextSourceProvider = yangTextSourceProvider;
+    }
+
     private ControllerContext() {
     }
 
index 614133bdd686ca38185c8aa2259743e3c0e8f23e..4afc5f8a6810716343653963f666648d5ded60e2 100644 (file)
@@ -15,6 +15,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.rest.api.RestConnector;
 import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
 import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
@@ -40,12 +42,13 @@ public class RestconfProviderImpl extends AbstractMXBean
     private final IpAddress websocketAddress;
     private final PortNumber websocketPort;
     private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
+    private final DOMSchemaService domSchemaService;
     private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private Thread webSocketServerThread;
 
     public RestconfProviderImpl(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
             DOMNotificationService notificationService, DOMMountPointService mountPointService,
-            IpAddress websocketAddress, PortNumber websocketPort) {
+            DOMSchemaService domSchemaService, IpAddress websocketAddress, PortNumber websocketPort) {
         super("Draft02ProviderStatistics", "restconf-connector", null);
         this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
         this.schemaService = Preconditions.checkNotNull(schemaService);
@@ -54,6 +57,7 @@ public class RestconfProviderImpl extends AbstractMXBean
         this.mountPointService = Preconditions.checkNotNull(mountPointService);
         this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
         this.websocketPort = Preconditions.checkNotNull(websocketPort);
+        this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
     }
 
     public void start() {
@@ -65,6 +69,10 @@ public class RestconfProviderImpl extends AbstractMXBean
 
         ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
         ControllerContext.getInstance().setMountService(mountPointService);
+        final DOMYangTextSourceProvider domSchemaServiceExtension =
+                (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
+                        .get(DOMYangTextSourceProvider.class);
+        ControllerContext.getInstance().setYangTextSourceProvider(domSchemaServiceExtension);
 
         this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
                 new String(websocketAddress.getValue()), websocketPort.getValue()));
index 676ab128e6359bb30c962336f87f88ed20373733..51d72f74ead1b3bc65aec37e09bc6252c2cd5a34 100644 (file)
@@ -43,6 +43,7 @@
   <reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
   <reference id="domDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
           ext:filter="(type=@{databroker-service-type})"/>
+  <reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
 
   <bean id="webSocketPort" class="org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber">
     <argument value="${websocket-port}"/>
@@ -59,6 +60,7 @@
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
     <argument ref="domMountPointService"/>
+    <argument ref="domSchemaService"/>
     <argument ref="webSocketAddress"/>
     <argument ref="webSocketPort"/>
   </bean>
index 6ad199e7aceb1b4e1ab99d0cedec417e67194d12..e2650032ff50fe7166a29b1722ad38285ae83015 100644 (file)
@@ -9,6 +9,9 @@
 package org.opendaylight.restconf.nb.rfc8040;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import java.util.Set;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
@@ -16,7 +19,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
@@ -57,21 +60,30 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
     private static DOMDataBroker dataBroker;
     private static DOMMountPointServiceHandler mountPointServiceHandler;
 
-    private final SchemaService schemaService;
     private final DOMRpcService rpcService;
     private final DOMNotificationService notificationService;
     private final DOMMountPointService mountPointService;
-    private final T wrapperServices;
+    private final DOMSchemaService domSchemaService;
+    private final Builder<Object> servicesProperties;
 
     private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private SchemaContextHandler schemaCtxHandler;
+    private T wrapperServices;
 
+    // FIXME: refactor this class and its users to interact via builder pattern, where individual
+    // services are injected and then the provider is created
     public RestConnectorProvider(final DOMDataBroker domDataBroker,
-            final SchemaService schemaService, final DOMRpcService rpcService,
-            final DOMNotificationService notificationService, final DOMMountPointService mountPointService,
-            final T wrapperServices) {
-        this.wrapperServices = Preconditions.checkNotNull(wrapperServices);
-        this.schemaService = Preconditions.checkNotNull(schemaService);
+            final DOMSchemaService domSchemaService, final DOMRpcService rpcService,
+            final DOMNotificationService notificationService, final DOMMountPointService mountPointService) {
+        this(domDataBroker, domSchemaService, rpcService, notificationService, mountPointService, null);
+    }
+
+    public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
+            final DOMRpcService rpcService, final DOMNotificationService notificationService,
+            final DOMMountPointService mountPointService, final T wrapperServices) {
+        this.servicesProperties = ImmutableSet.<Object>builder();
+        this.wrapperServices = wrapperServices;
+        this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
         this.mountPointService = Preconditions.checkNotNull(mountPointService);
@@ -79,25 +91,33 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
         RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
     }
 
-    public void start() {
+    public synchronized void start() {
         mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
+        servicesProperties.add(mountPointServiceHandler);
 
         final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
+        servicesProperties.add(brokerHandler);
 
         RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
                 .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
+        servicesProperties.add(transactionChainHandler);
 
         this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
-        this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler);
+        servicesProperties.add(schemaCtxHandler);
+        this.listenerRegistration = domSchemaService.registerSchemaContextListener(this.schemaCtxHandler);
 
         final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
+        servicesProperties.add(rpcServiceHandler);
 
         final NotificationServiceHandler notificationServiceHandler =
                 new NotificationServiceHandler(notificationService);
+        servicesProperties.add(notificationServiceHandler);
 
-        wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
-                RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
-                notificationServiceHandler);
+        if (wrapperServices != null) {
+            wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
+                    RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
+                    notificationServiceHandler, domSchemaService);
+        }
     }
 
     public DOMMountPointServiceHandler getMountPointServiceHandler() {
@@ -143,4 +163,8 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
         mountPointServiceHandler = null;
         dataBroker = null;
     }
+
+    public final synchronized Set<Object> getServicesProperties() {
+        return servicesProperties.build();
+    }
 }
index 96bc26b38f9328a82295f029ce75950e1f0e84bf..395f2362f49fe949e4b79279fd593a836995dca3 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import javax.ws.rs.Produces;
@@ -20,6 +19,9 @@ import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
 @Provider
 @Produces({ Rfc8040.MediaTypes.YANG })
@@ -42,8 +44,14 @@ public class SchemaExportContentYangBodyWriter implements MessageBodyWriter<Sche
             final Annotation[] annotations, final MediaType mediaType,
             final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
             WebApplicationException {
-        final PrintWriter writer = new PrintWriter(entityStream);
-        writer.write(context.getModule().getSource());
-
+        final RevisionSourceIdentifier sourceId = RevisionSourceIdentifier.create(context.getModule().getName(),
+                context.getModule().getQNameModule().getFormattedRevision());
+        final YangTextSchemaSource yangTextSchemaSource;
+        try {
+            yangTextSchemaSource = context.getSourceProvider().getSource(sourceId).checkedGet();
+        } catch (SchemaSourceException e) {
+            throw new WebApplicationException("Unable to retrieve source from SourceProvider.", e);
+        }
+        yangTextSchemaSource.copyTo(entityStream);
     }
 }
index 46314c57663106234a1324c47ce70f948c9bc099..87407ac46308a595ccb3ca039ac093d211e29e2b 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.restconf.common.patch.Patch;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.services.simple.api.UpdateHandlers;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 
 /**
@@ -32,7 +33,7 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
  * is a collection of configuration data and state data nodes.
  *
  */
-public interface RestconfDataService {
+public interface RestconfDataService extends UpdateHandlers {
 
     /**
      * Get target data resource.
index 1de502b25cfdd66ce7a06c651f968592b822450f..faa0a4a1e722b2b7ac0edfcb312fe9ffec1a2803 100644 (file)
@@ -18,6 +18,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.services.simple.api.UpdateHandlers;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 
 /**
@@ -25,7 +26,7 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
  * "rpc" statement. It is invoked using a POST method on the operation resource.
  *
  */
-public interface RestconfInvokeOperationsService {
+public interface RestconfInvokeOperationsService extends UpdateHandlers {
 
     /**
      * Invoke RPC operation.
index d131c2c80a7d59f04136d617d0da06d56bf1c782..978e3f1f280139a395cf8bf0735f07ad16a8f272 100644 (file)
@@ -14,12 +14,13 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.nb.rfc8040.services.simple.api.UpdateHandlers;
 
 /**
  * Subscribing to streams.
  *
  */
-public interface RestconfStreamsSubscriptionService {
+public interface RestconfStreamsSubscriptionService extends UpdateHandlers {
 
     /**
      * Subscribing to receive notification from stream support.
index a1424316e07492ec4a641268ccdf6ed358a177c0..0e8971ff4cac835b7619d96b3c104b87a59b0197 100644 (file)
@@ -61,9 +61,9 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
     private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss");
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final TransactionChainHandler transactionChainHandler;
-    private final DOMMountPointServiceHandler mountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private TransactionChainHandler transactionChainHandler;
+    private DOMMountPointServiceHandler mountPointServiceHandler;
 
     private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
 
@@ -77,6 +77,19 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         this.delegRestconfSubscrService = delegRestconfSubscrService;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                mountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            } else if (object instanceof TransactionChainHandler) {
+                transactionChainHandler = (TransactionChainHandler) object;
+            }
+        }
+    }
+
     @Override
     public Response readData(final UriInfo uriInfo) {
         return readData(null, uriInfo);
index 71c6c6c3b0a19cb48db3922ccc41534dd3732879..34c76dc3ae63d4d2737923b75e323bcd8c5a353d 100644 (file)
@@ -33,8 +33,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  */
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
 
-    private final RpcServiceHandler rpcServiceHandler;
-    private final SchemaContextHandler schemaContextHandler;
+    private RpcServiceHandler rpcServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
 
     public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
             final SchemaContextHandler schemaContextHandler) {
@@ -42,6 +42,17 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
         this.schemaContextHandler = schemaContextHandler;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof RpcServiceHandler) {
+                rpcServiceHandler = (RpcServiceHandler) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
                                            final UriInfo uriInfo) {
index 547c318ff33d8febcd032b101342f167bce7bc8b..f106fc634a6799510e0f53eb2b8e429c2524da7c 100644 (file)
@@ -46,7 +46,7 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
 
     private static final Logger LOG = LoggerFactory.getLogger(RestconfStreamsSubscriptionServiceImpl.class);
 
-    private final HandlersHolder handlersHolder;
+    private HandlersHolder handlersHolder;
 
     /**
      * Initialize holder of handlers with holders as parameters.
@@ -67,6 +67,15 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
                 transactionChainHandler, schemaHandler);
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof HandlersHolder) {
+                handlersHolder = (HandlersHolder) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
         final NotificationQueryParams notificationQueryParams = NotificationQueryParams.fromUriInfo(uriInfo);
index b90dd4b145b207a430c47efe1365b50762412b60..b7430c674a58b42acc6de0223b4fd97d74c3144f 100644 (file)
@@ -306,13 +306,11 @@ public final class SubscribeToStreamUtil {
     }
 
     static URI prepareUriByStreamName(final UriInfo uriInfo, final String streamName) {
-        final int port = SubscribeToStreamUtil.prepareNotificationPort();
+        final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
 
-        final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
-        final UriBuilder uriToWebSocketServer =
-                uriBuilder.port(port).scheme(RestconfStreamsConstants.SCHEMA_SUBSCIBRE_URI);
-        final URI uri = uriToWebSocketServer.replacePath(streamName).build();
-        return uri;
+        prepareNotificationPort(uriInfo.getBaseUri().getPort());
+        uriBuilder.scheme(RestconfStreamsConstants.SCHEMA_SUBSCIBRE_URI);
+        return uriBuilder.replacePath(streamName).build();
     }
 
     /**
@@ -345,17 +343,15 @@ public final class SubscribeToStreamUtil {
     /**
      * Get port from web socket server. If doesn't exit, create it.
      *
-     * @return port
+     * @param port
+     *            - port
      */
-    private static int prepareNotificationPort() {
-        int port = RestconfStreamsConstants.NOTIFICATION_PORT;
+    private static void prepareNotificationPort(final int port) {
         try {
-            final WebSocketServer webSocketServer = WebSocketServer.getInstance();
-            port = webSocketServer.getPort();
+            WebSocketServer.getInstance();
         } catch (final NullPointerException e) {
-            WebSocketServer.createInstance(RestconfStreamsConstants.NOTIFICATION_PORT);
+            WebSocketServer.createInstance(port);
         }
-        return port;
     }
 
     static boolean checkExist(final SchemaContext schemaContext,
index c313277eca8da3ab25b431c11d2cd151738f4942..3027def8e0720dbe4ae5b850f61082403633fef9 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
  * supported by the server.
  *
  */
-public interface RestconfOperationsService {
+public interface RestconfOperationsService extends UpdateHandlers {
 
     /**
      * List of rpc or action operations supported by the server.
index 2a87fd41d4d0a5ba469fcafbac489f879b7ad7ef..cffb2e9e61f0f4f7b1a5812621aba3a7479bec3d 100644 (file)
@@ -20,7 +20,7 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
  *
  */
 @Path("/")
-public interface RestconfSchemaService {
+public interface RestconfSchemaService extends UpdateHandlers {
 
     /**
      * Get schema of specific module.
index cd028fd86ac6bd86be887e2b087510f94c0665dd..844669eb89e8ab0b867e2ca5c4ed25a2f8c9a635 100644 (file)
@@ -19,7 +19,7 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
  * Service for getting yang library version.
  *
  */
-public interface RestconfService {
+public interface RestconfService extends UpdateHandlers {
 
     /**
      * Get yang library version.
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/UpdateHandlers.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/UpdateHandlers.java
new file mode 100644 (file)
index 0000000..0dfcfac
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Pantheon technologies 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.services.simple.api;
+
+/**
+ * Allow update of handlers in web application services, if needed.
+ */
+public interface UpdateHandlers {
+
+    /**
+     * Update method for handlers in specific service (resource) of web application.
+     * Has to be implemented as synchronized to avoid conflict of update variables in multithreaded application.
+     *
+     * @param handlers
+     *            array of handlers
+     */
+    default void updateHandlers(final Object... handlers) {
+        throw new UnsupportedOperationException("This method it's not allowed for this service by default.");
+    }
+}
index bb84a0921679bbcc90f8fbc6dad81f14e10e9e2e..386c991ad387e6ecd34e11fb2104a4b68ad8cff7 100644 (file)
@@ -25,7 +25,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
 public class RestconfImpl implements RestconfService {
 
-    private final SchemaContextHandler schemaContextHandler;
+    private SchemaContextHandler schemaContextHandler;
 
     public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
         this.schemaContextHandler = schemaContextHandler;
@@ -51,4 +51,13 @@ public class RestconfImpl implements RestconfService {
                 Builders.leafBuilder((LeafSchemaNode) schemaNode).withValue(IetfYangLibrary.REVISION).build();
         return new NormalizedNodeContext(iid, data);
     }
+
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            }
+        }
+    }
 }
index d2b383bad1721b358b32681414ca3b8ae63deaaf..93c99146c49bf1a43ef030ad5b7b8b01342677ea 100644 (file)
@@ -46,8 +46,8 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService
 
     private static final Logger LOG = LoggerFactory.getLogger(RestconfOperationsServiceImpl.class);
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final DOMMountPointServiceHandler domMountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private DOMMountPointServiceHandler domMountPointServiceHandler;
 
     /**
      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
@@ -63,6 +63,17 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService
         this.domMountPointServiceHandler = domMountPointServiceHandler;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
         final SchemaContextRef ref = new SchemaContextRef(this.schemaContextHandler.get());
index e19e9db38945b78de8b1e349d102f30dfdfcd1c3..e93c66827cd9a9d45328ede5f4fed1087eb4f5d1 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.services.simple.impl;
 
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
@@ -21,8 +22,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  */
 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final DOMMountPointServiceHandler domMountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private DOMMountPointServiceHandler domMountPointServiceHandler;
+    private DOMYangTextSourceProvider sourceProvider;
 
     /**
      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}
@@ -34,15 +36,30 @@ public class RestconfSchemaServiceImpl implements RestconfSchemaService {
      *             handling dom mount point service
      */
     public RestconfSchemaServiceImpl(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointServiceHandler domMountPointServiceHandler) {
+                                     final DOMMountPointServiceHandler domMountPointServiceHandler,
+                                     final DOMYangTextSourceProvider sourceProvider) {
         this.schemaContextHandler = schemaContextHandler;
         this.domMountPointServiceHandler = domMountPointServiceHandler;
+        this.sourceProvider = sourceProvider;
     }
 
     @Override
     public SchemaExportContext getSchema(final String identifier) {
         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
-                this.domMountPointServiceHandler.get());
+                this.domMountPointServiceHandler.get(), sourceProvider);
+    }
+
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            } else if (object instanceof DOMYangTextSourceProvider) {
+                sourceProvider = (DOMYangTextSourceProvider) object;
+            }
+        }
     }
 }
index ee2538d7b046f4a0a595312b1871a41f53202714..157d7d4934917ff8db3d6d2a986e4fb85365ecac 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.services.wrapper;
 
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
@@ -18,5 +19,6 @@ public interface ServiceWrapper {
 
     void setHandlers(SchemaContextHandler schemaCtxHandler, DOMMountPointServiceHandler domMountPointServiceHandler,
             TransactionChainHandler transactionChainHandler, DOMDataBrokerHandler domDataBrokerHandler,
-            RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler);
+            RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler,
+            DOMSchemaService domSchemaService);
 }
index 1d585c5c8b9ec37248651bfe72ab99ef40c22a87..269900231d4847b5dd6d808f2a7c11dd44cd4856 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.restconf.nb.rfc8040.services.wrapper;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
@@ -139,9 +141,14 @@ public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServ
     public void setHandlers(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
-            final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler) {
+            final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
+            final DOMSchemaService domSchemaService) {
         this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
-        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+        final DOMYangTextSourceProvider yangTextSourceProvider =
+                (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
+                        .get(DOMYangTextSourceProvider.class);
+        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
+                yangTextSourceProvider);
         this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
                 notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
         this.delegRestconfDataService =
index 78f6dd17c7e78db3edcf0e0e4e4b7dca03ed6780..768309fb17a5f5476ac50bb0a9b96b21a44ab1b7 100644 (file)
@@ -50,7 +50,7 @@ import org.w3c.dom.Element;
 abstract class AbstractNotificationsData {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractNotificationsData.class);
     private static final TransformerFactory TF = TransformerFactory.newInstance();
-    private static final XMLOutputFactory OF = XMLOutputFactory.newFactory();
+    private static final XMLOutputFactory OF = XMLOutputFactory.newInstance();
 
     private TransactionChainHandler transactionChainHandler;
     protected SchemaContextHandler schemaHandler;
index 875b5d88741496dbe0934f619e185b0b8b0e9987..0df51eacd3b65b7e0371c56a6208f3e769d5bebe 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Iterator;
 import java.util.List;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
@@ -204,14 +205,16 @@ public final class ParserIdentifier {
      * @return {@link SchemaExportContext}
      */
     public static SchemaExportContext toSchemaExportContextFromIdentifier(final SchemaContext schemaContext,
-            final String identifier, final DOMMountPointService domMountPointService) {
+            final String identifier, final DOMMountPointService domMountPointService,
+            final DOMYangTextSourceProvider sourceProvider) {
         final Iterable<String> pathComponents = RestconfConstants.SLASH_SPLITTER.split(identifier);
         final Iterator<String> componentIter = pathComponents.iterator();
         if (!Iterables.contains(pathComponents, RestconfConstants.MOUNT)) {
             final String moduleName = RestconfValidation.validateAndGetModulName(componentIter);
             final Date revision = RestconfValidation.validateAndGetRevision(componentIter);
             final Module module = schemaContext.findModuleByName(moduleName, revision);
-            return new SchemaExportContext(schemaContext, module);
+
+            return new SchemaExportContext(schemaContext, module, sourceProvider);
         } else {
             final StringBuilder pathBuilder = new StringBuilder();
             while (componentIter.hasNext()) {
@@ -234,7 +237,7 @@ public final class ParserIdentifier {
             final String moduleName = RestconfValidation.validateAndGetModulName(componentIter);
             final Date revision = RestconfValidation.validateAndGetRevision(componentIter);
             final Module module = point.getMountPoint().getSchemaContext().findModuleByName(moduleName, revision);
-            return new SchemaExportContext(point.getMountPoint().getSchemaContext(), module);
+            return new SchemaExportContext(point.getMountPoint().getSchemaContext(), module, sourceProvider);
         }
     }
 }
index 6498a76aa637ee1f383d6ee1bace533379ac4fbf..c78d2738eb25f7731e1436b3462bbae5b0e8cebe 100644 (file)
   <!-- We need the AAAService available even though we don't use it -->
   <reference interface="org.opendaylight.aaa.api.AAAService"/>
 
-  <reference id="schemaService" interface="org.opendaylight.controller.sal.core.api.model.SchemaService"/>
   <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
   <reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
   <reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
   <reference id="domDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
           ext:filter="(type=@{databroker-service-type})"/>
+  <reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
 
   <bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
           factory-method="getInstance" />
@@ -42,7 +42,7 @@
   <bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
           init-method="start" destroy-method="close">
     <argument ref="domDataBroker"/>
-    <argument ref="schemaService"/>
+    <argument ref="domSchemaService"/>
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
     <argument ref="domMountPointService"/>
index 1fcc3e00242aa2661a312cc39bbea355ad5a9dd2..2f3bcfad244ed0bb948c71ee42aef8acb61eef15 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
@@ -36,13 +36,14 @@ public class RestConnectorProviderTest {
     // service under test
     private RestConnectorProvider connectorProvider;
 
-    @Mock private SchemaService mockSchemaService;
     @Mock private DOMMountPointService mockMountPointService;
     @Mock private DOMDataBroker mockDataBroker;
     @Mock private DOMRpcService mockRpcService;
     @Mock private DOMNotificationService mockNotificationService;
     @Mock DOMTransactionChain mockTransactionChain;
     @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
+    @Mock
+    private DOMSchemaService domSchemaService;
 
     @Rule
     public ExpectedException thrown = ExpectedException.none();
@@ -52,10 +53,10 @@ public class RestConnectorProviderTest {
         MockitoAnnotations.initMocks(this);
 
         doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
-        doReturn(mockRegistration).when(mockSchemaService).registerSchemaContextListener(
+        doReturn(mockRegistration).when(domSchemaService).registerSchemaContextListener(
                 Mockito.any(SchemaContextHandler.class));
 
-        this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
+        this.connectorProvider = new RestConnectorProvider(mockDataBroker, domSchemaService, mockRpcService,
                 mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
     }
 
@@ -69,7 +70,7 @@ public class RestConnectorProviderTest {
 
         // verify interactions
         verify(mockDataBroker).createTransactionChain(Mockito.any());
-        verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
+        verify(domSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
     }
 
     /**
index 2ed12a543fc2f88388af74825227debcc86a5f11..cf6066b655c53d3d787b67d43347702da37be810 100644 (file)
@@ -50,6 +50,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
@@ -135,6 +136,9 @@ public class JSONRestconfServiceRfc8040ImplTest {
     @Mock
     private DOMRpcService mockRpcService;
 
+    @Mock
+    private DOMSchemaService domSchemaService;
+
     private JSONRestconfServiceRfc8040Impl service;
 
     @BeforeClass
@@ -181,7 +185,7 @@ public class JSONRestconfServiceRfc8040ImplTest {
         ServicesWrapperImpl.getInstance().setHandlers(mockSchemaContextHandler, mountPointServiceHandler,
                 txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
                 new RpcServiceHandler(mockRpcService),
-                new NotificationServiceHandler(mock(DOMNotificationService.class)));
+                new NotificationServiceHandler(mock(DOMNotificationService.class)), domSchemaService);
 
         service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
     }
index 764ea29c9eece7f11ac1a48e0f3c0a1b9ebdb38b..9f40febe48e70f709be65011f5d2bce8157ce948 100644 (file)
@@ -16,6 +16,7 @@ import static org.mockito.Mockito.mock;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.lang.reflect.Field;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -42,6 +43,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.util.SimpleUriInfo;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
@@ -54,6 +56,7 @@ import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev14070
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
+@SuppressWarnings("deprecation")
 public class RestconfStreamsSubscriptionServiceImplTest {
 
     private static final String URI = "/restconf/18/data/ietf-restconf-monitoring:restconf-state/streams/stream/"
@@ -71,6 +74,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
 
     private SchemaContextHandler schemaHandler;
 
+    @SuppressWarnings("unchecked")
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
@@ -101,10 +105,25 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         final Set<Entry<String, List<String>>> set = new HashSet<>();
         Mockito.when(map.entrySet()).thenReturn(set);
         Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(map);
+        final UriBuilder baseUriBuilder = new LocalUriInfo().getBaseUriBuilder();
+        Mockito.when(uriInfo.getBaseUri()).thenReturn(baseUriBuilder.build());
+        Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
         this.schemaHandler.onGlobalContextUpdated(
                 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications")));
     }
 
+    private static class LocalUriInfo extends SimpleUriInfo {
+
+        LocalUriInfo() {
+            super("/");
+        }
+
+        @Override
+        public URI getBaseUri() {
+            return UriBuilder.fromUri("http://localhost:8181").build();
+        }
+    }
+
     @BeforeClass
     public static void setUpBeforeTest() throws Exception {
         final Map<String, ListenerAdapter> listenersByStreamNameSetter = new HashMap<>();
@@ -128,7 +147,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStream() throws Exception {
         final UriBuilder uriBuilder = UriBuilder.fromUri(URI);
-        final ListenerAdapter createListener = Notificator.createListener(
+        Notificator.createListener(
                 IdentifierCodec.deserialize("toaster:toaster/toasterStatus", this.schemaHandler.get()),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
@@ -141,7 +160,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                         "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                         this.uriInfo);
         assertEquals(
-            "ws://:8181/data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
+                "ws://localhost:8181/data-change-event-subscription"
+                        + "/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
             response.getNewHeaders().get("Location").toString());
     }
 
index 9b74c5ec314b6c2753cebdac67933426eb83a519..d3c0a19cd94f82c3639114d7ca3eec96816c46f8 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
 import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
@@ -63,6 +64,8 @@ public class RestconfSchemaServiceTest {
     private SchemaContextHandler mockContextHandler;
     @Mock
     private DOMMountPointServiceHandler mockMountPointHandler;
+    @Mock
+    private DOMYangTextSourceProvider sourceProvider;
 
     // schema context with modules
     private SchemaContext schemaContext;
@@ -106,7 +109,8 @@ public class RestconfSchemaServiceTest {
         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
         when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
 
-        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler);
+        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler,
+                sourceProvider);
     }
 
     /**
index dd2330800eb12101f35e14459442b7d1e47308a3..ba33cd6ef0c608ff2a6ea1a5e34cf565d1574c3d 100644 (file)
@@ -27,6 +27,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
 import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
@@ -97,6 +99,10 @@ public class ParserIdentifierTest {
     private DOMMountPoint mockMountPoint;
     @Mock
     private DOMMountPointService mockMountPointService;
+    @Mock
+    private DOMSchemaService domSchemaService;
+    @Mock
+    private DOMYangTextSourceProvider sourceProvider;
 
     @Rule
     public final ExpectedException thrown = ExpectedException.none();
@@ -461,7 +467,7 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierTest() {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
+                this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
 
@@ -485,7 +491,7 @@ public class ParserIdentifierTest {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
                 this.schemaContext,
                 "not-existing-module" + "/" + "2016-01-01",
-                null);
+                null, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
         assertNull("Not-existing module should be null", exportContext.getModule());
@@ -500,7 +506,7 @@ public class ParserIdentifierTest {
     public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
         try {
             ParserIdentifier.toSchemaExportContextFromIdentifier(
-                    this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null);
+                    this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
             fail("Test should fail due to invalid identifier supplied");
         } catch (final RestconfDocumentedException e) {
             assertEquals("Not expected error type",
@@ -521,7 +527,7 @@ public class ParserIdentifierTest {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
                 this.schemaContext,
                 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
-                this.mountPointService);
+                this.mountPointService, sourceProvider);
 
         final Module module = exportContext.getModule();
         assertNotNull("Export context should contains test module", module);
@@ -543,7 +549,7 @@ public class ParserIdentifierTest {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
                 this.schemaContext,
                 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
-                this.mountPointService);
+                this.mountPointService, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
         assertNull("Not-existing module should be null", exportContext.getModule());
@@ -560,7 +566,7 @@ public class ParserIdentifierTest {
             ParserIdentifier.toSchemaExportContextFromIdentifier(
                     this.schemaContext,
                     MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
-                    this.mountPointService);
+                    this.mountPointService, sourceProvider);
 
             fail("Test should fail due to invalid identifier supplied");
         } catch (final RestconfDocumentedException e) {
@@ -580,7 +586,7 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
         this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null);
+        ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
     }
 
     /**
@@ -590,7 +596,8 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
         this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
+        ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
+                sourceProvider);
     }
 
     /**
@@ -608,7 +615,8 @@ public class ParserIdentifierTest {
                 + TEST_MODULE_NAME
                 + "/"
                 + TEST_MODULE_REVISION,
-                this.mountPointService);
+                this.mountPointService,
+                sourceProvider);
     }
 
     /**
@@ -626,7 +634,8 @@ public class ParserIdentifierTest {
                 + TEST_MODULE_NAME
                 + "/"
                 + TEST_MODULE_REVISION,
-                null);
+                null,
+                sourceProvider);
     }
 
     /**
@@ -644,7 +653,8 @@ public class ParserIdentifierTest {
                 + TEST_MODULE_NAME
                 + "/"
                 + TEST_MODULE_REVISION,
-                this.mockMountPointService);
+                this.mockMountPointService,
+                sourceProvider);
     }
 
     /**