Bug 4577 Allow specification of a distinct schema cache directory per netconf device 88/34188/12
authoradetalhouet <adetalhouet@inocybe.com>
Mon, 29 Feb 2016 21:58:33 +0000 (13:58 -0800)
committerTomas Cere <tcere@cisco.com>
Tue, 19 Apr 2016 11:48:35 +0000 (13:48 +0200)
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.

Change-Id: I6a5a6b23fc56bcc507734a99e48de88597b7ae2a
Signed-off-by: adetalhouet <adetalhouet@inocybe.com>
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);