import java.lang.reflect.Type;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
+import java.util.List;
import java.util.Map.Entry;
+import java.util.stream.Collectors;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.util.NetconfUtil;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.xml.sax.SAXException;
/**
private static void writeNormalizedNode(final JsonWriter jsonWriter,
final InstanceIdentifierContext<SchemaNode> context, NormalizedNode data,
final @Nullable Integer depth) throws IOException {
- SchemaPath path = context.getSchemaNode().getPath();
final RestconfNormalizedNodeWriter nnWriter;
- if (SchemaPath.ROOT.equals(path)) {
+ if (context.getSchemaNode() instanceof SchemaContext) {
/*
* Creates writer without initialNs and we write children of root data container
* which is not visible in restconf
*/
- nnWriter = createNormalizedNodeWriter(context, path, jsonWriter, depth);
+ nnWriter = createNormalizedNodeWriter(context, SchemaPath.ROOT, jsonWriter, depth);
if (data instanceof ContainerNode) {
- writeChildren(nnWriter,(ContainerNode) data);
+ writeChildren(nnWriter, (ContainerNode) data);
} else if (data instanceof DOMSourceAnyxmlNode) {
try {
writeChildren(nnWriter,
(ContainerNode) NetconfUtil.transformDOMSourceToNormalizedNode(
- context.getSchemaContext(), ((DOMSourceAnyxmlNode)data).body()).getResult());
+ context.getSchemaContext(), ((DOMSourceAnyxmlNode) data).body()).getResult());
} catch (XMLStreamException | URISyntaxException | SAXException e) {
throw new IOException("Cannot write anyxml.", e);
}
* RpcDefinition is not supported as initial codec in JSONStreamWriter,
* so we need to emit initial output declaratation..
*/
- path = ((RpcDefinition) context.getSchemaNode()).getOutput().getPath();
+ final RpcDefinition rpc = (RpcDefinition) context.getSchemaNode();
+ final SchemaPath path = SchemaPath.of(Absolute.of(rpc.getQName(), rpc.getOutput().getQName()));
nnWriter = createNormalizedNodeWriter(context, path, jsonWriter, depth);
jsonWriter.name("output");
jsonWriter.beginObject();
writeChildren(nnWriter, (ContainerNode) data);
jsonWriter.endObject();
} else {
- path = path.getParent();
+ final List<QName> qnames = context.getInstanceIdentifier().getPathArguments().stream()
+ .filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates))
+ .filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier))
+ .map(PathArgument::getNodeType)
+ .collect(Collectors.toList());
+ final SchemaPath path = SchemaPath.of(Absolute.of(qnames)).getParent();
if (data instanceof MapEntryNode) {
data = ImmutableNodes.mapNodeBuilder(data.getIdentifier().getNodeType())
- .withChild((MapEntryNode) data)
- .build();
+ .withChild((MapEntryNode) data)
+ .build();
}
nnWriter = createNormalizedNodeWriter(context, path, jsonWriter, depth);
nnWriter.write(data);
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import static org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule.MODULES_CONTAINER_QNAME;
+import static org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule.MODULE_LIST_QNAME;
+import static org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule.STREAMS_CONTAINER_QNAME;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicates;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.netconf.sal.rest.api.Draft02;
+import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
.appendOffset("+HH:MM", "Z").toFormatter();
+ private static final YangInstanceIdentifier MODULES = YangInstanceIdentifier.builder()
+ .node(QName.create(RestConfModule.IETF_RESTCONF_QNAME, "restconf"))
+ .node(QName.create(RestConfModule.IETF_RESTCONF_QNAME, "restconf"))
+ .node(MODULES_CONTAINER_QNAME)
+ .build();
+ private static final YangInstanceIdentifier MODULE = YangInstanceIdentifier.builder()
+ .node(QName.create(RestConfModule.IETF_RESTCONF_QNAME, "restconf"))
+ .node(QName.create(RestConfModule.IETF_RESTCONF_QNAME, "restconf"))
+ .node(MODULES_CONTAINER_QNAME)
+ .node(MODULE_LIST_QNAME)
+ .build();
+ private static final YangInstanceIdentifier STREAMS = YangInstanceIdentifier.builder()
+ .node(QName.create(RestConfModule.IETF_RESTCONF_QNAME, "restconf"))
+ .node(QName.create(RestConfModule.IETF_RESTCONF_QNAME, "restconf"))
+ .node(STREAMS_CONTAINER_QNAME)
+ .build();
+
private final BrokerFacade broker;
private final ControllerContext controllerContext;
final Module restconfModule = getRestconfModule();
final DataSchemaNode modulesSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
- restconfModule, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+ restconfModule, RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
checkState(modulesSchemaNode instanceof ContainerSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> moduleContainerBuilder =
SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) modulesSchemaNode);
moduleContainerBuilder.withChild(allModuleMap);
- return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, modulesSchemaNode, null, schemaContext),
- moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(MODULES, modulesSchemaNode, null,
+ schemaContext), moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
/**
final Module restconfModule = getRestconfModule();
final DataSchemaNode modulesSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
- restconfModule, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+ restconfModule, RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
checkState(modulesSchemaNode instanceof ContainerSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> moduleContainerBuilder =
moduleContainerBuilder.withChild(mountPointModulesMap);
return new NormalizedNodeContext(
- new InstanceIdentifierContext<>(null, modulesSchemaNode, mountPoint,
+ new InstanceIdentifierContext<>(MODULES, modulesSchemaNode, mountPoint,
controllerContext.getGlobalSchema()),
moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
final MapNode moduleMap = makeModuleMapNode(modules);
final DataSchemaNode moduleSchemaNode = controllerContext
- .getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
+ .getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.MODULE_LIST_SCHEMA_NODE);
checkState(moduleSchemaNode instanceof ListSchemaNode);
return new NormalizedNodeContext(
- new InstanceIdentifierContext<>(null, moduleSchemaNode, mountPoint, schemaContext), moduleMap,
+ new InstanceIdentifierContext<>(MODULE, moduleSchemaNode, mountPoint, schemaContext), moduleMap,
QueryParametersParser.parseWriterParameters(uriInfo));
}
final Set<String> availableStreams = Notificator.getStreamNames();
final Module restconfModule = getRestconfModule();
final DataSchemaNode streamSchemaNode = controllerContext
- .getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
+ .getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.STREAM_LIST_SCHEMA_NODE);
checkState(streamSchemaNode instanceof ListSchemaNode);
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listStreamsBuilder =
}
final DataSchemaNode streamsContainerSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
- restconfModule, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+ restconfModule, RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
checkState(streamsContainerSchemaNode instanceof ContainerSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> streamsContainerBuilder =
streamsContainerBuilder.withChild(listStreamsBuilder.build());
return new NormalizedNodeContext(
- new InstanceIdentifierContext<>(null, streamsContainerSchemaNode, null, schemaContext),
+ new InstanceIdentifierContext<>(STREAMS, streamsContainerSchemaNode, null, schemaContext),
streamsContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
requireNonNull(modules);
final Module restconfModule = getRestconfModule();
final DataSchemaNode moduleSchemaNode = controllerContext
- .getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
+ .getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.MODULE_LIST_SCHEMA_NODE);
checkState(moduleSchemaNode instanceof ListSchemaNode);
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listModuleBuilder =