text -> AST transformation of YANG takes majority of the time when tryinh to parse
SchemaContext. Caching is important when mounting a device where not all yang models
are valid or have their dependencies. Netconf connector tires to parse and eliminate
YANG models in a loop until a valid subset is found. Until now, the text -> AST has
been performed in each iteration, really slowing donw the mount process.
Also fix logs in NetconfDevice
Change-Id: I0587299eefdc7a813afd9967363200243b815551
Signed-off-by: Maros Marsalek <mmarsalek@frinx.io>
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
+import org.opendaylight.yangtools.yang.model.repo.util.InMemorySchemaSourceCache;
import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
new FilesystemSchemaSourceCache<>(DEFAULT_SCHEMA_REPOSITORY, YangTextSchemaSource.class,
new File(QUALIFIED_DEFAULT_CACHE_DIRECTORY));
+ public static final InMemorySchemaSourceCache<ASTSchemaSource> DEFAULT_AST_CACHE =
+ InMemorySchemaSourceCache.createSoftCache(DEFAULT_SCHEMA_REPOSITORY, ASTSchemaSource.class);
+
// The default factory for creating <code>SchemaContext</code> instances.
public static final SchemaContextFactory DEFAULT_SCHEMA_CONTEXT_FACTORY =
DEFAULT_SCHEMA_REPOSITORY.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
new NetconfDevice.SchemaResourcesDTO(DEFAULT_SCHEMA_REPOSITORY, DEFAULT_SCHEMA_REPOSITORY,
DEFAULT_SCHEMA_CONTEXT_FACTORY, new NetconfStateSchemasResolverImpl()));
DEFAULT_SCHEMA_REPOSITORY.registerSchemaSourceListener(DEFAULT_CACHE);
+ DEFAULT_SCHEMA_REPOSITORY.registerSchemaSourceListener(DEFAULT_AST_CACHE);
DEFAULT_SCHEMA_REPOSITORY.registerSchemaSourceListener(
TextToASTTransformer.create(DEFAULT_SCHEMA_REPOSITORY, DEFAULT_SCHEMA_REPOSITORY));
}
final FilesystemSchemaSourceCache<YangTextSchemaSource> deviceCache =
createDeviceFilesystemCache(moduleSchemaCacheDirectory, repository);
repository.registerSchemaSourceListener(deviceCache);
+ repository.registerSchemaSourceListener(InMemorySchemaSourceCache.createSoftCache(repository,
+ ASTSchemaSource.class));
return new NetconfDevice.SchemaResourcesDTO(repository, repository, schemaContextFactory,
new NetconfStateSchemasResolverImpl());
}
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
+import org.opendaylight.yangtools.yang.model.repo.util.InMemorySchemaSourceCache;
import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
new FilesystemSchemaSourceCache<>(DEFAULT_SCHEMA_REPOSITORY, YangTextSchemaSource.class,
new File(QUALIFIED_DEFAULT_CACHE_DIRECTORY));
+ public static final InMemorySchemaSourceCache<ASTSchemaSource> DEFAULT_AST_CACHE =
+ InMemorySchemaSourceCache.createSoftCache(DEFAULT_SCHEMA_REPOSITORY, ASTSchemaSource.class);
+
/**
* The default factory for creating <code>SchemaContext</code> instances.
*/
DEFAULT_SCHEMA_CONTEXT_FACTORY,
new NetconfStateSchemasResolverImpl()));
DEFAULT_SCHEMA_REPOSITORY.registerSchemaSourceListener(DEFAULT_CACHE);
+ DEFAULT_SCHEMA_REPOSITORY.registerSchemaSourceListener(DEFAULT_AST_CACHE);
DEFAULT_SCHEMA_REPOSITORY.registerSchemaSourceListener(
TextToASTTransformer.create(DEFAULT_SCHEMA_REPOSITORY, DEFAULT_SCHEMA_REPOSITORY));
}
final FilesystemSchemaSourceCache<YangTextSchemaSource> deviceCache =
createDeviceFilesystemCache(moduleSchemaCacheDirectory);
repository.registerSchemaSourceListener(deviceCache);
+ repository.registerSchemaSourceListener(
+ InMemorySchemaSourceCache.createSoftCache(repository, ASTSchemaSource.class));
return new NetconfDevice.SchemaResourcesDTO(repository, repository, contextFactory,
new NetconfStateSchemasResolverImpl());
}
final Collection<SourceIdentifier> requiredSources, final MissingSchemaSourceException exception) {
// In case source missing, try without it
final SourceIdentifier missingSource = exception.getSourceId();
- LOG.warn("{}: Unable to build schema context, missing source {}, will reattempt without it", id,
- missingSource);
+ LOG.warn("{}: Unable to build schema context, missing source {}, will reattempt without it",
+ id, missingSource);
LOG.debug("{}: Unable to build schema context, missing source {}, will reattempt without it",
- exception);
+ id, missingSource, exception);
final Collection<QName> qNameOfMissingSource =
- getQNameFromSourceIdentifiers(Sets.newHashSet(missingSource));
+ getQNameFromSourceIdentifiers(Sets.newHashSet(missingSource));
if (!qNameOfMissingSource.isEmpty()) {
capabilities.addUnresolvedCapabilities(
qNameOfMissingSource, UnavailableCapability.FailureReason.MissingSource);
// flawed model - exclude it
final SourceIdentifier failedSourceId = resolutionException.getFailedSource();
LOG.warn("{}: Unable to build schema context, failed to resolve source {}, will reattempt without it",
- id, failedSourceId);
+ id, failedSourceId);
LOG.warn("{}: Unable to build schema context, failed to resolve source {}, will reattempt without it",
- id, resolutionException);
- capabilities.addUnresolvedCapabilities(getQNameFromSourceIdentifiers(
- Collections.singleton(failedSourceId)), UnavailableCapability.FailureReason.UnableToResolve);
+ id, failedSourceId, resolutionException);
+ capabilities.addUnresolvedCapabilities(
+ getQNameFromSourceIdentifiers(Collections.singleton(failedSourceId)),
+ UnavailableCapability.FailureReason.UnableToResolve);
return stripUnavailableSource(requiredSources, resolutionException.getFailedSource());
}
// unsatisfied imports
final Set<SourceIdentifier> unresolvedSources = resolutionException.getUnsatisfiedImports().keySet();
- capabilities.addUnresolvedCapabilities(
- getQNameFromSourceIdentifiers(unresolvedSources), UnavailableCapability.FailureReason.UnableToResolve);
+ capabilities.addUnresolvedCapabilities(getQNameFromSourceIdentifiers(unresolvedSources),
+ UnavailableCapability.FailureReason.UnableToResolve);
LOG.warn("{}: Unable to build schema context, unsatisfied imports {}, will reattempt with resolved only",
- id, resolutionException.getUnsatisfiedImports());
+ id, resolutionException.getUnsatisfiedImports());
LOG.debug("{}: Unable to build schema context, unsatisfied imports {}, will reattempt with resolved only",
- resolutionException);
+ id, resolutionException.getUnsatisfiedImports(), resolutionException);
return resolutionException.getResolvedSources();
}