Search in sources :

Example 16 with NormalizedNodeContext

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;
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 17 with 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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 18 with NormalizedNodeContext

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();
    }
}
Also used : 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) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 19 with NormalizedNodeContext

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");
    }
}
Also used : 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) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 20 with NormalizedNodeContext

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"));
}
Also used : InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Aggregations

NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)105 Test (org.junit.Test)70 InputStream (java.io.InputStream)36 AbstractBodyReaderTest (org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)34 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)34 QName (org.opendaylight.yangtools.yang.common.QName)25 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)22 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)18 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)13 Module (org.opendaylight.yangtools.yang.model.api.Module)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 OutputStream (java.io.OutputStream)9 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)9 UriInfo (javax.ws.rs.core.UriInfo)8 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)8 IOException (java.io.IOException)7