2 * Copyright (c) 2014 Brocade Communications 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.controller.sal.restconf.rpc.impl;
10 import java.util.concurrent.CancellationException;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.Future;
14 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
15 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
16 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
21 public abstract class AbstractRpcExecutor implements RpcExecutor {
22 private final RpcDefinition rpcDef;
24 public AbstractRpcExecutor( RpcDefinition rpcDef ){
29 public RpcDefinition getRpcDefinition() {
33 protected RpcResult<CompositeNode> getRpcResult(
34 Future<RpcResult<CompositeNode>> fromFuture ) {
36 return fromFuture.get();
38 catch( InterruptedException e ) {
39 throw new RestconfDocumentedException(
40 "The operation was interrupted while executing and did not complete.",
41 ErrorType.RPC, ErrorTag.PARTIAL_OPERATION );
43 catch( ExecutionException e ) {
44 Throwable cause = e.getCause();
45 if( cause instanceof CancellationException ) {
46 throw new RestconfDocumentedException(
47 "The operation was cancelled while executing.",
48 ErrorType.RPC, ErrorTag.PARTIAL_OPERATION );
50 else if( cause != null ){
51 while( cause.getCause() != null ) {
52 cause = cause.getCause();
55 if( cause instanceof IllegalArgumentException ) {
56 throw new RestconfDocumentedException(
57 cause.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
60 throw new RestconfDocumentedException(
61 "The operation encountered an unexpected error while executing.", cause );
64 throw new RestconfDocumentedException(
65 "The operation encountered an unexpected error while executing.", e );