Search in sources :

Example 1 with InputSchemaNode

use of org.opendaylight.yangtools.yang.model.api.InputSchemaNode in project yangtools by opendaylight.

the class Bug6871Test method testValidYang11Model.

@Test
public void testValidYang11Model() {
    final Module foo = assertEffectiveModel("/rfc7950/bug6871/foo.yang").findModule("foo", Revision.of("2016-12-14")).orElseThrow();
    final var notifications = foo.getNotifications();
    assertEquals(1, notifications.size());
    final NotificationDefinition myNotification = notifications.iterator().next();
    var mustConstraints = myNotification.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final var rpcs = foo.getRpcs();
    assertEquals(1, rpcs.size());
    final RpcDefinition myRpc = rpcs.iterator().next();
    final InputSchemaNode input = myRpc.getInput();
    assertNotNull(input);
    mustConstraints = input.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final OutputSchemaNode output = myRpc.getOutput();
    assertNotNull(output);
    mustConstraints = output.getMustConstraints();
    assertEquals(2, mustConstraints.size());
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) Module(org.opendaylight.yangtools.yang.model.api.Module) AbstractYangTest(org.opendaylight.yangtools.yang.stmt.AbstractYangTest) Test(org.junit.Test)

Example 2 with InputSchemaNode

use of org.opendaylight.yangtools.yang.model.api.InputSchemaNode in project yangtools by opendaylight.

the class AugmentTest method testAugmentRpc.

@Test
public void testAugmentRpc() throws Exception {
    final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/rpc");
    final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
    final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
    final Revision revision = Revision.of("2013-10-11");
    final Module bar = context.findModules("bar").iterator().next();
    final Collection<? extends RpcDefinition> rpcs = bar.getRpcs();
    assertEquals(2, rpcs.size());
    RpcDefinition submit = null;
    for (final RpcDefinition rpc : rpcs) {
        if ("submit".equals(rpc.getQName().getLocalName())) {
            submit = rpc;
            break;
        }
    }
    assertNotNull(submit);
    final QName submitQName = QName.create(NS_BAR, revision, "submit");
    assertEquals(submitQName, submit.getQName());
    final InputSchemaNode input = submit.getInput();
    final QName inputQName = QName.create(NS_BAR, revision, "input");
    assertEquals(inputQName, input.getQName());
    final ChoiceSchemaNode arguments = (ChoiceSchemaNode) input.getDataChildByName(QName.create(NS_BAR, revision, "arguments"));
    final QName argumentsQName = QName.create(NS_BAR, revision, "arguments");
    assertEquals(argumentsQName, arguments.getQName());
    assertFalse(arguments.isAugmenting());
    final Collection<? extends CaseSchemaNode> cases = arguments.getCases();
    assertEquals(3, cases.size());
    CaseSchemaNode attach = null;
    CaseSchemaNode create = null;
    CaseSchemaNode destroy = null;
    for (final CaseSchemaNode child : cases) {
        if ("attach".equals(child.getQName().getLocalName())) {
            attach = child;
        } else if ("create".equals(child.getQName().getLocalName())) {
            create = child;
        } else if ("destroy".equals(child.getQName().getLocalName())) {
            destroy = child;
        }
    }
    assertNotNull(attach);
    assertNotNull(create);
    assertNotNull(destroy);
    assertTrue(attach.isAugmenting());
    assertTrue(create.isAugmenting());
    assertTrue(destroy.isAugmenting());
    // case attach
    assertEquals(QName.create(NS_FOO, revision, "attach"), attach.getQName());
    final Collection<? extends DataSchemaNode> attachChildren = attach.getChildNodes();
    assertEquals(1, attachChildren.size());
    // case create
    assertEquals(QName.create(NS_FOO, revision, "create"), create.getQName());
    final Collection<? extends DataSchemaNode> createChildren = create.getChildNodes();
    assertEquals(1, createChildren.size());
    // case attach
    assertEquals(QName.create(NS_FOO, revision, "destroy"), destroy.getQName());
    final Collection<? extends DataSchemaNode> destroyChildren = destroy.getChildNodes();
    assertEquals(1, destroyChildren.size());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 3 with InputSchemaNode

use of org.opendaylight.yangtools.yang.model.api.InputSchemaNode in project yangtools by opendaylight.

the class YinFileRpcStmtTest method testRpc.

@Test
public void testRpc() {
    Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
    Collection<? extends RpcDefinition> rpcs = testModule.getRpcs();
    assertEquals(1, rpcs.size());
    RpcDefinition rpc = rpcs.iterator().next();
    assertEquals("get-schema", rpc.getQName().getLocalName());
    assertEquals(Optional.of("This operation is used to retrieve a schema from the\n" + "NETCONF server.\n" + "\n" + "Positive Response:\n" + "The NETCONF server returns the requested schema.\n" + "\n" + "Negative Response:\n" + "If requested schema does not exist, the <error-tag> is\n" + "'invalid-value'.\n" + "\n" + "If more than one schema matches the requested parameters, the\n" + "<error-tag> is 'operation-failed', and <error-app-tag> is\n" + "'data-not-unique'."), rpc.getDescription());
    InputSchemaNode input = rpc.getInput();
    assertNotNull(input);
    assertEquals(3, input.getChildNodes().size());
    OutputSchemaNode output = rpc.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 4 with InputSchemaNode

use of org.opendaylight.yangtools.yang.model.api.InputSchemaNode in project netconf by opendaylight.

the class NetconfMessageTransformer method toActionRequest.

@Override
public NetconfMessage toActionRequest(final Absolute action, final DOMDataTreeIdentifier domDataTreeIdentifier, final NormalizedNode payload) {
    final ActionDefinition actionDef = actions.get(action);
    Preconditions.checkArgument(actionDef != null, "Action does not exist: %s", action);
    final InputSchemaNode inputDef = actionDef.getInput();
    if (inputDef.getChildNodes().isEmpty()) {
        return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForActionRequest(contextTree, domDataTreeIdentifier, counter, actionDef.getQName()).getNode().getOwnerDocument());
    }
    Preconditions.checkNotNull(payload, "Transforming an action with input: %s, payload cannot be null", action);
    Preconditions.checkArgument(payload instanceof ContainerNode, "Transforming an action with input: %s, payload has to be a container, but was: %s", action, payload);
    final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForActionRequest(contextTree, domDataTreeIdentifier, counter, actionDef.getQName());
    try {
        NetconfMessageTransformUtil.writeNormalizedOperationInput((ContainerNode) payload, result, action, mountContext.getEffectiveModelContext());
    } catch (final XMLStreamException | IOException | IllegalStateException e) {
        throw new IllegalStateException("Unable to serialize input of " + action, e);
    }
    return new NetconfMessage(result.getNode().getOwnerDocument());
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) XMLStreamException(javax.xml.stream.XMLStreamException) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) IOException(java.io.IOException) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition)

Example 5 with InputSchemaNode

use of org.opendaylight.yangtools.yang.model.api.InputSchemaNode in project netconf by opendaylight.

the class OperationBuilder method buildPostOperation.

public static ObjectNode buildPostOperation(final OperationDefinition operDef, final String moduleName, final Optional<String> deviceName, final String parentName, final DefinitionNames definitionNames, final OAversion oaversion) {
    final ObjectNode postOperation = JsonNodeFactory.instance.objectNode();
    final ArrayNode parameters = JsonNodeFactory.instance.arrayNode();
    final String operName = operDef.getQName().getLocalName();
    final String inputName = operName + INPUT_SUFFIX;
    final InputSchemaNode input = operDef.getInput();
    final OutputSchemaNode output = operDef.getOutput();
    if (!input.getChildNodes().isEmpty()) {
        final String discriminator = definitionNames.getDiscriminator(input);
        final String clearDefName = parentName + "_" + operName + INPUT_SUFFIX;
        final String defName = clearDefName + discriminator;
        final String defTopName = clearDefName + TOP + discriminator;
        insertRequestBodyParameter(parameters, postOperation, defTopName, defName, inputName, oaversion);
    } else {
        final ObjectNode payload = JsonNodeFactory.instance.objectNode();
        final ObjectNode jsonSchema = JsonNodeFactory.instance.objectNode();
        final ObjectNode properties = JsonNodeFactory.instance.objectNode();
        final ObjectNode inputSchema = JsonNodeFactory.instance.objectNode();
        inputSchema.put(TYPE_KEY, OBJECT);
        properties.set(INPUT_KEY, inputSchema);
        jsonSchema.put(TYPE_KEY, OBJECT);
        jsonSchema.set(PROPERTIES_KEY, properties);
        if (oaversion.equals(OAversion.V3_0)) {
            final ObjectNode content = JsonNodeFactory.instance.objectNode();
            final ObjectNode jsonTypeValue = JsonNodeFactory.instance.objectNode();
            jsonTypeValue.set(SCHEMA_KEY, jsonSchema);
            content.set(MediaType.APPLICATION_JSON, jsonTypeValue);
            final ObjectNode xmlSchema = JsonNodeFactory.instance.objectNode();
            xmlSchema.put(TYPE_KEY, OBJECT);
            final ObjectNode xml = JsonNodeFactory.instance.objectNode();
            xml.put(NAME_KEY, INPUT);
            xmlSchema.set(XML_KEY, xml);
            final ObjectNode xmlTypeValue = JsonNodeFactory.instance.objectNode();
            xmlTypeValue.set(SCHEMA_KEY, xmlSchema);
            content.set(MediaType.APPLICATION_XML, xmlTypeValue);
            payload.set(CONTENT_KEY, content);
            payload.put(DESCRIPTION_KEY, inputName);
            postOperation.set(REQUEST_BODY_KEY, payload);
        } else {
            payload.put(IN_KEY, BODY);
            payload.put(NAME_KEY, inputName);
            payload.set(SCHEMA_KEY, jsonSchema);
            parameters.add(payload);
        }
    }
    setConsumesIfNeeded(postOperation, oaversion);
    postOperation.set(PARAMETERS_KEY, parameters);
    final ObjectNode responses = JsonNodeFactory.instance.objectNode();
    final String description = String.format("RPC %s success", operName);
    if (!output.getChildNodes().isEmpty()) {
        final ObjectNode schema = JsonNodeFactory.instance.objectNode();
        final String defName = parentName + "_" + operName + OUTPUT_SUFFIX + TOP + definitionNames.getDiscriminator(output);
        schema.put(REF_KEY, getAppropriateModelPrefix(oaversion) + defName);
        responses.set(String.valueOf(Response.Status.OK.getStatusCode()), buildResponse(description, Optional.of(schema), oaversion));
    } else {
        responses.set(String.valueOf(Response.Status.NO_CONTENT.getStatusCode()), buildResponse(description, Optional.empty(), oaversion));
    }
    postOperation.set(RESPONSES_KEY, responses);
    postOperation.put(DESCRIPTION_KEY, operDef.getDescription().orElse(""));
    postOperation.put(SUMMARY_KEY, buildSummaryValue(HttpMethod.POST, moduleName, deviceName, operName));
    postOperation.set(TAGS_KEY, buildTagsValue(deviceName, moduleName));
    return postOperation;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

InputSchemaNode (org.opendaylight.yangtools.yang.model.api.InputSchemaNode)10 OutputSchemaNode (org.opendaylight.yangtools.yang.model.api.OutputSchemaNode)8 Test (org.junit.Test)7 Module (org.opendaylight.yangtools.yang.model.api.Module)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)6 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)2 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)2 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 NotificationDefinition (org.opendaylight.yangtools.yang.model.api.NotificationDefinition)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DOMResult (javax.xml.transform.dom.DOMResult)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 QName (org.opendaylight.yangtools.yang.common.QName)1