use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class StatisticsRestconfServiceWrapper method readOperationalData.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
this.operationalGet.incrementAndGet();
NormalizedNodeContext normalizedNodeContext = null;
try {
normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
if (normalizedNodeContext.getData() != null) {
this.successGetOperational.incrementAndGet();
} else {
this.failureGetOperational.incrementAndGet();
}
} catch (final Exception e) {
this.failureGetOperational.incrementAndGet();
throw e;
}
return normalizedNodeContext;
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class JSONRestconfServiceImpl method invokeRpc.
@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF", justification = "Unrecognised NullableDecl")
@Override
public Optional<String> invokeRpc(final String uriPath, final Optional<String> input) throws OperationFailedException {
requireNonNull(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, controllerContext);
LOG.debug("Parsed YangInstanceIdentifier: {}", inputContext.getInstanceIdentifierContext().getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", inputContext.getData());
outputContext = restconfService.invokeRpc(uriPath, inputContext, null);
} else {
outputContext = restconfService.invokeRpc(uriPath, null, null);
}
if (outputContext.getData() != null) {
output = toJson(outputContext);
}
} catch (final RuntimeException | IOException e) {
propagateExceptionAs(uriPath, e, "RPC");
}
return Optional.ofNullable(output);
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class JSONRestconfServiceImpl method get.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Optional<String> get(final String uriPath, final LogicalDatastoreType datastoreType) throws OperationFailedException {
LOG.debug("get: uriPath: {}", uriPath);
try {
NormalizedNodeContext readData;
final SimpleUriInfo uriInfo = new SimpleUriInfo(uriPath);
if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
readData = restconfService.readConfigurationData(uriPath, uriInfo);
} else {
readData = restconfService.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.empty();
}
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class JSONRestconfServiceImpl method put.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void put(final String uriPath, final String payload) throws OperationFailedException {
requireNonNull(payload, "payload can't be null");
LOG.debug("put: uriPath: {}, payload: {}", uriPath, payload);
final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, false, controllerContext);
LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", context.getData());
try {
restconfService.updateConfigurationData(uriPath, context, new SimpleUriInfo(uriPath));
} catch (final Exception e) {
propagateExceptionAs(uriPath, e, "PUT");
}
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class JsonToNnTest method invalidUriCharacterInValue.
@Test
public void invalidUriCharacterInValue() throws Exception {
mockBodyReader("array-with-null-yang:cont", this.jsonBodyReader, false);
final InputStream inputStream = this.getClass().getResourceAsStream("/json-to-nn/invalid-uri-character-in-value.json");
final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
assertNotNull(normalizedNodeContext);
assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
assertTrue(dataTree.contains("lf1 module<Name:value lf1"));
assertTrue(dataTree.contains("lf2 module>Name:value lf2"));
}
Aggregations