<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>
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:
::
<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>
<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>
</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>
*/
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());
registration = webServer.registerWebContext(webContextBuilder.build());
}
+ @PreDestroy
+ @Deactivate
@Override
public void close() {
registration.close();
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;
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;
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;
* 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 {
}
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);
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
@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())))
}
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) {
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) {
+++ /dev/null
-<?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>
+++ /dev/null
-<?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
+++ /dev/null
-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";
- }
- }
-}
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;
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;
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();
}
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);
}
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);