Search in sources :

Example 31 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.

the class RuntimeRpc method canHandle.

@Override
protected HandlingPriority canHandle(final String netconfOperationName, final String namespace) {
    final XMLNamespace namespaceURI = createNsUri(namespace);
    final Optional<? extends Module> module = getModule(namespaceURI);
    if (module.isEmpty()) {
        LOG.debug("Cannot handle rpc: {}, {}", netconfOperationName, namespace);
        return HandlingPriority.CANNOT_HANDLE;
    }
    getRpcDefinitionFromModule(module.get(), namespaceURI, netconfOperationName);
    return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
}
Also used : XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace)

Example 32 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.

the class FilterContentValidator method validate.

/**
 * Validates filter content against this validator schema context. If the filter is valid,
 * method returns {@link YangInstanceIdentifier} of node which can be used as root for data selection.
 *
 * @param filterContent filter content
 * @return YangInstanceIdentifier
 * @throws DocumentedException if filter content validation failed
 */
public YangInstanceIdentifier validate(final XmlElement filterContent) throws DocumentedException {
    final XMLNamespace namespace;
    try {
        namespace = XMLNamespace.of(filterContent.getNamespace());
    } catch (final IllegalArgumentException e) {
        throw new RuntimeException("Wrong namespace in element + " + filterContent.toString(), e);
    }
    try {
        final Module module = schemaContext.getCurrentContext().findModules(namespace).iterator().next();
        final DataSchemaNode schema = getRootDataSchemaNode(module, namespace, filterContent.getName());
        final FilterTree filterTree = validateNode(filterContent, schema, new FilterTree(schema.getQName(), Type.OTHER, schema));
        return getFilterDataRoot(filterTree, filterContent, YangInstanceIdentifier.builder());
    } catch (final ValidationException e) {
        LOG.debug("Filter content isn't valid", e);
        throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) DocumentedException(org.opendaylight.netconf.api.DocumentedException) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) Module(org.opendaylight.yangtools.yang.model.api.Module)

Example 33 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.

the class AbstractEdit method getSchemaNodeFromNamespace.

final SchemaTreeInference getSchemaNodeFromNamespace(final String namespace, final XmlElement element) throws DocumentedException {
    final XMLNamespace ns;
    try {
        ns = XMLNamespace.of(namespace);
    } catch (final IllegalArgumentException e) {
        throw new NetconfDocumentedException("Unable to create URI for namespace : " + namespace, e, ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
    }
    // Returns module with newest revision since findModuleByNamespace returns a set of modules and we only
    // need the newest one
    final EffectiveModelContext ctx = schemaContext.getCurrentContext();
    final Iterator<? extends @NonNull Module> it = ctx.findModules(ns).iterator();
    if (!it.hasNext()) {
        // No module is present with this namespace
        throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace, ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
    }
    final Module module = it.next();
    final SchemaInferenceStack stack = SchemaInferenceStack.of(ctx);
    final String elementName = element.getName();
    try {
        // FIXME: This is a bit suspect. The element is formed using XML encoding, hence it corresponds to
        // enterDataTree(). But then we use the result of this method to create a NormalizedNode tree,
        // which contains ChoiceNode. This needs to be tested with something like to following:
        // 
        // module mod {
        // choice foo {
        // case bar {
        // leaf baz {
        // type string;
        // }
        // }
        // }
        // }
        stack.enterSchemaTree(QName.create(module.getQNameModule(), elementName));
    } catch (IllegalArgumentException e) {
        throw new DocumentedException("Unable to find node " + elementName + " with namespace: " + namespace + " in module: " + module, e, ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
    }
    return stack.toSchemaTreeInference();
}
Also used : SchemaInferenceStack(org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) DocumentedException(org.opendaylight.netconf.api.DocumentedException) NonNull(org.eclipse.jdt.annotation.NonNull) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 34 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.

the class RestCodec method getModuleByNamespace.

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
    final XMLNamespace validNamespace = resolveValidNamespace(namespace, mountPoint, schemaContext);
    Module module = null;
    if (mountPoint != null) {
        module = modelContext(mountPoint).findModules(validNamespace).iterator().next();
    } else {
        module = schemaContext.findModules(validNamespace).iterator().next();
    }
    if (module == null) {
        LOG.info("Module for namespace {} was not found.", validNamespace);
        return null;
    }
    return module;
}
Also used : XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) Module(org.opendaylight.yangtools.yang.model.api.Module) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 35 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.

the class RestconfImpl method invokeSalRemoteRpcNotifiStrRPC.

/**
 * Prepare stream for notification.
 *
 * @param payload
 *            contains list of qnames of notifications
 * @return - checked future object
 */
private ListenableFuture<DOMRpcResult> invokeSalRemoteRpcNotifiStrRPC(final NormalizedNodeContext payload) {
    final ContainerNode data = (ContainerNode) payload.getData();
    LeafSetNode leafSet = null;
    String outputType = "XML";
    for (final DataContainerChild dataChild : data.body()) {
        if (dataChild instanceof LeafSetNode) {
            leafSet = (LeafSetNode) dataChild;
        } else if (dataChild instanceof AugmentationNode) {
            outputType = (String) ((AugmentationNode) dataChild).body().iterator().next().body();
        }
    }
    final Collection<LeafSetEntryNode<?>> entryNodes = leafSet.body();
    final List<SchemaPath> paths = new ArrayList<>();
    String streamName = CREATE_NOTIFICATION_STREAM + "/";
    StringBuilder streamNameBuilder = new StringBuilder(streamName);
    final Iterator<LeafSetEntryNode<?>> iterator = entryNodes.iterator();
    while (iterator.hasNext()) {
        final QName valueQName = QName.create((String) iterator.next().body());
        final XMLNamespace namespace = valueQName.getModule().getNamespace();
        final Module module = controllerContext.findModuleByNamespace(namespace);
        checkNotNull(module, "Module for namespace %s does not exist", namespace);
        NotificationDefinition notifiDef = null;
        for (final NotificationDefinition notification : module.getNotifications()) {
            if (notification.getQName().equals(valueQName)) {
                notifiDef = notification;
                break;
            }
        }
        final String moduleName = module.getName();
        checkNotNull(notifiDef, "Notification %s does not exist in module %s", valueQName, moduleName);
        paths.add(SchemaPath.of(Absolute.of(notifiDef.getQName())));
        streamNameBuilder.append(moduleName).append(':').append(valueQName.getLocalName());
        if (iterator.hasNext()) {
            streamNameBuilder.append(',');
        }
    }
    streamName = streamNameBuilder.toString();
    final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
    final QName outputQname = QName.create(rpcQName, "output");
    final QName streamNameQname = QName.create(rpcQName, "notification-stream-identifier");
    final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname)).withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
    if (!Notificator.existNotificationListenerFor(streamName)) {
        Notificator.createNotificationListener(paths, streamName, outputType, controllerContext);
    }
    return Futures.immediateFuture(new DefaultDOMRpcResult(output));
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) RestConfModule(org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule)

Aggregations

XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)35 Module (org.opendaylight.yangtools.yang.model.api.Module)14 QName (org.opendaylight.yangtools.yang.common.QName)12 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)9 Revision (org.opendaylight.yangtools.yang.common.Revision)9 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)9 Test (org.junit.Test)8 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)4 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)3 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)3 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)3 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 Optional (java.util.Optional)2