Search in sources :

Example 1 with JsonToPatchBodyReader

use of org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader in project netconf by opendaylight.

the class JSONRestconfServiceImpl method patch.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Optional<String> patch(final String uriPath, final String payload) throws OperationFailedException {
    String output = null;
    requireNonNull(payload, "payload can't be null");
    LOG.debug("patch: uriPath: {}, payload: {}", uriPath, payload);
    final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
    JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader(controllerContext);
    final PatchContext context = jsonToPatchBodyReader.readFrom(uriPath, entityStream);
    LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
    LOG.debug("Parsed NormalizedNode: {}", context.getData());
    try {
        PatchStatusContext patchStatusContext = restconfService.patchConfigurationData(context, new SimpleUriInfo(uriPath));
        output = toJson(patchStatusContext);
    } catch (final Exception e) {
        propagateExceptionAs(uriPath, e, "PATCH");
    }
    return Optional.ofNullable(output);
}
Also used : JsonToPatchBodyReader(org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader) PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SimpleUriInfo(org.opendaylight.restconf.common.util.SimpleUriInfo) IOException(java.io.IOException) OperationFailedException(org.opendaylight.yangtools.yang.common.OperationFailedException) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JsonToPatchBodyReader (org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader)1 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)1 PatchContext (org.opendaylight.restconf.common.patch.PatchContext)1 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)1 SimpleUriInfo (org.opendaylight.restconf.common.util.SimpleUriInfo)1 OperationFailedException (org.opendaylight.yangtools.yang.common.OperationFailedException)1