*/
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;
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.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.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 })
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);
}
}
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;
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);
}
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;
// 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(DOMYangTextSourceProvider yangTextSourceProvider) {
+ this.yangTextSourceProvider = yangTextSourceProvider;
+ }
+
private ControllerContext() {
}
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;
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);
this.mountPointService = Preconditions.checkNotNull(mountPointService);
this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
this.websocketPort = Preconditions.checkNotNull(websocketPort);
+ this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
}
public void start() {
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()));
<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}"/>
<argument ref="domRpcService"/>
<argument ref="domNotificationService"/>
<argument ref="domMountPointService"/>
+ <argument ref="domSchemaService"/>
<argument ref="webSocketAddress"/>
<argument ref="webSocketPort"/>
</bean>
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;
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;
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);
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() {
mountPointServiceHandler = null;
dataBroker = null;
}
+
+ public final synchronized Set<Object> getServicesProperties() {
+ return servicesProperties.build();
+ }
}
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.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 })
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);
}
}
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;
/**
* 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.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;
/**
* "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.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.
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);
}
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();
}
/**
/**
* 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,
* 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.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.");
+ }
+}
public class RestconfImpl implements RestconfService {
- private final SchemaContextHandler schemaContextHandler;
+ private SchemaContextHandler schemaContextHandler;
public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
this.schemaContextHandler = schemaContextHandler;
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;
+ }
+ }
+ }
}
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.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;
*/
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 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;
+ }
+ }
}
}
*/
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;
void setHandlers(SchemaContextHandler schemaCtxHandler, DOMMountPointServiceHandler domMountPointServiceHandler,
TransactionChainHandler transactionChainHandler, DOMDataBrokerHandler domDataBrokerHandler,
- RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler);
+ RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler,
+ DOMSchemaService domSchemaService);
}
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;
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 =
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;
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;
* @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="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
factory-method="getInstance" />
<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"/>
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;
// 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();
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());
}
// verify interactions
verify(mockDataBroker).createTransactionChain(Mockito.any());
- verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
+ verify(domSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
}
/**
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;
@Mock
private DOMRpcService mockRpcService;
+ @Mock
+ private DOMSchemaService domSchemaService;
+
private JSONRestconfServiceRfc8040Impl service;
@BeforeClass
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);
}
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.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;
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/"
private SchemaContextHandler schemaHandler;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
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<>();
@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);
"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.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;
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,
+ sourceProvider);
}
/**
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;
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);
}
/**