From 1754e90a9c72ab400ac15ad2d44ba31eeab317ef Mon Sep 17 00:00:00 2001 From: OleksandrZharov Date: Wed, 4 Jan 2023 10:05:07 +0100 Subject: [PATCH] Convert yanglib to OSGi DS 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 Signed-off-by: Robert Varga --- artifacts/pom.xml | 7 -- docs/user-guide.rst | 45 ++++---- features/odl-yanglib/pom.xml | 6 -- .../odl-yanglib/src/main/feature/feature.xml | 3 - netconf/yanglib/pom.xml | 102 +++++++++++++----- ...{WebInitializer.java => JaxRsYangLib.java} | 24 ++++- .../yanglib/impl/YangLibProvider.java | 101 +++++++++++------ .../yanglib/impl/YangLibRestApp.java | 2 +- .../resources/OSGI-INF/blueprint/yanglib.xml | 40 ------- .../main/resources/initial/yanglib-config.xml | 6 -- netconf/yanglib/src/main/yang/yanglib.yang | 39 ------- .../yanglib/impl/YangLibProviderTest.java | 56 ++++------ 12 files changed, 204 insertions(+), 227 deletions(-) rename netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/{WebInitializer.java => JaxRsYangLib.java} (62%) delete mode 100644 netconf/yanglib/src/main/resources/OSGI-INF/blueprint/yanglib.xml delete mode 100644 netconf/yanglib/src/main/resources/initial/yanglib-config.xml delete mode 100644 netconf/yanglib/src/main/yang/yanglib.yang diff --git a/artifacts/pom.xml b/artifacts/pom.xml index baa6ac6281..857e1591d4 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -266,13 +266,6 @@ yanglib ${project.version} - - org.opendaylight.netconf - yanglib - ${project.version} - config - xml - org.opendaylight.netconf diff --git a/docs/user-guide.rst b/docs/user-guide.rst index 5e31ff8054..74bb5e0371 100644 --- a/docs/user-guide.rst +++ b/docs/user-guide.rst @@ -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 - - cache/newSchema - localhost - 8181 - - -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: :: diff --git a/features/odl-yanglib/pom.xml b/features/odl-yanglib/pom.xml index 821011c3e6..15861051e5 100644 --- a/features/odl-yanglib/pom.xml +++ b/features/odl-yanglib/pom.xml @@ -25,12 +25,6 @@ org.opendaylight.netconf yanglib - - org.opendaylight.netconf - yanglib - xml - config - org.opendaylight.netconf odl-restconf diff --git a/features/odl-yanglib/src/main/feature/feature.xml b/features/odl-yanglib/src/main/feature/feature.xml index 8f4869c63b..5f8a7c2798 100644 --- a/features/odl-yanglib/src/main/feature/feature.xml +++ b/features/odl-yanglib/src/main/feature/feature.xml @@ -10,8 +10,5 @@ odl-karaf-feat-jetty odl-mdsal-model-rfc8525 - - mvn:org.opendaylight.netconf/yanglib/${project.version}/xml/config - diff --git a/netconf/yanglib/pom.xml b/netconf/yanglib/pom.xml index 91a5241145..09da59c0d8 100644 --- a/netconf/yanglib/pom.xml +++ b/netconf/yanglib/pom.xml @@ -32,52 +32,89 @@ - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - attach-artifact - - package - - - - ${project.build.directory}/classes/initial/yanglib-config.xml - xml - config - - - - - - - - org.opendaylight.mdsal - mdsal-binding-api - com.google.guava guava - org.opendaylight.mdsal.binding.model.ietf - rfc8525 + com.guicedee.services + javax.inject + true + + + jakarta.annotation + jakarta.annotation-api + provided + true + + + jakarta.ws.rs + jakarta.ws.rs-api + + + javax.servlet + javax.servlet-api + + + org.eclipse.jdt + org.eclipse.jdt.annotation + + + org.opendaylight.yangtools + concepts + + + org.opendaylight.yangtools + yang-common + + + org.opendaylight.yangtools + yang-parser-api org.opendaylight.yangtools yang-parser-impl + + org.opendaylight.yangtools + yang-repo-api + + + org.opendaylight.yangtools + yang-repo-spi + org.opendaylight.yangtools yang-repo-fs + + org.opendaylight.mdsal + mdsal-common-api + + + org.opendaylight.mdsal + mdsal-binding-api + + + org.opendaylight.mdsal + yang-binding + + + org.opendaylight.mdsal.binding.model.ietf + rfc6991-ietf-inet-types + + + org.opendaylight.mdsal.binding.model.ietf + rfc6991-ietf-yang-types + + + org.opendaylight.mdsal.binding.model.ietf + rfc8525 + org.opendaylight.aaa.web web-api @@ -86,6 +123,15 @@ org.opendaylight.aaa.web servlet-api + + org.osgi + org.osgi.service.metatype.annotations + + + org.osgi + org.osgi.service.component.annotations + + commons-io commons-io diff --git a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/WebInitializer.java b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/JaxRsYangLib.java 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 179c488da4..3bf4610240 100644 --- a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/WebInitializer.java +++ b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/JaxRsYangLib.java @@ -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(); diff --git a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java index 1806f1c9e2..c7b29d4b62 100644 --- a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java +++ b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java @@ -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> 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 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> sources) { - final Map newModules = new HashMap<>(); + final var newModules = new HashMap(); - 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) { diff --git a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibRestApp.java b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibRestApp.java index 51f6366897..426a114803 100644 --- a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibRestApp.java +++ b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibRestApp.java @@ -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 index 9fe5243513..0000000000 --- a/netconf/yanglib/src/main/resources/OSGI-INF/blueprint/yanglib.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 index fd1ab99e87..0000000000 --- a/netconf/yanglib/src/main/resources/initial/yanglib-config.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - cache/schema - localhost - 8181 - \ 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 index 275995b3b1..0000000000 --- a/netconf/yanglib/src/main/yang/yanglib.yang +++ /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"; - } - } -} diff --git a/netconf/yanglib/src/test/java/org/opendaylight/yanglib/impl/YangLibProviderTest.java b/netconf/yanglib/src/test/java/org/opendaylight/yanglib/impl/YangLibProviderTest.java index 794946ab1b..3dd93cc318 100644 --- a/netconf/yanglib/src/test/java/org/opendaylight/yanglib/impl/YangLibProviderTest.java +++ b/netconf/yanglib/src/test/java/org/opendaylight/yanglib/impl/YangLibProviderTest.java @@ -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(); - - 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>(); - 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); -- 2.36.6