Added new feature 'odl-yanglib-mdsal-writer'.
The 'mdsal-netconf-yang-library' module has been deleted,
and the usage of 'odl-yanglib-mdsal-writer' has been replaced.
JIRA: NETCONF-668
Change-Id: I79d5637f93391f93c1bea9e7da94f566abeb81e3
Signed-off-by: Yaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
<type>xml</type>
<classifier>features</classifier>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>odl-yanglib-mdsal-writer</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
<!-- netconf-connector features -->
<dependency>
</dependency>
<dependency>
<groupId>org.opendaylight.netconf</groupId>
- <artifactId>netconf-server-mdsal</artifactId>
+ <artifactId>odl-yanglib-mdsal-writer</artifactId>
+ <type>xml</type>
+ <classifier>features</classifier>
</dependency>
<dependency>
<groupId>org.opendaylight.netconf</groupId>
- <artifactId>mdsal-netconf-yang-library</artifactId>
+ <artifactId>netconf-server-mdsal</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.netconf</groupId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>odl-yanglib-mdsal-writer</artifactId>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
<dependency>
<groupId>org.opendaylight.netconf</groupId>
<artifactId>restconf-nb</artifactId>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2023 PANTHEON.tech, s.r.o. 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>feature-parent</artifactId>
+ <version>7.0.0-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+
+ <artifactId>odl-yanglib-mdsal-writer</artifactId>
+ <packaging>feature</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>odl-mdsal-model-rfc8525</artifactId>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>odl-mdsal-broker</artifactId>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>yanglib-mdsal-writer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ Copyright (c) 2023 PANTHEON.tech s.r.o. 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
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-netconf-${project.version}">
+ <feature name="odl-yanglib-mdsal-writer" version="${project.version}">
+ <feature version="[12,13)">odl-mdsal-model-rfc8525</feature>
+ <feature version="[8,9)">odl-mdsal-broker</feature>
+ </feature>
+</features>
<module>odl-restconf</module>
<module>odl-restconf-nb</module>
<module>odl-yanglib</module>
+ <module>odl-yanglib-mdsal-writer</module>
</modules>
</project>
+++ /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.0-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
-
- <artifactId>mdsal-netconf-yang-library</artifactId>
- <name>${project.artifactId}</name>
- <packaging>bundle</packaging>
-
- <dependencies>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-dom-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-binding-api</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>rfc8525</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.component.annotations</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>
- <optional>true</optional>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-test-util</artifactId>
- </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.netconf.mdsal.yang.library;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.MoreExecutors;
-import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.stream.Collectors;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.checkerframework.checker.lock.qual.GuardedBy;
-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.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.datastores.rev180214.Operational;
-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.RevisionUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module.ConformanceType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.SubmoduleBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.DatastoreBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSetBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.SchemaBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.util.BindingMap;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleLike;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Listens for updates on global schema context, transforms context to ietf-yang-library/yang-library and writes this
- * state to operational data store.
- */
-@Singleton
-@Component(immediate = true, service = {})
-public final class YangLibraryWriter implements EffectiveModelContextListener, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(YangLibraryWriter.class);
- private static final String MODULE_SET_NAME = "state-modules";
- private static final String SCHEMA_NAME = "state-schema";
-
- private static final InstanceIdentifier<YangLibrary> YANG_LIBRARY_INSTANCE_IDENTIFIER =
- InstanceIdentifier.create(YangLibrary.class);
- @Deprecated
- private static final InstanceIdentifier<ModulesState> MODULES_STATE_INSTANCE_IDENTIFIER =
- InstanceIdentifier.create(ModulesState.class);
-
- private final DataBroker dataBroker;
- @GuardedBy("this")
- private long moduleSetId;
- @GuardedBy("this")
- private Registration reg;
-
- @Inject
- @Activate
- public YangLibraryWriter(final @Reference DOMSchemaService schemaService,
- final @Reference DataBroker dataBroker) {
- this.dataBroker = requireNonNull(dataBroker);
- reg = schemaService.registerSchemaContextListener(this);
- }
-
- @Deactivate
- @PreDestroy
- @Override
- public synchronized void close() throws InterruptedException, ExecutionException {
- if (reg == null) {
- // Already shut down
- return;
- }
-
- reg.close();
- reg = null;
-
- // FIXME: we should be using a transaction chain for this, but, really, this should be a dynamically-populated
- // shard (i.e. no storage whatsoever)!
- final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
- tx.delete(LogicalDatastoreType.OPERATIONAL, YANG_LIBRARY_INSTANCE_IDENTIFIER);
- tx.delete(LogicalDatastoreType.OPERATIONAL, MODULES_STATE_INSTANCE_IDENTIFIER);
-
- final FluentFuture<? extends CommitInfo> future = tx.commit();
- future.addCallback(new FutureCallback<CommitInfo>() {
- @Override
- public void onSuccess(final CommitInfo info) {
- LOG.debug("YANG library cleared successfully");
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- LOG.warn("Unable to clear YANG library", throwable);
- }
- }, MoreExecutors.directExecutor());
-
- // We need to synchronize here, otherwise we'd end up trampling over ourselves
- future.get();
- }
-
- @Override
- public void onModelContextUpdated(final EffectiveModelContext context) {
- final Module ietfYangLibraryModule = context.findModule(YangLibrary.QNAME.getModule()).orElse(null);
- if (ietfYangLibraryModule != null) {
- updateYangLibrary(context);
- } else {
- LOG.debug("ietf-yang-library not present in context, skipping update");
- }
- }
-
- private synchronized void updateYangLibrary(final EffectiveModelContext context) {
- if (reg == null) {
- // Already shut down, do not do anything
- return;
- }
-
- final long currentSetId = moduleSetId++;
-
- final YangLibrary newYangLibrary = createYangLibraryFromContext(context.getModules(), currentSetId);
- final ModulesState newModuleState = createModuleStateFromModules(context.getModules(), currentSetId);
- LOG.debug("Trying to write new yang-library: {}", newYangLibrary);
- LOG.debug("Trying to write new module-state: {}", newModuleState);
-
- final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
- tx.put(LogicalDatastoreType.OPERATIONAL, YANG_LIBRARY_INSTANCE_IDENTIFIER, newYangLibrary);
- tx.put(LogicalDatastoreType.OPERATIONAL, MODULES_STATE_INSTANCE_IDENTIFIER, newModuleState);
- tx.commit().addCallback(new FutureCallback<CommitInfo>() {
- @Override
- public void onSuccess(final CommitInfo result) {
- LOG.debug("Yang library updated successfully");
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- LOG.warn("Failed to update yang library", throwable);
- }
- }, MoreExecutors.directExecutor());
- }
-
- private static YangLibrary createYangLibraryFromContext(final Collection<? extends Module> modules,
- final long moduleSetId) {
- final var moduleMap = modules.stream()
- .map(module -> {
- final var submoduleMap = module.getSubmodules().stream()
- .map(subModule -> new SubmoduleBuilder()
- .setName(new YangIdentifier(subModule.getName()))
- .setRevision(RevisionUtils.fromYangCommon(subModule.getQNameModule().getRevision())
- .getRevisionIdentifier())
- .build())
- .collect(BindingMap.toMap());
-
- return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library
- .rev190104.module.set.parameters.ModuleBuilder()
- .setName(new YangIdentifier(module.getName() + "_"
- // FIXME: 'orElse' seems to be wrong here
- + module.getRevision().map(Revision::toString).orElse(null)))
- .setRevision(RevisionUtils.fromYangCommon(module.getQNameModule().getRevision())
- .getRevisionIdentifier())
- .setNamespace(new Uri(module.getNamespace().toString()))
- .setFeature(extractFeatures(module))
- // FIXME: inline this once it's disambiguated
- .setSubmodule(submoduleMap)
- .build();
- })
- .collect(BindingMap.toMap());
-
- return new YangLibraryBuilder()
- .setModuleSet(BindingMap.of(new ModuleSetBuilder()
- .setName(MODULE_SET_NAME)
- // FIXME: inline this once it's disambiguated
- .setModule(moduleMap)
- .build()))
- .setSchema(BindingMap.of(new SchemaBuilder()
- .setName(SCHEMA_NAME)
- .setModuleSet(Set.of(MODULE_SET_NAME))
- .build()))
- .setDatastore(BindingMap.of(new DatastoreBuilder()
- .setName(Operational.VALUE)
- .setSchema(SCHEMA_NAME)
- .build()))
- .setContentId(String.valueOf(moduleSetId))
- .build();
- }
-
- @Deprecated
- private static ModulesState createModuleStateFromModules(final Collection<? extends Module> modules,
- final long moduleSetId) {
- final var moduleMap = modules.stream()
- .map(module -> {
- final var submoduleMap = module.getSubmodules().stream()
- .map(subModule -> new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library
- .rev190104.module.list.module.SubmoduleBuilder()
- .setName(new YangIdentifier(subModule.getName()))
- .setRevision(LegacyRevisionUtils.fromYangCommon(subModule.getQNameModule()
- .getRevision()))
- .build())
- .collect(BindingMap.toMap());
-
- return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library
- .rev190104.module.list.ModuleBuilder()
- .setName(new YangIdentifier(module.getName()))
- .setRevision(LegacyRevisionUtils.fromYangCommon(module.getQNameModule().getRevision()))
- .setNamespace(new Uri(module.getNamespace().toString()))
- // FIXME: Conformance type is always set to Implement value, but it should it really be like this?
- .setConformanceType(ConformanceType.Implement)
- // FIXME: inline this once it's disambiguated
- .setSubmodule(submoduleMap)
- .setFeature(extractFeatures(module))
- // FIXME: Add also deviations to module entries
- .build();
- })
- .collect(BindingMap.toMap());
-
- return new ModulesStateBuilder()
- // FIXME: inline this once it's disambiguated
- .setModule(moduleMap)
- .setModuleSetId(String.valueOf(moduleSetId))
- .build();
- }
-
- private static Set<YangIdentifier> extractFeatures(final ModuleLike module) {
- final var namespace = module.getQNameModule();
-
- return module.getFeatures().stream()
- .map(FeatureDefinition::getQName)
- // belt-and-suspenders: make sure the feature namespace matches
- .filter(featureName -> namespace.equals(featureName.getModule()))
- .map(featureName -> new YangIdentifier(featureName.getLocalName()))
- .collect(Collectors.toUnmodifiableSet());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.netconf.mdsal.yang.library;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoInteractions;
-import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.WriteTransaction;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-public abstract class AbstractYangLibraryWriterTest {
- @Mock
- private DOMSchemaService schemaService;
- @Mock
- private DataBroker dataBroker;
- @Mock
- private WriteTransaction writeTransaction;
-
- YangLibraryWriter writer;
-
- @Before
- public void setUp() {
- doReturn(writeTransaction).when(dataBroker).newWriteOnlyTransaction();
- doNothing().when(writeTransaction).put(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
- doReturn(emptyFluentFuture()).when(writeTransaction).commit();
- // FIXME: use a mock for this
- doReturn(new ListenerRegistration<EffectiveModelContextListener>() {
- @Override
- public void close() {
-
- }
-
- @Override
- public EffectiveModelContextListener getInstance() {
- return null;
- }
- }).when(schemaService).registerSchemaContextListener(any());
- writer = new YangLibraryWriter(schemaService, dataBroker);
- }
-
- @Test
- public void testNoUpdate() {
- writer.onModelContextUpdated(YangParserTestUtils.parseYangResources(YangLibraryTest.class,
- "/test-module.yang", "/test-submodule.yang"));
- verifyNoInteractions(dataBroker);
- }
-
- final <T extends DataObject> void assertOperationalUpdate(final InstanceIdentifier<T> path, final T object) {
- writer.onModelContextUpdated(YangParserTestUtils.parseYangResources(YangLibraryTest.class,
- "/test-module.yang", "/test-submodule.yang", "/ietf-yang-library.yang"));
- verify(writeTransaction).put(LogicalDatastoreType.OPERATIONAL, path, object);
- verify(writeTransaction).commit();
- }
-}
+++ /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.netconf.mdsal.yang.library;
-
-import java.util.Set;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-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.module.SubmoduleBuilder;
-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;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ModulesStateTest extends AbstractYangLibraryWriterTest {
- @Test
- public void testUpdate() {
- assertOperationalUpdate(InstanceIdentifier.create(ModulesState.class), new ModulesStateBuilder()
- .setModuleSetId("0")
- .setModule(BindingMap.of(new ModuleBuilder()
- .setName(new YangIdentifier("test-module"))
- .setNamespace(new Uri("test:namespace"))
- .setRevision(new Revision(new RevisionIdentifier("2013-07-22")))
- .setSubmodule(BindingMap.of(new SubmoduleBuilder()
- .setName(new YangIdentifier("test-submodule"))
- .setRevision(LegacyRevisionUtils.emptyRevision())
- .build()))
- .setConformanceType(Module.ConformanceType.Implement)
- .setFeature(Set.of())
- .build(), new ModuleBuilder()
- .setName(new YangIdentifier("ietf-yang-library"))
- .setNamespace(new Uri("urn:ietf:params:xml:ns:yang:ietf-yang-library"))
- .setRevision(new Revision(new RevisionIdentifier("2019-01-04")))
- .setConformanceType(Module.ConformanceType.Implement)
- .setFeature(Set.of())
- .build()))
- .build());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Pantheon Technologies s.r.o. 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.netconf.mdsal.yang.library;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.Set;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.datastores.rev180214.Operational;
-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.RevisionIdentifier;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.Module;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ModuleBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.Submodule;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.SubmoduleBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.Datastore;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.DatastoreBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSet;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSetBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.Schema;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.SchemaBuilder;
-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;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class YangLibraryTest extends AbstractYangLibraryWriterTest {
- @Test
- public void testUpdate() {
- assertOperationalUpdate(InstanceIdentifier.create(YangLibrary.class), createTestModuleSet());
- }
-
- private static YangLibrary createTestModuleSet() {
- Submodule sub = new SubmoduleBuilder()
- .setName(new YangIdentifier("test-submodule"))
- .setRevision(RevisionUtils.emptyRevision().getRevisionIdentifier())
- .build();
-
- Module modules = new ModuleBuilder().setName(new YangIdentifier("test-module_2013-07-22"))
- .setNamespace(new Uri("test:namespace"))
- .setRevision(new RevisionIdentifier("2013-07-22"))
- .setSubmodule(ImmutableMap.of(sub.key(), sub))
- .setFeature(Set.of())
- .build();
-
- Module yangLibrary = new ModuleBuilder().setName(new YangIdentifier("ietf-yang-library_2019-01-04"))
- .setNamespace(new Uri("urn:ietf:params:xml:ns:yang:ietf-yang-library"))
- .setRevision(new RevisionIdentifier("2019-01-04"))
- .setFeature(Set.of())
- .build();
-
- ModuleSet modulesSet = new ModuleSetBuilder()
- .setName("state-modules")
- .setModule(ImmutableMap.of(modules.key(), modules, yangLibrary.key(), yangLibrary))
- .build();
-
-
- Schema schema = new SchemaBuilder().setName("state-schema")
- .setModuleSet(Set.of(modulesSet.getName()))
- .build();
-
- Datastore datastore = new DatastoreBuilder().setName(Operational.VALUE)
- .setSchema(schema.getName())
- .build();
-
- return new YangLibraryBuilder()
- .setModuleSet(BindingMap.of(modulesSet))
- .setSchema(BindingMap.of(schema))
- .setDatastore(BindingMap.of(datastore))
- .setContentId("0")
- .build();
- }
-}
\ No newline at end of file
+++ /dev/null
-module ietf-yang-library {
- yang-version 1.1;
- namespace "urn:ietf:params:xml:ns:yang:ietf-yang-library";
- prefix yanglib;
-
- revision 2019-01-04 {
- }
-
- container yang-library {
- }
-}
+++ /dev/null
-module test-module {
- yang-version 1;
- namespace "test:namespace";
- prefix "tt";
-
- include test-submodule;
-
- description
- "Types for testing";
-
- revision "2013-07-22";
-
-
- container c {
- leaf a {
- type string;
- }
- }
-
-}
+++ /dev/null
-submodule test-submodule {
- belongs-to "test-module" {
- prefix "tt";
- }
-
- container cont {
-
- }
-}
\ No newline at end of file
<modules>
<module>netconf-config</module>
- <module>mdsal-netconf-yang-library</module>
<module>netconf-netty-util</module>
<module>netconf-auth</module>
<module>yanglib</module>
+++ /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.restconf.nb.rfc8040.legacy;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.atomic.AtomicInteger;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-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.YangLibrary;
-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.Module.ConformanceType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Deviation;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Submodule;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.ModuleLike;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A component which maintains the state of {@code ietf-yang-library} inside the datastore.
- */
-// FIXME: this should be reconciled with the two other implementations we have.
-@Singleton
-@Component(service = { })
-public final class SchemaContextHandler implements EffectiveModelContextListener, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(SchemaContextHandler.class);
-
- private static final NodeIdentifier MODULE_CONFORMANCE_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "conformance-type").intern());
- private static final NodeIdentifier MODULE_FEATURE_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "feature").intern());
- private static final NodeIdentifier MODULE_NAME_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "name").intern());
- private static final NodeIdentifier MODULE_NAMESPACE_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "namespace").intern());
- private static final NodeIdentifier MODULE_REVISION_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "revision").intern());
- private static final NodeIdentifier MODULE_SCHEMA_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "schema").intern());
- private static final NodeIdentifier MODULE_SET_ID_LEAF_NODEID =
- NodeIdentifier.create(QName.create(YangLibrary.QNAME, "module-set-id").intern());
-
- private final AtomicInteger moduleSetId = new AtomicInteger();
- private final DOMDataBroker domDataBroker;
- private final Registration listenerRegistration;
-
- private volatile EffectiveModelContext schemaContext;
-
- @Inject
- @Activate
- public SchemaContextHandler(@Reference final DOMDataBroker domDataBroker,
- @Reference final DOMSchemaService domSchemaService) {
- this.domDataBroker = requireNonNull(domDataBroker);
- listenerRegistration = domSchemaService.registerSchemaContextListener(this);
- }
-
- @PreDestroy
- @Deactivate
- @Override
- public void close() {
- listenerRegistration.close();
- }
-
- @Override
- public void onModelContextUpdated(final EffectiveModelContext context) {
- schemaContext = requireNonNull(context);
-
- if (context.findModuleStatement(YangLibrary.QNAME.getModule()).isPresent()) {
- putData(mapModulesByIetfYangLibraryYang(context, String.valueOf(moduleSetId.incrementAndGet())));
- }
- }
-
- @VisibleForTesting
- EffectiveModelContext get() {
- return schemaContext;
- }
-
- private void putData(final ContainerNode normNode) {
- final DOMDataTreeWriteTransaction wTx = domDataBroker.newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL,
- YangInstanceIdentifier.of(NodeIdentifier.create(normNode.name().getNodeType())), normNode);
- try {
- wTx.commit().get();
- } catch (InterruptedException e) {
- throw new RestconfDocumentedException("Problem occurred while putting data to DS.", e);
- } catch (ExecutionException e) {
- final TransactionCommitFailedException failure = Throwables.getCauseAs(e,
- TransactionCommitFailedException.class);
- if (failure.getCause() instanceof ConflictingModificationAppliedException) {
- /*
- * Ignore error when another cluster node is already putting the same data to DS.
- * We expect that cluster is homogeneous and that node was going to write the same data
- * (that means no retry is needed). Transaction chain reset must be invoked to be able
- * to continue writing data with another transaction after failed transaction.
- * This is workaround for bug https://bugs.opendaylight.org/show_bug.cgi?id=7728
- */
- LOG.warn("Ignoring that another cluster node is already putting the same data to DS.", e);
- } else {
- throw new RestconfDocumentedException("Problem occurred while putting data to DS.", failure);
- }
- }
- }
-
- /**
- * Map data from modules to {@link NormalizedNode}.
- *
- * @param context schema context
- * @param moduleSetId module-set-id of actual set
- * @return mapped data as {@link NormalizedNode}
- */
- @VisibleForTesting
- public static ContainerNode mapModulesByIetfYangLibraryYang(final EffectiveModelContext context,
- final String moduleSetId) {
- final var mapBuilder = Builders.mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(Module.QNAME));
- for (var module : context.getModules()) {
- fillMapByModules(mapBuilder, Module.QNAME, false, module, context);
- }
- return Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(ModulesState.QNAME))
- .withChild(ImmutableNodes.leafNode(MODULE_SET_ID_LEAF_NODEID, moduleSetId))
- .withChild(mapBuilder.build())
- .build();
- }
-
- /**
- * Map data by the specific module or submodule.
- *
- * @param mapBuilder ordered list builder for children
- * @param mapQName QName corresponding to the list builder
- * @param isSubmodule true if module is specified as submodule, false otherwise
- * @param module specific module or submodule
- * @param context schema context
- */
- private static void fillMapByModules(final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder,
- final QName mapQName, final boolean isSubmodule, final ModuleLike module,
- final EffectiveModelContext context) {
- final var mapEntryBuilder = newCommonLeafsMapEntryBuilder(mapQName, module);
-
- mapEntryBuilder.withChild(ImmutableNodes.leafNode(MODULE_SCHEMA_NODEID,
- "/modules/" + module.getName() + "/"
- // FIXME: orElse(null) does not seem appropriate here
- + module.getQNameModule().getRevision().map(Revision::toString).orElse(null)));
-
- if (!isSubmodule) {
- mapEntryBuilder.withChild(ImmutableNodes.leafNode(MODULE_NAMESPACE_NODEID,
- module.getNamespace().toString()));
-
- // features - not mandatory
- if (module.getFeatures() != null && !module.getFeatures().isEmpty()) {
- addFeatureLeafList(mapEntryBuilder, module.getFeatures());
- }
- // deviations - not mandatory
- final ConformanceType conformance;
- if (module.getDeviations() != null && !module.getDeviations().isEmpty()) {
- addDeviationList(module, mapEntryBuilder, context);
- conformance = ConformanceType.Implement;
- } else {
- conformance = ConformanceType.Import;
- }
- mapEntryBuilder.withChild(
- ImmutableNodes.leafNode(MODULE_CONFORMANCE_NODEID, conformance.getName()));
-
- // submodules - not mandatory
- if (module.getSubmodules() != null && !module.getSubmodules().isEmpty()) {
- addSubmodules(module, mapEntryBuilder, context);
- }
- }
- mapBuilder.withChild(mapEntryBuilder.build());
- }
-
- /**
- * Mapping submodules of specific module.
- *
- * @param module module with submodules
- * @param mapEntryBuilder mapEntryBuilder of parent for mapping children
- * @param context schema context
- */
- private static void addSubmodules(final ModuleLike module,
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder,
- final EffectiveModelContext context) {
- final var mapBuilder = Builders.mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(Submodule.QNAME));
-
- for (var submodule : module.getSubmodules()) {
- fillMapByModules(mapBuilder, Submodule.QNAME, true, submodule, context);
- }
- mapEntryBuilder.withChild(mapBuilder.build());
- }
-
- /**
- * Mapping deviations of specific module.
- *
- * @param module
- * module with deviations
- * @param mapEntryBuilder
- * mapEntryBuilder of parent for mapping children
- * @param context
- * schema context
- */
- private static void addDeviationList(final ModuleLike module,
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder,
- final EffectiveModelContext context) {
- final var deviations = Builders.mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(Deviation.QNAME));
- for (var deviation : module.getDeviations()) {
- final List<QName> ids = deviation.getTargetPath().getNodeIdentifiers();
- final QName lastComponent = ids.get(ids.size() - 1);
-
- deviations.withChild(newCommonLeafsMapEntryBuilder(Deviation.QNAME,
- context.findModule(lastComponent.getModule()).orElseThrow())
- .build());
- }
- mapEntryBuilder.withChild(deviations.build());
- }
-
- /**
- * Mapping features of specific module.
- *
- * @param mapEntryBuilder mapEntryBuilder of parent for mapping children
- * @param features features of specific module
- */
- private static void addFeatureLeafList(
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder,
- final Collection<? extends FeatureDefinition> features) {
- final var leafSetBuilder = Builders.<String>leafSetBuilder()
- .withNodeIdentifier(MODULE_FEATURE_NODEID);
- for (var feature : features) {
- leafSetBuilder.withChildValue(feature.getQName().getLocalName());
- }
- mapEntryBuilder.withChild(leafSetBuilder.build());
- }
-
- private static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> newCommonLeafsMapEntryBuilder(
- final QName qname, final ModuleLike module) {
- final var name = module.getName();
- final var revision = module.getQNameModule().getRevision().map(Revision::toString).orElse("");
- return Builders.mapEntryBuilder()
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(qname,
- Map.of(MODULE_NAME_NODEID.getNodeType(), name, MODULE_REVISION_NODEID.getNodeType(), revision)))
- .withChild(ImmutableNodes.leafNode(MODULE_NAME_NODEID, name))
- .withChild(ImmutableNodes.leafNode(MODULE_REVISION_NODEID, revision));
- }
-}
+++ /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.restconf.nb.rfc8040.legacy;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-/**
- * Tests for handling {@link SchemaContext}.
- */
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class SchemaContextHandlerTest {
- private static EffectiveModelContext SCHEMA_CONTEXT;
-
- private SchemaContextHandler schemaContextHandler;
-
- @Mock
- private DOMDataBroker mockDOMDataBroker;
- @Mock
- private DOMSchemaService mockDOMSchemaService;
- @Mock
- private ListenerRegistration<?> mockListenerReg;
-
- @BeforeClass
- public static void beforeClass() {
- SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/modules");
- }
-
- @AfterClass
- public static void afterClass() {
- SCHEMA_CONTEXT = null;
- }
-
- @Before
- public void setup() throws Exception {
- doReturn(mockListenerReg).when(mockDOMSchemaService).registerSchemaContextListener(any());
-
- schemaContextHandler = new SchemaContextHandler(mockDOMDataBroker, mockDOMSchemaService);
- verify(mockDOMSchemaService).registerSchemaContextListener(schemaContextHandler);
-
- schemaContextHandler.onModelContextUpdated(SCHEMA_CONTEXT);
- }
-
- /**
- * Testing init and close.
- */
- @Test
- public void testInitAndClose() {
- schemaContextHandler.close();
- verify(mockListenerReg).close();
- }
-
- /**
- * Test getting actual {@link SchemaContext}.
- *
- * <p>
- * Get <code>SchemaContext</code> from <code>SchemaContextHandler</code> and compare it to actual
- * <code>SchemaContext</code>.
- */
- @Test
- public void getSchemaContextTest() {
- assertEquals("SchemaContextHandler should has reference to actual SchemaContext",
- SCHEMA_CONTEXT, schemaContextHandler.get());
- }
-
- /**
- * Test updating of {@link SchemaContext}.
- *
- * <p>
- * Create new <code>SchemaContext</code>, set it to <code>SchemaContextHandler</code> and check if
- * <code>SchemaContextHandler</code> reference to new <code>SchemaContext</code> instead of old one.
- */
- @Test
- public void onGlobalContextUpdateTest() {
- // create new SchemaContext and update SchemaContextHandler
- final EffectiveModelContext newSchemaContext =
- YangParserTestUtils.parseYangResourceDirectory("/modules/modules-behind-mount-point");
- schemaContextHandler.onModelContextUpdated(newSchemaContext);
-
- assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
- SCHEMA_CONTEXT, schemaContextHandler.get());
- assertEquals("SchemaContextHandler should has reference to new SchemaContext",
- newSchemaContext, schemaContextHandler.get());
- }
-}
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.restconf.nb.rfc8040.legacy.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
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.module.Deviation;
schemaContextMonitoring = YangParserTestUtils.parseYangResourceDirectory("/modules");
}
- /**
- * Test of writing modules into {@link RestconfModule#MODULE_LIST_SCHEMA_NODE} and checking if modules were
- * correctly written.
- */
- @Test
- public void restconfMappingNodeTest() {
- // write modules into list module in Restconf
- final ContainerNode mods = SchemaContextHandler.mapModulesByIetfYangLibraryYang(schemaContext, "1");
-
- // verify loaded modules
- verifyLoadedModules(mods);
- // verify deviations
- verifyDeviations(mods);
- }
-
@Test
public void toStreamEntryNodeTest() throws Exception {
final YangInstanceIdentifier path = ParserIdentifier.toInstanceIdentifier(