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%2FControllerContext.xtend;h=9a61b43df51467dbe76e40a6f10709e60089e4a0;hb=065ef4acddbae75329e75562c533120d2d615efe;hp=61237f01a16933ef742041c787874ec9ee8fc957;hpb=d71e327e51db32e967f7ebcb186e148f37f28117;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index 61237f01a1..9a61b43df5 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -10,7 +10,7 @@ import java.util.HashMap import java.util.List import java.util.Map import java.util.concurrent.ConcurrentHashMap -import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener +import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener import org.opendaylight.controller.sal.core.api.mount.MountService import org.opendaylight.controller.sal.rest.impl.RestUtil import org.opendaylight.controller.sal.rest.impl.RestconfProvider @@ -45,11 +45,11 @@ class ControllerContext implements SchemaServiceListener { val static NULL_VALUE = "null" val static MOUNT_MODULE = "yang-ext" val static MOUNT_NODE = "mount" - val static MOUNT = "yang-ext:mount" + public val static MOUNT = "yang-ext:mount" @Property var SchemaContext globalSchema; - + @Property var MountService mountService; @@ -104,7 +104,7 @@ class ControllerContext implements SchemaServiceListener { val modules = schema.modules.filter[m|m.name == moduleName] return modules.filterLatestModule } - + private def filterLatestModule(Iterable modules) { var latestModule = modules.head for (module : modules) { @@ -114,25 +114,26 @@ class ControllerContext implements SchemaServiceListener { } return latestModule } - + def findModuleByName(String moduleName) { checkPreconditions checkArgument(moduleName !== null && !moduleName.empty) return globalSchema.getLatestModule(moduleName) } - + def findModuleByName(MountInstance mountPoint, String moduleName) { checkArgument(moduleName !== null && mountPoint !== null) val mountPointSchema = mountPoint.schemaContext; return mountPointSchema?.getLatestModule(moduleName); } - + def findModuleByNamespace(URI namespace) { checkPreconditions + checkArgument(namespace !== null) val moduleSchemas = globalSchema.findModuleByNamespace(namespace) return moduleSchemas?.filterLatestModule } - + def findModuleByNamespace(MountInstance mountPoint, URI namespace) { checkArgument(namespace !== null && mountPoint !== null) val mountPointSchema = mountPoint.schemaContext; @@ -170,29 +171,37 @@ class ControllerContext implements SchemaServiceListener { def findModuleNameByNamespace(URI namespace) { checkPreconditions - var module = uriToModuleName.get(namespace) - if (module === null) { - val moduleSchemas = globalSchema.findModuleByNamespace(namespace); - if(moduleSchemas === null) return null - var latestModule = moduleSchemas.filterLatestModule - if(latestModule === null) return null - uriToModuleName.put(namespace, latestModule.name) - module = latestModule.name; + var moduleName = uriToModuleName.get(namespace) + if (moduleName === null) { + val module = findModuleByNamespace(namespace) + if (module === null) return null + moduleName = module.name + uriToModuleName.put(namespace, moduleName) } - return module + return moduleName } - def findNamespaceByModuleName(String module) { - var namespace = moduleNameToUri.get(module) + def findModuleNameByNamespace(MountInstance mountPoint, URI namespace) { + val module = mountPoint.findModuleByNamespace(namespace); + return module?.name + } + + def findNamespaceByModuleName(String moduleName) { + var namespace = moduleNameToUri.get(moduleName) if (namespace === null) { - var latestModule = globalSchema.getLatestModule(module) - if(latestModule === null) return null - namespace = latestModule.namespace - uriToModuleName.put(namespace, latestModule.name) + var module = findModuleByName(moduleName) + if(module === null) return null + namespace = module.namespace + uriToModuleName.put(namespace, moduleName) } return namespace } + def findNamespaceByModuleName(MountInstance mountPoint, String moduleName) { + val module = mountPoint.findModuleByName(moduleName) + return module?.namespace + } + def CharSequence toRestconfIdentifier(QName qname) { checkPreconditions var module = uriToModuleName.get(qname.namespace) @@ -254,7 +263,7 @@ class ControllerContext implements SchemaServiceListener { if(object === null) return ""; return URLEncoder.encode(object.toString) } - + private def InstanceIdWithSchemaNode collectPathArguments(InstanceIdentifierBuilder builder, List strings, DataNodeContainer parentNode, MountInstance mountPoint) { checkNotNull(strings) @@ -264,7 +273,7 @@ class ControllerContext implements SchemaServiceListener { if (strings.empty) { return new InstanceIdWithSchemaNode(builder.toInstance, parentNode as DataSchemaNode, mountPoint) } - + val nodeName = strings.head.toNodeName val moduleName = strings.head.toModuleName var DataSchemaNode targetNode = null @@ -274,45 +283,45 @@ class ControllerContext implements SchemaServiceListener { if (mountPoint !== null) { throw new ResponseException(BAD_REQUEST, "Restconf supports just one mount point in URI.") } - + if (mountService === null) { - throw new ResponseException(SERVICE_UNAVAILABLE, "MountService was not found. " + throw new ResponseException(SERVICE_UNAVAILABLE, "MountService was not found. " + "Finding behind mount points does not work." ) } - + val partialPath = builder.toInstance; val mount = mountService.getMountPoint(partialPath) if (mount === null) { LOG.debug("Instance identifier to missing mount point: {}", partialPath) throw new ResponseException(BAD_REQUEST, "Mount point does not exist.") } - + val mountPointSchema = mount.schemaContext; if (mountPointSchema === null) { throw new ResponseException(BAD_REQUEST, "Mount point does not contain any schema with modules.") } - + if (strings.size == 1) { // any data node is not behind mount point return new InstanceIdWithSchemaNode(InstanceIdentifier.builder().toInstance, mountPointSchema, mount) } - + val moduleNameBehindMountPoint = strings.get(1).toModuleName() if (moduleNameBehindMountPoint === null) { throw new ResponseException(BAD_REQUEST, "First node after mount point in URI has to be in format \"moduleName:nodeName\"") } - + val moduleBehindMountPoint = mountPointSchema.getLatestModule(moduleNameBehindMountPoint) if (moduleBehindMountPoint === null) { throw new ResponseException(BAD_REQUEST, "URI has bad format. \"" + moduleName + "\" module does not exist in mount point.") } - + return collectPathArguments(InstanceIdentifier.builder(), strings.subList(1, strings.size), moduleBehindMountPoint, mount); } - + var Module module = null; if (mountPoint === null) { module = globalSchema.getLatestModule(moduleName) @@ -329,8 +338,8 @@ class ControllerContext implements SchemaServiceListener { } targetNode = parentNode.findInstanceDataChild(nodeName, module.namespace) if (targetNode === null) { - throw new ResponseException(BAD_REQUEST, "URI has bad format. Possible reasons:\n" + - "1. \"" + strings.head + "\" was not found in parent data node.\n" + + throw new ResponseException(BAD_REQUEST, "URI has bad format. Possible reasons:\n" + + "1. \"" + strings.head + "\" was not found in parent data node.\n" + "2. \"" + strings.head + "\" is behind mount point. Then it should be in format \"/" + MOUNT + "/" + strings.head + "\".") } } else { // string without module name @@ -339,7 +348,7 @@ class ControllerContext implements SchemaServiceListener { throw new ResponseException(BAD_REQUEST, "URI has bad format. \"" + nodeName + "\" was not found in parent data node.\n") } } - + // Number of consumed elements var consumed = 1; if (targetNode instanceof ListSchemaNode) { @@ -358,7 +367,7 @@ class ControllerContext implements SchemaServiceListener { // key value cannot be NULL if (uriKeyValue.equals(NULL_VALUE)) { - throw new ResponseException(BAD_REQUEST, "URI has bad format. List \"" + listNode.QName.localName + throw new ResponseException(BAD_REQUEST, "URI has bad format. List \"" + listNode.QName.localName + "\" cannot contain \"null\" value as a key." ) } @@ -388,7 +397,7 @@ class ControllerContext implements SchemaServiceListener { } else { potentialNode = container.childNodes.filter[n|n.QName.localName == name && n.QName.namespace == moduleNamespace].head } - + if (potentialNode.instantiatedDataSchema) { return potentialNode; } @@ -401,7 +410,7 @@ class ControllerContext implements SchemaServiceListener { } return null; } - + static def boolean isInstantiatedDataSchema(DataSchemaNode node) { switch node { LeafSchemaNode: return true @@ -417,7 +426,7 @@ class ControllerContext implements SchemaServiceListener { checkArgument(node instanceof LeafSchemaNode); val urlDecoded = URLDecoder.decode(uriValue); val typedef = (node as LeafSchemaNode).type; - + var decoded = TypeDefinitionAwareCodec.from(typedef)?.deserialize(urlDecoded) if(decoded === null) { var baseType = RestUtil.resolveBaseTypeFrom(typedef)