use of org.opendaylight.yangtools.yang.model.api.ActionDefinition in project lighty-netconf-simulator by PANTHEONtech.
the class ActionServiceDeviceProcessor method getAction.
private Collection<ActionDefinition> getAction() {
final Builder<ActionDefinition> builder = ImmutableSet.builder();
Collection<? extends DataSchemaNode> childNodes = this.adapterContext.currentSerializer().getRuntimeContext().getEffectiveModelContext().getChildNodes();
for (final DataSchemaNode dataSchemaNode : childNodes) {
if (dataSchemaNode instanceof ActionNodeContainer) {
findAction(dataSchemaNode, builder);
}
}
return builder.build();
}
use of org.opendaylight.yangtools.yang.model.api.ActionDefinition in project yangtools by opendaylight.
the class Bug9241Test method testImplicitInputAndOutputInAction.
@Test
public void testImplicitInputAndOutputInAction() throws Exception {
final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
assertNotNull(schemaContext);
final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-10-13")).get();
final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(fooModule.getQNameModule(), "action-cont"));
final ActionDefinition actionInCont = actionCont.getActions().iterator().next();
final InputSchemaNode input = actionInCont.getInput();
assertNotNull(input);
assertEquals(1, input.getChildNodes().size());
assertEquals(StatementOrigin.CONTEXT, ((EffectiveStatement<?, ?>) input).statementOrigin());
final OutputSchemaNode output = actionInCont.getOutput();
assertNotNull(output);
assertEquals(1, output.getChildNodes().size());
assertEquals(StatementOrigin.CONTEXT, ((EffectiveStatement<?, ?>) output).statementOrigin());
}
use of org.opendaylight.yangtools.yang.model.api.ActionDefinition in project netconf by opendaylight.
the class NetconfMessageTransformerTest method getActionsTest.
@Test
public void getActionsTest() {
Set<Absolute> schemaPaths = new HashSet<>();
schemaPaths.add(RESET_SERVER_PATH);
schemaPaths.add(START_DEVICE_PATH);
schemaPaths.add(ENABLE_INTERFACE_PATH);
schemaPaths.add(OPEN_BOXES_PATH);
schemaPaths.add(KILL_SERVER_APP_PATH);
schemaPaths.add(XYZZY_FOO_PATH);
schemaPaths.add(XYZZY_BAR_PATH);
schemaPaths.add(CHOICE_ACTION_PATH);
schemaPaths.add(DISABLE_INTERFACE_PATH);
schemaPaths.add(CHECK_WITH_OUTPUT_INTERFACE_PATH);
schemaPaths.add(CHECK_WITHOUT_OUTPUT_INTERFACE_PATH);
List<ActionDefinition> actions = NetconfMessageTransformer.getActions(ACTION_SCHEMA);
assertEquals(schemaPaths.size(), actions.size());
for (ActionDefinition actionDefinition : actions) {
Absolute path = actionDefinition.getPath().asAbsolute();
assertTrue(schemaPaths.remove(path));
}
}
use of org.opendaylight.yangtools.yang.model.api.ActionDefinition in project netconf by opendaylight.
the class RestconfDataServiceImpl method invokeAction.
/**
* Invoke Action operation.
*
* @param payload {@link NormalizedNodePayload} - the body of the operation
* @return {@link NormalizedNodePayload} wrapped in {@link Response}
*/
public Response invokeAction(final NormalizedNodePayload payload) {
final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
final DOMMountPoint mountPoint = context.getMountPoint();
final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
final NormalizedNode data = payload.getData();
if (yangIIdContext.isEmpty() && !NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
final List<QName> qNames = yangIIdContext.getPathArguments().stream().filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)).filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)).map(PathArgument::getNodeType).collect(Collectors.toList());
qNames.add(context.getSchemaNode().getQName());
final Absolute schemaPath = Absolute.of(qNames);
final DOMActionResult response;
final EffectiveModelContext schemaContextRef;
if (mountPoint != null) {
response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, mountPoint);
schemaContextRef = modelContext(mountPoint);
} else {
response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, actionService);
schemaContextRef = schemaContextHandler.get();
}
final DOMActionResult result = checkActionResponse(response);
ActionDefinition resultNodeSchema = null;
ContainerNode resultData = null;
if (result != null) {
final Optional<ContainerNode> optOutput = result.getOutput();
if (optOutput.isPresent()) {
resultData = optOutput.get();
resultNodeSchema = (ActionDefinition) context.getSchemaNode();
}
}
if (resultData != null && resultData.isEmpty()) {
return Response.status(Status.NO_CONTENT).build();
}
return Response.status(Status.OK).entity(NormalizedNodePayload.ofNullable(new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef), resultData)).build();
}
use of org.opendaylight.yangtools.yang.model.api.ActionDefinition in project netconf by opendaylight.
the class RestconfDataServiceImpl method postData.
@Override
public Response postData(final NormalizedNodePayload payload, final UriInfo uriInfo) {
requireNonNull(payload);
if (payload.getInstanceIdentifierContext().getSchemaNode() instanceof ActionDefinition) {
return invokeAction(payload);
}
final WriteDataParams params = QueryParams.newWriteDataParams(uriInfo);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
return PostDataTransactionUtil.postData(uriInfo, payload, strategy, getSchemaContext(mountPoint), params);
}
Aggregations