Search in sources :

Example 1 with ActionNodeContainer

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

the class ActionStatementTest method assertContainsActions.

private static void assertContainsActions(final SchemaContext schemaContext, final String dataContainerName, final String... actionNames) {
    final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(QName.create(FOO_NS, FOO_REV, dataContainerName));
    assertTrue(dataChildByName instanceof ActionNodeContainer);
    assertContainsActions((ActionNodeContainer) dataChildByName, actionNames);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ActionNodeContainer(org.opendaylight.yangtools.yang.model.api.ActionNodeContainer)

Example 2 with ActionNodeContainer

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

the class ParserIdentifier method getPathSchema.

private static SchemaNode getPathSchema(final EffectiveModelContext schemaContext, final YangInstanceIdentifier urlPath) {
    // First things first: an empty path means data invocation on SchemaContext
    if (urlPath.isEmpty()) {
        return schemaContext;
    }
    // Peel the last component and locate the parent data node, empty path resolves to SchemaContext
    final DataSchemaContextNode<?> parent = DataSchemaContextTree.from(schemaContext).findChild(verifyNotNull(urlPath.getParent())).orElseThrow(// Parent data node is not present, this is not a valid location.
    () -> new RestconfDocumentedException("Parent of " + urlPath + " not found", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE));
    // Now try to resolve the last component as a data item...
    final DataSchemaContextNode<?> data = parent.getChild(urlPath.getLastPathArgument());
    if (data != null) {
        return data.getDataSchemaNode();
    }
    // ... otherwise this has to be an operation invocation. RPCs cannot be defined anywhere but schema root,
    // actions can reside everywhere else (and SchemaContext reports them empty)
    final QName qname = urlPath.getLastPathArgument().getNodeType();
    final DataSchemaNode parentSchema = parent.getDataSchemaNode();
    if (parentSchema instanceof SchemaContext) {
        for (final RpcDefinition rpc : ((SchemaContext) parentSchema).getOperations()) {
            if (qname.equals(rpc.getQName())) {
                return rpc;
            }
        }
    }
    if (parentSchema instanceof ActionNodeContainer) {
        for (final ActionDefinition action : ((ActionNodeContainer) parentSchema).getActions()) {
            if (qname.equals(action.getQName())) {
                return action;
            }
        }
    }
    // is deemed invalid
    throw new RestconfDocumentedException("Context for " + urlPath + " not found", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ActionNodeContainer(org.opendaylight.yangtools.yang.model.api.ActionNodeContainer) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition)

Example 3 with ActionNodeContainer

use of org.opendaylight.yangtools.yang.model.api.ActionNodeContainer 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)

Aggregations

ActionNodeContainer (org.opendaylight.yangtools.yang.model.api.ActionNodeContainer)3 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)3 ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)2 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)1 QName (org.opendaylight.yangtools.yang.common.QName)1 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1