Examine supported features in yanglib 67/99567/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 3 Feb 2022 08:43:00 +0000 (09:43 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 3 Feb 2022 11:55:02 +0000 (12:55 +0100)
yang-model-library exposes the features that are actually supported from
a particular module. Process this information and pass it to
SchemaContextResolver so that it can create a correct
EffectiveModelContext.

JIRA: MDSAL-719
Change-Id: I32af4cdec4acb823ad90f2608036f0d71210910b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit cf58c213929bfe0f02649dae81e06a89b3cab75c)

yanglib/mdsal-yanglib-api/src/main/java/module-info.java
yanglib/mdsal-yanglib-api/src/main/java/org/opendaylight/mdsal/yanglib/api/SchemaContextResolver.java
yanglib/mdsal-yanglib-rfc7895/src/main/java/org/opendaylight/mdsal/yanglib/rfc7895/MountPointContextFactoryImpl.java
yanglib/mdsal-yanglib-rfc8525/src/main/java/org/opendaylight/mdsal/yanglib/rfc8525/MountPointContextFactoryImpl.java

index 1f1cf38f854b15d3b7da652c8ef5f98c357dca41..a23e6071b96dd82c74ed189ff7d5c32d1c327a84 100644 (file)
@@ -8,6 +8,7 @@
 module org.opendaylight.mdsal.yanglib.api {
     exports org.opendaylight.mdsal.yanglib.api;
 
+    requires transitive org.opendaylight.yangtools.yang.common;
     requires transitive org.opendaylight.yangtools.yang.model.api;
     requires transitive org.opendaylight.yangtools.rfc8528.data.api;
 
index ea8af299fd8fda34d49ad9c6f7b48137d7c65588..335f7c9652a8358661860fa716c74859f343991c 100644 (file)
@@ -9,7 +9,9 @@ package org.opendaylight.mdsal.yanglib.api;
 
 import com.google.common.annotations.Beta;
 import java.util.List;
+import java.util.Set;
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 
@@ -27,5 +29,5 @@ import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 public interface SchemaContextResolver {
 
     EffectiveModelContext resolveSchemaContext(List<SourceReference> librarySources,
-            List<SourceReference> requiredSources) throws YangParserException;
+        List<SourceReference> requiredSources, Set<QName> supportedFeatures) throws YangParserException;
 }
index 42b562a85e3b58fcde762d3baf3659edce5b63b0..26557bd5071eb9205c020d4fb2e96bf5627d1f49 100644 (file)
@@ -14,8 +14,10 @@ import static java.util.Objects.requireNonNull;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
 import org.opendaylight.mdsal.yanglib.api.SchemaContextResolver;
@@ -31,6 +33,8 @@ import org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory;
 import org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier;
 import org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.ContainerName;
 import org.opendaylight.yangtools.rfc8528.data.util.AbstractMountPointContextFactory;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
@@ -52,7 +56,7 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
         super(mountId);
         this.resolver = requireNonNull(resolver);
         this.yangLibContext = requireNonNull(yangLibContext);
-        this.codec = requireNonNull(moduleStateCodec);
+        codec = requireNonNull(moduleStateCodec);
     }
 
     @Override
@@ -86,11 +90,16 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
             throws YangParserException {
         final List<SourceReference> requiredSources = new ArrayList<>();
         final List<SourceReference> librarySources = new ArrayList<>();
+        final Set<QName> supportedFeatures = new HashSet<>();
 
         for (Module module : modState.nonnullModule().values()) {
             final SourceReference modRef = sourceRefFor(module, module.getSchema());
+            final var namespace = XMLNamespace.of(module.requireNamespace().getValue());
+            for (var feature : module.requireFeature()) {
+                supportedFeatures.add(QName.create(namespace, feature.getValue()).intern());
+            }
 
-            // TODO: take deviations/features into account
+            // TODO: take deviations into account
 
             if (ConformanceType.Import == module.getConformanceType()) {
                 librarySources.add(modRef);
@@ -104,7 +113,7 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
             }
         }
 
-        return resolver.resolveSchemaContext(librarySources, requiredSources);
+        return resolver.resolveSchemaContext(librarySources, requiredSources, supportedFeatures);
     }
 
     private static SourceReference sourceRefFor(final CommonLeafs obj, final Uri uri) {
index ee79eb7227c33fe0050d76c68e5526eb40f648d9..4064655b46ab9fa4530a2839747eae3d8117e572 100644 (file)
@@ -18,6 +18,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
@@ -44,6 +45,7 @@ import org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.Containe
 import org.opendaylight.yangtools.rfc8528.data.util.AbstractMountPointContextFactory;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
@@ -112,15 +114,16 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
 
         final var requiredSources = new ArrayList<SourceReference>();
         final var librarySources = new ArrayList<SourceReference>();
+        final var supportedFeatures = new HashSet<QName>();
         final var moduleSet = findModuleSet(yangLib, findSchemaName(datastores, Operational.QNAME));
         for (var modSet : yangLib.nonnullModuleSet().values()) {
             if (moduleSet.remove(modSet.getName())) {
-                fillModules(librarySources, requiredSources, modSet);
+                fillModules(librarySources, requiredSources, supportedFeatures, modSet);
             }
         }
         checkArgument(moduleSet.isEmpty(), "Failed to resolve module sets %s", moduleSet);
 
-        return resolver.resolveSchemaContext(librarySources, requiredSources);
+        return resolver.resolveSchemaContext(librarySources, requiredSources, supportedFeatures);
     }
 
     @SuppressWarnings("deprecation")
@@ -128,11 +131,17 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
             throws YangParserException {
         final var requiredSources = new ArrayList<SourceReference>();
         final var librarySources = new ArrayList<SourceReference>();
+        final var supportedFeatures = new HashSet<QName>();
 
         for (var module : modState.nonnullModule().values()) {
             final var modRef = sourceRefFor(module, module.getSchema());
 
-            // TODO: take deviations/features into account
+            final var namespace = XMLNamespace.of(module.requireNamespace().getValue());
+            for (var feature : module.requireFeature()) {
+                supportedFeatures.add(QName.create(namespace, feature.getValue()).intern());
+            }
+
+            // TODO: take deviations into account
 
             if (ConformanceType.Import == module.getConformanceType()) {
                 librarySources.add(modRef);
@@ -146,7 +155,7 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
             }
         }
 
-        return resolver.resolveSchemaContext(librarySources, requiredSources);
+        return resolver.resolveSchemaContext(librarySources, requiredSources, supportedFeatures);
     }
 
     private String findSchemaName(final Map<DatastoreKey, Datastore> datastores, final QName qname) {
@@ -191,7 +200,7 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
     }
 
     private static void fillModules(final List<SourceReference> librarySources,
-            final List<SourceReference> requiredSources, final ModuleSet modSet) {
+            final List<SourceReference> requiredSources, final Set<QName> supportedFeatures, final ModuleSet modSet) {
         // TODO: take deviations/features into account
 
         for (var mod : modSet.nonnullImportOnlyModule().values()) {
@@ -203,6 +212,8 @@ final class MountPointContextFactoryImpl extends AbstractMountPointContextFactor
         }
         for (var mod : modSet.nonnullModule().values()) {
             fillSource(requiredSources, mod.getName(), toYangCommon(mod.getRevision()), mod.getLocation());
+            final var namespace = XMLNamespace.of(mod.requireNamespace().getValue());
+            mod.requireFeature().forEach(feature -> supportedFeatures.add(QName.create(namespace, feature.getValue())));
             mod.nonnullSubmodule().values().forEach(sub -> {
                 fillSource(librarySources, sub.getName(), toYangCommon(sub.getRevision()), sub.getLocation());
             });