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;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import org.opendaylight.restconf.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({ SchemaRetrievalService.YANG_MEDIA_TYPE, Rfc8040.MediaTypes.YANG })
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 (final SchemaSourceException e) {
+ throw new WebApplicationException("Unable to retrieve source from SourceProvider.", e);
+ }
+ yangTextSchemaSource.copyTo(entityStream);
}
}
*/
package org.opendaylight.netconf.md.sal.rest.schema;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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() {
return module;
}
+ public DOMYangTextSourceProvider getSourceProvider() {
+ return sourceProvider;
+ }
}
import java.text.ParseException;
import java.util.Date;
import java.util.Iterator;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.netconf.md.sal.rest.common.RestconfValidationUtils;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
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 yangTextSourceProvide) {
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),
+ yangTextSourceProvide);
} catch (final ParseException e) {
throw new RestconfDocumentedException("Supplied revision is not in expected date format YYYY-mm-dd", e);
}
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.netconf.sal.rest.impl.RestUtil;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
// FIXME; these three should be final
private volatile SchemaContext globalSchema;
private volatile DOMMountPointService mountService;
+ private volatile DOMYangTextSourceProvider yangTextSourceProvider;
private DataNormalizer dataNormalizer;
this.mountService = mountService;
}
+ public DOMYangTextSourceProvider getYangTextSourceProvider() {
+ return yangTextSourceProvider;
+ }
+
+ public void setYangTextSourceProvider(final DOMYangTextSourceProvider yangTextSourceProvider) {
+ this.yangTextSourceProvider = yangTextSourceProvider;
+ }
+
private ControllerContext() {
}
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
-import java.net.URI;
import java.nio.charset.StandardCharsets;
-import java.util.Collections;
import java.util.List;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
}
}
}
-
- private static class SimpleUriInfo implements UriInfo {
- private final String path;
- private final MultivaluedMap<String, String> queryParams;
-
- SimpleUriInfo(String path) {
- this(path, new MultivaluedHashMap<>());
- }
-
- SimpleUriInfo(String path, MultivaluedMap<String, String> queryParams) {
- this.path = path;
- this.queryParams = queryParams;
- }
-
- @Override
- public String getPath() {
- return path;
- }
-
- @Override
- public String getPath(boolean decode) {
- return path;
- }
-
- @Override
- public List<PathSegment> getPathSegments() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public List<PathSegment> getPathSegments(boolean decode) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public URI getRequestUri() {
- return URI.create(path);
- }
-
- @Override
- public UriBuilder getRequestUriBuilder() {
- return UriBuilder.fromUri(getRequestUri());
- }
-
- @Override
- public URI getAbsolutePath() {
- return getRequestUri();
- }
-
- @Override
- public UriBuilder getAbsolutePathBuilder() {
- return UriBuilder.fromUri(getAbsolutePath());
- }
-
- @Override
- public URI getBaseUri() {
- return URI.create("");
- }
-
- @Override
- public UriBuilder getBaseUriBuilder() {
- return UriBuilder.fromUri(getBaseUri());
- }
-
- @Override
- public MultivaluedMap<String, String> getPathParameters() {
- return new MultivaluedHashMap<>();
- }
-
- @Override
- public MultivaluedMap<String, String> getPathParameters(boolean decode) {
- return getPathParameters();
- }
-
- @Override
- public MultivaluedMap<String, String> getQueryParameters() {
- return queryParams;
- }
-
- @Override
- public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
- return getQueryParameters();
- }
-
- @Override
- public List<String> getMatchedURIs() {
- return Collections.emptyList();
- }
-
- @Override
- public List<String> getMatchedURIs(boolean decode) {
- return getMatchedURIs();
- }
-
- @Override
- public List<Object> getMatchedResources() {
- return Collections.emptyList();
- }
-
- @Override
- public URI resolve(URI uri) {
- return uri;
- }
-
- @Override
- public URI relativize(URI uri) {
- return uri;
- }
- }
}
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;
public class RestconfProviderImpl extends AbstractMXBean
implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
private final DOMDataBroker domDataBroker;
- private final SchemaService schemaService;
+ private final DOMSchemaService schemaService;
private final DOMRpcService rpcService;
private final DOMNotificationService notificationService;
private final DOMMountPointService mountPointService;
private ListenerRegistration<SchemaContextListener> listenerRegistration;
private Thread webSocketServerThread;
- public RestconfProviderImpl(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
- DOMNotificationService notificationService, DOMMountPointService mountPointService,
- IpAddress websocketAddress, PortNumber websocketPort) {
+ public RestconfProviderImpl(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
+ final DOMRpcService rpcService,
+ final DOMNotificationService notificationService, final DOMMountPointService mountPointService,
+ final IpAddress websocketAddress, final PortNumber websocketPort) {
super("Draft02ProviderStatistics", "restconf-connector", null);
this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
- this.schemaService = Preconditions.checkNotNull(schemaService);
+ this.schemaService = Preconditions.checkNotNull(domSchemaService);
this.rpcService = Preconditions.checkNotNull(rpcService);
this.notificationService = Preconditions.checkNotNull(notificationService);
this.mountPointService = Preconditions.checkNotNull(mountPointService);
ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
ControllerContext.getInstance().setMountService(mountPointService);
+ final DOMYangTextSourceProvider domSchemaServiceExtension = (DOMYangTextSourceProvider) schemaService
+ .getSupportedExtensions().get(DOMYangTextSourceProvider.class);
+ ControllerContext.getInstance().setYangTextSourceProvider(domSchemaServiceExtension);
+
this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
new String(websocketAddress.getValue()), websocketPort.getValue()));
this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
--- /dev/null
+/*
+ * 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.netconf.sal.restconf.impl;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+public class SimpleUriInfo implements UriInfo {
+ private final String path;
+ private final MultivaluedMap<String, String> queryParams;
+
+ public SimpleUriInfo(final String path) {
+ this(path, new MultivaluedHashMap<>());
+ }
+
+ public SimpleUriInfo(final String path, final MultivaluedMap<String, String> queryParams) {
+ this.path = path;
+ this.queryParams = queryParams;
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ @Override
+ public String getPath(final boolean decode) {
+ return path;
+ }
+
+ @Override
+ public List<PathSegment> getPathSegments() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<PathSegment> getPathSegments(final boolean decode) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public URI getRequestUri() {
+ return URI.create(path);
+ }
+
+ @Override
+ public UriBuilder getRequestUriBuilder() {
+ return UriBuilder.fromUri(getRequestUri());
+ }
+
+ @Override
+ public URI getAbsolutePath() {
+ return getRequestUri();
+ }
+
+ @Override
+ public UriBuilder getAbsolutePathBuilder() {
+ return UriBuilder.fromUri(getAbsolutePath());
+ }
+
+ @Override
+ public URI getBaseUri() {
+ return URI.create("");
+ }
+
+ @Override
+ public UriBuilder getBaseUriBuilder() {
+ return UriBuilder.fromUri(getBaseUri());
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getPathParameters() {
+ return new MultivaluedHashMap<>();
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getPathParameters(final boolean decode) {
+ return getPathParameters();
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getQueryParameters() {
+ return queryParams;
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getQueryParameters(final boolean decode) {
+ return getQueryParameters();
+ }
+
+ @Override
+ public List<String> getMatchedURIs() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<String> getMatchedURIs(final boolean decode) {
+ return getMatchedURIs();
+ }
+
+ @Override
+ public List<Object> getMatchedResources() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public URI resolve(final URI uri) {
+ return uri;
+ }
+
+ @Override
+ public URI relativize(final URI uri) {
+ return uri;
+ }
+}
\ No newline at end of file
package org.opendaylight.restconf;
+import com.google.common.annotations.VisibleForTesting;
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;
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.netconf.sal.rest.api.RestConnector;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.restconf.common.wrapper.services.ServicesWrapperImpl;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.handlers.TransactionChainHandler;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static TransactionChainHandler transactionChainHandler;
private static DOMDataBroker dataBroker;
private static DOMMountPointServiceHandler mountPointServiceHandler;
+ private static SchemaContextHandler schemaCtxHandler;
- private final SchemaService schemaService;
+ private final DOMSchemaService schemaService;
private final DOMRpcService rpcService;
private final DOMNotificationService notificationService;
private final DOMMountPointService mountPointService;
- private ListenerRegistration<SchemaContextListener> listenerRegistration;
+ private final Builder<Object> servicesProperties;
- private SchemaContextHandler schemaCtxHandler;
+ private ListenerRegistration<SchemaContextListener> listenerRegistration;
- public RestConnectorProvider(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
- DOMNotificationService notificationService, DOMMountPointService mountPointService) {
+ public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService schemaService,
+ final DOMRpcService rpcService, final DOMNotificationService notificationService,
+ final DOMMountPointService mountPointService) {
+ this.servicesProperties = ImmutableSet.<Object>builder();
this.schemaService = Preconditions.checkNotNull(schemaService);
this.rpcService = Preconditions.checkNotNull(rpcService);
this.notificationService = Preconditions.checkNotNull(notificationService);
final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance();
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);
+
+ schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
+ servicesProperties.add(schemaCtxHandler);
- this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
- this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler);
+ this.listenerRegistration = schemaService.registerSchemaContextListener(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,
+ wrapperServices.setHandlers(schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
- notificationServiceHandler);
+ notificationServiceHandler, schemaService);
+ }
+
+ public final synchronized Set<Object> getServicesProperties() {
+ return servicesProperties.build();
}
public DOMMountPointServiceHandler getMountPointServiceHandler() {
return mountPointServiceHandler;
}
+ public static SchemaContext getActualSchemaContext() {
+ return schemaCtxHandler.get();
+ }
+
/**
* After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain.
*
mountPointServiceHandler = null;
dataBroker = null;
}
+
+ @VisibleForTesting
+ public static void setSchemaContextHandler(final SchemaContextHandler schemaContextHandler) {
+ schemaCtxHandler = schemaContextHandler;
+ }
}
* supported by the server.
*
*/
-public interface RestconfOperationsService {
+public interface RestconfOperationsService extends UpdateHandlers {
/**
* List of rpc or action operations supported by the server.
*
*/
@Path("/")
-public interface RestconfSchemaService {
+public interface RestconfSchemaService extends UpdateHandlers {
/**
* Get schema of specific module.
* Service for getting yang library version.
*
*/
-public interface RestconfService {
+public interface RestconfService extends UpdateHandlers {
/**
* Get yang library version.
--- /dev/null
+/*
+ * 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.base.services.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.");
+ }
+}
\ No newline at end of file
public class RestconfImpl implements RestconfService {
- private final SchemaContextHandler schemaContextHandler;
+ private SchemaContextHandler schemaContextHandler;
public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
this.schemaContextHandler = schemaContextHandler;
}
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof SchemaContextHandler) {
+ schemaContextHandler = (SchemaContextHandler) object;
+ }
+ }
+ }
+
@Override
public NormalizedNodeContext getLibraryVersion() {
final SchemaContext context = this.schemaContextHandler.get();
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}.
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());
*/
package org.opendaylight.restconf.base.services.impl;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.restconf.base.services.api.RestconfSchemaService;
import org.opendaylight.restconf.common.references.SchemaContextRef;
*/
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}
* 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 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;
+ }
+ }
}
@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);
}
}
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.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
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 =
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.MessageBodyReader;
import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
-import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.restconf.RestConnectorProvider;
import org.opendaylight.restconf.utils.parser.ParserIdentifier;
final PushbackInputStream pushbackInputStream = new PushbackInputStream(entityStream);
- int firstByte = pushbackInputStream.read();
+ final int firstByte = pushbackInputStream.read();
if (firstByte == -1) {
return emptyBody(path);
} else {
private InstanceIdentifierContext<?> getInstanceIdentifierContext() {
return ParserIdentifier.toInstanceIdentifier(
getIdentifier(),
- ControllerContext.getInstance().getGlobalSchema(),
+ RestConnectorProvider.getActualSchemaContext(),
Optional.of(RestConnectorProvider.getMountPointService()));
}
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
import org.opendaylight.netconf.sal.restconf.impl.PatchStatusContext;
import org.opendaylight.restconf.Rfc8040;
+import org.opendaylight.restconf.base.services.api.UpdateHandlers;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
* is a collection of configuration data and state data nodes.
*
*/
-public interface RestconfDataService {
+public interface RestconfDataService extends UpdateHandlers {
/**
* Get target data resource.
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.restconf.Rfc8040;
+import org.opendaylight.restconf.base.services.api.UpdateHandlers;
import org.opendaylight.restconf.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.
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.restconf.base.services.api.UpdateHandlers;
/**
* Subscribing to streams.
*
*/
-public interface RestconfStreamsSubscriptionService {
+public interface RestconfStreamsSubscriptionService extends UpdateHandlers {
/**
* Subscribing to receive notification from stream support.
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;
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);
*/
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) {
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) {
private static final Logger LOG = LoggerFactory.getLogger(RestconfStreamsSubscriptionServiceImpl.class);
- private final HandlersHolder handlersHolder;
+ private HandlersHolder handlersHolder;
/**
* Initialize holder of handlers with holders as parameters.
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);
final TemporalAccessor p;
try {
p = FORMATTER.parse(value);
- } catch (DateTimeParseException e) {
+ } catch (final DateTimeParseException e) {
throw new RestconfDocumentedException("Cannot parse of value in date: " + value, e);
}
return Instant.from(p);
}
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();
}
/**
}
final YangInstanceIdentifier path = listener.getPath();
- DOMDataTreeChangeService changeService = (DOMDataTreeChangeService)
+ final DOMDataTreeChangeService changeService = (DOMDataTreeChangeService)
domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
if (changeService == null) {
throw new UnsupportedOperationException("DOMDataTreeChangeService not supported by DOMDataBroker");
}
- DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, path);
+ final DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, path);
listener.setRegistration(changeService.registerDataTreeChangeListener(loc, listener));
}
*
* @return port
*/
- private static int prepareNotificationPort() {
+ private static int prepareNotificationPort(final int port) {
final WebSocketServer webSocketServer =
- WebSocketServer.getInstance(RestconfStreamsConstants.NOTIFICATION_PORT);
+ WebSocketServer.getInstance(port);
return webSocketServer.getPort();
}
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.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
}
/**
- * Parsing {@link Module} module by {@link String} module name and
- * {@link Date} revision and from the parsed module create
- * {@link SchemaExportContext}.
+ * Parsing {@link Module} module by {@link String} module name and {@link Date} revision and from the parsed module
+ * create {@link SchemaExportContext}.
*
* @param schemaContext
- * {@link SchemaContext}
+ * {@link SchemaContext}
* @param identifier
- * path parameter
+ * path parameter
* @param domMountPointService
- * {@link DOMMountPointService}
+ * {@link DOMMountPointService}
+ * @param sourceProvider
+ * - source provider
* @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()) {
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);
}
}
}
<!-- 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="webSocketPort" class="org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber">
<argument value="${websocket-port}"/>
<bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
init-method="start" destroy-method="close">
<argument ref="domDataBroker"/>
- <argument ref="schemaService"/>
+ <argument ref="domSchemaService"/>
<argument ref="domRpcService"/>
<argument ref="domNotificationService"/>
<argument ref="domMountPointService"/>
<bean id="restconfProviderDraft18" class="org.opendaylight.restconf.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"/>
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.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceDraft18;
import org.opendaylight.restconf.common.wrapper.services.ServicesWrapperImpl;
@Mock
private SchemaContextHandler mockSchemaContextHandler;
+ @Mock
+ private DOMSchemaService domSchemaService;
+
@Mock
private DOMDataBroker mockDOMDataBroker;
doReturn(schemaContext).when(mockSchemaContextHandler).get();
- TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
+ final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
final DOMMountPointServiceHandler mountPointServiceHandler =
new DOMMountPointServiceHandler(mockMountPointService);
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 JSONRestconfServiceDraft18(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
}
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.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
private SchemaContextHandler mockContextHandler;
@Mock
private DOMMountPointServiceHandler mockMountPointHandler;
+ @Mock
+ private DOMYangTextSourceProvider sourceProvider;
// schema context with modules
private SchemaContext schemaContext;
((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,
+ this.sourceProvider);
}
/**
import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
-import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
import org.opendaylight.restconf.RestConnectorProvider;
abstract class AbstractBodyReaderTest {
- protected static final ControllerContext CONTROLLER_CONTEXT = ControllerContext.getInstance();
protected static final DOMMountPointServiceHandler MOUNT_POINT_SERVICE_HANDLER =
mock(DOMMountPointServiceHandler.class);
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
schemaContext = YangParserTestUtils.parseYangSources(testFiles);
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
+ when(RestConnectorProvider.getActualSchemaContext()).thenReturn(schemaContext);
when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
}
import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
}
@Test
import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
}
@Test
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
}
@Test
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/foo-xml-test/yang"));
schemaContext = YangParserTestUtils.parseYangSources(testFiles);
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
}
import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
}
@Test
import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
- CONTROLLER_CONTEXT.setSchemas(schemaContext);
+ final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+ when(schemaContextHandler.get()).thenReturn(schemaContext);
+ RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
}
@Test
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;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.netconf.sal.restconf.impl.SimpleUriInfo;
import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
final ListenerRegistration<DOMDataChangeListener> listener = mock(ListenerRegistration.class);
doReturn(dataBroker).when(this.dataBrokerHandler).get();
doReturn(listener).when(dataBroker).registerDataChangeListener(any(), any(), any(), any());
- DOMDataTreeChangeService changeService = Mockito.mock(DOMDataTreeChangeService.class);
+ final DOMDataTreeChangeService changeService = Mockito.mock(DOMDataTreeChangeService.class);
Mockito.when(changeService.registerDataTreeChangeListener(any(), any()))
.thenReturn(Mockito.mock(ListenerRegistration.class));
- HashMap extensions = new HashMap();
+ final HashMap extensions = new HashMap();
extensions.put(DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class));
Mockito.when(dataBroker.getSupportedExtensions()).thenReturn(extensions);
final MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
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<>();
"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());
}
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.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
private DOMMountPoint mockMountPoint;
@Mock
private DOMMountPointService mockMountPointService;
+ @Mock
+ private DOMSchemaService domSchemaService;
+ @Mock
+ private DOMYangTextSourceProvider sourceProvider;
@Rule
public final ExpectedException thrown = ExpectedException.none();
@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);
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());
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",
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);
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());
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) {
@Test
public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null);
+ ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
}
/**
@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);
}
/**
+ TEST_MODULE_NAME
+ "/"
+ TEST_MODULE_REVISION,
- this.mountPointService);
+ this.mountPointService, sourceProvider);
}
/**
+ TEST_MODULE_NAME
+ "/"
+ TEST_MODULE_REVISION,
- null);
+ null, sourceProvider);
}
/**
+ TEST_MODULE_NAME
+ "/"
+ TEST_MODULE_REVISION,
- this.mockMountPointService);
+ this.mockMountPointService, sourceProvider);
}
/**