+ override getAvailableStreams(){
+ var Set<String> availableStreams = Notificator.getStreamNames();
+ val List<Node<?>> streamsAsData = new ArrayList
+ val streamSchemaNode = restconfModule.getSchemaNode(RESTCONF_MODULE_DRAFT02_STREAM_LIST_SCHEMA_NODE)
+ for (String streamName:availableStreams){
+ streamsAsData.add(streamName.toStreamCompositeNode(streamSchemaNode))
+ }
+ val streamsSchemaNode = restconfModule.getSchemaNode(RESTCONF_MODULE_DRAFT02_STREAMS_CONTAINER_SCHEMA_NODE)
+ val streamsNode = NodeFactory.createImmutableCompositeNode(streamsSchemaNode.QName, null, streamsAsData)
+ return new StructuredData(streamsNode, streamsSchemaNode, null)
+ }
+ override getModules(String identifier) {
+ var Set<Module> modules = null
+ var MountInstance mountPoint = null
+ if (identifier.contains(ControllerContext.MOUNT)) {
+ mountPoint = identifier.toMountPointIdentifier.mountPoint
+ modules = mountPoint.allModules
+ } else {
+ throw new ResponseException(BAD_REQUEST, "URI has bad format. If modules behind mount point should be showed, URI has to end with " + ControllerContext.MOUNT)
+ }
+ val List<Node<?>> modulesAsData = new ArrayList
+ val moduleSchemaNode = restconfModule.getSchemaNode(RESTCONF_MODULE_DRAFT02_MODULE_LIST_SCHEMA_NODE)
+ for (module : modules) {
+ modulesAsData.add(module.toModuleCompositeNode(moduleSchemaNode))
+ }
+ val modulesSchemaNode = restconfModule.getSchemaNode(RESTCONF_MODULE_DRAFT02_MODULES_CONTAINER_SCHEMA_NODE)
+ val modulesNode = NodeFactory.createImmutableCompositeNode(modulesSchemaNode.QName, null, modulesAsData)
+ return new StructuredData(modulesNode, modulesSchemaNode, mountPoint)
+ }
+
+ override getModule(String identifier) {
+ val moduleNameAndRevision = identifier.moduleNameAndRevision
+ var Module module = null
+ var MountInstance mountPoint = null
+ if (identifier.contains(ControllerContext.MOUNT)) {
+ mountPoint = identifier.toMountPointIdentifier.mountPoint
+ module = mountPoint.findModuleByNameAndRevision(moduleNameAndRevision)
+ } else {
+ module = findModuleByNameAndRevision(moduleNameAndRevision)
+ }
+ if (module === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "Module with name '" + moduleNameAndRevision.localName + "' and revision '" +
+ moduleNameAndRevision.revision + "' was not found.")
+ }
+ val moduleSchemaNode = restconfModule.getSchemaNode(RESTCONF_MODULE_DRAFT02_MODULE_LIST_SCHEMA_NODE)
+ val moduleNode = module.toModuleCompositeNode(moduleSchemaNode)
+ return new StructuredData(moduleNode, moduleSchemaNode, mountPoint)
+ }
+
+ override getOperations() {
+ return operationsFromModulesToStructuredData(allModules,null)
+ }
+
+ override getOperations(String identifier) {
+ var Set<Module> modules = null
+ var MountInstance mountPoint = null
+ if (identifier.contains(ControllerContext.MOUNT)) {
+ mountPoint = identifier.toMountPointIdentifier.mountPoint
+ modules = mountPoint.allModules
+ } else {
+ throw new ResponseException(BAD_REQUEST, "URI has bad format. If operations behind mount point should be showed, URI has to end with " + ControllerContext.MOUNT)
+ }
+ return operationsFromModulesToStructuredData(modules,mountPoint)
+ }
+
+ private def StructuredData operationsFromModulesToStructuredData(Set<Module> modules,MountInstance mountPoint) {
+ val List<Node<?>> operationsAsData = new ArrayList
+ val operationsSchemaNode = restconfModule.getSchemaNode(RESTCONF_MODULE_DRAFT02_OPERATIONS_CONTAINER_SCHEMA_NODE)
+ val fakeOperationsSchemaNode = new ContainerSchemaNodeBuilder(RESTCONF_MODULE_DRAFT02_NAME, 0, operationsSchemaNode.QName, operationsSchemaNode.path)
+ for (module : modules) {
+ for (rpc : module.rpcs) {
+ operationsAsData.add(NodeFactory.createImmutableSimpleNode(rpc.QName, null, null))
+ val fakeRpcSchemaNode = new LeafSchemaNodeBuilder(module.name, 0, rpc.QName, null)
+ fakeRpcSchemaNode.setAugmenting(true)
+ fakeRpcSchemaNode.setType(EmptyType.instance)
+ fakeOperationsSchemaNode.addChildNode(fakeRpcSchemaNode.build)
+ }
+ }
+ val operationsNode = NodeFactory.createImmutableCompositeNode(operationsSchemaNode.QName, null, operationsAsData)
+ return new StructuredData(operationsNode, fakeOperationsSchemaNode.build, mountPoint)
+ }
+
+ private def Module getRestconfModule() {
+ val restconfModule = findModuleByNameAndRevision(
+ QName.create(RESTCONF_MODULE_DRAFT02_NAMESPACE, RESTCONF_MODULE_DRAFT02_REVISION,
+ RESTCONF_MODULE_DRAFT02_NAME))
+ if (restconfModule === null) {
+ throw new ResponseException(INTERNAL_SERVER_ERROR, "Restconf module was not found.")
+ }
+ return restconfModule
+ }
+
+ private def QName getModuleNameAndRevision(String identifier) {
+ val indexOfMountPointFirstLetter = identifier.indexOf(ControllerContext.MOUNT)
+ var moduleNameAndRevision = "";
+ if (indexOfMountPointFirstLetter !== -1) { // module and revision is behind mount point string
+ moduleNameAndRevision = identifier.substring(indexOfMountPointFirstLetter + ControllerContext.MOUNT.length)
+ } else (
+ moduleNameAndRevision = identifier
+ )
+ val pathArgs = Lists.newArrayList(Splitter.on("/").omitEmptyStrings.split(moduleNameAndRevision))
+ if (pathArgs.length < 2) {
+ throw new ResponseException(BAD_REQUEST,
+ "URI has bad format. End of URI should be in format 'moduleName/yyyy-MM-dd'")
+ }
+ try {
+ val moduleName = pathArgs.head
+ val moduleRevision = REVISION_FORMAT.parse(pathArgs.get(1))
+ return QName.create(null, moduleRevision, moduleName)
+ } catch(ParseException e) {
+ throw new ResponseException(BAD_REQUEST, "URI has bad format. It should be 'moduleName/yyyy-MM-dd'")
+ }
+ }
+
+ private def CompositeNode toStreamCompositeNode(String streamName, DataSchemaNode streamSchemaNode) {
+ val List<Node<?>> streamNodeValues = new ArrayList
+ val nameSchemaNode = (streamSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("name").head
+ streamNodeValues.add(NodeFactory.createImmutableSimpleNode(nameSchemaNode.QName, null, streamName))
+
+ val descriptionSchemaNode = (streamSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("description").head
+ streamNodeValues.add(NodeFactory.createImmutableSimpleNode(descriptionSchemaNode.QName, null, "DESCRIPTION_PLACEHOLDER"))
+
+ val replaySupportSchemaNode = (streamSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("replay-support").head
+ streamNodeValues.add(NodeFactory.createImmutableSimpleNode(replaySupportSchemaNode.QName, null, true))
+
+ val replayLogCreationTimeSchemaNode = (streamSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("replay-log-creation-time").head
+ streamNodeValues.add(NodeFactory.createImmutableSimpleNode(replayLogCreationTimeSchemaNode.QName, null, ""))
+
+ val eventsSchemaNode = (streamSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("events").head
+ streamNodeValues.add(NodeFactory.createImmutableSimpleNode(eventsSchemaNode.QName, null, ""))
+
+ return NodeFactory.createImmutableCompositeNode(streamSchemaNode.QName, null, streamNodeValues)
+ }
+ private def CompositeNode toModuleCompositeNode(Module module, DataSchemaNode moduleSchemaNode) {
+ val List<Node<?>> moduleNodeValues = new ArrayList
+ val nameSchemaNode = (moduleSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("name").head
+ moduleNodeValues.add(NodeFactory.createImmutableSimpleNode(nameSchemaNode.QName, null, module.name))
+ val revisionSchemaNode = (moduleSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("revision").head
+ moduleNodeValues.add(NodeFactory.createImmutableSimpleNode(revisionSchemaNode.QName, null, REVISION_FORMAT.format(module.revision)))
+ val namespaceSchemaNode = (moduleSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("namespace").head
+ moduleNodeValues.add(NodeFactory.createImmutableSimpleNode(namespaceSchemaNode.QName, null, module.namespace.toString))
+ val featureSchemaNode = (moduleSchemaNode as DataNodeContainer).findInstanceDataChildrenByName("feature").head
+ for (feature : module.features) {
+ moduleNodeValues.add(NodeFactory.createImmutableSimpleNode(featureSchemaNode.QName, null, feature.QName.localName))
+ }
+ return NodeFactory.createImmutableCompositeNode(moduleSchemaNode.QName, null, moduleNodeValues)
+ }
+
+ private def DataSchemaNode getSchemaNode(Module restconfModule, String schemaNodeName) {
+ val restconfGrouping = restconfModule.groupings.filter[g|g.QName.localName == RESTCONF_MODULE_DRAFT02_RESTCONF_GROUPING_SCHEMA_NODE].head
+ val restconfContainer = restconfGrouping.findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_RESTCONF_CONTAINER_SCHEMA_NODE).head
+ if (schemaNodeName == RESTCONF_MODULE_DRAFT02_OPERATIONS_CONTAINER_SCHEMA_NODE) {
+ return (restconfContainer as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_OPERATIONS_CONTAINER_SCHEMA_NODE).head
+ } else if (schemaNodeName == RESTCONF_MODULE_DRAFT02_STREAMS_CONTAINER_SCHEMA_NODE) {
+ return (restconfContainer as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_STREAMS_CONTAINER_SCHEMA_NODE).head
+ } else if (schemaNodeName == RESTCONF_MODULE_DRAFT02_STREAM_LIST_SCHEMA_NODE) {
+ val modules = (restconfContainer as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_STREAMS_CONTAINER_SCHEMA_NODE).head
+ return (modules as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_STREAM_LIST_SCHEMA_NODE).head
+ }else if (schemaNodeName == RESTCONF_MODULE_DRAFT02_MODULES_CONTAINER_SCHEMA_NODE) {
+ return (restconfContainer as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_MODULES_CONTAINER_SCHEMA_NODE).head
+ } else if (schemaNodeName == RESTCONF_MODULE_DRAFT02_MODULE_LIST_SCHEMA_NODE) {
+ val modules = (restconfContainer as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_MODULES_CONTAINER_SCHEMA_NODE).head
+ return (modules as DataNodeContainer).findInstanceDataChildrenByName(RESTCONF_MODULE_DRAFT02_MODULE_LIST_SCHEMA_NODE).head
+ }
+ return null