X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Frpc%2Fimpl%2FMountPointRpcExecutor.java;fp=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Frpc%2Fimpl%2FMountPointRpcExecutor.java;h=b56db21951ee2d2eb01f6e3208ebb8912d0a5530;hb=aceaaf6a5ba5acada57ad0fa2c60be6567e55167;hp=0000000000000000000000000000000000000000;hpb=64e9d2770900b6f301ff8d9307a228b7048d0b5d;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/MountPointRpcExecutor.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/MountPointRpcExecutor.java new file mode 100644 index 0000000000..b56db21951 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/MountPointRpcExecutor.java @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved. +* +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License v1.0 which accompanies this distribution, +* and is available at http://www.eclipse.org/legal/epl-v10.html +*/ +package org.opendaylight.controller.sal.restconf.rpc.impl; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.core.Response.Status; + +import org.opendaylight.controller.sal.core.api.mount.MountInstance; +import org.opendaylight.controller.sal.restconf.impl.ResponseException; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.model.api.RpcDefinition; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides an implementation which invokes rpc methods via a mounted yang data model. + * @author Devin Avery + * + */ +public class MountPointRpcExecutor extends AbstractRpcExecutor { + private final MountInstance mountPoint; + + public MountPointRpcExecutor(RpcDefinition rpcDef, MountInstance mountPoint) { + super( rpcDef ); + this.mountPoint = mountPoint; + Preconditions.checkNotNull( mountPoint, "MountInstance can not be null." ); + } + + @Override + public RpcResult invokeRpc( CompositeNode rpcRequest ) throws ResponseException { + ListenableFuture> rpcFuture = + mountPoint.rpc( getRpcDefinition().getQName(), rpcRequest); + try { + return rpcFuture.get(); + } catch (InterruptedException | ExecutionException e) { + throw new ResponseException(Status.INTERNAL_SERVER_ERROR, + e.getCause().getMessage() ); + } + } +} \ No newline at end of file