@Override public Optional<String> get( final String uriPath, final LogicalDatastoreType datastoreType, final UriInfo uriInfo) throws OperationFailedException { LOG.debug("get: uriPath: {}", uriPath); try { NormalizedNodeContext readData; if (datastoreType == LogicalDatastoreType.CONFIGURATION) { readData = RestconfImpl.getInstance().readConfigurationData(uriPath, uriInfo); } else { readData = RestconfImpl.getInstance().readOperationalData(uriPath, uriInfo); } final Optional<String> result = Optional.of(toJson(readData)); LOG.debug("get returning: {}", result.get()); return result; } catch (final Exception e) { if (!isDataMissing(e)) { propagateExceptionAs(uriPath, e, "GET"); } LOG.debug("Data missing - returning absent"); return Optional.absent(); } }
@Override public void delete(final String uriPath) throws OperationFailedException { LOG.debug("delete: uriPath: {}", uriPath); try { RestconfImpl.getInstance().deleteConfigurationData(uriPath); } catch (final Exception e) { propagateExceptionAs(uriPath, e, "DELETE"); } }
@Override public Optional<String> invokeRpc(final String uriPath, final Optional<String> input) throws OperationFailedException { Preconditions.checkNotNull(uriPath, "uriPath can't be null"); final String actualInput = input.isPresent() ? input.get() : null; LOG.debug("invokeRpc: uriPath: {}, input: {}", uriPath, actualInput); String output = null; try { NormalizedNodeContext outputContext; if (actualInput != null) { final InputStream entityStream = new ByteArrayInputStream(actualInput.getBytes(StandardCharsets.UTF_8)); final NormalizedNodeContext inputContext = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true); LOG.debug( "Parsed YangInstanceIdentifier: {}", inputContext.getInstanceIdentifierContext().getInstanceIdentifier()); LOG.debug("Parsed NormalizedNode: {}", inputContext.getData()); outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, inputContext, null); } else { outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, "", null); } if (outputContext.getData() != null) { output = toJson(outputContext); } } catch (final Exception e) { propagateExceptionAs(uriPath, e, "RPC"); } return Optional.fromNullable(output); }
@Override public void post(final String uriPath, final String payload, final UriInfo uriInfo) throws OperationFailedException { Preconditions.checkNotNull(payload, "payload can't be null"); LOG.debug("post: uriPath: {}, payload: {}", uriPath, payload); final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true); LOG.debug( "Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier()); LOG.debug("Parsed NormalizedNode: {}", context.getData()); try { RestconfImpl.getInstance().createConfigurationData(uriPath, context, uriInfo); } catch (final Exception e) { propagateExceptionAs(uriPath, e, "POST"); } }