package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
import com.google.common.collect.ImmutableSet;
+import java.util.Optional;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfFuture;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
import org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106.SubscribeDeviceNotificationInput;
* }
* }
* </pre>
- * @param refSchemaCtx Reference to {@link EffectiveModelContext}.
+ * @param modelContext Reference to {@link EffectiveModelContext}.
* @return {@link DOMRpcResult} - Output of RPC - example in JSON:
* <pre>
* {@code
* </pre>
*/
// FIXME: this really should be a normal RPC implementation
- static ContainerNode createDataChangeNotifiStream(final ListenersBroker listenersBroker, final ContainerNode input,
- final EffectiveModelContext refSchemaCtx) {
+ static RestconfFuture<Optional<ContainerNode>> createDataChangeNotifiStream(final ListenersBroker listenersBroker,
+ final ContainerNode input, final EffectiveModelContext modelContext) {
final var datastoreName = extractStringLeaf(input, DATASTORE_NODEID);
final var scopeName = extractStringLeaf(input, SCOPE_NODEID);
- final var adapter = listenersBroker.registerDataChangeListener(refSchemaCtx,
+ final var adapter = listenersBroker.registerDataChangeListener(modelContext,
datastoreName != null ? LogicalDatastoreType.valueOf(datastoreName) : LogicalDatastoreType.CONFIGURATION,
preparePath(input), scopeName != null ? Scope.ofName(scopeName) : Scope.BASE, prepareOutputType(input));
// building of output
- return Builders.containerBuilder()
+ return RestconfFuture.of(Optional.of(Builders.containerBuilder()
.withNodeIdentifier(SAL_REMOTE_OUTPUT_NODEID)
.withChild(ImmutableNodes.leafNode(STREAM_NAME_NODEID, adapter.getStreamName()))
- .build();
+ .build()));
}
// FIXME: this really should be a normal RPC implementation
- static ContainerNode createNotificationStream(final ListenersBroker listenersBroker, final ContainerNode input,
- final EffectiveModelContext refSchemaCtx) {
+ static RestconfFuture<Optional<ContainerNode>> createNotificationStream(final ListenersBroker listenersBroker,
+ final ContainerNode input, final EffectiveModelContext modelContext) {
final var qnames = ((LeafSetNode<String>) input.getChildByArg(NOTIFICATIONS)).body().stream()
.map(LeafSetEntryNode::body)
.map(QName::create)
.collect(ImmutableSet.toImmutableSet());
for (var qname : qnames) {
- if (refSchemaCtx.findNotification(qname).isEmpty()) {
+ if (modelContext.findNotification(qname).isEmpty()) {
throw new RestconfDocumentedException(qname + " refers to an unknown notification",
ErrorType.APPLICATION, ErrorTag.INVALID_VALUE);
}
}
// registration of the listener
- final var adapter = listenersBroker.registerNotificationListener(refSchemaCtx, qnames,
+ final var adapter = listenersBroker.registerNotificationListener(modelContext, qnames,
prepareOutputType(input));
- return Builders.containerBuilder()
+ return RestconfFuture.of(Optional.of(Builders.containerBuilder()
.withNodeIdentifier(SAL_REMOTE_OUTPUT_NODEID)
.withChild(ImmutableNodes.leafNode(STREAM_NAME_NODEID, adapter.getStreamName()))
- .build();
+ .build()));
}
/**
* @return {@link DOMRpcResult} - Output of RPC - example in JSON
*/
// FIXME: this should be an RPC invocation
- static ContainerNode createDeviceNotificationListener(final String baseUrl, final ContainerNode input,
- final SubscribeToStreamUtil streamUtil, final DOMMountPointService mountPointService,
- final ListenersBroker listenersBroker) {
+ static RestconfFuture<Optional<ContainerNode>> createDeviceNotificationListener(
+ final ListenersBroker listenersBroker, final ContainerNode input, final String baseUrl,
+ final DOMMountPointService mountPointService) {
// parsing out of container with settings and path
// FIXME: ugly cast
final var path = (YangInstanceIdentifier) input.findChildByArg(DEVICE_NOTIFICATION_PATH_NODEID)
prepareOutputType(input), mountModelContext, mountPointService, mountPoint.getIdentifier());
notificationListenerAdapter.listen(mountNotifService, notificationPaths);
- return Builders.containerBuilder()
+ return RestconfFuture.of(Optional.of(Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(SubscribeDeviceNotificationOutput.QNAME))
.withChild(ImmutableNodes.leafNode(DEVICE_NOTIFICATION_STREAM_PATH,
baseUrl + notificationListenerAdapter.getStreamName() + "?"
+ RestconfStreamsConstants.NOTIFICATION_TYPE + "=" + RestconfStreamsConstants.DEVICE))
- .build();
+ .build()));
}
/**
.orElseGet(() -> Response.noContent().build());
}
});
-
}
private RestconfFuture<Optional<ContainerNode>> hackInvokeRpc(final DatabindContext localDatabind,
if (mountPoint == null) {
// Hacked-up integration of streams
if (CreateDataChangeEventSubscription.QNAME.equals(type)) {
- return RestconfFuture.of(Optional.of(CreateStreamUtil.createDataChangeNotifiStream(
- streamUtils.listenersBroker(), input, localDatabind.modelContext())));
+ return CreateStreamUtil.createDataChangeNotifiStream(streamUtils.listenersBroker(), input,
+ localDatabind.modelContext());
} else if (CreateNotificationStream.QNAME.equals(type)) {
- return RestconfFuture.of(Optional.of(CreateStreamUtil.createNotificationStream(
- streamUtils.listenersBroker(), input, localDatabind.modelContext())));
+ return CreateStreamUtil.createNotificationStream(streamUtils.listenersBroker(), input,
+ localDatabind.modelContext());
} else if (SubscribeDeviceNotification.QNAME.equals(type)) {
- final var baseUrl = streamUtils.prepareUriByStreamName(uriInfo, "").toString();
- return RestconfFuture.of(Optional.of(CreateStreamUtil.createDeviceNotificationListener(baseUrl, input,
- streamUtils, mountPointService, listenersBroker)));
+ return CreateStreamUtil.createDeviceNotificationListener(listenersBroker, input,
+ streamUtils.prepareUriByStreamName(uriInfo, "").toString(), mountPointService);
}
}