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);
}
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;
}
Aggregations