X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FRestconfImpl.java;h=c82cf8e0bc5050b682d9b99896f786f68381cb58;hb=6561b5cd3b3d2d8bcb26a6c4f3b8efa52b63523d;hp=a875615172228cb629c52aeabaf0dceefa9c71b9;hpb=365c9751fb9b8b5464e2576c417e97be64732def;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java index a875615172..c82cf8e0bc 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java @@ -249,50 +249,68 @@ public class RestconfImpl implements RestconfService { mountPoint, schemaContext), moduleContainerBuilder.build()); } - @Override - public StructuredData getAvailableStreams(final UriInfo uriInfo) { - final Set availableStreams = Notificator.getStreamNames(); - - final List> streamsAsData = new ArrayList>(); - final Module restconfModule = getRestconfModule(); - final DataSchemaNode streamSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, - Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); - for (final String streamName : availableStreams) { - streamsAsData.add(toStreamCompositeNode(streamName, streamSchemaNode)); - } - - final DataSchemaNode streamsSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, - Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); - final QName qName = streamsSchemaNode.getQName(); - final CompositeNode streamsNode = NodeFactory.createImmutableCompositeNode(qName, null, streamsAsData); - return new StructuredData(streamsNode, streamsSchemaNode, null, parsePrettyPrintParameter(uriInfo)); - } - - @Override - public StructuredData getModule(final String identifier, final UriInfo uriInfo) { + public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) { + Preconditions.checkNotNull(identifier); final QName moduleNameAndRevision = getModuleNameAndRevision(identifier); Module module = null; DOMMountPoint mountPoint = null; + final SchemaContext schemaContext; if (identifier.contains(ControllerContext.MOUNT)) { final InstanceIdentifierContext mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier); mountPoint = mountPointIdentifier.getMountPoint(); module = controllerContext.findModuleByNameAndRevision(mountPoint, moduleNameAndRevision); + schemaContext = mountPoint.getSchemaContext(); } else { module = controllerContext.findModuleByNameAndRevision(moduleNameAndRevision); + schemaContext = controllerContext.getGlobalSchema(); } if (module == null) { - throw new RestconfDocumentedException("Module with name '" + moduleNameAndRevision.getLocalName() - + "' and revision '" + moduleNameAndRevision.getRevision() + "' was not found.", - ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); + final String errMsg = "Module with name '" + moduleNameAndRevision.getLocalName() + + "' and revision '" + moduleNameAndRevision.getRevision() + "' was not found."; + throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } final Module restconfModule = getRestconfModule(); - final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, - Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE); - final CompositeNode moduleNode = toModuleCompositeNode(module, moduleSchemaNode); - return new StructuredData(moduleNode, moduleSchemaNode, mountPoint, parsePrettyPrintParameter(uriInfo)); + final Set modules = Collections.singleton(module); + final MapNode moduleMap = makeModuleMapNode(modules); + + final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode( + restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE); + Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode); + + return new NormalizedNodeContext(new InstanceIdentifierContext(null, moduleSchemaNode, mountPoint, + schemaContext), moduleMap); + } + + @Override + public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) { + final SchemaContext schemaContext = controllerContext.getGlobalSchema(); + final Set availableStreams = Notificator.getStreamNames(); + final Module restconfModule = getRestconfModule(); + final DataSchemaNode streamSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, + Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); + Preconditions.checkState(streamSchemaNode instanceof ListSchemaNode); + + final CollectionNodeBuilder listStreamsBuilder = Builders + .mapBuilder((ListSchemaNode) streamSchemaNode); + + for (final String streamName : availableStreams) { + listStreamsBuilder.withChild(toStreamEntryNode(streamName, streamSchemaNode)); + } + + final DataSchemaNode streamsContainerSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode( + restconfModule, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); + Preconditions.checkState(streamsContainerSchemaNode instanceof ContainerSchemaNode); + + final DataContainerNodeAttrBuilder streamsContainerBuilder = + Builders.containerBuilder((ContainerSchemaNode) streamsContainerSchemaNode); + streamsContainerBuilder.withChild(listStreamsBuilder.build()); + + + return new NormalizedNodeContext(new InstanceIdentifierContext(null, streamsContainerSchemaNode, null, + schemaContext), streamsContainerBuilder.build()); } @Override @@ -1655,4 +1673,49 @@ public class RestconfImpl implements RestconfService { Preconditions.checkArgument(moduleSchemaNode instanceof ListSchemaNode, "moduleSchemaNode has to be of type ListSchemaNode"); final ListSchemaNode listModuleSchemaNode = (ListSchemaNode) moduleSchemaNode; final DataContainerNodeAttrBuilder moduleNodeValues = Builders .mapEntryBuilder(listModuleSchemaNode); List instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( (listModuleSchemaNode), "name"); final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); Preconditions.checkState(nameSchemaNode instanceof LeafSchemaNode); moduleNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) nameSchemaNode).withValue(module.getName()) .build()); instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( (listModuleSchemaNode), "revision"); final DataSchemaNode revisionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); Preconditions.checkState(revisionSchemaNode instanceof LeafSchemaNode); final String revision = REVISION_FORMAT.format(module.getRevision()); moduleNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) revisionSchemaNode).withValue(revision) .build()); instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( (listModuleSchemaNode), "namespace"); final DataSchemaNode namespaceSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); Preconditions.checkState(namespaceSchemaNode instanceof LeafSchemaNode); moduleNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) namespaceSchemaNode) .withValue(module.getNamespace().toString()).build()); instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( (listModuleSchemaNode), "feature"); final DataSchemaNode featureSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); Preconditions.checkState(featureSchemaNode instanceof LeafListSchemaNode); final ListNodeBuilder> featuresBuilder = Builders .leafSetBuilder((LeafListSchemaNode) featureSchemaNode); for (final FeatureDefinition feature : module.getFeatures()) { featuresBuilder.withChild(Builders.leafSetEntryBuilder(((LeafListSchemaNode) featureSchemaNode)) .withValue(feature.getQName().getLocalName()).build()); } moduleNodeValues.withChild(featuresBuilder.build()); return moduleNodeValues.build(); } + + protected MapEntryNode toStreamEntryNode(final String streamName, final DataSchemaNode streamSchemaNode) { + Preconditions.checkArgument(streamSchemaNode instanceof ListSchemaNode, + "streamSchemaNode has to be of type ListSchemaNode"); + final ListSchemaNode listStreamSchemaNode = (ListSchemaNode) streamSchemaNode; + final DataContainerNodeAttrBuilder streamNodeValues = Builders + .mapEntryBuilder(listStreamSchemaNode); + + List instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( + (listStreamSchemaNode), "name"); + final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + Preconditions.checkState(nameSchemaNode instanceof LeafSchemaNode); + streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) nameSchemaNode).withValue(streamName) + .build()); + + instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( + (listStreamSchemaNode), "description"); + final DataSchemaNode descriptionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + Preconditions.checkState(descriptionSchemaNode instanceof LeafSchemaNode); + streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) nameSchemaNode) + .withValue("DESCRIPTION_PLACEHOLDER").build()); + + instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( + (listStreamSchemaNode), "replay-support"); + final DataSchemaNode replaySupportSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + Preconditions.checkState(replaySupportSchemaNode instanceof LeafSchemaNode); + streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) replaySupportSchemaNode) + .withValue(Boolean.valueOf(true)).build()); + + instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( + (listStreamSchemaNode), "replay-log-creation-time"); + final DataSchemaNode replayLogCreationTimeSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + Preconditions.checkState(replayLogCreationTimeSchemaNode instanceof LeafSchemaNode); + streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) replayLogCreationTimeSchemaNode) + .withValue("").build()); + + instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName( + (listStreamSchemaNode), "events"); + final DataSchemaNode eventsSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + Preconditions.checkState(eventsSchemaNode instanceof LeafSchemaNode); + streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) eventsSchemaNode) + .withValue("").build()); + + return streamNodeValues.build(); + } }