- public StructuredData invokeRpc(final String identifier, final CompositeNode payload) {
- final RpcExecutor rpc = this.resolveIdentifierInInvokeRpc(identifier);
- QName rpcName = rpc.getRpcDefinition().getQName();
- 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());
- }
-
- validateInput( rpc.getRpcDefinition().getInput(), payload );
-
- return callRpc(rpc, payload);
- }
-
- private void validateInput(DataSchemaNode inputSchema, CompositeNode payload) {
- if( inputSchema != null && payload == null )
- {
- //expected a non null payload
- throw new RestconfDocumentedException( "Input is required.",
- ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE );
- }
- else if( inputSchema == null && payload != null )
- {
- //did not expect any input
- throw new RestconfDocumentedException( "No input expected.",
- ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE );
- }
- //else
- //{
- //TODO: Validate "mandatory" and "config" values here??? Or should those be
+ public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
+ final SchemaPath type = payload.getInstanceIdentifierContext().getSchemaNode().getPath();
+ final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
+ final CheckedFuture<DOMRpcResult, DOMRpcException> response;
+ final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
+ final SchemaContext schemaContext;
+ if (identifier.contains(MOUNT_POINT_MODULE_NAME) && mountPoint != null) {
+ final Optional<DOMRpcService> mountRpcServices = mountPoint.getService(DOMRpcService.class);
+ if ( ! mountRpcServices.isPresent()) {
+ throw new RestconfDocumentedException("Rpc service is missing.");
+ }
+ schemaContext = mountPoint.getSchemaContext();
+ response = mountRpcServices.get().invokeRpc(type, payload.getData());
+ } else {
+ if (namespace.toString().equals(SAL_REMOTE_NAMESPACE)) {
+ response = invokeSalRemoteRpcSubscribeRPC(payload);
+ } else {
+ response = broker.invokeRpc(type, payload.getData());
+ }
+ schemaContext = controllerContext.getGlobalSchema();
+ }
+
+ final DOMRpcResult result = checkRpcResponse(response);
+
+ RpcDefinition resultNodeSchema = null;
+ final NormalizedNode<?, ?> resultData = result.getResult();
+ if (result != null && result.getResult() != null) {
+ resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
+ }
+
+ return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null,
+ resultNodeSchema, mountPoint, schemaContext), resultData);
+ }
+
+ private DOMRpcResult checkRpcResponse(final CheckedFuture<DOMRpcResult, DOMRpcException> response) {
+ if (response == null) {
+ return null;
+ }
+ try {
+ final DOMRpcResult retValue = response.get();
+ if (retValue.getErrors() == null || retValue.getErrors().isEmpty()) {
+ return retValue;
+ }
+ throw new RestconfDocumentedException("RpcError message", null, retValue.getErrors());
+ }
+ catch (final InterruptedException e) {
+ throw new RestconfDocumentedException(
+ "The operation was interrupted while executing and did not complete.", ErrorType.RPC,
+ ErrorTag.PARTIAL_OPERATION);
+ }
+ catch (final ExecutionException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof CancellationException) {
+ throw new RestconfDocumentedException("The operation was cancelled while executing.", ErrorType.RPC,
+ ErrorTag.PARTIAL_OPERATION);
+ } else if (cause != null) {
+ while (cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+
+ if (cause instanceof IllegalArgumentException) {
+ throw new RestconfDocumentedException(cause.getMessage(), ErrorType.PROTOCOL,
+ ErrorTag.INVALID_VALUE);
+ }
+
+ throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.",
+ cause);
+ } else {
+ throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.",
+ e);
+ }
+ }
+ }
+
+ private void validateInput(final SchemaNode inputSchema, final NormalizedNodeContext payload) {
+ if (inputSchema != null && payload.getData() == null) {
+ // expected a non null payload
+ throw new RestconfDocumentedException("Input is required.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
+ } else if (inputSchema == null && payload.getData() != null) {
+ // did not expect any input
+ throw new RestconfDocumentedException("No input expected.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
+ }
+ // else
+ // {
+ // TODO: Validate "mandatory" and "config" values here??? Or should those be
+ // those be