<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>11.0.5</version>
+ <version>13.0.0</version>
<dependencies>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
requires org.opendaylight.mdsal.binding.runtime.api;
requires org.opendaylight.mdsal.binding.spec.util;
requires org.opendaylight.mdsal.dom.spi;
+ requires org.opendaylight.yangtools.concepts;
requires org.opendaylight.yangtools.yang.common;
requires org.opendaylight.yangtools.yang.model.api;
requires org.slf4j;
// AugmentationResult already points to parent path
final var parentPath = normalized instanceof AugmentationResult ? path : path.getParent();
if (parentPath != null && !parentPath.isEmpty()) {
- final var parentNode = ImmutableNodes.fromInstanceId(
- serializer.getRuntimeContext().getEffectiveModelContext(), parentPath);
+ final var parentNode = ImmutableNodes.fromInstanceId(serializer.getRuntimeContext().modelContext(),
+ parentPath);
getDelegate().merge(store, YangInstanceIdentifier.of(parentNode.name()), parentNode);
}
}
}
private @NonNull Entry<SchemaInferenceStack, QNameModule> resolvePath(final @NonNull InstanceIdentifier<?> path) {
- final var stack = SchemaInferenceStack.of(getRuntimeContext().getEffectiveModelContext());
+ final var stack = SchemaInferenceStack.of(getRuntimeContext().modelContext());
final var it = toYangInstanceIdentifier(path).getPathArguments().iterator();
verify(it.hasNext(), "Unexpected empty instance identifier for %s", path);
return addPostponedOpAndWait(new FutureSchemaPredicate() {
@Override
public boolean test(final BindingRuntimeContext input) {
- return input.getEffectiveModelContext().findModule(module).isPresent();
+ return input.modelContext().findModule(module).isPresent();
}
});
}
*/
package org.opendaylight.mdsal.binding.dom.adapter;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doReturn;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class BindingStructuralTypeTest {
+@ExtendWith(MockitoExtension.class)
+class BindingStructuralTypeTest {
@Mock
- private NormalizedNode normalizedNode;
+ private AnydataNode<?> normalizedNode;
@Mock
private DataTreeCandidateNode dataTreeCandidateNode;
@Test
- public void basicTest() {
+ void basicTest() {
doReturn(normalizedNode).when(dataTreeCandidateNode).dataBefore();
assertEquals(BindingStructuralType.UNKNOWN, BindingStructuralType.from(dataTreeCandidateNode));
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class CurrentAdapterSerializerTest {
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
+ public EffectiveModelContext modelContext() {
throw new UnsupportedOperationException();
}
@Override
- public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
throw new UnsupportedOperationException();
}
}
public DOMStore createConfigurationDatastore() {
- final InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", getDataTreeChangeListenerExecutor());
- schemaService.registerSchemaContextListener(store);
+ final var store = new InMemoryDOMDataStore("CFG", getDataTreeChangeListenerExecutor());
+ schemaService.registerSchemaContextListener(store::onModelContextUpdated);
return store;
}
public DOMStore createOperationalDatastore() {
- final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", getDataTreeChangeListenerExecutor());
- schemaService.registerSchemaContextListener(store);
+ final var store = new InMemoryDOMDataStore("OPER", getDataTreeChangeListenerExecutor());
+ schemaService.registerSchemaContextListener(store::onModelContextUpdated);
return store;
}
return RUNTIME_CONTEXT_CACHE.getUnchecked(getModuleInfos());
}
- protected EffectiveModelContext getSchemaContext() throws Exception {
- return getRuntimeContext().getEffectiveModelContext();
+ protected EffectiveModelContext modelContext() throws Exception {
+ return getRuntimeContext().modelContext();
}
protected void setupWithRuntimeContext(final BindingRuntimeContext runtimeContext) {
- setupWithSchema(runtimeContext.getEffectiveModelContext());
+ setupWithSchema(runtimeContext.modelContext());
}
/**
public void startNewDomDataBroker() {
checkState(executor != null, "Executor needs to be set");
- final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER",
- MoreExecutors.newDirectExecutorService());
- final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG",
- MoreExecutors.newDirectExecutorService());
+ final var operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
+ final var configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService());
newDatastores = ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.OPERATIONAL, operStore)
.put(LogicalDatastoreType.CONFIGURATION, configStore)
newDOMDataBroker = new SerializedDOMDataBroker(newDatastores, executor);
- mockSchemaService.registerSchemaContextListener(configStore);
- mockSchemaService.registerSchemaContextListener(operStore);
+ mockSchemaService.registerSchemaContextListener(configStore::onModelContextUpdated);
+ mockSchemaService.registerSchemaContextListener(operStore::onModelContextUpdated);
}
public void startBindingDataBroker() {
}
public EffectiveModelContext getContext() {
- return mockSchemaService.getEffectiveModelContext();
+ return mockSchemaService.getGlobalContext();
}
public void start() {
private void startDomBroker() {
checkState(executor != null);
- domRouter = new DOMRpcRouter();
- mockSchemaService.registerSchemaContextListener(domRouter);
+ domRouter = new DOMRpcRouter(mockSchemaService);
}
public void startBindingNotificationBroker() {
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.ServiceLoader;
+import java.util.function.Consumer;
import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext;
import org.opendaylight.mdsal.binding.dom.adapter.CurrentAdapterSerializer;
import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.util.ListenerRegistry;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.util.ObjectRegistry;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-public final class MockSchemaService implements DOMSchemaService, EffectiveModelContextProvider, AdapterContext {
+public final class MockSchemaService implements DOMSchemaService, AdapterContext {
// Codec has some amount of non-trivial state, such as generated classes. Its operation should not be affected by
// anything except BindingRuntimeContext, hence we should be able to reuse it.
private static final LoadingCache<BindingRuntimeContext, BindingDOMCodecServices> CODEC_CACHE =
}
});
- private EffectiveModelContext schemaContext;
+ private EffectiveModelContext modelContext;
private CurrentAdapterSerializer serializer;
- final ListenerRegistry<EffectiveModelContextListener> listeners = ListenerRegistry.create();
+ final ObjectRegistry<Consumer<EffectiveModelContext>> listeners = ObjectRegistry.createConcurrent("mock schema");
@Override
public synchronized EffectiveModelContext getGlobalContext() {
- return schemaContext;
+ return modelContext;
}
@Override
- public ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
- final EffectiveModelContextListener listener) {
+ public Registration registerSchemaContextListener(final Consumer<EffectiveModelContext> listener) {
return listeners.register(listener);
}
- @Override
- public synchronized EffectiveModelContext getEffectiveModelContext() {
- return schemaContext;
- }
-
public synchronized void changeSchema(final BindingRuntimeContext newContext) {
serializer = new CurrentAdapterSerializer(CODEC_CACHE.getUnchecked(newContext));
- schemaContext = newContext.getEffectiveModelContext();
- listeners.streamListeners().forEach(listener -> listener.onModelContextUpdated(schemaContext));
+ modelContext = newContext.modelContext();
+ listeners.streamObjects().forEach(listener -> listener.accept(modelContext));
}
@Override
return identifier;
}
- @Override
- @Deprecated(since = "12.0.0", forRemoval = true)
- public final NodeIdentifier getIdentifier() {
- return identifier;
- }
-
@Override
public final ContainerNode getDelegate() {
return delegate();
final var child = type.schemaTreeChild(qname);
if (child == null) {
final var module = qname.getModule();
- if (context.getEffectiveModelContext().findModule(module).isEmpty()) {
+ if (context.modelContext().findModule(module).isEmpty()) {
throw new MissingSchemaException(
"Module " + module + " is not present in current schema context.");
}
final Class<?> valueType = method.getReturnType();
final ValueCodec<Object, Object> codec = getCodec(valueType, leafSchema.getType());
valueNode = LeafNodeCodecContext.of(leafSchema, codec, method.getName(), valueType,
- context.getEffectiveModelContext());
+ context.modelContext());
} else if (schema instanceof LeafListSchemaNode leafListSchema) {
final Optional<Type> optType = ClassLoaderUtils.getFirstGenericParameter(
method.getGenericReturnType());
private final @NonNull DataContainerNode data;
// Accessed via a VarHandle
- @SuppressWarnings("unused")
// FIXME: consider using a primitive int-based cache (with 0 being uninit)
+ @SuppressWarnings("unused")
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "https://github.com/spotbugs/spotbugs/issues/2749")
private volatile Integer cachedHashcode;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
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;
@CheckReturnValue
private IllegalArgumentException childNullException(final QName child, final String message, final Object... args) {
- final QNameModule module = child.getModule();
- if (!factory().getRuntimeContext().getEffectiveModelContext().findModule(module).isPresent()) {
+ final var module = child.getModule();
+ if (!factory().getRuntimeContext().modelContext().findModule(module).isPresent()) {
return new MissingSchemaException("Module " + module + " is not present in current schema context.");
}
return new IncorrectNestingException(message, args);
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
public class Mdsal673Test extends AbstractBindingCodecTest {
private static final NodeIdentifier FOO = new NodeIdentifier(Foo.QNAME);
@Test
public void testNonnullContainer() {
final var entry = codecContext.fromNormalizedNode(YangInstanceIdentifier.of(FOO),
- Builders.containerBuilder().withNodeIdentifier(FOO).build());
+ ImmutableNodes.newContainerBuilder().withNodeIdentifier(FOO).build());
assertNotNull(entry);
assertEquals(InstanceIdentifier.create(Foo.class), entry.getKey());
@Test
public void testEmptyContainer() {
final var entry = codecContext.fromNormalizedNode(YangInstanceIdentifier.of(FOO),
- Builders.containerBuilder()
+ ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(FOO)
- .withChild(Builders.containerBuilder().withNodeIdentifier(BAR).build())
+ .withChild(ImmutableNodes.newContainerBuilder().withNodeIdentifier(BAR).build())
.build());
assertNotNull(entry);
assertEquals(InstanceIdentifier.create(Foo.class), entry.getKey());
@Test
public void testNotEmptyContainer() {
// FIXME: MDSAL-670: these should get translated to YangInstanceIdentifier.of(FOO)
- final var identifier = new YangInstanceIdentifier.NodeWithValue<>(Bar.QNAME, FOO);
- final var data = Builders.containerBuilder()
+ final var data = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(FOO)
- .withChild(Builders.containerBuilder()
+ .withChild(ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(BAR)
- .withChild(Builders.leafSetBuilder()
+ .withChild(ImmutableNodes.newSystemLeafSetBuilder()
.withNodeIdentifier(BAR)
- .withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(identifier).withValue(FOO).build())
+ .withChild(ImmutableNodes.leafSetEntry(Bar.QNAME, FOO))
.build())
.build())
.build();
import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeCodec;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class NonCachingCodecTest {
@Mock
public BindingNormalizedNodeCodec<DataObject> codec;
@Mock
- public NormalizedNode node;
+ public ContainerNode node;
@Mock
public DataObject object;
// Hidden on purpose
}
- static @NonNull BindingRuntimeTypes createTypes(final @NonNull EffectiveModelContext context) {
- final var moduleGens = new GeneratorReactor(context).execute(TypeBuilderFactory.runtime());
+ static @NonNull BindingRuntimeTypes createTypes(final @NonNull EffectiveModelContext modelContext) {
+ final var moduleGens = new GeneratorReactor(modelContext).execute(TypeBuilderFactory.runtime());
final var sw = Stopwatch.createStarted();
final var factory = new BindingRuntimeTypesFactory();
factory.indexModules(moduleGens);
LOG.debug("Indexed {} generators in {}", moduleGens.size(), sw);
- return new DefaultBindingRuntimeTypes(context, factory.modules, factory.allTypes, factory.identities,
+ return new DefaultBindingRuntimeTypes(modelContext, factory.modules, factory.allTypes, factory.identities,
factory.choiceToCases);
}
private static final Logger LOG = LoggerFactory.getLogger(DefaultBindingRuntimeGenerator.class);
@Override
- public BindingRuntimeTypes generateTypeMapping(final EffectiveModelContext context) {
- return BindingRuntimeTypesFactory.createTypes(context);
+ public BindingRuntimeTypes generateTypeMapping(final EffectiveModelContext modelContext) {
+ return BindingRuntimeTypesFactory.createTypes(modelContext);
}
@Activate
*/
package org.opendaylight.mdsal.binding.generator.impl.reactor;
+import static java.util.Objects.requireNonNull;
+
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
/**
* Abstract view on generation tree as viewed by a particular {@link Generator}.
*/
-abstract class GeneratorContext extends AbstractEffectiveModelContextProvider {
+abstract class GeneratorContext {
+ private final @NonNull EffectiveModelContext modelContext;
+
GeneratorContext(final EffectiveModelContext modelContext) {
- super(modelContext);
+ this.modelContext = requireNonNull(modelContext);
+ }
+
+ final @NonNull EffectiveModelContext modelContext() {
+ return modelContext;
}
/**
* The result of BindingGenerator run. Contains mapping between Types and SchemaNodes.
*/
public final class DefaultBindingRuntimeTypes implements BindingRuntimeTypes {
- private final @NonNull EffectiveModelContext context;
+ private final @NonNull EffectiveModelContext modelContext;
private final ImmutableSetMultimap<JavaTypeName, CaseRuntimeType> choiceToCases;
private final ImmutableMap<QNameModule, ModuleRuntimeType> modulesByNamespace;
private final ImmutableSortedMap<String, ModuleRuntimeType> modulesByPackage;
private final ImmutableMap<QName, IdentityRuntimeType> identities;
private final ImmutableMap<JavaTypeName, RuntimeType> types;
- public DefaultBindingRuntimeTypes(final EffectiveModelContext context,
+ public DefaultBindingRuntimeTypes(final EffectiveModelContext modelContext,
final Map<QNameModule, ModuleRuntimeType> modules, final Map<JavaTypeName, RuntimeType> types,
final Map<QName, IdentityRuntimeType> identities,
final SetMultimap<JavaTypeName, CaseRuntimeType> choiceToCases) {
- this.context = requireNonNull(context);
+ this.modelContext = requireNonNull(modelContext);
this.identities = ImmutableMap.copyOf(identities);
this.types = ImmutableMap.copyOf(types);
this.choiceToCases = ImmutableSetMultimap.copyOf(choiceToCases);
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
- return context;
+ public EffectiveModelContext modelContext() {
+ return modelContext;
}
@Override
import static org.junit.Assert.assertSame;
import java.util.Set;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Mdsal829Test {
- private static EffectiveModelContext CONTEXT;
-
- @BeforeClass
- public static void beforeClass() {
- CONTEXT = YangParserTestUtils.parseYangResource("/mdsal829.yang", Set.of());
- }
+ private static final EffectiveModelContext MODEL_CONTEXT =
+ YangParserTestUtils.parseYangResource("/mdsal829.yang", Set.of());
@Test
public void testCompileTimeTypes() {
- assertEquals(1, DefaultBindingGenerator.generateFor(CONTEXT).size());
+ assertEquals(1, DefaultBindingGenerator.generateFor(MODEL_CONTEXT).size());
}
@Test
public void testRunTimeTypes() {
- final var types = BindingRuntimeTypesFactory.createTypes(CONTEXT);
- assertSame(CONTEXT, types.getEffectiveModelContext());
+ final var types = BindingRuntimeTypesFactory.createTypes(MODEL_CONTEXT);
+ assertSame(MODEL_CONTEXT, types.modelContext());
final var schema = types.findSchema(
JavaTypeName.create("org.opendaylight.yang.gen.v1.mdsal829.norev", "Mdsal829Data")).orElseThrow();
assertNotNull(schema);
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final Builder<String> bindingProviders = ImmutableSet.builder();
for (Module module : localModules) {
final YangModuleInfoTemplate template = new YangModuleInfoTemplate(module, context,
- mod -> moduleResourcePathResolver.findModuleResourcePath(mod, YangTextSchemaSource.class));
+ mod -> moduleResourcePathResolver.findModuleResourcePath(mod, YangTextSource.class));
final String path = DOT_MATCHER.replaceFrom(template.getPackageName(), '/') + "/";
result.put(GeneratedFileType.SOURCE, GeneratedFilePath.ofPath(path + MODULE_INFO),
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>rfc8040-model-api</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>
requires transitive org.opendaylight.yangtools.yang.common;
requires transitive org.opendaylight.yangtools.yang.model.api;
requires transitive org.opendaylight.yangtools.yang.binding;
- requires transitive org.opendaylight.yangtools.yang.repo.api;
requires transitive org.opendaylight.yangtools.yang.repo.spi;
requires transitive org.opendaylight.yangtools.rfc8040.model.api;
requires transitive org.opendaylight.mdsal.binding.model.api;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
*/
@Beta
// FIXME: refactor return to follow foo()/getFoo()/findFoo() naming
-public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
+public interface BindingRuntimeContext extends Immutable {
+
@NonNull BindingRuntimeTypes getTypes();
@NonNull <T> Class<T> loadClass(JavaTypeName type) throws ClassNotFoundException;
return loadClass(type.getIdentifier());
}
- @Override
- default EffectiveModelContext getEffectiveModelContext() {
- return getTypes().getEffectiveModelContext();
+ default @NonNull EffectiveModelContext modelContext() {
+ return getTypes().modelContext();
}
/**
* The EffectiveModelContext MUST contain all of the sub modules otherwise the there is no guarantee that result
* List of Generated Types will contain correct Generated Types.
*
- * @param context Schema Context
+ * @param modelContext effective model context
* @return Generated type mapping.
*/
- BindingRuntimeTypes generateTypeMapping(EffectiveModelContext context);
+ BindingRuntimeTypes generateTypeMapping(EffectiveModelContext modelContext);
}
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangDataName;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
/**
* The result of BindingGenerator run. Contains mapping between Types and SchemaNodes.
*/
@Beta
-public interface BindingRuntimeTypes extends EffectiveModelContextProvider, RuntimeTypeContainer, Immutable {
+public interface BindingRuntimeTypes extends RuntimeTypeContainer, Immutable {
+ /**
+ * Return the {@link EffectiveModelContext} underlying this object.
+ *
+ * @return the {@link EffectiveModelContext} underlying this object
+ */
+ @NonNull EffectiveModelContext modelContext();
+
/**
* Lookup {@link IdentityRuntimeType} by its QNamme.
*
package org.opendaylight.mdsal.binding.runtime.api;
import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+/**
+ * A snapshot of a set of {@link YangModuleInfo}s, assembled to form an {@link EffectiveModelContext}.
+ */
@Beta
-public interface ModuleInfoSnapshot extends Immutable, EffectiveModelContextProvider,
- SchemaSourceProvider<YangTextSchemaSource> {
+public interface ModuleInfoSnapshot extends Immutable, SchemaSourceProvider<YangTextSource> {
+ /**
+ * The {@link EffectiveModelContext} resulting from all models exposed from constituent module infos.
+ *
+ * @return the resulting model context
+ */
+ @NonNull EffectiveModelContext modelContext();
<T> Class<T> loadClass(String fullyQualifiedName) throws ClassNotFoundException;
}
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator;
-import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeTypes;
import org.opendaylight.mdsal.binding.runtime.api.DefaultBindingRuntimeContext;
-import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
@Override
void add(final OSGiModuleInfoSnapshot snapshot) {
- final ModuleInfoSnapshot context = snapshot.getService();
- final BindingRuntimeTypes types = generator.generateTypeMapping(context.getEffectiveModelContext());
+ final var infoSnapshot = snapshot.getService();
+ final var types = generator.generateTypeMapping(infoSnapshot.modelContext());
instances.put(snapshot, factory.newInstance(OSGiBindingRuntimeContextImpl.props(
snapshot.getGeneration(), snapshot.getServiceRanking(),
- new DefaultBindingRuntimeContext(types, context))));
+ new DefaultBindingRuntimeContext(types, infoSnapshot))));
}
@Override
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-model-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-spi</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
requires org.opendaylight.yangtools.concepts;
requires org.opendaylight.yangtools.util;
requires org.opendaylight.yangtools.yang.model.api;
+ requires org.opendaylight.yangtools.yang.model.spi;
requires org.opendaylight.yangtools.yang.parser.impl;
requires org.opendaylight.mdsal.binding.model.api;
requires org.opendaylight.mdsal.binding.spec.util;
public static @NonNull EffectiveModelContext createEffectiveModel(final YangParserFactory parserFactory,
final Iterable<? extends YangModuleInfo> moduleInfos) throws YangParserException {
- return prepareContext(parserFactory, moduleInfos).getEffectiveModelContext();
+ return prepareContext(parserFactory, moduleInfos).modelContext();
}
public static @NonNull BindingRuntimeContext createRuntimeContext() {
throw new IllegalStateException("Failed to parse models", e);
}
return new DefaultBindingRuntimeContext(ServiceLoaderState.Generator.INSTANCE.generateTypeMapping(
- infos.getEffectiveModelContext()), infos);
+ infos.modelContext()), infos);
}
public static @NonNull BindingRuntimeContext createRuntimeContext(final Class<?>... classes) {
}
return new DefaultBindingRuntimeContext(
- ServiceLoaderState.Generator.INSTANCE.generateTypeMapping(snapshot.getEffectiveModelContext()), snapshot);
+ ServiceLoaderState.Generator.INSTANCE.generateTypeMapping(snapshot.modelContext()), snapshot);
}
public static @NonNull BindingRuntimeContext createRuntimeContext(final YangParserFactory parserFactory,
public static @NonNull BindingRuntimeContext createRuntimeContext(final YangParserFactory parserFactory,
final BindingRuntimeGenerator generator, final Collection<Class<?>> classes) throws YangParserException {
- final ModuleInfoSnapshot infos = prepareContext(parserFactory, classes.stream()
+ final var infos = prepareContext(parserFactory, classes.stream()
.map(BindingRuntimeHelpers::getYangModuleInfo)
.collect(Collectors.toList()));
- return new DefaultBindingRuntimeContext(generator.generateTypeMapping(infos.getEffectiveModelContext()), infos);
+ return new DefaultBindingRuntimeContext(generator.generateTypeMapping(infos.modelContext()), infos);
}
public static @NonNull YangModuleInfo getYangModuleInfo(final Class<?> clazz) {
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+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.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
final class DefaultModuleInfoSnapshot implements ModuleInfoSnapshot {
private final ImmutableMap<SourceIdentifier, YangModuleInfo> moduleInfos;
private final ImmutableMap<String, ClassLoader> classLoaders;
- private final @NonNull EffectiveModelContext effectiveModel;
+ private final @NonNull EffectiveModelContext modelContext;
- DefaultModuleInfoSnapshot(final EffectiveModelContext effectiveModel,
+ DefaultModuleInfoSnapshot(final EffectiveModelContext modelContext,
final Map<SourceIdentifier, YangModuleInfo> moduleInfos, final Map<String, ClassLoader> classLoaders) {
- this.effectiveModel = requireNonNull(effectiveModel);
+ this.modelContext = requireNonNull(modelContext);
this.moduleInfos = ImmutableMap.copyOf(moduleInfos);
this.classLoaders = ImmutableMap.copyOf(classLoaders);
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
- return effectiveModel;
+ public EffectiveModelContext modelContext() {
+ return modelContext;
}
@Override
- public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
- final YangModuleInfo info = moduleInfos.get(sourceIdentifier);
- if (info == null) {
- return Futures.immediateFailedFuture(
- new MissingSchemaSourceException("No source registered", sourceIdentifier));
- }
- return Futures.immediateFuture(YangTextSchemaSource.delegateForCharSource(sourceIdentifier,
- info.getYangTextCharSource()));
+ public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceId) {
+ final var info = moduleInfos.get(sourceId);
+ return info == null
+ ? Futures.immediateFailedFuture(new MissingSchemaSourceException(sourceId, "No source registered"))
+ : Futures.immediateFuture(new DelegatedYangTextSource(sourceId, info.getYangTextCharSource()));
}
@Override
public <T> Class<T> loadClass(final String fullyQualifiedName) throws ClassNotFoundException {
- final String packageName = Naming.getModelRootPackageName(fullyQualifiedName);
- final ClassLoader loader = classLoaders.get(packageName);
+ final var packageName = Naming.getModelRootPackageName(fullyQualifiedName);
+ final var loader = classLoaders.get(packageName);
if (loader == null) {
throw new ClassNotFoundException("Package " + packageName + " not found");
}
@SuppressWarnings("unchecked")
- final Class<T> loaded = (Class<T>) loader.loadClass(fullyQualifiedName);
+ final var loaded = (Class<T>) loader.loadClass(fullyQualifiedName);
return loaded;
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
@Beta
public abstract class ForwardingModuleInfoSnapshot extends ForwardingObject implements ModuleInfoSnapshot {
}
@Override
- public @NonNull EffectiveModelContext getEffectiveModelContext() {
- return delegate().getEffectiveModelContext();
+ public @NonNull EffectiveModelContext modelContext() {
+ return delegate().modelContext();
}
@Override
- public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
return delegate().getSource(sourceIdentifier);
}
}
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
for (var info : moduleInfos) {
final var source = ModuleInfoSnapshotResolver.toYangTextSource(info);
- mappedInfos.put(source.getIdentifier(), info);
+ mappedInfos.put(source.sourceId(), info);
final Class<?> infoClass = info.getClass();
final String infoRoot = Naming.getModelRootPackageName(infoClass.getPackage().getName());
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+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.stmt.SubmoduleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver;
public synchronized @NonNull ModuleInfoSnapshot takeSnapshot() {
final var effectiveModel = ctxResolver.getEffectiveModelContext().orElseThrow();
final var local = currentSnapshot;
- if (local != null && local.getEffectiveModelContext().equals(effectiveModel)) {
+ if (local != null && local.modelContext().equals(effectiveModel)) {
return local;
}
}
@Holding("this")
- private @NonNull ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext effectiveModel) {
+ private @NonNull ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext modelContext) {
// Alright, now let's find out which sources got captured
final var sources = new HashSet<SourceIdentifier>();
- for (var entry : effectiveModel.getModuleStatements().entrySet()) {
+ for (var entry : modelContext.getModuleStatements().entrySet()) {
final var revision = entry.getKey().getRevision().orElse(null);
final var module = entry.getValue();
infoClass.getClassLoader());
}
- final var next = new DefaultModuleInfoSnapshot(effectiveModel, moduleInfos, classLoaders);
+ final var next = new DefaultModuleInfoSnapshot(modelContext, moduleInfos, classLoaders);
currentSnapshot = next;
return next;
}
}
}
- static @NonNull YangTextSchemaSource toYangTextSource(final YangModuleInfo moduleInfo) {
- return YangTextSchemaSource.delegateForCharSource(sourceIdentifierFrom(moduleInfo),
- moduleInfo.getYangTextCharSource());
+ static @NonNull YangTextSource toYangTextSource(final YangModuleInfo moduleInfo) {
+ return new DelegatedYangTextSource(sourceIdentifierFrom(moduleInfo), moduleInfo.getYangTextCharSource());
}
- private static @NonNull YangTextSchemaSource toYangTextSource(final SourceIdentifier identifier,
+ private static @NonNull YangTextSource toYangTextSource(final SourceIdentifier identifier,
final YangModuleInfo moduleInfo) {
- return YangTextSchemaSource.delegateForCharSource(identifier, moduleInfo.getYangTextCharSource());
+ return new DelegatedYangTextSource(identifier, moduleInfo.getYangTextCharSource());
}
private static SourceIdentifier sourceIdentifierFrom(final YangModuleInfo moduleInfo) {
final var name = moduleInfo.getName();
- return new SourceIdentifier(name.getLocalName(), name.getRevision().map(Revision::toString).orElse(null));
+ return new SourceIdentifier(name.getLocalName(), name.getRevision().orElse(null));
}
private static @NonNull List<@NonNull YangModuleInfo> flatDependencies(final YangModuleInfo moduleInfo) {
*/
package org.opendaylight.mdsal.binding.runtime.spi;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Map;
import java.util.Set;
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yang.gen.v1.mdsal767.norev.$YangModuleInfoImpl;
import org.opendaylight.yang.gen.v1.mdsal767.norev.Mdsal767Data;
import org.opendaylight.yang.gen.v1.mdsal767.norev.One$F;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.api.YangParserException;
-import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
-public class ModuleInfoSnapshotBuilderTest {
- private static final YangParserFactory PARSER_FACTORY = new DefaultYangParserFactory();
-
+class ModuleInfoSnapshotBuilderTest {
@Test
- public void testModuleRegistration() throws YangParserException {
- final ModuleInfoSnapshotBuilder snapshotBuilder = new ModuleInfoSnapshotBuilder(PARSER_FACTORY);
+ void testModuleRegistration() throws Exception {
+ final var snapshotBuilder = new ModuleInfoSnapshotBuilder(new DefaultYangParserFactory());
snapshotBuilder.add($YangModuleInfoImpl.getInstance());
snapshotBuilder.addModuleFeatures(Mdsal767Data.class, Set.of(One$F.VALUE));
- final ModuleInfoSnapshot snapshot = snapshotBuilder.build();
- final EffectiveModelContext modelContext = snapshot.getEffectiveModelContext();
- final Map<QNameModule, ModuleEffectiveStatement> modules = modelContext.getModuleStatements();
- final ModuleEffectiveStatement module = modules.get(QNameModule.create(XMLNamespace.of("mdsal767")));
+ final var snapshot = snapshotBuilder.build();
+ final var modelContext = snapshot.modelContext();
+ final var modules = modelContext.getModuleStatements();
+ final var module = modules.get(QNameModule.create(XMLNamespace.of("mdsal767")));
assertEquals(1, module.features().size());
- final FeatureEffectiveStatement feature = module.features().stream().findAny().orElseThrow();
+ final var feature = module.features().stream().findAny().orElseThrow();
assertEquals(QName.create("mdsal767", "one"), feature.argument());
}
}
import com.google.common.annotations.Beta;
import com.google.common.base.Throwables;
+import java.util.function.Supplier;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.dom.adapter.CurrentAdapterSerializer;
import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@Beta
public class DataBrokerTestModule {
return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
}
- public EffectiveModelContextProvider getSchemaContextProvider() {
+ public Supplier<EffectiveModelContext> getModelContextSupplier() {
return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService()::getGlobalContext;
}
}
<link>https://commons.apache.org/proper/commons-lang/javadocs/api-release/</link>
<link>https://www.javadoc.io/doc/org.opendaylight.odlparent/odlparent-docs/13.0.10/</link>
- <link>https://www.javadoc.io/doc/org.opendaylight.yangtools/yangtools-docs/11.0.5/</link>
+ <link>https://www.javadoc.io/doc/org.opendaylight.yangtools/yangtools-docs/13.0.0/</link>
</links>
<groups>
<group>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-artifacts</artifactId>
- <version>11.0.5</version>
+ <version>13.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-api</artifactId>
+ <artifactId>yang-model-spi</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
requires transitive org.opendaylight.yangtools.yang.data.api;
requires transitive org.opendaylight.yangtools.yang.data.tree.api;
requires transitive org.opendaylight.yangtools.yang.model.api;
- requires transitive org.opendaylight.yangtools.yang.repo.api;
+ requires transitive org.opendaylight.yangtools.yang.model.spi;
requires transitive org.opendaylight.yangtools.yang.repo.spi;
requires transitive org.opendaylight.mdsal.common.api;
requires transitive org.opendaylight.yangtools.concepts;
*/
package org.opendaylight.mdsal.dom.api;
-import org.eclipse.jdt.annotation.NonNull;
+import java.util.function.Consumer;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
+@NonNullByDefault
public interface DOMSchemaService extends DOMService<DOMSchemaService, DOMSchemaService.Extension> {
/**
* Type capture of a {@link DOMService.Extension} applicable to {@link DOMSchemaService} implementations.
* @return Listener registration handle
* @throws NullPointerException if {@code listener} is {@code null}
*/
- @NonNull Registration registerSchemaContextListener(EffectiveModelContextListener listener);
+ Registration registerSchemaContextListener(Consumer<EffectiveModelContext> listener);
}
package org.opendaylight.mdsal.dom.api;
import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
/**
- * A {@link DOMSchemaService.Extension} exposing access to {@link YangTextSchemaSource}. Instances of this method should
+ * A {@link DOMSchemaService.Extension} exposing access to {@link YangTextSource}. Instances of this method should
* be acquired from {@link DOMSchemaService}.
*/
@Beta
public interface DOMYangTextSourceProvider
- extends DOMSchemaService.Extension, SchemaSourceProvider<YangTextSchemaSource> {
+ extends DOMSchemaService.Extension, SchemaSourceProvider<YangTextSource> {
}
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-api</artifactId>
+ <artifactId>yang-model-spi</artifactId>
</dependency>
<dependency>
<groupId>com.guicedee.services</groupId>
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@Singleton
@Component(service = DOMRpcRouter.class)
-public final class DOMRpcRouter extends AbstractRegistration implements EffectiveModelContextListener {
+public final class DOMRpcRouter extends AbstractRegistration {
private static final Logger LOG = LoggerFactory.getLogger(DOMRpcRouter.class);
private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder().setNameFormat(
"DOMRpcRouter-listener-%s").setDaemon(true).build();
@Inject
@Activate
public DOMRpcRouter(@Reference final DOMSchemaService schemaService) {
- listenerRegistration = schemaService.registerSchemaContextListener(this);
+ listenerRegistration = schemaService.registerSchemaContextListener(this::onModelContextUpdated);
LOG.info("DOM RPC/Action router started");
}
}
}
- @Override
- public synchronized void onModelContextUpdated(final EffectiveModelContext newModelContext) {
+
+ synchronized void onModelContextUpdated(final @NonNull EffectiveModelContext newModelContext) {
final DOMRpcRoutingTable oldTable = routingTable;
final DOMRpcRoutingTable newTable = (DOMRpcRoutingTable) oldTable.setSchemaContext(newModelContext);
routingTable = newTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
final class Rpcs {
static final EffectiveModelContext CONTEXT = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT,
null,
- YangTextSchemaSource.delegateForCharSource("yang-ext.yang",
+ new DelegatedYangTextSource(new SourceIdentifier("yang-ext.yang"),
$YangModuleInfoImpl.getInstance().getYangTextCharSource()),
- YangTextSchemaSource.forResource(Rpcs.class, "/rpcs.yang"));
+ new URLYangTextSource(Rpcs.class.getResource("/rpcs.yang")));
static final QName FOO = QName.create("rpcs", "foo");
static final QName BAR = QName.create(FOO, "bar");
import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* {@link org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadTransaction} to implement {@link DOMStore} contract.
*/
public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> implements DOMStore,
- Identifiable<String>, EffectiveModelContextListener, AutoCloseable, DOMStoreTreeChangePublisher {
+ Identifiable<String>, AutoCloseable, DOMStoreTreeChangePublisher {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class);
private final AtomicLong txCounter = new AtomicLong(0);
return name;
}
+ public final synchronized void onModelContextUpdated(final EffectiveModelContext newModelContext) {
+ dataTree.setEffectiveModelContext(newModelContext);
+ }
+
@Override
public DOMStoreReadTransaction newReadOnlyTransaction() {
return SnapshotBackedTransactions.newReadTransaction(nextIdentifier(), debugTransactions,
return new DOMStoreTransactionChainImpl(this);
}
- @Override
- public synchronized void onModelContextUpdated(final EffectiveModelContext newModelContext) {
- dataTree.setEffectiveModelContext(newModelContext);
- }
-
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void close() {
properties.getMaxDataChangeListenerQueueSize(), properties.getDebugTransactions());
if (schemaService != null) {
- schemaService.registerSchemaContextListener(dataStore);
+ schemaService.registerSchemaContextListener(dataStore::onModelContextUpdated);
}
return dataStore;
*/
package org.opendaylight.mdsal.dom.store.inmemory;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-public class InMemoryDOMDataStoreFactoryTest {
+@ExtendWith(MockitoExtension.class)
+class InMemoryDOMDataStoreFactoryTest {
+ @Mock
+ private DOMSchemaService domSchemaService;
+ @Mock
+ private DOMDataTreeChangeListener domDataTreeChangeListener;
+ @Mock
+ private AutoCloseable autoCloseable;
@Test
public void basicTest() throws Exception {
final String testStoreName = "TestStore";
- final DOMSchemaService domSchemaService = mock(DOMSchemaService.class);
- doReturn(null).when(domSchemaService).registerSchemaContextListener(any(EffectiveModelContextListener.class));
+ doReturn(null).when(domSchemaService).registerSchemaContextListener(any());
- final InMemoryDOMDataStore inMemoryDOMDataStore =
- InMemoryDOMDataStoreFactory.create(testStoreName, domSchemaService);
+ final var inMemoryDOMDataStore = InMemoryDOMDataStoreFactory.create(testStoreName, domSchemaService);
assertNotNull(inMemoryDOMDataStore);
assertEquals(testStoreName, inMemoryDOMDataStore.getIdentifier());
- final DOMDataTreeChangeListener domDataTreeChangeListener = mock(DOMDataTreeChangeListener.class);
- doReturn("testListener").when(domDataTreeChangeListener).toString();
- doNothing().when(domDataTreeChangeListener).onDataTreeChanged(any());
doNothing().when(domDataTreeChangeListener).onInitialData();
inMemoryDOMDataStore.onModelContextUpdated(TestModel.createTestContext());
inMemoryDOMDataStore.registerTreeChangeListener(YangInstanceIdentifier.of(), domDataTreeChangeListener);
- final AutoCloseable autoCloseable = mock(AutoCloseable.class);
doNothing().when(autoCloseable).close();
inMemoryDOMDataStore.setCloseable(autoCloseable);
inMemoryDOMDataStore.close();
<dependencies>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-dom-spi</artifactId>
+ <artifactId>mdsal-dom-api</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
requires transitive com.google.common;
requires transitive org.opendaylight.mdsal.binding.runtime.api;
requires org.opendaylight.mdsal.binding.runtime.spi;
- requires org.opendaylight.mdsal.dom.spi;
+ requires org.opendaylight.mdsal.dom.api;
requires org.opendaylight.yangtools.yang.binding;
requires org.opendaylight.yangtools.yang.model.api;
requires org.opendaylight.yangtools.yang.parser.api;
// Annotations
requires static org.apache.karaf.features.core;
requires static org.osgi.service.component.annotations;
-}
\ No newline at end of file
+}
import com.google.common.annotations.VisibleForTesting;
import java.util.Dictionary;
import java.util.Map;
+import java.util.function.Consumer;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
/**
- * A Factory Component which implements {@link EffectiveModelContextListener}. Instances of this component are created
- * through by {@link OSGiDOMSchemaService} each time a listener is registered.
+ * A Factory Component for OSGi SR manifestation of a {@code Consumer<EffectiveModelContext>}. Instances of this
+ * component are created through by {@link OSGiDOMSchemaService} each time a listener is registered.
*/
-@Component(factory = EffectiveModelContextImpl.FACTORY_NAME, service = EffectiveModelContextListener.class)
-public final class EffectiveModelContextImpl implements EffectiveModelContextListener {
+@Component(factory = ModelContextListener.FACTORY_NAME, service = ModelContextListener.class)
+public final class ModelContextListener {
static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.SchemaSchemaContextListener";
@VisibleForTesting
static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.SchemaSchemaContextListener";
- private EffectiveModelContextListener delegate = null;
-
- @Override
- public void onModelContextUpdated(final EffectiveModelContext newModelContext) {
- delegate.onModelContextUpdated(newModelContext);
- }
+ private Consumer<EffectiveModelContext> delegate = null;
@Activate
- void activate(final Map<String, ?> properties) {
- delegate = (EffectiveModelContextListener) verifyNotNull(properties.get(DELEGATE));
+ public ModelContextListener(final Map<String, ?> properties) {
+ delegate = (Consumer<EffectiveModelContext>) verifyNotNull(properties.get(DELEGATE));
}
@Deactivate
delegate = null;
}
- static Dictionary<String, ?> props(final EffectiveModelContextListener delegate) {
+ void onModelContextUpdated(final EffectiveModelContext newModelContext) {
+ delegate.accept(newModelContext);
+ }
+
+ static Dictionary<String, ?> props(final Consumer<EffectiveModelContext> delegate) {
return FrameworkUtil.asDictionary(Map.of(DELEGATE, delegate));
}
}
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
-import org.opendaylight.mdsal.dom.spi.AbstractDOMSchemaService;
import org.opendaylight.yangtools.concepts.AbstractRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
* OSGi Service Registry-backed implementation of {@link DOMSchemaService}.
*/
@Component(service = DOMSchemaService.class, immediate = true)
-public final class OSGiDOMSchemaService extends AbstractDOMSchemaService.WithYangTextSources {
+public final class OSGiDOMSchemaService implements DOMSchemaService, DOMYangTextSourceProvider {
private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMSchemaService.class);
-
- private final List<EffectiveModelContextListener> listeners = new CopyOnWriteArrayList<>();
+ private final List<Consumer<EffectiveModelContext>> listeners = new CopyOnWriteArrayList<>();
private final AtomicReference<ModuleInfoSnapshot> currentSnapshot = new AtomicReference<>();
- private final ComponentFactory<EffectiveModelContextImpl> listenerFactory;
+ private final ComponentFactory<ModelContextListener> listenerFactory;
private boolean deactivated;
@Activate
public OSGiDOMSchemaService(
- @Reference(target = "(component.factory=" + EffectiveModelContextImpl.FACTORY_NAME + ")")
- final ComponentFactory<EffectiveModelContextImpl> listenerFactory) {
+ @Reference(target = "(component.factory=" + ModelContextListener.FACTORY_NAME + ")")
+ final ComponentFactory<ModelContextListener> listenerFactory) {
this.listenerFactory = requireNonNull(listenerFactory);
LOG.info("DOM Schema services activated");
}
void bindSnapshot(final OSGiModuleInfoSnapshot newContext) {
LOG.info("Updating context to generation {}", newContext.getGeneration());
final var snapshot = newContext.getService();
- final var modelContext = snapshot.getEffectiveModelContext();
+ final var modelContext = snapshot.modelContext();
final var previous = currentSnapshot.getAndSet(snapshot);
LOG.debug("Snapshot updated from {} to {}", previous, snapshot);
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC,
policyOption = ReferencePolicyOption.GREEDY)
- void addListener(final EffectiveModelContextListener listener) {
+ void addListener(final Consumer<EffectiveModelContext> listener) {
LOG.trace("Adding listener {}", listener);
listeners.add(listener);
- listener.onModelContextUpdated(getGlobalContext());
+ listener.accept(getGlobalContext());
}
- void removeListener(final EffectiveModelContextListener listener) {
+ void removeListener(final Consumer<EffectiveModelContext> listener) {
LOG.trace("Removing listener {}", listener);
listeners.remove(listener);
}
@Override
public @NonNull EffectiveModelContext getGlobalContext() {
- return currentSnapshot.get().getEffectiveModelContext();
+ return currentSnapshot.get().modelContext();
}
@Override
- public Registration registerSchemaContextListener(final EffectiveModelContextListener listener) {
- final var reg = listenerFactory.newInstance(EffectiveModelContextImpl.props(listener));
+ public Registration registerSchemaContextListener(final Consumer<EffectiveModelContext> listener) {
+ final var reg = listenerFactory.newInstance(ModelContextListener.props(listener));
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
}
@Override
- public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
return currentSnapshot.get().getSource(sourceIdentifier);
}
@SuppressWarnings("checkstyle:illegalCatch")
private static void notifyListener(final @NonNull EffectiveModelContext modelContext,
- final EffectiveModelContextListener listener) {
+ final Consumer<EffectiveModelContext> listener) {
try {
- listener.onModelContextUpdated(modelContext);
+ listener.accept(modelContext);
} catch (RuntimeException e) {
LOG.warn("Failed to notify listener {}", listener, e);
}
+++ /dev/null
-/*
- * Copyright (c) 2019 Red Hat, 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.mdsal.dom.spi;
-
-import java.util.List;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-
-/**
- * Base class to implement DOMSchemaService more easily while providing a bridge between MD-SAL DOM Schema services
- * and YANG Tools Schema consumers.
- *
- * @author Michael Vorburger.ch
- */
-public abstract class AbstractDOMSchemaService implements DOMSchemaService, EffectiveModelContextProvider {
- public abstract static class WithYangTextSources extends AbstractDOMSchemaService
- implements DOMYangTextSourceProvider {
- @Override
- public List<Extension> supportedExtensions() {
- return List.of(this);
- }
- }
-
- @Override
- public final EffectiveModelContext getEffectiveModelContext() {
- final var ret = getGlobalContext();
- if (ret == null) {
- throw new IllegalStateException("Global context is not available in " + this);
- }
- return ret;
- }
-}
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
-import org.eclipse.jdt.annotation.NonNull;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
/**
* {@link DOMSchemaService} (and {@link DOMYangTextSourceProvider}) implementations backed by a
- * {@link EffectiveModelContextProvider} (and {@link SchemaSourceProvider}) which are known to be fixed and never change
- * schemas.
+ * {@code Supplier<EffectiveModelContext>} (and {@link SchemaSourceProvider}) which are known to be fixed and never
+ * change schemas.
*
* @author Michael Vorburger.ch
*/
@Beta
-public class FixedDOMSchemaService extends AbstractDOMSchemaService {
+@NonNullByDefault
+public sealed class FixedDOMSchemaService implements DOMSchemaService {
private static final class WithYangTextSources extends FixedDOMSchemaService implements DOMYangTextSourceProvider {
- private final @NonNull SchemaSourceProvider<YangTextSchemaSource> schemaSourceProvider;
+ private final SchemaSourceProvider<YangTextSource> schemaSourceProvider;
- WithYangTextSources(final EffectiveModelContextProvider schemaContextProvider,
- final SchemaSourceProvider<YangTextSchemaSource> schemaSourceProvider) {
- super(schemaContextProvider);
+ WithYangTextSources(final Supplier<EffectiveModelContext> modelContextSupplier,
+ final SchemaSourceProvider<YangTextSource> schemaSourceProvider) {
+ super(modelContextSupplier);
this.schemaSourceProvider = requireNonNull(schemaSourceProvider);
}
}
@Override
- public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
return schemaSourceProvider.getSource(sourceIdentifier);
}
}
- private final @NonNull EffectiveModelContextProvider schemaContextProvider;
+ private final Supplier<EffectiveModelContext> modelContextSupplier;
- private FixedDOMSchemaService(final EffectiveModelContextProvider schemaContextProvider) {
- this.schemaContextProvider = requireNonNull(schemaContextProvider);
+ private FixedDOMSchemaService(final Supplier<EffectiveModelContext> modelContextSupplier) {
+ this.modelContextSupplier = requireNonNull(modelContextSupplier);
}
- public static @NonNull DOMSchemaService of(final EffectiveModelContext effectiveModel) {
+ public static DOMSchemaService of(final EffectiveModelContext effectiveModel) {
final var checked = requireNonNull(effectiveModel);
- return of(() -> checked);
+ return new FixedDOMSchemaService(() -> checked);
}
- public static @NonNull DOMSchemaService of(final EffectiveModelContextProvider schemaContextProvider) {
- return new FixedDOMSchemaService(schemaContextProvider);
+ public static DOMSchemaService of(final Supplier<EffectiveModelContext> modelContextSupplier) {
+ return new FixedDOMSchemaService(modelContextSupplier);
}
- public static @NonNull DOMSchemaService of(final EffectiveModelContextProvider schemaContextProvider,
- final SchemaSourceProvider<YangTextSchemaSource> yangTextSourceProvider) {
- return new WithYangTextSources(schemaContextProvider, requireNonNull(yangTextSourceProvider));
+ public static DOMSchemaService of(final Supplier<EffectiveModelContext> modelContextSupplier,
+ final SchemaSourceProvider<YangTextSource> yangTextSourceProvider) {
+ return new WithYangTextSources(modelContextSupplier, requireNonNull(yangTextSourceProvider));
}
@Override
- public final @NonNull EffectiveModelContext getGlobalContext() {
- return schemaContextProvider.getEffectiveModelContext();
+ public final EffectiveModelContext getGlobalContext() {
+ return modelContextSupplier.get();
}
@Override
- public final Registration registerSchemaContextListener(final EffectiveModelContextListener listener) {
- listener.onModelContextUpdated(getGlobalContext());
+ public final Registration registerSchemaContextListener(final Consumer<EffectiveModelContext> listener) {
+ listener.accept(getGlobalContext());
return () -> { };
}
}
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@BeforeClass
public static void beforeClass() {
final var ctx = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT, null,
- YangTextSchemaSource.delegateForCharSource("yang-ext.yang",
+ new DelegatedYangTextSource(new SourceIdentifier("yang-ext.yang"),
$YangModuleInfoImpl.getInstance().getYangTextCharSource()),
- YangTextSchemaSource.forResource(ContentRoutedRpcContext.class, "/rpc-routing-strategy.yang"));
+ new URLYangTextSource(ContentRoutedRpcContext.class.getResource("/rpc-routing-strategy.yang")));
RPCS = ctx.findModuleStatements("foo").iterator().next()
.streamEffectiveSubstatements(RpcEffectiveStatement.class)
assertEquals(QName.create("foo", "identity"), context.identity());
assertEquals(QName.create("foo", "ctx"), context.leaf());
}
-}
\ No newline at end of file
+}
import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class PingPongTransactionChainTest {
tx.delete(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.of());
verify(rwTx).delete(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.of());
- final var data = mock(NormalizedNode.class);
+ final var data = mock(ContainerNode.class);
doNothing().when(rwTx).merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.of(), data);
tx.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.of(), data);
verify(rwTx).merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.of(), data);
import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
public class SnapshotBackedReadTransactionTest {
@Test
public void basicTest() throws Exception {
- final NormalizedNode testNode = mock(NormalizedNode.class);
- final Optional<NormalizedNode> optional = Optional.of(testNode);
+ final var testNode = mock(ContainerNode.class);
+ final var optional = Optional.of(testNode);
doReturn("testNode").when(testNode).toString();
doReturn(Optional.of(testNode)).when(DATA_TREE_SNAPSHOT).readNode(YangInstanceIdentifier.of());
assertTrue(snapshotBackedReadTransaction.exists(YangInstanceIdentifier.of()).get());
assertEquals(optional, snapshotBackedReadTransaction.read(YangInstanceIdentifier.of()).get());
- final Field stableSnapshotField = SnapshotBackedReadTransaction.class.getDeclaredField("stableSnapshot");
+ final var stableSnapshotField = SnapshotBackedReadTransaction.class.getDeclaredField("stableSnapshot");
stableSnapshotField.setAccessible(true);
DataTreeSnapshot stableSnapshot = (DataTreeSnapshot) stableSnapshotField.get(snapshotBackedReadTransaction);
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
@Test
public void basicTest() throws Exception {
- final NormalizedNode testNode = mock(NormalizedNode.class);
- final Optional<NormalizedNode> optional = Optional.of(testNode);
+ final var testNode = mock(ContainerNode.class);
+ final var optional = Optional.of(testNode);
doReturn("testNode").when(testNode).toString();
doReturn(Optional.of(testNode)).when(DATA_TREE_MODIFICATION).readNode(YangInstanceIdentifier.of());
assertTrue(snapshotBackedReadWriteTransaction.exists(YangInstanceIdentifier.of()).get());
import org.junit.Test;
import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
mock(TransactionReadyPrototype.class);
private static final DOMStoreThreePhaseCommitCohort DOM_STORE_THREE_PHASE_COMMIT_COHORT =
mock(DOMStoreThreePhaseCommitCohort.class);
- private static final NormalizedNode NORMALIZED_NODE = mock(NormalizedNode.class);
- private static final Optional<NormalizedNode> NORMALIZED_NODE_OPTIONAL = Optional.of(NORMALIZED_NODE);
+ private static final ContainerNode NORMALIZED_NODE = mock(ContainerNode.class);
+ private static final Optional<ContainerNode> NORMALIZED_NODE_OPTIONAL = Optional.of(NORMALIZED_NODE);
private static SnapshotBackedWriteTransaction<Object> snapshotBackedWriteTransaction;
@Before
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-artifacts</artifactId>
- <version>11.0.5</version>
+ <version>13.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-binding-api">
<feature name="odl-mdsal-binding-api">
- <feature version="[11,12)">odl-yangtools-data-api</feature>
+ <feature version="[13,14)">odl-yangtools-data-api</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-binding-base">
<feature name="odl-mdsal-binding-base">
- <feature version="[11,12)">odl-yangtools-common</feature>
+ <feature version="[13,14)">odl-yangtools-common</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-runtime-api">
<feature name="odl-mdsal-binding-runtime-api">
- <feature version="[11,12)">odl-yangtools-data</feature>
- <feature version="[11,12)">odl-yangtools-parser</feature>
+ <feature version="[13,14)">odl-yangtools-data</feature>
+ <feature version="[13,14)">odl-yangtools-parser</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-common">
<feature name="odl-mdsal-common">
- <feature version="[11,12)">odl-yangtools-common</feature>
+ <feature version="[13,14)">odl-yangtools-common</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-dom-api">
<feature name="odl-mdsal-dom-api">
- <feature version="[11,12)">odl-yangtools-data-api</feature>
+ <feature version="[13,14)">odl-yangtools-data-api</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-eos-common">
<feature name="odl-mdsal-eos-common">
- <feature version="[11,12)">odl-yangtools-data-api</feature>
+ <feature version="[13,14)">odl-yangtools-data-api</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-exp-yanglib-api">
<feature name="odl-mdsal-exp-yanglib-api">
- <feature version="[11,12)">odl-yangtools-data-api</feature>
+ <feature version="[13,14)">odl-yangtools-data-api</feature>
</feature>
</features>
<configfile finalname="etc/org.opendaylight.mdsal.replicate.netty.sink.cfg">mvn:org.opendaylight.mdsal/mdsal-replicate-netty/${project.version}/config/sink</configfile>
<configfile finalname="etc/org.opendaylight.mdsal.replicate.netty.source.cfg">mvn:org.opendaylight.mdsal/mdsal-replicate-netty/${project.version}/config/source</configfile>
<feature version="[12,14)">odl-netty-4</feature>
- <feature version="[11,12)">odl-yangtools-codec</feature>
+ <feature version="[13,14)">odl-yangtools-codec</feature>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-uint24-netty">
<feature name="odl-mdsal-uint24-netty">
- <feature version="[11,12)">odl-yangtools-netty</feature>
+ <feature version="[13,14)">odl-yangtools-netty</feature>
</feature>
</features>
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
+ public EffectiveModelContext modelContext() {
throw new UnsupportedOperationException();
}
}
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
+ public EffectiveModelContext modelContext() {
throw new UnsupportedOperationException();
}
private Registration reg;
- public NettyReplicationSource() {
- // Visible for DI
- }
-
@Activate
public NettyReplicationSource(@Reference final BootstrapSupport bootstrapSupport,
@Reference final DOMDataBroker dataBroker,
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-parser-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-repo-api</artifactId>
- </dependency>
</dependencies>
<scm>
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* A reference to a YANG source, potentially containing a location hint.
import org.opendaylight.yangtools.yang.data.api.schema.MountPointException;
import org.opendaylight.yangtools.yang.data.util.AbstractMountPointContextFactory;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("deprecation")
private final BindingDataObjectCodecTreeNode<ModulesState> legacyCodec;
private final BindingIdentityCodec identityCodec;
- private final EffectiveModelContext context;
+ private final EffectiveModelContext modelContext;
private final BindingCodecTree codecTree;
@Inject
final ModuleInfoSnapshot snapshot = new ModuleInfoSnapshotBuilder(parserFactory)
.add(YangLibrary.class)
.build();
- context = snapshot.getEffectiveModelContext();
+ modelContext = snapshot.modelContext();
codecTree = codecFactory.create(new DefaultBindingRuntimeContext(
- generator.generateTypeMapping(context), snapshot));
+ generator.generateTypeMapping(modelContext), snapshot));
identityCodec = codecTree.getIdentityCodec();
codec = codecTree.getDataObjectCodec(InstanceIdentifier.create(YangLibrary.class));
@Override
public MountPointContextFactory createMountPointContextFactory(final MountPointLabel label,
final SchemaContextResolver resolver) {
- return new MountPointContextFactoryImpl(label, resolver, context, identityCodec, codec, legacyCodec);
+ return new MountPointContextFactoryImpl(label, resolver, modelContext, identityCodec, codec, legacyCodec);
}
@Override
package org.opendaylight.mdsal.yanglib.rfc8525;
import java.util.ServiceLoader;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeEach;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
private static final BindingCodecTreeFactory CODEC_FACTORY = ServiceLoader.load(BindingCodecTreeFactory.class)
.findFirst().orElseThrow();
- static BindingRuntimeContext runtimeContext;
- static BindingCodecTree codecTree;
+ static final BindingRuntimeContext RUNTIME_CONTEXT = BindingRuntimeHelpers.createRuntimeContext();
+ static final BindingCodecTree CODEC_TREE = CODEC_FACTORY.create(RUNTIME_CONTEXT);
YangLibrarySupport yangLib;
- @BeforeClass
- public static void beforeClass() {
- runtimeContext = BindingRuntimeHelpers.createRuntimeContext();
- codecTree = CODEC_FACTORY.create(runtimeContext);
- }
-
- @Before
+ @BeforeEach
public void before() throws YangParserException {
yangLib = new YangLibrarySupport(YANG_PARSER_FACTORY, BINDING_RUNTIME_GENERATOR, CODEC_FACTORY);
}
*/
package org.opendaylight.mdsal.yanglib.rfc8525;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Map;
-import java.util.Optional;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
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.ModulesState;
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.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.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.data.api.schema.ContainerNode;
-public class LegacyYangLibraryFormatTest extends AbstractYangLibraryTest {
+class LegacyYangLibraryFormatTest extends AbstractYangLibraryTest {
@Test
- public void testLegacyFormat() {
- final var legacyCodec = codecTree.getDataObjectCodec(InstanceIdentifier.create(ModulesState.class));
+ void testLegacyFormat() {
+ final var legacyCodec = CODEC_TREE.getDataObjectCodec(InstanceIdentifier.create(ModulesState.class));
- final Optional<ContainerNode> legacyContent = yangLib.newContentBuilder()
- .defaultContext(runtimeContext.getEffectiveModelContext())
+ final var legacyContent = yangLib.newContentBuilder()
+ .defaultContext(RUNTIME_CONTEXT.modelContext())
.includeLegacy()
.formatYangLibraryLegacyContent();
assertTrue(legacyContent.isPresent());
- final ModulesState modulesState = legacyCodec.deserialize(legacyContent.orElseThrow());
-
- assertEquals(4, modulesState.nonnullModule().size());
- assertEquals(createControlModules(), modulesState.getModule());
- }
-
- private static Map<ModuleKey, Module> createControlModules() {
- return BindingMap.of(
+ final var modulesState = legacyCodec.deserialize(legacyContent.orElseThrow());
+ assertEquals(BindingMap.of(
createModule("ietf-yang-library", "urn:ietf:params:xml:ns:yang:ietf-yang-library", "2019-01-04"),
createModule("ietf-inet-types", "urn:ietf:params:xml:ns:yang:ietf-inet-types", "2013-07-15"),
createModule("ietf-datastores", "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"),
- createModule("ietf-yang-types", "urn:ietf:params:xml:ns:yang:ietf-yang-types", "2013-07-15"));
+ createModule("ietf-yang-types", "urn:ietf:params:xml:ns:yang:ietf-yang-types", "2013-07-15")),
+ modulesState.getModule());
}
private static Module createModule(final String name, final String namespace, final String revision) {
return new ModuleBuilder()
- .setName(new YangIdentifier(name))
- .setNamespace(new Uri(namespace))
- .setRevision(new Revision(new RevisionIdentifier(revision)))
- .setConformanceType(ConformanceType.Implement)
- .setFeature(Set.of())
- .build();
+ .setName(new YangIdentifier(name))
+ .setNamespace(new Uri(namespace))
+ .setRevision(new Revision(new RevisionIdentifier(revision)))
+ .setConformanceType(ConformanceType.Implement)
+ .setFeature(Set.of())
+ .build();
}
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.yanglib.rfc8525;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Map;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
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.YangLibrary;
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.ModuleKey;
-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.ModuleSetKey;
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.data.api.schema.ContainerNode;
-public class YangLibrarySupportTest extends AbstractYangLibraryTest {
+class YangLibrarySupportTest extends AbstractYangLibraryTest {
@Test
- public void testFormatSchema() {
- final var codec = codecTree.getDataObjectCodec(InstanceIdentifier.create(YangLibrary.class));
+ void testFormatSchema() {
+ final var codec = CODEC_TREE.getDataObjectCodec(InstanceIdentifier.create(YangLibrary.class));
- final ContainerNode nonLegacyContent = yangLib.newContentBuilder()
- .defaultContext(runtimeContext.getEffectiveModelContext()).formatYangLibraryContent();
- final YangLibrary yangLibrary = codec.deserialize(nonLegacyContent);
+ final var nonLegacyContent = yangLib.newContentBuilder()
+ .defaultContext(RUNTIME_CONTEXT.modelContext()).formatYangLibraryContent();
+ final var yangLibrary = codec.deserialize(nonLegacyContent);
- assertEquals(1, yangLibrary.nonnullModuleSet().size());
- final ModuleSet moduleSet = yangLibrary.nonnullModuleSet().get(new ModuleSetKey("ODL_modules"));
- assertEquals(4, moduleSet.nonnullModule().size());
- assertEquals(moduleSet.getModule(), createControlModules());
- }
-
- private static Map<ModuleKey, Module> createControlModules() {
- return BindingMap.of(
+ final var modulesSets = yangLibrary.nonnullModuleSet();
+ assertNotNull(modulesSets);
+ assertEquals(1, modulesSets.size());
+ final var moduleSet = modulesSets.get(new ModuleSetKey("ODL_modules"));
+ assertNotNull(moduleSet);
+ assertEquals(BindingMap.of(
createModule("ietf-yang-library", "urn:ietf:params:xml:ns:yang:ietf-yang-library", "2019-01-04"),
createModule("ietf-inet-types", "urn:ietf:params:xml:ns:yang:ietf-inet-types", "2013-07-15"),
createModule("ietf-datastores", "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"),
- createModule("ietf-yang-types", "urn:ietf:params:xml:ns:yang:ietf-yang-types", "2013-07-15"));
+ createModule("ietf-yang-types", "urn:ietf:params:xml:ns:yang:ietf-yang-types", "2013-07-15")),
+ moduleSet.getModule());
}
private static Module createModule(final String name, final String namespace, final String revision) {