<classifier>features</classifier>
</dependency>
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>yanglib</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netconf-client</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>odl-yanglib</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
</dependencies>
</dependencyManagement>
</project>
<type>xml</type>
<classifier>features</classifier>
</dependency>
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>odl-yanglib</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
</dependencies>
</project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright © 2017 Red Hat, Inc. and others.
-
- 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
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>feature-parent</artifactId>
- <version>7.0.3-SNAPSHOT</version>
- <relativePath>../parent</relativePath>
- </parent>
-
- <artifactId>odl-yanglib</artifactId>
- <packaging>feature</packaging>
- <name>OpenDaylight :: Yanglib</name>
-
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>yanglib</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>odl-restconf</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>odl-karaf-feat-jetty</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal.model</groupId>
- <artifactId>odl-mdsal-model-rfc8525</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Copyright © 2018 Red Hat, Inc. and others.
- ~
- ~ 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
- -->
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-netconf-${project.version}">
- <feature name="odl-yanglib" version="${project.version}">
- <feature version="[13,14)">odl-karaf-feat-jetty</feature>
- <feature version="[13,14)">odl-mdsal-model-rfc8525</feature>
- </feature>
-</features>
<module>odl-restconf-common</module>
<module>odl-restconf</module>
<module>odl-restconf-nb</module>
- <module>odl-yanglib</module>
<module>odl-yanglib-mdsal-writer</module>
</modules>
</project>
<modules>
<module>netconf-netty-util</module>
<module>netconf-auth</module>
- <module>yanglib</module>
<module>tools</module>
<module>netconf-test-models</module>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 Cisco Systems, 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
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>netconf-parent</artifactId>
- <version>7.0.3-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
-
- <artifactId>yanglib</artifactId>
- <packaging>bundle</packaging>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>YangLib</Bundle-Name>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <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>
- </dependency>
- <dependency>
- <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>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.yanglib.api;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import org.opendaylight.yangtools.yang.common.YangConstants;
-
-/**
- * Service provides YANG schema sources for modules from yang library.
- */
-@Path("/")
-@Produces({ YangConstants.RFC6020_YANG_MEDIA_TYPE, MediaType.TEXT_PLAIN })
-public interface YangLibService {
-
- /**
- * Get module's source for each module from yang library.
- * @param name Module's name
- * @param revision Module's revision
- * @return Module's source
- */
- @GET
- @Path("/schemas/{modelName}/{revision:([0-9\\-]*)}")
- String getSchema(@PathParam("modelName") String name, @PathParam("revision") String revision);
-
- /**
- * Get module's source for each module from yang library without a revision.
- * @param name Module's name
- * @return Module's source
- */
- @GET
- @Path("/schemas/{modelName}")
- String getSchema(@PathParam("modelName") String name);
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Inocybe Technologies 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
- */
-package org.opendaylight.yanglib.impl;
-
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletException;
-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
- */
-@Singleton
-@Component(service = { })
-public final class JaxRsYangLib implements AutoCloseable {
- private final Registration registration;
-
- @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(new YangLibRestApp(yangLibService)).build())
- .addUrlPattern("/*")
- .build());
-
- webContextSecurer.requireAuthentication(webContextBuilder, "/*");
-
- registration = webServer.registerWebContext(webContextBuilder.build());
- }
-
- @PreDestroy
- @Deactivate
- @Override
- public void close() {
- registration.close();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.yanglib.impl;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
-
-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.Optional;
-import java.util.concurrent.ExecutionException;
-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.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.LegacyRevisionUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
-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.yanglib.api.YangLibService;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
-import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache;
-import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
-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;
-
-/**
- * Listens on new schema sources registered event. For each new source
- * registered generates URL representing its schema source and write this URL
- * along with source identifier to
- * ietf-netconf-yang-library/modules-state/module list.
- */
-@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 -> YangTextSource.class.isAssignableFrom(input.getRepresentation());
-
- private final DataBroker dataBroker;
- private final String bindingAddress;
- private final Uint32 bindingPort;
- private final SharedSchemaRepository schemaRepository;
- private final Registration schemaListenerRegistration;
-
- @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()));
- }
-
- @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(cacheFolder);
- if (cacheFolderFile.exists()) {
- LOG.info("cache-folder {} already exists", cacheFolderFile);
- } else {
- checkArgument(cacheFolderFile.mkdirs(), "cache-folder %s cannot be created", cacheFolderFile);
- LOG.info("cache-folder {} was created", cacheFolderFile);
- }
- checkArgument(cacheFolderFile.isDirectory(), "cache-folder %s is not a directory", cacheFolderFile);
-
- schemaRepository = new SharedSchemaRepository("yang-library", parserFactory);
- final var cache = new FilesystemSchemaSourceCache<>(schemaRepository, YangTextSource.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 SourceRepresentation source) {
- // NOOP
- }
-
- @Override
- public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> sources) {
- final var newModules = new HashMap<ModuleKey, Module>();
-
- for (var potentialYangSource : Iterables.filter(sources, YANG_SCHEMA_SOURCE::test)) {
- final var moduleName = new YangIdentifier(potentialYangSource.getSourceIdentifier().name().getLocalName());
-
- final var newModule = new ModuleBuilder()
- .setName(moduleName)
- .setRevision(LegacyRevisionUtils.fromYangCommon(
- Optional.ofNullable(potentialYangSource.getSourceIdentifier().revision())))
- .setSchema(getUrlForModule(potentialYangSource.getSourceIdentifier()))
- .build();
-
- newModules.put(newModule.key(), newModule);
- }
-
- if (newModules.isEmpty()) {
- // If no new yang modules then do nothing
- return;
- }
-
- WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
- tx.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ModulesState.class),
- new ModulesStateBuilder().setModule(newModules).build());
-
- tx.commit().addCallback(new FutureCallback<CommitInfo>() {
- @Override
- public void onSuccess(final CommitInfo result) {
- LOG.debug("Modules state successfully populated with new modules");
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- LOG.warn("Unable to update modules state", throwable);
- }
- }, MoreExecutors.directExecutor());
- }
-
- @Override
- public void schemaSourceUnregistered(final PotentialSchemaSource<?> source) {
- if (!YANG_SCHEMA_SOURCE.test(source)) {
- // if representation of potential schema source is not yang text schema source do nothing
- // we do not want to delete this module entry from module list
- return;
- }
-
- WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
- tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ModulesState.class)
- .child(Module.class, new ModuleKey(new YangIdentifier(source.getSourceIdentifier().name().getLocalName()),
- LegacyRevisionUtils.fromYangCommon(Optional.ofNullable(source.getSourceIdentifier().revision())))));
-
- tx.commit().addCallback(new FutureCallback<CommitInfo>() {
- @Override
- public void onSuccess(final CommitInfo result) {
- LOG.debug("Modules state successfully updated.");
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- LOG.warn("Unable to update modules state", throwable);
- }
- }, MoreExecutors.directExecutor());
- }
-
- @Override
- public String getSchema(final String name, final String revision) {
- LOG.debug("Attempting load for schema source {}:{}", name, revision);
- return getYangModel(name, revision.isEmpty() ? null : revision);
- }
-
- @Override
- public String getSchema(final String name) {
- LOG.debug("Attempting load for schema source {}: no-revision", name);
- return getYangModel(name, null);
- }
-
- private String getYangModel(final String name, final String revision) {
- final var sourceId = new SourceIdentifier(name, revision);
- final var yangTextSchemaFuture = schemaRepository.getSchemaSource(sourceId, YangTextSource.class);
- try {
- final var yangTextSchemaSource = yangTextSchemaFuture.get();
- return yangTextSchemaSource.read();
- } catch (ExecutionException e) {
- if (e.getCause() instanceof MissingSchemaSourceException) {
- throw new NotFoundException("Schema source " + sourceId + " not found", e);
- }
- throw new WebApplicationException("Unable to retrieve schema source " + sourceId, e);
- } catch (IOException e) {
- throw new WebApplicationException("Unable to read schema " + sourceId, e);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new WebApplicationException("Retrieving schema source " + sourceId + " has been interrupted", e);
- }
- }
-
- private Uri getUrlForModule(final SourceIdentifier sourceIdentifier) {
- return new Uri("http://" + bindingAddress + ':' + bindingPort + "/yanglib/schemas/"
- + sourceIdentifier.name().getLocalName() + revString(sourceIdentifier));
- }
-
- private static String revString(final SourceIdentifier id) {
- final var rev = id.revision();
- return rev != null ? "/" + rev : "";
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.yanglib.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Set;
-import javax.ws.rs.core.Application;
-import org.opendaylight.yanglib.api.YangLibService;
-
-public final class YangLibRestApp extends Application {
- private final YangLibService yangLibService;
-
- public YangLibRestApp(final YangLibService yangLibService) {
- this.yangLibService = requireNonNull(yangLibService);
- }
-
- @Override
- public Set<Object> getSingletons() {
- return Set.of(yangLibService);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.yanglib.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.clearInvocations;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture;
-
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.WriteTransaction;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.LegacyRevisionUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafs.Revision;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
-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.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.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.api.source.YinSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
-import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class YangLibProviderTest {
- @Mock
- private DataBroker dataBroker;
- @Mock
- private WriteTransaction writeTransaction;
-
- private YangLibProvider yangLibProvider;
-
- @Before
- public void setUp() {
- doReturn(emptyFluentFuture()).when(writeTransaction).commit();
- doReturn(writeTransaction).when(dataBroker).newWriteOnlyTransaction();
-
- 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
- verify(dataBroker).newWriteOnlyTransaction();
- verify(writeTransaction).merge(eq(LogicalDatastoreType.OPERATIONAL),
- eq(InstanceIdentifier.create(ModulesState.class)),
- 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();
- }
-
- @Test
- public void testFilteringEmptySchemaSourceRegistered() {
- clearInvocations(dataBroker, writeTransaction);
-
- // test empty list of schema sources registered
- yangLibProvider.schemaSourceRegistered(List.of());
- // expected behavior is to do nothing
- verifyNoMoreInteractions(dataBroker, writeTransaction);
- }
-
- @Test
- public void testFilteringNonYangSchemaSourceRegistered() {
- clearInvocations(dataBroker, writeTransaction);
-
- // test list of non yang schema sources registered
- yangLibProvider.schemaSourceRegistered(List.of(
- PotentialSchemaSource.create(new SourceIdentifier("yin-source-representation"),
- YinSourceRepresentation.class, Costs.IMMEDIATE.getValue()),
- PotentialSchemaSource.create(new SourceIdentifier("asts-schema-source"),
- YangIRSource.class, Costs.IMMEDIATE.getValue())));
-
- // expected behavior is to do nothing
- verifyNoMoreInteractions(dataBroker, writeTransaction);
- }
-
- @Test
- public void testSchemaSourceWithRevisionUnregistered() {
- clearInvocations(dataBroker, writeTransaction);
-
- // try to unregister YANG source with revision
- final var schemaSourceWithRevision = PotentialSchemaSource.create(
- new SourceIdentifier("unregistered-yang-with-revision", "2016-04-28"),
- YangTextSource.class, Costs.LOCAL_IO.getValue());
- yangLibProvider.schemaSourceUnregistered(schemaSourceWithRevision);
-
- // source is unregistered
- verify(dataBroker).newWriteOnlyTransaction();
- verify(writeTransaction).delete(eq(LogicalDatastoreType.OPERATIONAL),
- eq(InstanceIdentifier.create(ModulesState.class)
- .child(Module.class,
- new ModuleKey(new YangIdentifier("unregistered-yang-with-revision"),
- new Revision(new RevisionIdentifier("2016-04-28"))))));
- verify(writeTransaction).commit();
- }
-
- @Test
- public void testSchemaSourceWithoutRevisionUnregistered() {
- clearInvocations(dataBroker, writeTransaction);
-
- // try to unregister YANG source without revision
- final var schemaSourceWithoutRevision = PotentialSchemaSource.create(
- new SourceIdentifier("unregistered-yang-schema-without-revision"), YangTextSource.class,
- Costs.LOCAL_IO.getValue());
- yangLibProvider.schemaSourceUnregistered(schemaSourceWithoutRevision);
-
- // source is unregistered
- verify(dataBroker).newWriteOnlyTransaction();
- verify(writeTransaction).delete(eq(LogicalDatastoreType.OPERATIONAL),
- eq(InstanceIdentifier.create(ModulesState.class)
- .child(Module.class,
- new ModuleKey(new YangIdentifier("unregistered-yang-schema-without-revision"),
- LegacyRevisionUtils.emptyRevision()))));
- verify(writeTransaction).commit();
- }
-
- @Test
- public void testNonYangSchemaSourceUnregistered() {
- clearInvocations(dataBroker, writeTransaction);
-
- // try to unregister non-YANG source
- final var nonYangSources = PotentialSchemaSource.create(new SourceIdentifier("yin-source-representation"),
- YinSourceRepresentation.class, Costs.IMMEDIATE.getValue());
- yangLibProvider.schemaSourceUnregistered(nonYangSources);
-
- // expected behaviour is to do nothing if non yang based source is unregistered
- verifyNoMoreInteractions(dataBroker, writeTransaction);
- }
-
- @Test
- public void testGetSchemaWithRevision() {
- final var modelWithRevision = yangLibProvider.getSchema("model1", "2023-02-21");
- assertNotNull(modelWithRevision);
- assertEquals("""
- module model1 {
- namespace "model:with:revision";
- prefix mwr;
-
- revision 2023-02-21 {
- description
- "Initial revision;";
- }
-
- container test {
- leaf test-leaf {
- type string;
- }
- }
- }
- """, modelWithRevision);
- }
-
- @Test
- public void testGetSchemaWithoutRevision() {
- final var modelWithoutRevision = yangLibProvider.getSchema("model2");
- assertNotNull(modelWithoutRevision);
- assertEquals("""
- module model2 {
- namespace "model:with:no:revision";
- prefix mwnr;
-
- container test {
- leaf test-leaf {
- type string;
- }
- }
- }
- """, modelWithoutRevision);
- }
-}
+++ /dev/null
-module model1 {
- namespace "model:with:revision";
- prefix mwr;
-
- revision 2023-02-21 {
- description
- "Initial revision;";
- }
-
- container test {
- leaf test-leaf {
- type string;
- }
- }
-}
+++ /dev/null
-module model2 {
- namespace "model:with:no:revision";
- prefix mwnr;
-
- container test {
- leaf test-leaf {
- type string;
- }
- }
-}