Search in sources :

Example 6 with RestconfError

use of org.onosproject.restconf.api.RestconfError 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

RestconfError (org.onosproject.restconf.api.RestconfError)6 RestconfException (org.onosproject.restconf.api.RestconfException)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 IOException (java.io.IOException)5 URI (java.net.URI)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)2 RestconfRpcOutput (org.onosproject.restconf.api.RestconfRpcOutput)2 GET (javax.ws.rs.GET)1 PATCH (javax.ws.rs.PATCH)1 PUT (javax.ws.rs.PUT)1 FailedException (org.onosproject.config.FailedException)1 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)1 DataNode (org.onosproject.yang.model.DataNode)1 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)1 ResourceData (org.onosproject.yang.model.ResourceData)1 ResourceId (org.onosproject.yang.model.ResourceId)1