Search in sources :

Example 16 with ResourceData

use of org.onosproject.yang.model.ResourceData in project onos by opennetworkinglab.

the class RestconfManager method executeRpc.

private RestconfRpcOutput executeRpc(URI uri, ObjectNode input, String clientIpAddress) {
    ResourceData rpcInputNode = convertJsonToDataNode(uri, input);
    ResourceId resourceId = rpcInputNode.resourceId();
    List<DataNode> inputDataNodeList = rpcInputNode.dataNodes();
    DataNode inputDataNode = inputDataNodeList.get(0);
    RpcInput rpcInput = new RpcInput(resourceId, inputDataNode);
    RestconfRpcOutput restconfOutput = null;
    try {
        CompletableFuture<RpcOutput> rpcFuture = dynamicConfigService.invokeRpc(rpcInput);
        RpcOutput rpcOutput = rpcFuture.get();
        restconfOutput = RestconfUtils.convertRpcOutput(resourceId, rpcOutput);
    } catch (InterruptedException e) {
        log.error("ERROR: computeResultQ.take() has been interrupted.");
        log.debug("executeRpc Exception:", e);
        RestconfError error = RestconfError.builder(RestconfError.ErrorType.RPC, RestconfError.ErrorTag.OPERATION_FAILED).errorMessage("RPC execution has been interrupted").errorPath(uri.getPath()).build();
        restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, RestconfError.wrapErrorAsJson(Arrays.asList(error)));
        restconfOutput.reason("RPC execution has been interrupted");
    } catch (Exception e) {
        log.error("ERROR: executeRpc: {}", e.getMessage());
        log.debug("executeRpc Exception:", e);
        RestconfError error = RestconfError.builder(RestconfError.ErrorType.RPC, RestconfError.ErrorTag.OPERATION_FAILED).errorMessage(e.getMessage()).errorPath(uri.getPath()).build();
        restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, RestconfError.wrapErrorAsJson(Arrays.asList(error)));
        restconfOutput.reason(e.getMessage());
    }
    return restconfOutput;
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) RestconfRpcOutput(org.onosproject.restconf.api.RestconfRpcOutput) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) RpcInput(org.onosproject.yang.model.RpcInput) RestconfRpcOutput(org.onosproject.restconf.api.RestconfRpcOutput) RpcOutput(org.onosproject.yang.model.RpcOutput) RestconfError(org.onosproject.restconf.api.RestconfError) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Aggregations

ResourceData (org.onosproject.yang.model.ResourceData)16 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)15 DataNode (org.onosproject.yang.model.DataNode)7 RestconfException (org.onosproject.restconf.api.RestconfException)6 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)5 DefaultModelObjectData (org.onosproject.yang.model.DefaultModelObjectData)5 ModelObjectData (org.onosproject.yang.model.ModelObjectData)5 FailedException (org.onosproject.config.FailedException)4 ResourceId (org.onosproject.yang.model.ResourceId)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CompositeData (org.onosproject.yang.runtime.CompositeData)2 CompositeStream (org.onosproject.yang.runtime.CompositeStream)2 DefaultCompositeData (org.onosproject.yang.runtime.DefaultCompositeData)2 DefaultCompositeStream (org.onosproject.yang.runtime.DefaultCompositeStream)2 DefaultRuntimeContext (org.onosproject.yang.runtime.DefaultRuntimeContext)2 RuntimeContext (org.onosproject.yang.runtime.RuntimeContext)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 YangToolUtil.toCharSequence (org.onosproject.odtn.utils.YangToolUtil.toCharSequence)1