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.RestconfDocumentedException;
15 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
16 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
17 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
18 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
19 import org.opendaylight.restconf.common.references.SchemaContextRef;
20 import org.opendaylight.restconf.handlers.RpcServiceHandler;
21 import org.opendaylight.restconf.handlers.SchemaContextHandler;
22 import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
23 import org.opendaylight.restconf.restful.utils.CreateStreamUtil;
24 import org.opendaylight.restconf.restful.utils.RestconfInvokeOperationsUtil;
25 import org.opendaylight.restconf.restful.utils.RestconfStreamsConstants;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
31 * Implementation of {@link RestconfInvokeOperationsService}.
34 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
36 private final RpcServiceHandler rpcServiceHandler;
37 private final SchemaContextHandler schemaContextHandler;
39 public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
40 final SchemaContextHandler schemaContextHandler) {
41 this.rpcServiceHandler = rpcServiceHandler;
42 this.schemaContextHandler = schemaContextHandler;
46 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
47 final UriInfo uriInfo) {
48 final SchemaContextRef refSchemaCtx = new SchemaContextRef(this.schemaContextHandler.get());
49 final SchemaPath schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getPath();
50 final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
51 final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
52 DOMRpcResult response;
54 SchemaContextRef schemaContextRef;
56 if (mountPoint == null) {
57 if (namespace.toString().equals(RestconfStreamsConstants.SAL_REMOTE_NAMESPACE)) {
58 if (identifier.contains(RestconfStreamsConstants.CREATE_DATA_SUBSCR)) {
59 response = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
61 throw new RestconfDocumentedException("Not supported operation", ErrorType.RPC,
62 ErrorTag.OPERATION_NOT_SUPPORTED);
65 response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath,
66 this.rpcServiceHandler);
68 schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
70 response = RestconfInvokeOperationsUtil.invokeRpcViaMountPoint(mountPoint, payload.getData(), schemaPath);
71 schemaContextRef = new SchemaContextRef(mountPoint.getSchemaContext());
74 final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response);
76 RpcDefinition resultNodeSchema = null;
77 final NormalizedNode<?, ?> resultData = result.getResult();
78 if ((result != null) && (result.getResult() != null)) {
79 resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
81 return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null, resultNodeSchema,
82 mountPoint, schemaContextRef.get()), resultData);