Bug 4577 Allow specification of a distinct schema cache directory per netconf device 89/34189/10
authoradetalhouet <adetalhouet@inocybe.com>
Thu, 10 Mar 2016 13:23:39 +0000 (08:23 -0500)
committerAlexis de Talhouët <adetalhouet@inocybe.com>
Tue, 19 Apr 2016 12:43:05 +0000 (12:43 +0000)
First iteration done here https://git.opendaylight.org/gerrit/#/c/30163 introduce a BUG:
sideloaded schemas, manually added in cache/schema, and specified in the netconf connector,
where not being taking in account in the specified cache folder.

This path add the capability to register the sideloaded schema in the new FilesystemSchemaSourceCache

Change-Id: I6a5a6b23fc56bcc507734a99e48de88597b7ae2a
Signed-off-by: adetalhouet <adetalhouet@inocybe.com>
opendaylight/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java

index d7222c1bb26beb1ce03bb3acdded9a35d65003f8..4538857184f42f7befc4c9034dd42fd6e9f85e25 100644 (file)
@@ -47,10 +47,13 @@ import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.protocol.framework.TimedReconnectStrategy;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Host;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
@@ -105,6 +108,8 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
     private static final SchemaContextFactory DEFAULT_SCHEMA_CONTEXT_FACTORY =
             DEFAULT_SCHEMA_REPOSITORY.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
 
+    private static final int LOCAL_IO_FALLBACK_COST = PotentialSchemaSource.Costs.LOCAL_IO.getValue() + 1;
+
     /**
      * Keeps track of initialized Schema resources.  A Map is maintained in which the key represents the name
      * of the schema cache directory, and the value is a corresponding <code>SchemaResourcesDTO</code>.  The
@@ -226,6 +231,12 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
                         setSchemaRegistry(dto.getSchemaRegistry());
                         schemaResourcesDTO = dto;
                     }
+                    if (userCapabilities.isPresent()) {
+                        for (QName qname : userCapabilities.get().getModuleBasedCaps()) {
+                            final SourceIdentifier sourceIdentifier = new SourceIdentifier(qname.getLocalName(), qname.getFormattedRevision());
+                            dto.getSchemaRegistry().registerSchemaSource(DEFAULT_CACHE, PotentialSchemaSource.create(sourceIdentifier, YangTextSchemaSource.class, LOCAL_IO_FALLBACK_COST));
+                        }
+                    }
                 }
                 LOG.info("Netconf connector for device {} will use schema cache directory {} instead of {}",
                         instanceName, moduleSchemaCacheDirectory, DEFAULT_CACHE_DIRECTORY);