Convert yanglib to OSGi DS 19/103919/18
authorOleksandrZharov <Oleksandr.Zharov@pantheon.tech>
Wed, 4 Jan 2023 09:05:07 +0000 (10:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 4 Jul 2023 21:42:48 +0000 (23:42 +0200)
This is a rather simple component, convert it to OSGi DS, along with
configuration in Config Admin. This means we are removing an initial
configuration XML and replacing it with defaults in
ObjectClassDefinition.

Further changes entail:
- renaming WebInitialized to JaxRsYangLib to make it clear the component
  is a JAX-RS specific thing
- fixing up pom.xml dependency declarations to eliminate maven warnings

Finally we update the documetation to make sure we do not have stale
references.

JIRA: NETCONF-772
Change-Id: I1ef32510c7acf134d8d548003fc607e2800d235e
Signed-off-by: OleksandrZharov <Oleksandr.Zharov@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
artifacts/pom.xml
docs/user-guide.rst
features/odl-yanglib/pom.xml
features/odl-yanglib/src/main/feature/feature.xml
netconf/yanglib/pom.xml
netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/JaxRsYangLib.java [moved from netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/WebInitializer.java with 62% similarity]
netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java
netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibRestApp.java
netconf/yanglib/src/main/resources/OSGI-INF/blueprint/yanglib.xml [deleted file]
netconf/yanglib/src/main/resources/initial/yanglib-config.xml [deleted file]
netconf/yanglib/src/main/yang/yanglib.yang [deleted file]
netconf/yanglib/src/test/java/org/opendaylight/yanglib/impl/YangLibProviderTest.java

index baa6ac6281d391a1ac7fdfc6ef8b614207a04322..857e1591d4f8c9b2f76bdc9b5397818c4092da26 100644 (file)
                 <artifactId>yanglib</artifactId>
                 <version>${project.version}</version>
             </dependency>
-            <dependency>
-                <groupId>org.opendaylight.netconf</groupId>
-                <artifactId>yanglib</artifactId>
-                <version>${project.version}</version>
-                <classifier>config</classifier>
-                <type>xml</type>
-            </dependency>
 
             <dependency>
                 <groupId>org.opendaylight.netconf</groupId>
index 5e31ff80544eddb55b8bca14015fbfd6126af9ce..74bb5e037197211c3b8abb10af8ab68b0260817a 100644 (file)
@@ -1137,37 +1137,34 @@ To start this plugin, you have to install odl-yanglib feature. Then you
 have to configure YANGLIB either through RESTCONF or NETCONF. We will
 show how to configure YANGLIB through RESTCONF.
 
-YANGLIB configuration through RESTCONF
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-You have to specify what local YANG modules directory you want to provide.
-Then you have to specify address and port whre you want to provide YANG
-sources. For example, we want to serve yang sources from folder /sources
-on localhost:8181 adress. The configuration for this scenario will be
-as follows:
+YANGLIB configuration
+~~~~~~~~~~~~~~~~~~~~~
+YANGLIB configuration works through OSGi Configuration Admin interface, in the
+``org.opendaylight.netconf.yanglib`` configuration PID. There are three tuneables you can
+set:
 
-::
+* ``cache-folder``, which defaults to ``cache/schema``
+* ``binding-address``, which defaults to ``localhost``
+* ``binding-port``, which defaults to ``8181``
 
-    PUT  http://localhost:8181/rests/data/yanglib:yanglib-config
-
-Headers:
+In order to change these settings, you can either modify the corresponding configuration
+file, ``etc/org.opendaylight.netconf.yanglib.cfg``, for example:
 
--  Accept: application/xml
-
--  Content-Type: application/xml
+::
+    cache-folder = cache/newSchema
+    binding-address = localhost
+    binding-port = 8181
 
-Payload:
+Or use Karaf CLI:
 
 ::
+    opendaylight-user@root>config:edit org.opendaylight.netconf.yanglib
+    opendaylight-user@root>config:property-set cache-folder cache/newSchema
+    opendaylight-user@root>config:property-set binding-address localhost
+    opendaylight-user@root>config:property-set binding-port 8181
+    opendaylight-user@root>config:update
 
-    <yanglib-config xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">
-        <cache-folder>cache/newSchema</cache-folder>
-        <binding-addr>localhost</binding-addr>
-        <binding-port>8181</binding-port>
-    </yanglib-config>
-
-This should result in a 2xx response and new YANGLIB instance should be
-created. This YANGLIB takes all YANG sources from /sources folder and
+This YANGLIB takes all YANG sources from the configured sources folder and
 for each generates URL in form:
 
 ::
index 821011c3e625a0abc7f26557439e09c3382b1017..15861051e534d46b94c3520e30d80c1e4c57724d 100644 (file)
             <groupId>org.opendaylight.netconf</groupId>
             <artifactId>yanglib</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.netconf</groupId>
-            <artifactId>yanglib</artifactId>
-            <type>xml</type>
-            <classifier>config</classifier>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.netconf</groupId>
             <artifactId>odl-restconf</artifactId>
index 8f4869c63b8b9e3d245ee1cc2665533e0c0a9fa8..5f8a7c27983ddd9a511937c5136f5aa4d7250174 100644 (file)
@@ -10,8 +10,5 @@
     <feature name="odl-yanglib" version="${project.version}">
         <feature version="[13,14)">odl-karaf-feat-jetty</feature>
         <feature version="[12,13)">odl-mdsal-model-rfc8525</feature>
-        <configfile finalname="etc/opendaylight/datastore/initial/config/yanglib-config.xml">
-            mvn:org.opendaylight.netconf/yanglib/${project.version}/xml/config
-        </configfile>
     </feature>
 </features>
index 91a52411454e13758bb97a1fbc319d51985e9b5b..09da59c0d8b7b4dcb6c64f9e80a3dba94ab3448f 100644 (file)
                     </instructions>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>attach-artifacts</id>
-                        <goals>
-                            <goal>attach-artifact</goal>
-                        </goals>
-                        <phase>package</phase>
-                        <configuration>
-                            <artifacts>
-                                <artifact>
-                                    <file>${project.build.directory}/classes/initial/yanglib-config.xml</file>
-                                    <type>xml</type>
-                                    <classifier>config</classifier>
-                                </artifact>
-                            </artifacts>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
 
     <dependencies>
-        <dependency>
-            <groupId>org.opendaylight.mdsal</groupId>
-            <artifactId>mdsal-binding-api</artifactId>
-        </dependency>
         <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
-            <artifactId>rfc8525</artifactId>
+            <groupId>com.guicedee.services</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>jakarta.annotation</groupId>
+            <artifactId>jakarta.annotation-api</artifactId>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>jakarta.ws.rs</groupId>
+            <artifactId>jakarta.ws.rs-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jdt</groupId>
+            <artifactId>org.eclipse.jdt.annotation</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>concepts</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-parser-api</artifactId>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-parser-impl</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-repo-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-repo-spi</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-repo-fs</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>mdsal-common-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>mdsal-binding-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+            <artifactId>rfc6991-ietf-inet-types</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+            <artifactId>rfc6991-ietf-yang-types</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+            <artifactId>rfc8525</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.aaa.web</groupId>
             <artifactId>web-api</artifactId>
             <groupId>org.opendaylight.aaa.web</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
similarity index 62%
rename from netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/WebInitializer.java
rename to netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/JaxRsYangLib.java
index 179c488da4d4d774f67e12c8b6dfecb23274bb8b..3bf4610240ce69ca2279348a8a9fc090d4b44a50 100644 (file)
@@ -7,31 +7,43 @@
  */
 package org.opendaylight.yanglib.impl;
 
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.servlet.ServletException;
-import javax.ws.rs.core.Application;
 import org.opendaylight.aaa.web.ServletDetails;
 import org.opendaylight.aaa.web.WebContext;
 import org.opendaylight.aaa.web.WebContextSecurer;
 import org.opendaylight.aaa.web.WebServer;
 import org.opendaylight.aaa.web.servlet.ServletSupport;
+import org.opendaylight.yanglib.api.YangLibService;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * Initializes the wep app.
  *
  * @author Thomas Pantelis
  */
-public final class WebInitializer implements AutoCloseable {
+@Singleton
+@Component(service = { })
+public final class JaxRsYangLib implements AutoCloseable {
     private final Registration registration;
 
-    public WebInitializer(final WebServer webServer,  final WebContextSecurer webContextSecurer,
-            final ServletSupport servletSupport, final Application webApp) throws ServletException {
+    @Activate
+    @Inject
+    public JaxRsYangLib(@Reference final WebServer webServer, @Reference final WebContextSecurer webContextSecurer,
+            @Reference final ServletSupport servletSupport, @Reference final YangLibService yangLibService)
+                throws ServletException {
         final var webContextBuilder = WebContext.builder()
             .name("RFC8525 YANG Library")
             .contextPath("/yanglib")
             .supportsSessions(true)
             .addServlet(ServletDetails.builder()
-                .servlet(servletSupport.createHttpServletBuilder(webApp).build())
+                .servlet(servletSupport.createHttpServletBuilder(new YangLibRestApp(yangLibService)).build())
                 .addUrlPattern("/*")
                 .build());
 
@@ -40,6 +52,8 @@ public final class WebInitializer implements AutoCloseable {
         registration = webServer.registerWebContext(webContextBuilder.build());
     }
 
+    @PreDestroy
+    @Deactivate
     @Override
     public void close() {
         registration.close();
index 1806f1c9e2e6404ed65fffa4bbb773782999629c..c7b29d4b627bcfd5ffccde2394e6a6b11d6cdebb 100644 (file)
@@ -10,19 +10,22 @@ package org.opendaylight.yanglib.impl;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Strings;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
-import java.util.function.Predicate;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
@@ -35,9 +38,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.librar
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.ModuleBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.ModuleKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.yanglib.impl.rev141210.YanglibConfig;
 import org.opendaylight.yanglib.api.YangLibService;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -48,6 +51,13 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaListenerRegistration
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,38 +67,56 @@ import org.slf4j.LoggerFactory;
  * along with source identifier to
  * ietf-netconf-yang-library/modules-state/module list.
  */
-public class YangLibProvider implements AutoCloseable, SchemaSourceListener, YangLibService {
+@Singleton
+@Component(service = YangLibService.class, configurationPid = "org.opendaylight.netconf.yanglib")
+@Designate(ocd = YangLibProvider.Configuration.class)
+public final class YangLibProvider implements YangLibService, SchemaSourceListener, AutoCloseable {
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition(min = "1",
+            description = "Local filesystem folder to use as cache + to load yang models from")
+        @NonNull String cache$_$folder() default "cache/schema";
+
+        @AttributeDefinition(
+            description = "Binding address is necessary for generating proper URLS (accessible from the outside world) "
+                + "for models present directly in the library")
+        @NonNull String binding$_$address() default "localhost";
+
+        @AttributeDefinition(required = true, min = "1", max = "65535",
+            description = "binding port is necessary for generating proper URLS (accessible from the outside world) "
+                + "for models present directly in the library")
+        int binding$_$port() default 8181;
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(YangLibProvider.class);
 
     private static final Predicate<PotentialSchemaSource<?>> YANG_SCHEMA_SOURCE =
         input -> YangTextSchemaSource.class.isAssignableFrom(input.getRepresentation());
 
     private final DataBroker dataBroker;
-    private final YanglibConfig yanglibConfig;
+    private final String bindingAddress;
+    private final Uint32 bindingPort;
     private final SharedSchemaRepository schemaRepository;
-    private SchemaListenerRegistration schemaListenerRegistration;
 
-    public YangLibProvider(final YanglibConfig yanglibConfig, final DataBroker dataBroker,
-            final YangParserFactory parserFactory) {
-        this.yanglibConfig = requireNonNull(yanglibConfig);
-        this.dataBroker = requireNonNull(dataBroker);
-        schemaRepository = new SharedSchemaRepository("yang-library", parserFactory);
-    }
+    private final SchemaListenerRegistration schemaListenerRegistration;
 
-    @Override
-    public void close() {
-        if (schemaListenerRegistration != null) {
-            schemaListenerRegistration.close();
-        }
+    @Inject
+    @Activate
+    public YangLibProvider(@Reference final @NonNull DataBroker dataBroker,
+            @Reference final @NonNull YangParserFactory parserFactory, final @NonNull Configuration configuration) {
+        this(dataBroker, parserFactory, configuration.cache$_$folder(), configuration.binding$_$address(),
+                Uint32.valueOf(configuration.binding$_$port()));
     }
 
-    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;
-        }
+    @VisibleForTesting
+    YangLibProvider(final @NonNull DataBroker dataBroker, final @NonNull YangParserFactory parserFactory,
+                    final @NonNull String cacheFolder, final @NonNull String bindingAddress,
+                    final @NonNull Uint32 bindingPort) {
+        this.bindingAddress = bindingAddress;
+        this.bindingPort = bindingPort;
+        this.dataBroker = requireNonNull(dataBroker);
 
-        final File cacheFolderFile = new File(yanglibConfig.getCacheFolder());
+        final File cacheFolderFile = new File(cacheFolder);
         if (cacheFolderFile.exists()) {
             LOG.info("cache-folder {} already exists", cacheFolderFile);
         } else {
@@ -97,8 +125,9 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener, Yan
         }
         checkArgument(cacheFolderFile.isDirectory(), "cache-folder %s is not a directory", cacheFolderFile);
 
-        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache =
-                new FilesystemSchemaSourceCache<>(schemaRepository, YangTextSchemaSource.class, cacheFolderFile);
+        schemaRepository = new SharedSchemaRepository("yang-library", parserFactory);
+        final var cache = new FilesystemSchemaSourceCache<>(schemaRepository, YangTextSchemaSource.class,
+            cacheFolderFile);
         schemaRepository.registerSchemaSourceListener(cache);
 
         schemaListenerRegistration = schemaRepository.registerSchemaSourceListener(this);
@@ -106,6 +135,13 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener, Yan
         LOG.info("Started yang library with sources from {}", cacheFolderFile);
     }
 
+    @PreDestroy
+    @Deactivate
+    @Override
+    public void close() {
+        schemaListenerRegistration.close();
+    }
+
     @Override
     public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
         // NOOP
@@ -113,13 +149,12 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener, Yan
 
     @Override
     public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> sources) {
-        final Map<ModuleKey, Module> newModules = new HashMap<>();
+        final var newModules = new HashMap<ModuleKey, Module>();
 
-        for (PotentialSchemaSource<?> potentialYangSource : Iterables.filter(sources, YANG_SCHEMA_SOURCE::test)) {
-            final YangIdentifier moduleName =
-                new YangIdentifier(potentialYangSource.getSourceIdentifier().name().getLocalName());
+        for (var potentialYangSource : Iterables.filter(sources, YANG_SCHEMA_SOURCE::test)) {
+            final var moduleName = new YangIdentifier(potentialYangSource.getSourceIdentifier().name().getLocalName());
 
-            final Module newModule = new ModuleBuilder()
+            final var newModule = new ModuleBuilder()
                     .setName(moduleName)
                     .setRevision(LegacyRevisionUtils.fromYangCommon(
                         Optional.ofNullable(potentialYangSource.getSourceIdentifier().revision())))
@@ -209,8 +244,8 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener, Yan
     }
 
     private Uri getUrlForModule(final SourceIdentifier sourceIdentifier) {
-        return new Uri("http://" + yanglibConfig.getBindingAddr() + ':' + yanglibConfig.getBindingPort()
-                + "/yanglib/schemas/" + sourceIdentifier.name().getLocalName() + revString(sourceIdentifier));
+        return new Uri("http://" + bindingAddress + ':' + bindingPort + "/yanglib/schemas/"
+                + sourceIdentifier.name().getLocalName() + revString(sourceIdentifier));
     }
 
     private static String revString(final SourceIdentifier id) {
index 51f6366897a34e11816f36daa80e4f0b35871a1e..426a1148035992eabe18fce576f2419e5fecf56e 100644 (file)
@@ -13,7 +13,7 @@ import java.util.Set;
 import javax.ws.rs.core.Application;
 import org.opendaylight.yanglib.api.YangLibService;
 
-public class YangLibRestApp extends Application {
+public final class YangLibRestApp extends Application {
     private final YangLibService yangLibService;
 
     public YangLibRestApp(final YangLibService yangLibService) {
diff --git a/netconf/yanglib/src/main/resources/OSGI-INF/blueprint/yanglib.xml b/netconf/yanglib/src/main/resources/OSGI-INF/blueprint/yanglib.xml
deleted file mode 100644 (file)
index 9fe5243..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2017 Inocybe Technologies Inc. and others.  All rights reserved.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-
-  <odl:clustered-app-config id="yanglibConfig" default-config-file-name="yanglib-config.xml"
-      binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.yanglib.impl.rev141210.YanglibConfig"/>
-
-  <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
-  <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer"/>
-  <reference id="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer"/>
-  <reference id="servletSupport" interface="org.opendaylight.aaa.web.servlet.ServletSupport" />
-  <reference id="parserFactory" interface="org.opendaylight.yangtools.yang.parser.api.YangParserFactory" />
-
-  <bean id="yangLibProvider" class="org.opendaylight.yanglib.impl.YangLibProvider"
-          init-method="init" destroy-method="close">
-    <argument ref="yanglibConfig"/>
-    <argument ref="dataBroker"/>
-    <argument ref="parserFactory"/>
-  </bean>
-
-  <bean id="yangLibRestApp" class="org.opendaylight.yanglib.impl.YangLibRestApp">
-    <argument ref="yangLibProvider"/>
-  </bean>
-
-  <bean id="webInitializer" class="org.opendaylight.yanglib.impl.WebInitializer"
-      destroy-method="close">
-    <argument ref="webServer"/>
-    <argument ref="webContextSecurer"/>
-    <argument ref="servletSupport"/>
-    <argument ref="yangLibRestApp"/>
-  </bean>
-</blueprint>
diff --git a/netconf/yanglib/src/main/resources/initial/yanglib-config.xml b/netconf/yanglib/src/main/resources/initial/yanglib-config.xml
deleted file mode 100644 (file)
index fd1ab99..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<yanglib-config xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">
-    <cache-folder>cache/schema</cache-folder>
-    <binding-addr>localhost</binding-addr>
-    <binding-port>8181</binding-port>
-</yanglib-config>
\ No newline at end of file
diff --git a/netconf/yanglib/src/main/yang/yanglib.yang b/netconf/yanglib/src/main/yang/yanglib.yang
deleted file mode 100644 (file)
index 275995b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-module yanglib {
-    yang-version 1;
-    namespace "urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl";
-    prefix "yanglib";
-
-    description
-        "Service configuration for yanglib project";
-
-    revision "2014-12-10" {
-        description
-            "Initial revision";
-    }
-
-    container yanglib-config {
-        // TODO extracting the schema repositories
-        leaf cache-folder {
-            mandatory true;
-            type string;
-            description "local filesystem folder to use as cache + to load yang models from";
-        }
-
-        // TODO it would be better if the binding arguments could be located by the app automatically
-        leaf binding-addr {
-            mandatory true;
-            type string;
-            // TODO make this uri
-            description "binding address is necessary for generating proper URLS (accessible from the outside world)
-                         for models present directly in the library";
-        }
-
-        leaf binding-port {
-            mandatory true;
-            type uint32;
-            // TODO proper type
-            description "binding port is necessary for generating proper URLS (accessible from the outside world)
-                         for models present directly in the library";
-        }
-    }
-}
index 794946ab1b375b067df89dd88d01715aa81ac978..3dd93cc31870e8cbb894b1b363b2d01025aea951 100644 (file)
@@ -16,9 +16,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -37,8 +35,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.librar
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.ModuleBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.ModuleKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.yanglib.impl.rev141210.YanglibConfigBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
@@ -62,38 +60,27 @@ public class YangLibProviderTest {
         doReturn(emptyFluentFuture()).when(writeTransaction).commit();
         doReturn(writeTransaction).when(dataBroker).newWriteOnlyTransaction();
 
-        final var yanglibConfig = new YanglibConfigBuilder().setBindingAddr("www.fake.com")
-            .setBindingPort(Uint32.valueOf(300))
-            .setCacheFolder(YangLibProviderTest.class.getResource("/model").getPath())
-            .build();
-        yangLibProvider = new YangLibProvider(yanglibConfig, dataBroker, new DefaultYangParserFactory());
-        // this will automatically register all models from /model directory
-        yangLibProvider.init();
+        yangLibProvider = new YangLibProvider(dataBroker, new DefaultYangParserFactory(),
+            YangLibProviderTest.class.getResource("/model").getPath(), "www.fake.com", Uint32.valueOf(300));
     }
 
     @Test
     public void testSchemaSourceRegistered() {
         // test that initial models are registered
-        final var newModulesMap = new HashMap<ModuleKey, Module>();
-
-        final var model1 = new ModuleBuilder()
-            .setName(new YangIdentifier("model1"))
-            .setRevision(new Revision(new RevisionIdentifier("2023-02-21")))
-            .setSchema(new Uri("http://www.fake.com:300/yanglib/schemas/model1/2023-02-21"))
-            .build();
-        newModulesMap.put(model1.key(), model1);
-
-        final var model2 = new ModuleBuilder()
-            .setName(new YangIdentifier("model2"))
-            .setRevision(LegacyRevisionUtils.emptyRevision())
-            .setSchema(new Uri("http://www.fake.com:300/yanglib/schemas/model2"))
-            .build();
-        newModulesMap.put(model2.key(), model2);
-
         verify(dataBroker).newWriteOnlyTransaction();
         verify(writeTransaction).merge(eq(LogicalDatastoreType.OPERATIONAL),
             eq(InstanceIdentifier.create(ModulesState.class)),
-            eq(new ModulesStateBuilder().setModule(newModulesMap).build()));
+            eq(new ModulesStateBuilder()
+                .setModule(BindingMap.of(new ModuleBuilder()
+                    .setName(new YangIdentifier("model1"))
+                    .setRevision(new Revision(new RevisionIdentifier("2023-02-21")))
+                    .setSchema(new Uri("http://www.fake.com:300/yanglib/schemas/model1/2023-02-21"))
+                    .build(), new ModuleBuilder()
+                    .setName(new YangIdentifier("model2"))
+                    .setRevision(LegacyRevisionUtils.emptyRevision())
+                    .setSchema(new Uri("http://www.fake.com:300/yanglib/schemas/model2"))
+                    .build()))
+                .build()));
         verify(writeTransaction).commit();
     }
 
@@ -102,7 +89,7 @@ public class YangLibProviderTest {
         clearInvocations(dataBroker, writeTransaction);
 
         // test empty list of schema sources registered
-        yangLibProvider.schemaSourceRegistered(Collections.emptyList());
+        yangLibProvider.schemaSourceRegistered(List.of());
         // expected behavior is to do nothing
         verifyNoMoreInteractions(dataBroker, writeTransaction);
     }
@@ -112,12 +99,11 @@ public class YangLibProviderTest {
         clearInvocations(dataBroker, writeTransaction);
 
         // test list of non yang schema sources registered
-        final var nonYangSources = new ArrayList<PotentialSchemaSource<?>>();
-        nonYangSources.add(PotentialSchemaSource.create(new SourceIdentifier("yin-source-representation"),
-            YinSchemaSourceRepresentation.class, Costs.IMMEDIATE.getValue()));
-        nonYangSources.add(PotentialSchemaSource.create(new SourceIdentifier("asts-schema-source"),
-            YangIRSchemaSource.class, Costs.IMMEDIATE.getValue()));
-        yangLibProvider.schemaSourceRegistered(nonYangSources);
+        yangLibProvider.schemaSourceRegistered(List.of(
+            PotentialSchemaSource.create(new SourceIdentifier("yin-source-representation"),
+                YinSchemaSourceRepresentation.class, Costs.IMMEDIATE.getValue()),
+            PotentialSchemaSource.create(new SourceIdentifier("asts-schema-source"),
+                YangIRSchemaSource.class, Costs.IMMEDIATE.getValue())));
 
         // expected behavior is to do nothing
         verifyNoMoreInteractions(dataBroker, writeTransaction);