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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations