Silence all info messages about all features being used 97/56097/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Apr 2017 16:13:26 +0000 (18:13 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 27 Apr 2017 10:42:02 +0000 (10:42 +0000)
This message:

2017-04-26 17:55:00,136 | INFO  | l for user karaf | CrossSourceStatementReactor      | 85 - org.opendaylight.yangtools.yang-parser-impl - 1.1.0.SNAPSHOT | Set of supported features has not been provided, so all features are supported by default.

is featured prominently during startup operations. As it turns out,
we do not have a proper API to express 'use everything', hence the
callers, which really mean that, are passing down nulls.

Expose proper Optional-based methods which are as expressive, thus
allowing us to side-step this pesky flood.

Change-Id: I11c95c58be01deac8bbb587883d152fc6e647a6c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IfFeatureResolutionTest.java

index f4cf163821e04d9e7bcd1648b30af711c1e4eb09..c9c3db8f730298c0b2cfd8864e2a8c5fbb1e6334 100644 (file)
@@ -26,6 +26,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.Set;
 import javax.annotation.Nonnull;
 import org.antlr.v4.runtime.ParserRuleContext;
@@ -41,7 +42,6 @@ import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
 import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
@@ -50,16 +50,20 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 final class SharedSchemaContextFactory implements SchemaContextFactory {
-    private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper.create("resolve sources", SchemaResolutionException.class);
+    private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper
+            .create("resolve sources", SchemaResolutionException.class);
     private static final Logger LOG = LoggerFactory.getLogger(SharedSchemaContextFactory.class);
 
-    private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().weakValues().build();
-    private final Cache<Collection<SourceIdentifier>, SchemaContext> semVerCache = CacheBuilder.newBuilder().weakValues().build();
+    private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().weakValues()
+            .build();
+    private final Cache<Collection<SourceIdentifier>, SchemaContext> semVerCache = CacheBuilder.newBuilder()
+            .weakValues().build();
     private final SharedSchemaRepository repository;
     // FIXME: ignored right now
     private final SchemaSourceFilter filter;
 
-    // FIXME SchemaRepository should be the type for repository parameter instead of SharedSchemaRepository (final implementation)
+    // FIXME SchemaRepository should be the type for repository parameter instead of SharedSchemaRepository
+    //       (final implementation)
     public SharedSchemaContextFactory(final SharedSchemaRepository repository, final SchemaSourceFilter filter) {
         this.repository = Preconditions.checkNotNull(repository);
         this.filter = Preconditions.checkNotNull(filter);
@@ -71,7 +75,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
             final Set<QName> supportedFeatures) {
         return createSchemaContext(requiredSources,
                 statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache,
-                new AssembleSources(supportedFeatures, statementParserMode));
+                new AssembleSources(Optional.ofNullable(supportedFeatures), statementParserMode));
     }
 
     private ListenableFuture<ASTSchemaSource> requestSource(final SourceIdentifier identifier) {
@@ -134,7 +138,8 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
         return ImmutableList.copyOf(uniqueSourceIdentifiers);
     }
 
-    private static final class SourceIdMismatchDetector implements Function<List<ASTSchemaSource>, List<ASTSchemaSource>> {
+    private static final class SourceIdMismatchDetector implements Function<List<ASTSchemaSource>,
+            List<ASTSchemaSource>> {
         private final List<SourceIdentifier> sourceIdentifiers;
 
         public SourceIdMismatchDetector(final List<SourceIdentifier> sourceIdentifiers) {
@@ -152,8 +157,8 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
                 final SourceIdentifier realSId = astSchemaSource.getIdentifier();
 
                 if (!expectedSId.equals(realSId)) {
-                    LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. Using actual id",
-                        expectedSId.getName(), expectedSId, realSId);
+                    LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. "
+                        + "Using actual id", expectedSId.getName(), expectedSId, realSId);
                 }
 
                 if (filtered.containsKey(realSId)) {
@@ -169,11 +174,11 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
 
     private static final class AssembleSources implements AsyncFunction<List<ASTSchemaSource>, SchemaContext> {
 
-        private final Set<QName> supportedFeatures;
+        private final Optional<Set<QName>> supportedFeatures;
         private final StatementParserMode statementParserMode;
         private final Function<ASTSchemaSource, SourceIdentifier> getIdentifier;
 
-        private AssembleSources(final Set<QName> supportedFeatures,
+        private AssembleSources(final Optional<Set<QName>> supportedFeatures,
                 final StatementParserMode statementParserMode) {
             this.supportedFeatures = supportedFeatures;
             this.statementParserMode = Preconditions.checkNotNull(statementParserMode);
@@ -187,25 +192,26 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
         }
 
         @Override
-        public ListenableFuture<SchemaContext> apply(@Nonnull final List<ASTSchemaSource> sources) throws SchemaResolutionException,
-                SourceException, ReactorException {
+        public ListenableFuture<SchemaContext> apply(@Nonnull final List<ASTSchemaSource> sources)
+                throws SchemaResolutionException, ReactorException {
             final Map<SourceIdentifier, ASTSchemaSource> srcs = Maps.uniqueIndex(sources, getIdentifier);
             final Map<SourceIdentifier, YangModelDependencyInfo> deps =
                     Maps.transformValues(srcs, ASTSchemaSource::getDependencyInformation);
 
             LOG.debug("Resolving dependency reactor {}", deps);
 
-            final DependencyResolver res = this.statementParserMode == StatementParserMode.SEMVER_MODE ? SemVerDependencyResolver
-                    .create(deps) : RevisionDependencyResolver.create(deps);
+            final DependencyResolver res = this.statementParserMode == StatementParserMode.SEMVER_MODE
+                    ? SemVerDependencyResolver.create(deps) : RevisionDependencyResolver.create(deps);
             if (!res.getUnresolvedSources().isEmpty()) {
-                LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(), res.getUnsatisfiedImports());
+                LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(),
+                    res.getUnsatisfiedImports());
                 throw new SchemaResolutionException("Failed to resolve required models",
                         res.getResolvedSources(), res.getUnsatisfiedImports());
             }
 
             final Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource::getAST);
-            final CrossSourceStatementReactor.BuildAction reactor =
-                    YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, supportedFeatures);
+            final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
+                statementParserMode, supportedFeatures);
 
             for (final Entry<SourceIdentifier, ParserRuleContext> e : asts.entrySet()) {
                 final ParserRuleContext parserRuleCtx = e.getValue();
index 26fde0e6f1b1ead0137664af3c13a0fa485b51e1..f116991ab7943d5319b9adc2918463010966596e 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collection;
 import java.util.EnumMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -68,11 +69,24 @@ public final class CrossSourceStatementReactor {
      *
      * @param supportedFeatures The set of supported features in the final SchemaContext
      * @return A new {@link BuildAction}.
+     *
+     * @deprecated Use {@link #newBuild(Optional)} instead.
      */
+    @Deprecated
     public BuildAction newBuild(final Set<QName> supportedFeatures) {
         return new BuildAction(warnOnNull(supportedFeatures), StatementParserMode.DEFAULT_MODE);
     }
 
+    /**
+     * Start a new reactor build using default statement parser mode and only specified features.
+     *
+     * @param supportedFeatures The set of supported features in the final SchemaContext, if present.
+     * @return A new {@link BuildAction}.
+     */
+    public BuildAction newBuild(final Optional<Set<QName>> supportedFeatures) {
+        return new BuildAction(supportedFeatures.orElse(null), StatementParserMode.DEFAULT_MODE);
+    }
+
     /**
      * Start a new reactor build using specified statement parser mode and enabling all features.
      *
@@ -87,15 +101,33 @@ public final class CrossSourceStatementReactor {
     /**
      * Start a new reactor build using default statement parser mode and only specified features.
      *
+     * @param statementParserMode Parser mode to use
      * @param supportedFeatures The set of supported features in the final SchemaContext
      * @return A new {@link BuildAction}.
      * @throws NullPointerException if statementParserMode is null
+     *
+     * @deprecated Use {@link #newBuild(StatementParserMode, Optional)} instead.
      */
+    @Deprecated
     public BuildAction newBuild(final StatementParserMode statementParserMode,
             final Set<QName> supportedFeatures) {
         return new BuildAction(warnOnNull(supportedFeatures), statementParserMode);
     }
 
+    /**
+     * Start a new reactor build using default statement parser mode and only specified features.
+     *
+     * @param statementParserMode Parser mode to use
+     * @param supportedFeatures The set of supported features in the final SchemaContext, or absent if all features
+     *                          encountered should be supported.
+     * @return A new {@link BuildAction}.
+     * @throws NullPointerException if statementParserMode is null
+     */
+    public BuildAction newBuild(final StatementParserMode statementParserMode,
+            final Optional<Set<QName>> supportedFeatures) {
+        return new BuildAction(supportedFeatures.orElse(null), statementParserMode);
+    }
+
     private static <T> T warnOnNull(final T obj) {
         if (obj == null) {
             LOG.info("Set of supported features has not been provided, so all features are supported by default.");
index f1f16df8a3fd6f39e689ccf43abc2827e2b48574..ea7983c08d336916f8b26dcf07c3b95eeb57a9f9 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertNull;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import com.google.common.collect.ImmutableSet;
+import java.util.Optional;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -40,7 +41,8 @@ public class IfFeatureResolutionTest {
                 QName.create("foo-namespace", "1970-01-01", "test-feature-3"),
                 QName.create("bar-namespace", "1970-01-01", "imp-feature"));
 
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(supportedFeatures);
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
+            Optional.of(supportedFeatures));
         reactor.addSources(FOO_MODULE, BAR_MODULE);
 
         final SchemaContext schemaContext = reactor.buildEffective();
@@ -273,9 +275,8 @@ public class IfFeatureResolutionTest {
 
     @Test
     public void testNoFeaturesSupported() throws ReactorException {
-        final Set<QName> supportedFeatures = ImmutableSet.of();
-
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(supportedFeatures);
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
+            Optional.of(ImmutableSet.of()));
         reactor.addSources(FOO_MODULE, BAR_MODULE);
 
         final SchemaContext schemaContext = reactor.buildEffective();