Search in sources :

Example 96 with NormalizedNodeContext

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

the class TestJsonBodyReaderMountPoint method moduleSubContainerDataPutTest.

@Test
public void moduleSubContainerDataPutTest() throws Exception {
    final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
    final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
    mockBodyReader(uri, this.jsonBodyReader, false);
    final InputStream inputStream = TestJsonBodyReaderMountPoint.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
    final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkMountPointNormalizedNodeContext(returnValue);
    checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, QName.create(dataSchemaNode.getQName(), "cont1"));
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 97 with NormalizedNodeContext

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

the class JSONRestconfServiceImpl method post.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void post(final String uriPath, final String payload) throws OperationFailedException {
    requireNonNull(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, controllerContext);
    LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
    LOG.debug("Parsed NormalizedNode: {}", context.getData());
    try {
        restconfService.createConfigurationData(uriPath, context, new SimpleUriInfo(uriPath));
    } catch (final Exception e) {
        propagateExceptionAs(uriPath, e, "POST");
    }
}
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 98 with NormalizedNodeContext

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

the class JSONRestconfServiceImpl method subscribeToStream.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Optional<String> subscribeToStream(final String identifier, final MultivaluedMap<String, String> params) throws OperationFailedException {
    // Note: We use http://127.0.0.1 because the Uri parser requires something there though it does nothing
    String uri = new StringBuilder("http://127.0.0.1:8081/restconf/streams/stream/").append(identifier).toString();
    MultivaluedMap queryParams = params != null ? params : new MultivaluedHashMap<String, String>();
    UriInfo uriInfo = new SimpleUriInfo(uri, queryParams);
    String jsonRes = null;
    try {
        NormalizedNodeContext res = restconfService.subscribeToStream(identifier, uriInfo);
        jsonRes = toJson(res);
    } catch (final Exception e) {
        propagateExceptionAs(identifier, e, "RPC");
    }
    return Optional.ofNullable(jsonRes);
}
Also used : SimpleUriInfo(org.opendaylight.restconf.common.util.SimpleUriInfo) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) SimpleUriInfo(org.opendaylight.restconf.common.util.SimpleUriInfo) UriInfo(javax.ws.rs.core.UriInfo) 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 99 with NormalizedNodeContext

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

the class JsonToNnTest method simpleTest.

private void simpleTest(final String jsonPath, final String topLevelElementName, final String moduleName) throws Exception {
    final String uri = moduleName + ":" + topLevelElementName;
    final NormalizedNodeContext normalizedNodeContext = prepareNNC(jsonPath, uri);
    assertNotNull(normalizedNodeContext);
    verifyNormaluizedNodeContext(normalizedNodeContext, topLevelElementName);
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 100 with NormalizedNodeContext

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

the class JsonToNnTest method testJsonBlankInput.

@Test
public void testJsonBlankInput() throws Exception {
    final NormalizedNodeContext normalizedNodeContext = prepareNNC("", "array-with-null-yang:cont");
    assertNull(normalizedNodeContext);
}
Also used : 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