X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FRestconfImpl.xtend;h=b134f9bf6b8acefb82974a2e0203da22e4063a97;hp=5ad6f1eea88d1ec33fc1cc67c155c601d7f30880;hb=b29204146ca6957b5f968e07d9e7e2052ba70ef1;hpb=f35e990600d56b1d524cc9d9cfc44b725199b1a6 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend index 5ad6f1eea8..b134f9bf6b 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend @@ -30,10 +30,12 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition import static javax.ws.rs.core.Response.Status.* +import org.opendaylight.yangtools.yang.model.api.SchemaContext class RestconfImpl implements RestconfService { val static RestconfImpl INSTANCE = new RestconfImpl + val static MOUNT_POINT_MODULE_NAME = "ietf-netconf" @Property BrokerFacade broker @@ -92,7 +94,7 @@ class RestconfImpl implements RestconfService { if (rpcResult.result === null) { return null } - return new StructuredData(rpcResult.result, rpc.output) + return new StructuredData(rpcResult.result, rpc.output, null) } override readData(String identifier) { @@ -103,7 +105,7 @@ class RestconfImpl implements RestconfService { } else { data = broker.readOperationalData(iiWithData.getInstanceIdentifier); } - return new StructuredData(data, iiWithData.schemaNode) + return new StructuredData(data, iiWithData.schemaNode, iiWithData.mountPoint) } override readConfigurationData(String identifier) { @@ -114,7 +116,7 @@ class RestconfImpl implements RestconfService { } else { data = broker.readConfigurationData(iiWithData.getInstanceIdentifier); } - return new StructuredData(data, iiWithData.schemaNode) + return new StructuredData(data, iiWithData.schemaNode, iiWithData.mountPoint) } override readOperationalData(String identifier) { @@ -125,7 +127,7 @@ class RestconfImpl implements RestconfService { } else { data = broker.readOperationalData(iiWithData.getInstanceIdentifier); } - return new StructuredData(data, iiWithData.schemaNode) + return new StructuredData(data, iiWithData.schemaNode, iiWithData.mountPoint) } override updateConfigurationDataLegacy(String identifier, CompositeNode payload) { @@ -157,16 +159,30 @@ class RestconfImpl implements RestconfService { throw new ResponseException(BAD_REQUEST, "Data has bad format. Root element node must have namespace (XML format) or module name(JSON format)"); } - val uncompleteInstIdWithData = identifier.toInstanceIdentifier - val schemaNode = uncompleteInstIdWithData.mountPoint.findModule(payload)?.getSchemaChildNode(payload) - val value = normalizeNode(payload, schemaNode, uncompleteInstIdWithData.mountPoint) - val completeInstIdWithData = uncompleteInstIdWithData.addLastIdentifierFromData(value, schemaNode) + var InstanceIdWithSchemaNode iiWithData; + var CompositeNode value; + if (payload.representsMountPointRootData) { // payload represents mount point data and URI represents path to the mount point + if (identifier.endsWithMountPoint) { + throw new ResponseException(BAD_REQUEST, + "URI has bad format. URI should be without \"" + ControllerContext.MOUNT + "\" for POST operation."); + } + val completIdentifier = identifier.addMountPointIdentifier + iiWithData = completIdentifier.toInstanceIdentifier + value = normalizeNode(payload, iiWithData.schemaNode, iiWithData.mountPoint) + } else { + val uncompleteInstIdWithData = identifier.toInstanceIdentifier + val parentSchema = uncompleteInstIdWithData.schemaNode as DataNodeContainer + val namespace = uncompleteInstIdWithData.mountPoint.findModule(payload)?.namespace + val schemaNode = parentSchema.findInstanceDataChild(payload.name, namespace) + value = normalizeNode(payload, schemaNode, uncompleteInstIdWithData.mountPoint) + iiWithData = uncompleteInstIdWithData.addLastIdentifierFromData(value, schemaNode) + } var RpcResult status = null - if (completeInstIdWithData.mountPoint !== null) { - status = broker.commitConfigurationDataPostBehindMountPoint(completeInstIdWithData.mountPoint, - completeInstIdWithData.instanceIdentifier, value)?.get(); + if (iiWithData.mountPoint !== null) { + status = broker.commitConfigurationDataPostBehindMountPoint(iiWithData.mountPoint, + iiWithData.instanceIdentifier, value)?.get(); } else { - status = broker.commitConfigurationDataPost(completeInstIdWithData.instanceIdentifier, value)?.get(); + status = broker.commitConfigurationDataPost(iiWithData.instanceIdentifier, value)?.get(); } if (status === null) { return Response.status(ACCEPTED).build @@ -182,7 +198,12 @@ class RestconfImpl implements RestconfService { throw new ResponseException(BAD_REQUEST, "Data has bad format. Root element node must have namespace (XML format) or module name(JSON format)"); } - val schemaNode = findModule(null, payload)?.getSchemaChildNode(payload) + val module = findModule(null, payload) + if (module === null) { + throw new ResponseException(BAD_REQUEST, + "Data has bad format. Root element node has incorrect namespace (XML format) or module name(JSON format)"); + } + val schemaNode = module.findInstanceDataChild(payload.name, module.namespace) val value = normalizeNode(payload, schemaNode, null) val iiWithData = addLastIdentifierFromData(null, value, schemaNode) var RpcResult status = null @@ -223,6 +244,14 @@ class RestconfImpl implements RestconfService { private def dispatch URI namespace(CompositeNodeWrapper data) { return data.namespace } + + private def dispatch String localName(CompositeNode data) { + return data.nodeType.localName + } + + private def dispatch String localName(CompositeNodeWrapper data) { + return data.localName + } private def dispatch Module findModule(MountInstance mountPoint, CompositeNode data) { if (mountPoint !== null) { @@ -249,14 +278,14 @@ class RestconfImpl implements RestconfService { return module } - private def dispatch DataSchemaNode getSchemaChildNode(DataNodeContainer parentSchemaNode, CompositeNode data) { - return parentSchemaNode?.getDataChildByName(data.nodeType.localName) + private def dispatch getName(CompositeNode data) { + return data.nodeType.localName } - private def dispatch DataSchemaNode getSchemaChildNode(DataNodeContainer parentSchemaNode, CompositeNodeWrapper data) { - return parentSchemaNode?.getDataChildByName(data.localName) + private def dispatch getName(CompositeNodeWrapper data) { + return data.localName } - + private def InstanceIdWithSchemaNode addLastIdentifierFromData(InstanceIdWithSchemaNode identifierWithSchemaNode, CompositeNode data, DataSchemaNode schemaOfData) { val iiOriginal = identifierWithSchemaNode?.instanceIdentifier @@ -288,7 +317,23 @@ class RestconfImpl implements RestconfService { } return keyValues } - + + private def endsWithMountPoint(String identifier) { + return (identifier.endsWith(ControllerContext.MOUNT) || identifier.endsWith(ControllerContext.MOUNT + "/")) + } + + private def representsMountPointRootData(CompositeNode data) { + return ((data.namespace == SchemaContext.NAME.namespace || data.namespace == MOUNT_POINT_MODULE_NAME) && + data.localName == SchemaContext.NAME.localName) + } + + private def addMountPointIdentifier(String identifier) { + if (identifier.endsWith("/")) { + return identifier + ControllerContext.MOUNT + } + return identifier + "/" + ControllerContext.MOUNT + } + private def CompositeNode normalizeNode(CompositeNode node, DataSchemaNode schema, MountInstance mountPoint) { if (schema === null) { throw new ResponseException(INTERNAL_SERVER_ERROR, "Data schema node was not found for " + node?.nodeType?.localName) @@ -304,7 +349,7 @@ class RestconfImpl implements RestconfService { } return node } - + private def void normalizeNode(NodeWrapper nodeBuilder, DataSchemaNode schema, QName previousAugment, MountInstance mountPoint) { if (schema === null) { @@ -322,10 +367,10 @@ class RestconfImpl implements RestconfService { if (mountPoint === null) { moduleName = controllerContext.findModuleNameByNamespace(validQName.namespace); } else { - moduleName = mountPoint.findModuleByNamespace(validQName.namespace)?.name + moduleName = controllerContext.findModuleNameByNamespace(mountPoint, validQName.namespace) } if (nodeBuilder.namespace === null || nodeBuilder.namespace == validQName.namespace || - nodeBuilder.namespace.toString == moduleName) { + nodeBuilder.namespace.toString == moduleName || nodeBuilder.namespace == MOUNT_POINT_MODULE_NAME) { nodeBuilder.qname = validQName } else { throw new ResponseException(BAD_REQUEST, @@ -367,7 +412,7 @@ class RestconfImpl implements RestconfService { } // else value is instance of ValuesDTO } - val outputValue = RestCodec.from(schema.typeDefinition)?.deserialize(inputValue); + val outputValue = RestCodec.from(schema.typeDefinition, mountPoint)?.deserialize(inputValue); simpleNode.setValue(outputValue) } else if (nodeBuilder instanceof EmptyNodeWrapper) { val emptyNodeBuilder = nodeBuilder as EmptyNodeWrapper