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 RpcServiceHandler rpcServiceHandler;
34 private SchemaContextHandler schemaContextHandler;
37 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
38 final SchemaContextRef refSchemaCtx = new SchemaContextRef(this.schemaContextHandler.get());
39 final SchemaPath schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getPath();
40 final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
41 final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
42 DOMRpcResult response;
44 SchemaContextRef schemaContextRef;
46 if (mountPoint == null) {
47 if (namespace.toString().equals(RestconfStreamsConstants.SAL_REMOTE_NAMESPACE)) {
48 response = CreateStreamUtil.createStream(payload, refSchemaCtx);
50 response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath,
51 this.rpcServiceHandler);
53 schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
55 response = RestconfInvokeOperationsUtil.invokeRpcViaMountPoint(mountPoint, payload.getData(), schemaPath);
56 schemaContextRef = new SchemaContextRef(mountPoint.getSchemaContext());
59 final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response);
61 RpcDefinition resultNodeSchema = null;
62 final NormalizedNode<?, ?> resultData = result.getResult();
63 if ((result != null) && (result.getResult() != null)) {
64 resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
66 return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null, resultNodeSchema,
67 mountPoint, schemaContextRef.get()), resultData);