import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
final @NonNull SchemaContextFactoryConfiguration config) {
this.parserFactory = parserFactory;
this.config = config;
- switch (config.getStatementParserMode()) {
- case SEMVER_MODE:
- this.getIdentifier = AssembleSources::getSemVerIdentifier;
- break;
- default:
- this.getIdentifier = IRSchemaSource::getIdentifier;
- }
+ getIdentifier = switch (config.getStatementParserMode()) {
+ case DEFAULT_MODE -> IRSchemaSource::getIdentifier;
+ };
}
@Override
LOG.debug("Resolving dependency reactor {}", deps);
- final StatementParserMode statementParserMode = config.getStatementParserMode();
- final DependencyResolver res = statementParserMode == StatementParserMode.SEMVER_MODE
- ? SemVerDependencyResolver.create(deps) : RevisionDependencyResolver.create(deps);
+ final DependencyResolver res = switch (config.getStatementParserMode()) {
+ case DEFAULT_MODE -> RevisionDependencyResolver.create(deps);
+ };
+
if (!res.getUnresolvedSources().isEmpty()) {
LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(),
res.getUnsatisfiedImports());
return immediateFluentFuture(schemaContext);
}
-
- private static SemVerSourceIdentifier getSemVerIdentifier(final IRSchemaSource source) {
- final SourceIdentifier identifier = source.getIdentifier();
- final SemVer semver = YangModelDependencyInfo.findSemanticVersion(source.getRootStatement(), identifier);
- if (identifier instanceof SemVerSourceIdentifier && semver == null) {
- return (SemVerSourceIdentifier) identifier;
- }
-
- return SemVerSourceIdentifier.create(identifier.getName(), identifier.getRevision(), semver);
- }
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.repo;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Optional;
-import org.opendaylight.yangtools.concepts.SemVer;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
-import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
-
-final class SemVerDependencyResolver extends DependencyResolver {
- private static final YangParserConfiguration CONFIG = YangParserConfiguration.builder()
- .importResolutionMode(ImportResolutionMode.OPENCONFIG_SEMVER)
- .build();
-
- SemVerDependencyResolver(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
- super(depInfo);
- }
-
- protected static SourceIdentifier findCompatibleVersion(final Iterable<SourceIdentifier> haystack,
- final ModuleImport mi) {
- final String requestedModuleName = mi.getModuleName();
- for (SourceIdentifier r : haystack) {
- if (requestedModuleName.equals(r.getName())
- && isCompatible(((SemVerSourceIdentifier) r).getSemanticVersion(), mi.getSemanticVersion())) {
- return r;
- }
- }
-
- return null;
- }
-
- private static boolean isCompatible(final Optional<SemVer> moduleSemVer, final Optional<SemVer> importSemVer) {
- if (importSemVer.isEmpty()) {
- // Import does not care about the version
- return true;
- }
- if (moduleSemVer.isEmpty()) {
- // Modules which do not declare a semantic version are incompatible with imports which do
- return false;
- }
-
- final SemVer modVer = moduleSemVer.get();
- final SemVer impVer = importSemVer.get();
- return modVer.getMajor() == impVer.getMajor() && modVer.compareTo(impVer) >= 0;
- }
-
- @Override
- YangParserConfiguration parserConfig() {
- return CONFIG;
- }
-
- @Override
- protected boolean isKnown(final Collection<SourceIdentifier> haystack, final ModuleImport mi) {
- final SemVerSourceIdentifier msi = SemVerSourceIdentifier.create(mi.getModuleName(), mi.getRevision(),
- mi.getSemanticVersion().orElse(null));
-
- // Quick lookup
- if (haystack.contains(msi)) {
- return true;
- }
-
- // Slow revision-less walk
- return findCompatibleVersion(haystack, mi) != null;
- }
-
- public static SemVerDependencyResolver create(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
- return new SemVerDependencyResolver(depInfo);
- }
-}
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
-import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class OpenconfigVerSharedSchemaRepositoryTest {
-
- @Test
- public void testSemVerSharedSchemaRepository() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "openconfig-ver-shared-schema-repo-test");
-
- final SettableSchemaProvider<IRSchemaSource> bar = getImmediateYangSourceProviderFromResource(
- "/openconfig-version/openconfigver-shared-schema-repository/bar@2016-01-01.yang");
- bar.register(sharedSchemaRepository);
- bar.setResult();
- final SettableSchemaProvider<IRSchemaSource> foo = getImmediateYangSourceProviderFromResource(
- "/openconfig-version/openconfigver-shared-schema-repository/foo.yang");
- foo.register(sharedSchemaRepository);
- foo.setResult();
- final SettableSchemaProvider<IRSchemaSource> semVer = getImmediateYangSourceProviderFromResource(
- "/openconfig-version/openconfigver-shared-schema-repository/openconfig-extensions.yang");
- semVer.register(sharedSchemaRepository);
- semVer.setResult();
-
- final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory(
- SchemaContextFactoryConfiguration.builder().setStatementParserMode(StatementParserMode.SEMVER_MODE)
- .build());
-
- final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture =
- fact.createEffectiveModelContext(bar.getId(), foo.getId(), semVer.getId());
- assertTrue(inetAndTopologySchemaContextFuture.isDone());
- assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 3);
-
- final ListenableFuture<EffectiveModelContext> barSchemaContextFuture = fact.createEffectiveModelContext(
- bar.getId(), semVer.getId());
- assertTrue(barSchemaContextFuture.isDone());
- assertSchemaContext(barSchemaContextFuture.get(), 2);
- }
-
@Test
public void testSharedSchemaRepository() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-test");
+++ /dev/null
-module bar {
- namespace "bar";
- prefix bar;
- yang-version 1;
-
- import openconfig-extensions { prefix oc-ext; revision-date 2017-01-29; oc-ext:openconfig-version "0.0.1"; }
-
- revision "2016-01-01" {
- description "Initial version";
- }
- oc-ext:openconfig-version "0.1.2";
-
- container root {
- }
-}
+++ /dev/null
-module foo {
- namespace "foo";
- prefix foo;
- yang-version 1;
-
- import openconfig-extensions { prefix oc-ext; revision-date 2017-01-29; oc-ext:openconfig-version "0.0.1"; }
- import bar { prefix bar; revision-date 2016-01-31; oc-ext:openconfig-version "0.1.2";}
-
- revision "2016-02-01" {
- description "Initial version";
- }
- oc-ext:openconfig-version "0.1.1";
-
- container root {
- }
-}
+++ /dev/null
-module openconfig-extensions {
- yang-version "1";
- namespace "http://openconfig.net/yang/openconfig-ext";
- prefix "oc-ext";
-
- organization "OpenConfig working group";
-
- contact
- "OpenConfig working group
- www.openconfig.net";
-
- description
- "This module provides extensions to the YANG language to allow
- OpenConfig specific functionality and meta-data to be defined.";
-
- revision "2017-01-29" {
- description
- "Added extension for annotating encrypted values.";
- reference "TBD";
- }
-
- revision "2015-10-09" {
- description
- "Initial OpenConfig public release";
- reference "TBD";
- }
-
- revision "2015-10-05" {
- description
- "Initial revision";
- reference "TBD";
- }
-
- oc-ext:openconfig-version "0.0.1";
-
- extension openconfig-version {
- argument "semver" {
- yin-element false;
- }
- description
- "The OpenConfig version number for the module. This is
- expressed as a semantic version number of the form:
- x.y.z
- where:
- * x corresponds to the major version,
- * y corresponds to a minor version,
- * z corresponds to a patch version.
- This version corresponds to the model file within which it is
- defined, and does not cover the whole set of OpenConfig models.
- Where several modules are used to build up a single block of
- functionality, the same module version is specified across each
- file that makes up the module.
-
- A major version number of 0 indicates that this model is still
- in development (whether within OpenConfig or with industry
- partners), and is potentially subject to change.
-
- Following a release of major version 1, all modules will
- increment major revision number where backwards incompatible
- changes to the model are made.
-
- The minor version is changed when features are added to the
- model that do not impact current clients use of the model.
-
- The patch-level version is incremented when non-feature changes
- (such as bugfixes or clarifications to human-readable
- descriptions that do not impact model functionality) are made
- that maintain backwards compatibility.
-
- The version number is stored in the module meta-data.";
- }
-
- extension openconfig-encrypted-value {
- description
- "This extension provides an annotation on schema nodes to
- indicate that the corresponding value should be stored and
- reported in encrypted form.
- Clients reading the configuration or applied configuration
- for the node should expect to receive only the encrypted value.
- This annotation may be used on nodes such as secure passwords
- in which the device never reports a cleartext value, even
- if the input is provided as cleartext.";
- }
-}
\ No newline at end of file
/**
* Default mode of statement parser.
*/
- DEFAULT_MODE,
- /**
- * Semantic version mode of statement parser. If it is enabled, module imports are processed on the basis of
- * semantic versions.
- */
- @Deprecated(since = "7.0.11", forRemoval = true)
- SEMVER_MODE
-}
\ No newline at end of file
+ DEFAULT_MODE;
+}