Search in sources :

Example 16 with RestconfException

use of org.onosproject.restconf.api.RestconfException in project onos by opennetworkinglab.

the class RestconfManager method runPatchOperationOnDataResource.

@Override
public void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
    ResourceId rid = receivedData.resourceId();
    List<DataNode> dataNodeList = receivedData.dataNodes();
    if (dataNodeList == null || dataNodeList.isEmpty()) {
        log.warn("There is no one Data Node can be proceed.");
        return;
    }
    if (dataNodeList.size() > 1) {
        log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
    }
    DataNode dataNode = dataNodeList.get(0);
    if (rid == null) {
        rid = ResourceId.builder().addBranchPointSchema("/", null).build();
        dataNode = removeTopNode(dataNode);
    }
    try {
        dynamicConfigService.updateNode(parentOf(rl.ridForDynConfig()), dataNode);
    } catch (FailedException e) {
        log.error("ERROR: DynamicConfigService: ", e);
        throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Aggregations

RestconfException (org.onosproject.restconf.api.RestconfException)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 IOException (java.io.IOException)9 URI (java.net.URI)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 RestconfError (org.onosproject.restconf.api.RestconfError)5 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)5 ResourceData (org.onosproject.yang.model.ResourceData)5 Consumes (javax.ws.rs.Consumes)4 FailedException (org.onosproject.config.FailedException)4 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)4 DataNode (org.onosproject.yang.model.DataNode)4 InputStream (java.io.InputStream)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 POST (javax.ws.rs.POST)2 WebTarget (javax.ws.rs.client.WebTarget)2 Test (org.junit.Test)2 ResourceTest (org.onosproject.rest.resources.ResourceTest)2