Search in sources :

Example 1 with SchemaSourceRegistry

use of org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry in project netconf by opendaylight.

the class NetconfDeviceTest method getSchemaRegistry.

private static SchemaSourceRegistry getSchemaRegistry() {
    final SchemaSourceRegistry mock = mock(SchemaSourceRegistry.class);
    final SchemaSourceRegistration<?> mockReg = mock(SchemaSourceRegistration.class);
    doNothing().when(mockReg).close();
    doReturn(mockReg).when(mock).registerSchemaSource(any(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider.class), any(PotentialSchemaSource.class));
    return mock;
}
Also used : SchemaSourceRegistry(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource)

Example 2 with SchemaSourceRegistry

use of org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry in project netconf by opendaylight.

the class AbstractNetconfTopology method registerDeviceSchemaSources.

private List<SchemaSourceRegistration<?>> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId, final NetconfNode node, final SchemaResourcesDTO resources) {
    final YangLibrary yangLibrary = node.getYangLibrary();
    if (yangLibrary != null) {
        final Uri uri = yangLibrary.getYangLibraryUrl();
        if (uri != null) {
            final List<SchemaSourceRegistration<?>> registrations = new ArrayList<>();
            final String yangLibURL = uri.getValue();
            final SchemaSourceRegistry schemaRegistry = resources.getSchemaRegistry();
            // pre register yang library sources as fallback schemas to schema registry
            final LibraryModulesSchemas schemas;
            final String yangLibUsername = yangLibrary.getUsername();
            final String yangLigPassword = yangLibrary.getPassword();
            if (yangLibUsername != null && yangLigPassword != null) {
                schemas = LibraryModulesSchemas.create(yangLibURL, yangLibUsername, yangLigPassword);
            } else {
                schemas = LibraryModulesSchemas.create(yangLibURL);
            }
            for (final Map.Entry<SourceIdentifier, URL> entry : schemas.getAvailableModels().entrySet()) {
                registrations.add(schemaRegistry.registerSchemaSource(new YangLibrarySchemaYangSourceProvider(remoteDeviceId, schemas.getAvailableModels()), PotentialSchemaSource.create(entry.getKey(), YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
            }
            return List.copyOf(registrations);
        }
    }
    return List.of();
}
Also used : YangLibrarySchemaYangSourceProvider(org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider) ArrayList(java.util.ArrayList) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) YangLibrary(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) URL(java.net.URL) LibraryModulesSchemas(org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) SchemaSourceRegistry(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SchemaSourceRegistry (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LibraryModulesSchemas (org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas)1 YangLibrarySchemaYangSourceProvider (org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider)1 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)1 YangLibrary (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 PotentialSchemaSource (org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource)1 SchemaSourceRegistration (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration)1