Search in sources :

Example 6 with ActionDefinition

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();
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ActionNodeContainer(org.opendaylight.yangtools.yang.model.api.ActionNodeContainer) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition)

Example 7 with ActionDefinition

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());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) Test(org.junit.Test)

Example 8 with ActionDefinition

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));
    }
}
Also used : Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) HashSet(java.util.HashSet) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 9 with ActionDefinition

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();
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) WriteDataParams(org.opendaylight.restconf.nb.rfc8040.WriteDataParams) PlainPatchDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PlainPatchDataTransactionUtil) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) DOMActionException(org.opendaylight.mdsal.dom.api.DOMActionException) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) STREAM_ACCESS_PATH_PART(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_ACCESS_PATH_PART) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) Map(java.util.Map) QueryParams(org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) URI(java.net.URI) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) CancellationException(java.util.concurrent.CancellationException) STREAM_LOCATION_PATH_PART(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_LOCATION_PATH_PART) NotificationOutputType(org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType) Collectors(java.util.stream.Collectors) STREAM_PATH_PART(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH_PART) ParserIdentifier(org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier) List(java.util.List) NOTIFICATION_STREAM(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.NOTIFICATION_STREAM) Revision(org.opendaylight.yangtools.yang.common.Revision) Response(javax.ws.rs.core.Response) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) RestconfDataService(org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ReadDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil) ReadDataParams(org.opendaylight.restconf.nb.rfc8040.ReadDataParams) PutDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PutDataTransactionUtil) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) PostDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PostDataTransactionUtil) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) DOMMountPointService(org.opendaylight.mdsal.dom.api.DOMMountPointService) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) STREAMS_PATH(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAMS_PATH) NotificationListenerAdapter(org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter) DeleteDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil) PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) Status(javax.ws.rs.core.Response.Status) PatchDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PatchDataTransactionUtil) Logger(org.slf4j.Logger) DOMDataTreeWriteOperations(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) QueryParameters(org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters) Configuration(org.opendaylight.restconf.nb.rfc8040.streams.Configuration) QName(org.opendaylight.yangtools.yang.common.QName) RestconfStreamsSubscriptionService(org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) ExecutionException(java.util.concurrent.ExecutionException) STREAM_PATH(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) Futures(com.google.common.util.concurrent.Futures) RestconfMappingNodeUtil(org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Clock(java.time.Clock) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) Rfc8040(org.opendaylight.restconf.nb.rfc8040.Rfc8040) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 10 with ActionDefinition

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);
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) WriteDataParams(org.opendaylight.restconf.nb.rfc8040.WriteDataParams)

Aggregations

ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)11 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 QName (org.opendaylight.yangtools.yang.common.QName)4 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)3 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)3 OutputStream (java.io.OutputStream)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Set (java.util.Set)2 Test (org.junit.Test)2