2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.restful.services.impl;
11 import javax.ws.rs.core.UriInfo;
12 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
13 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
14 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
15 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
16 import org.opendaylight.restconf.common.references.SchemaContextRef;
17 import org.opendaylight.restconf.handlers.RpcServiceHandler;
18 import org.opendaylight.restconf.handlers.SchemaContextHandler;
19 import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
20 import org.opendaylight.restconf.restful.utils.CreateStreamUtil;
21 import org.opendaylight.restconf.restful.utils.RestconfInvokeOperationsUtil;
22 import org.opendaylight.restconf.restful.utils.RestconfStreamsConstants;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
28 * Implementation of {@link RestconfInvokeOperationsService}
31 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
33 private final RpcServiceHandler rpcServiceHandler;
34 private final SchemaContextHandler schemaContextHandler;
36 public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
37 final SchemaContextHandler schemaContextHandler) {
38 this.rpcServiceHandler = rpcServiceHandler;
39 this.schemaContextHandler = schemaContextHandler;
43 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
44 final SchemaContextRef refSchemaCtx = new SchemaContextRef(this.schemaContextHandler.get());
45 final SchemaPath schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getPath();
46 final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
47 final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
48 DOMRpcResult response;
50 SchemaContextRef schemaContextRef;
52 if (mountPoint == null) {
53 if (namespace.toString().equals(RestconfStreamsConstants.SAL_REMOTE_NAMESPACE)) {
54 response = CreateStreamUtil.createStream(payload, refSchemaCtx);
56 response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath,
57 this.rpcServiceHandler);
59 schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
61 response = RestconfInvokeOperationsUtil.invokeRpcViaMountPoint(mountPoint, payload.getData(), schemaPath);
62 schemaContextRef = new SchemaContextRef(mountPoint.getSchemaContext());
65 final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response);
67 RpcDefinition resultNodeSchema = null;
68 final NormalizedNode<?, ?> resultData = result.getResult();
69 if ((result != null) && (result.getResult() != null)) {
70 resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
72 return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null, resultNodeSchema,
73 mountPoint, schemaContextRef.get()), resultData);