Search in sources :

Example 1 with WebSocketServer

use of org.opendaylight.netconf.sal.streams.websockets.WebSocketServer in project netconf by opendaylight.

the class RestconfImpl method notifStream.

/**
 * Register notification listener by stream name.
 *
 * @param identifier
 *            stream name
 * @param uriInfo
 *            uriInfo
 * @param stop
 *            stop-time of getting notification
 * @param start
 *            start-time of getting notification
 * @param filter
 *            indicate which subset of all possible events are of interest
 * @return {@link URI} of location
 */
private URI notifStream(final String identifier, final UriInfo uriInfo, final Instant start, final Instant stop, final String filter) {
    final String streamName = Notificator.createStreamNameFromUri(identifier);
    if (Strings.isNullOrEmpty(streamName)) {
        throw new RestconfDocumentedException("Stream name is empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
    }
    final List<NotificationListenerAdapter> listeners = Notificator.getNotificationListenerFor(streamName);
    if (listeners == null || listeners.isEmpty()) {
        throw new RestconfDocumentedException("Stream was not found.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
    }
    for (final NotificationListenerAdapter listener : listeners) {
        broker.registerToListenNotification(listener);
        listener.setQueryParams(start, Optional.ofNullable(stop), Optional.ofNullable(filter), false, false);
    }
    final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
    final WebSocketServer webSocketServerInstance = WebSocketServer.getInstance(NOTIFICATION_PORT);
    final int notificationPort = webSocketServerInstance.getPort();
    final UriBuilder uriToWebsocketServerBuilder = uriBuilder.port(notificationPort).scheme(getWsScheme(uriInfo));
    return uriToWebsocketServerBuilder.replacePath(streamName).build();
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) NotificationListenerAdapter(org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter) WebSocketServer(org.opendaylight.netconf.sal.streams.websockets.WebSocketServer) UriBuilder(javax.ws.rs.core.UriBuilder) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint)

Example 2 with WebSocketServer

use of org.opendaylight.netconf.sal.streams.websockets.WebSocketServer in project netconf by opendaylight.

the class RestconfImpl method dataSubs.

/**
 * Register data change listener by stream name.
 *
 * @param identifier
 *            stream name
 * @param uriInfo
 *            uri info
 * @param stop
 *            start-time of getting notification
 * @param start
 *            stop-time of getting notification
 * @param filter
 *            indicate which subset of all possible events are of interest
 * @return {@link URI} of location
 */
private URI dataSubs(final String identifier, final UriInfo uriInfo, final Instant start, final Instant stop, final String filter, final boolean leafNodesOnly, final boolean skipNotificationData) {
    final String streamName = Notificator.createStreamNameFromUri(identifier);
    if (Strings.isNullOrEmpty(streamName)) {
        throw new RestconfDocumentedException("Stream name is empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
    }
    final ListenerAdapter listener = Notificator.getListenerFor(streamName);
    if (listener == null) {
        throw new RestconfDocumentedException("Stream was not found.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
    }
    listener.setQueryParams(start, Optional.ofNullable(stop), Optional.ofNullable(filter), leafNodesOnly, skipNotificationData);
    final Map<String, String> paramToValues = resolveValuesFromUri(identifier);
    final LogicalDatastoreType datastore = parserURIEnumParameter(LogicalDatastoreType.class, paramToValues.get(DATASTORE_PARAM_NAME));
    if (datastore == null) {
        throw new RestconfDocumentedException("Stream name doesn't contains datastore value (pattern /datastore=)", ErrorType.APPLICATION, ErrorTag.MISSING_ATTRIBUTE);
    }
    final Scope scope = parserURIEnumParameter(Scope.class, paramToValues.get(SCOPE_PARAM_NAME));
    if (scope == null) {
        throw new RestconfDocumentedException("Stream name doesn't contains datastore value (pattern /scope=)", ErrorType.APPLICATION, ErrorTag.MISSING_ATTRIBUTE);
    }
    broker.registerToListenDataChanges(datastore, scope, listener);
    final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
    final WebSocketServer webSocketServerInstance = WebSocketServer.getInstance(NOTIFICATION_PORT);
    final int notificationPort = webSocketServerInstance.getPort();
    final UriBuilder uriToWebsocketServerBuilder = uriBuilder.port(notificationPort).scheme(getWsScheme(uriInfo));
    return uriToWebsocketServerBuilder.replacePath(streamName).build();
}
Also used : ListenerAdapter(org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter) NotificationListenerAdapter(org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) Scope(org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope) WebSocketServer(org.opendaylight.netconf.sal.streams.websockets.WebSocketServer) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) UriBuilder(javax.ws.rs.core.UriBuilder) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)2 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)2 NotificationListenerAdapter (org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter)2 WebSocketServer (org.opendaylight.netconf.sal.streams.websockets.WebSocketServer)2 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)2 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)1 ListenerAdapter (org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter)1 Scope (org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope)1