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.nb.rfc8040.rests.services.impl;
11 import javax.ws.rs.Path;
12 import javax.ws.rs.core.UriInfo;
13 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
14 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
15 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
16 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
17 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
18 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
19 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
20 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
21 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
22 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
23 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
24 import org.opendaylight.restconf.nb.rfc8040.rests.utils.CreateStreamUtil;
25 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil;
26 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
27 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
29 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
32 * Implementation of {@link RestconfInvokeOperationsService}.
36 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
38 private volatile RpcServiceHandler rpcServiceHandler;
39 private volatile SchemaContextHandler schemaContextHandler;
41 public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
42 final SchemaContextHandler schemaContextHandler) {
43 this.rpcServiceHandler = rpcServiceHandler;
44 this.schemaContextHandler = schemaContextHandler;
48 public synchronized void updateHandlers(final Object... handlers) {
49 for (final Object object : handlers) {
50 if (object instanceof SchemaContextHandler) {
51 schemaContextHandler = (SchemaContextHandler) object;
52 } else if (object instanceof RpcServiceHandler) {
53 rpcServiceHandler = (RpcServiceHandler) object;
59 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
60 final UriInfo uriInfo) {
61 final SchemaContextRef refSchemaCtx = new SchemaContextRef(this.schemaContextHandler.get());
62 final SchemaPath schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getPath();
63 final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
64 final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
65 DOMRpcResult response;
67 SchemaContextRef schemaContextRef;
69 if (mountPoint == null) {
70 if (namespace.toString().equals(RestconfStreamsConstants.SAL_REMOTE_NAMESPACE)) {
71 if (identifier.contains(RestconfStreamsConstants.CREATE_DATA_SUBSCR)) {
72 response = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
74 throw new RestconfDocumentedException("Not supported operation", ErrorType.RPC,
75 ErrorTag.OPERATION_NOT_SUPPORTED);
78 response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath,
79 this.rpcServiceHandler);
81 schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
83 response = RestconfInvokeOperationsUtil.invokeRpcViaMountPoint(mountPoint, payload.getData(), schemaPath);
84 schemaContextRef = new SchemaContextRef(mountPoint.getSchemaContext());
87 final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response);
89 RpcDefinition resultNodeSchema = null;
90 NormalizedNode<?, ?> resultData = null;
91 if (result != null && result.getResult() != null) {
92 resultData = result.getResult();
93 resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
95 return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema,
96 mountPoint, schemaContextRef.get()), resultData);