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=20e27c8a143e41e3630fc3943278405d7c8becc9;hb=ddaf5bf1e47671e5e9ddf65e9456b7c582fb381e;hp=e9a87090a7d0bcc317c66f413f289e9248b09680;hpb=88216bef92ecb0d4df4345ed823faf1777966256;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 e9a87090a7..20e27c8a14 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 @@ -685,26 +685,75 @@ public class RestconfImpl implements RestconfService { } @Override - public StructuredData invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) { + public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) { if (StringUtils.isNotBlank(noPayload)) { throw new RestconfDocumentedException("Content must be empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } - final CompositeNode payload = null; - final RpcExecutor rpc = resolveIdentifierInInvokeRpc(identifier); - final QName rpcName = rpc.getRpcDefinition().getQName(); - final URI rpcNamespace = rpcName.getNamespace(); - if (Objects.equal(rpcNamespace.toString(), SAL_REMOTE_NAMESPACE) - && Objects.equal(rpcName.getLocalName(), SAL_REMOTE_RPC_SUBSRCIBE)) { - return invokeSalRemoteRpcSubscribeRPC(payload, rpc.getRpcDefinition(), parsePrettyPrintParameter(uriInfo)); + + String identifierEncoded = null; + DOMMountPoint mountPoint = null; + final SchemaContext schemaContext; + if (identifier.contains(ControllerContext.MOUNT)) { + // mounted RPC call - look up mount instance. + final InstanceIdentifierContext mountPointId = controllerContext.toMountPointIdentifier(identifier); + mountPoint = mountPointId.getMountPoint(); + schemaContext = mountPoint.getSchemaContext(); + final int startOfRemoteRpcName = identifier.lastIndexOf(ControllerContext.MOUNT) + + ControllerContext.MOUNT.length() + 1; + final String remoteRpcName = identifier.substring(startOfRemoteRpcName); + identifierEncoded = remoteRpcName; + + } else if (identifier.indexOf("/") != CHAR_NOT_FOUND) { + final String slashErrorMsg = String.format("Identifier %n%s%ncan\'t contain slash " + + "character (/).%nIf slash is part of identifier name then use %%2F placeholder.", identifier); + throw new RestconfDocumentedException(slashErrorMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); + } else { + identifierEncoded = identifier; + schemaContext = controllerContext.getGlobalSchema(); } - validateInput(rpc.getRpcDefinition().getInput(), payload); + final String identifierDecoded = controllerContext.urlPathArgDecode(identifierEncoded); - return callRpc(rpc, payload, parsePrettyPrintParameter(uriInfo)); - } + RpcDefinition rpc = null; + if (mountPoint == null) { + rpc = controllerContext.getRpcDefinition(identifierDecoded); + } else { + rpc = findRpc(mountPoint.getSchemaContext(), identifierDecoded); + } - private void resolveInvokeRpc(final String identifier, final DOMMountPoint mountPoint) { + if (rpc == null) { + throw new RestconfDocumentedException("RPC does not exist.", ErrorType.RPC, ErrorTag.UNKNOWN_ELEMENT); + } + + if (rpc.getInput() != null) { + // FIXME : find a correct Error from specification + throw new IllegalStateException("RPC " + rpc + " needs input value!"); + } + final CheckedFuture response; + if (mountPoint != null) { + final Optional mountRpcServices = mountPoint.getService(DOMRpcService.class); + if ( ! mountRpcServices.isPresent()) { + throw new RestconfDocumentedException("Rpc service is missing."); + } + response = mountRpcServices.get().invokeRpc(rpc.getPath(), null); + } else { + response = broker.invokeRpc(rpc.getPath(), null); + } + + final DOMRpcResult result = checkRpcResponse(response); + + DataSchemaNode resultNodeSchema = null; + NormalizedNode resultData = null; + if (result != null && result.getResult() != null) { + resultData = result.getResult(); + final ContainerSchemaNode rpcDataSchemaNode = + SchemaContextUtil.getRpcDataSchema(schemaContext, rpc.getOutput().getPath()); + resultNodeSchema = rpcDataSchemaNode.getDataChildByName(result.getResult().getNodeType()); + } + + return new NormalizedNodeContext(new InstanceIdentifierContext(null, resultNodeSchema, mountPoint, + schemaContext), resultData); } private RpcExecutor resolveIdentifierInInvokeRpc(final String identifier) {