import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionResult;
import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
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.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
import org.opendaylight.yangtools.concepts.Immutable;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss");
private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
- private final SubscribeToStreamUtil streamUtils;
-
private final SchemaContextHandler schemaContextHandler;
- private final TransactionChainHandler transactionChainHandler;
- private final DOMMountPointServiceHandler mountPointServiceHandler;
+ private final MdsalRestconfStrategy restconfStrategy;
+ private final DOMMountPointService mountPointService;
+ private final SubscribeToStreamUtil streamUtils;
private final DOMActionService actionService;
public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler,
- final TransactionChainHandler transactionChainHandler,
- final DOMMountPointServiceHandler mountPointServiceHandler,
+ final DOMDataBroker dataBroker, final DOMMountPointService mountPointService,
final RestconfStreamsSubscriptionService delegRestconfSubscrService,
- final DOMActionService actionService,
- final Configuration configuration) {
- this.actionService = requireNonNull(actionService);
+ final DOMActionService actionService, final Configuration configuration) {
this.schemaContextHandler = requireNonNull(schemaContextHandler);
- this.transactionChainHandler = requireNonNull(transactionChainHandler);
- this.mountPointServiceHandler = requireNonNull(mountPointServiceHandler);
+ this.restconfStrategy = new MdsalRestconfStrategy(dataBroker);
+ this.mountPointService = requireNonNull(mountPointService);
this.delegRestconfSubscrService = requireNonNull(delegRestconfSubscrService);
+ this.actionService = requireNonNull(actionService);
streamUtils = configuration.isUseSSE() ? SubscribeToStreamUtil.serverSentEvents()
: SubscribeToStreamUtil.webSockets();
}
public Response readData(final String identifier, final UriInfo uriInfo) {
final EffectiveModelContext schemaContextRef = this.schemaContextHandler.get();
final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(
- identifier, schemaContextRef, Optional.of(this.mountPointServiceHandler.get()));
+ identifier, schemaContextRef, Optional.of(mountPointService));
final WriterParameters parameters = ReadDataTransactionUtil.parseUriParameters(instanceIdentifier, uriInfo);
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
- final NormalizedNode<?, ?> node;
+ final NormalizedNode node;
if (parameters.getFieldPaths() != null && !parameters.getFieldPaths().isEmpty()) {
node = ReadDataTransactionUtil.readData(parameters.getContent(), instanceIdentifier.getInstanceIdentifier(),
strategy, parameters.getWithDefault(), schemaContextRef, parameters.getFieldPaths());
}
if (identifier != null && identifier.contains(STREAM_PATH) && identifier.contains(STREAM_ACCESS_PATH_PART)
&& identifier.contains(STREAM_LOCATION_PATH_PART)) {
- final String value = (String) node.getValue();
+ final String value = (String) node.body();
final String streamName = value.substring(value.indexOf(NOTIFICATION_STREAM + '/'));
this.delegRestconfSubscrService.subscribeToStream(streamName, uriInfo);
}
if (parameters.getContent().equals(RestconfDataServiceConstant.ReadData.ALL)
|| parameters.getContent().equals(RestconfDataServiceConstant.ReadData.CONFIG)) {
- final QName type = node.getNodeType();
+ final QName type = node.getIdentifier().getNodeType();
return Response.status(200)
.entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
.header("ETag", '"' + type.getModule().getRevision().map(Revision::toString).orElse(null)
* @param uriInfo uri info
* @return {@link NormalizedNode}
*/
- private NormalizedNode<?, ?> readData(final String identifier, final String content,
+ private NormalizedNode readData(final String identifier, final String content,
final YangInstanceIdentifier path, final RestconfStrategy strategy, final String withDefa,
final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
if (identifier != null && identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) {
listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null,
listener.getOutputType(), uri);
- final String name = listener.getSchemaPath().lastNodeIdentifier().getLocalName();
transaction.merge(LogicalDatastoreType.OPERATIONAL,
- IdentifierCodec.deserialize(Rfc8040.MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name, schemaContext),
- mapToStreams);
+ Rfc8040.restconfStateStreamPath(mapToStreams.getIdentifier()), mapToStreams);
}
@Override
@Override
public Response deleteData(final String identifier) {
final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(
- identifier, this.schemaContextHandler.get(), Optional.of(this.mountPointServiceHandler.get()));
+ identifier, this.schemaContextHandler.get(), Optional.of(mountPointService));
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
// FIXME: why is this synchronized?
public synchronized RestconfStrategy getRestconfStrategy(final DOMMountPoint mountPoint) {
if (mountPoint == null) {
- return new MdsalRestconfStrategy(transactionChainHandler);
+ return restconfStrategy;
}
return RestconfStrategy.forMountPoint(mountPoint).orElseThrow(() -> {
final Absolute schemaPath = Absolute.of(ImmutableList.copyOf(context.getSchemaNode().getPath()
.getPathFromRoot()));
final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
- final NormalizedNode<?, ?> data = payload.getData();
+ final NormalizedNode data = payload.getData();
- if (yangIIdContext.isEmpty() && !RestconfDataServiceConstant.NETCONF_BASE_QNAME.equals(data.getNodeType())) {
+ if (yangIIdContext.isEmpty()
+ && !RestconfDataServiceConstant.NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument",
ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
}
}
- if (resultData != null && resultData.getValue().isEmpty()) {
+ if (resultData != null && resultData.isEmpty()) {
throw new WebApplicationException(Response.Status.NO_CONTENT);
}