Search in sources :

Example 1 with FilesystemSchemaSourceCache

use of org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache in project netconf by opendaylight.

the class YangLibProvider method init.

public void init() {
    if (Strings.isNullOrEmpty(yanglibConfig.getCacheFolder())) {
        LOG.info("No cache-folder set in yanglib-config - yang library services will not be available");
        return;
    }
    final File cacheFolderFile = new File(yanglibConfig.getCacheFolder());
    checkArgument(cacheFolderFile.exists(), "cache-folder %s does not exist", cacheFolderFile);
    checkArgument(cacheFolderFile.isDirectory(), "cache-folder %s is not a directory", cacheFolderFile);
    final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(schemaRepository, YangTextSchemaSource.class, cacheFolderFile);
    schemaRepository.registerSchemaSourceListener(cache);
    schemaListenerRegistration = schemaRepository.registerSchemaSourceListener(this);
    LOG.info("Started yang library with sources from {}", cacheFolderFile);
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) FilesystemSchemaSourceCache(org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache) File(java.io.File)

Example 2 with FilesystemSchemaSourceCache

use of org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache in project netconf by opendaylight.

the class NetconfDeviceSimulator method parseSchemasToModuleCapabilities.

private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
    final Set<SourceIdentifier> loadedSources = new HashSet<>();
    consumer.registerSchemaSourceListener(TextToIRTransformer.create(consumer, consumer));
    consumer.registerSchemaSourceListener(new SchemaSourceListener() {

        @Override
        public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
        }

        @Override
        public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
            for (final PotentialSchemaSource<?> potentialSchemaSource : potentialSchemaSources) {
                loadedSources.add(potentialSchemaSource.getSourceIdentifier());
            }
        }

        @Override
        public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
        }
    });
    if (configuration.getSchemasDir() != null) {
        LOG.info("Loading models from directory.");
        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getSchemasDir());
        consumer.registerSchemaSourceListener(cache);
    } else if (configuration.getModels() != null) {
        LOG.info("Loading models from classpath.");
        final SchemaSourceCache<YangTextSchemaSource> cache = new SchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getModels());
        consumer.registerSchemaSourceListener(cache);
    } else {
        LOG.info("Custom module loading skipped.");
    }
    configuration.getDefaultYangResources().forEach(r -> {
        final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(), Revision.ofNullable(r.getRevision()));
        registerSource(consumer, r.getResourcePath(), sourceIdentifier);
    });
    try {
        // necessary for creating mdsal data stores and operations
        this.schemaContext = consumer.createEffectiveModelContextFactory().createEffectiveModelContext(loadedSources).get();
    } catch (final InterruptedException | ExecutionException e) {
        throw new RuntimeException("Cannot parse schema context. " + "Please read stack trace and check YANG files in schema directory.", e);
    }
    final Set<Capability> capabilities = new HashSet<>();
    for (final Module module : schemaContext.getModules()) {
        for (final Submodule subModule : module.getSubmodules()) {
            addModuleCapability(consumer, capabilities, subModule);
        }
        addModuleCapability(consumer, capabilities, module);
    }
    return capabilities;
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) Capability(org.opendaylight.netconf.api.capability.Capability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) SchemaSourceCache(org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache) FilesystemSchemaSourceCache(org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) SchemaSourceListener(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener) FilesystemSchemaSourceCache(org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache) ExecutionException(java.util.concurrent.ExecutionException) Module(org.opendaylight.yangtools.yang.model.api.Module) HashSet(java.util.HashSet)

Aggregations

YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)2 FilesystemSchemaSourceCache (org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache)2 File (java.io.File)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 BasicCapability (org.opendaylight.netconf.api.capability.BasicCapability)1 Capability (org.opendaylight.netconf.api.capability.Capability)1 YangModuleCapability (org.opendaylight.netconf.api.capability.YangModuleCapability)1 SchemaSourceCache (org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 Submodule (org.opendaylight.yangtools.yang.model.api.Submodule)1 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)1 SchemaSourceRepresentation (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 PotentialSchemaSource (org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource)1 SchemaSourceListener (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener)1