Search in sources :

Example 1 with MountPointContext

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointContext in project yangtools by opendaylight.

the class AbstractMountPointContextFactory method createMountPointContext.

@Override
protected final MountPointContext createMountPointContext(final EffectiveModelContext schemaContext, final ContainerNode mountData) {
    checkArgument(SCHEMA_MOUNTS.equals(mountData.getIdentifier()), "Unexpected top-level container %s", mountData);
    final DataContainerChild mountPoint = mountData.childByArg(MOUNT_POINT);
    if (mountPoint == null) {
        LOG.debug("mount-point list not present in {}", mountData);
        return new EmptyMountPointContext(schemaContext);
    }
    checkArgument(mountPoint instanceof MapNode, "mount-point list %s is not a MapNode", mountPoint);
    return new ImmutableMountPointContext(schemaContext, ((MapNode) mountPoint).body().stream().map(entry -> {
        final String moduleName = entry.findChildByArg(MODULE).map(mod -> {
            checkArgument(mod instanceof LeafNode, "Unexpected module leaf %s", mod);
            final Object value = mod.body();
            checkArgument(value instanceof String, "Unexpected module leaf value %s", value);
            return (String) value;
        }).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry));
        final Iterator<? extends Module> it = schemaContext.findModules(moduleName).iterator();
        checkArgument(it.hasNext(), "Failed to find a module named %s", moduleName);
        final QNameModule module = it.next().getQNameModule();
        return new MountPointDefinition(MountPointIdentifier.of(QName.create(module, entry.findChildByArg(LABEL).map(lbl -> {
            checkArgument(lbl instanceof LeafNode, "Unexpected label leaf %s", lbl);
            final Object value = lbl.body();
            checkArgument(value instanceof String, "Unexpected label leaf value %s", value);
            return (String) value;
        }).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry)))), entry.findChildByArg(CONFIG).map(cfg -> {
            checkArgument(cfg instanceof LeafNode, "Unexpected config leaf %s", cfg);
            final Object value = cfg.body();
            checkArgument(value instanceof Boolean, "Unexpected config leaf value %s", cfg);
            return (Boolean) value;
        }).orElse(Boolean.TRUE), getSchema(entry.findChildByArg(SCHEMA_REF).orElseThrow(() -> new IllegalArgumentException("Missing schema-ref choice in " + entry))));
    }).collect(Collectors.toList()), this::createContextFactory);
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) SchemaMountConstants(org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants) LoggerFactory(org.slf4j.LoggerFactory) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MountPointIdentifier(org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Objects.requireNonNull(java.util.Objects.requireNonNull) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MountPointContextFactory(org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) Immutable(org.opendaylight.yangtools.concepts.Immutable) ImmutableSet(com.google.common.collect.ImmutableSet) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Module(org.opendaylight.yangtools.yang.model.api.Module) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Collectors(java.util.stream.Collectors) AbstractSimpleIdentifiable(org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) QName(org.opendaylight.yangtools.yang.common.QName) Beta(com.google.common.annotations.Beta) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 2 with MountPointContext

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointContext in project yangtools by opendaylight.

the class AbstractDynamicMountPointContextFactory method createContext.

@Override
public final MountPointContext createContext(final Map<ContainerName, MountPointChild> libraryContainers, final MountPointChild schemaMounts) throws YangParserException {
    for (Entry<ContainerName, MountPointChild> entry : libraryContainers.entrySet()) {
        // Context for the specific code word
        final Optional<EffectiveModelContext> optLibContext = findSchemaForLibrary(entry.getKey());
        if (optLibContext.isEmpty()) {
            LOG.debug("YANG Library context for mount point {} container {} not found", getIdentifier(), entry.getKey());
            continue;
        }
        final NormalizedNode libData;
        try {
            libData = entry.getValue().normalizeTo(optLibContext.get());
        } catch (IOException e) {
            throw new YangParserException("Failed to interpret yang-library data", e);
        }
        if (!(libData instanceof ContainerNode)) {
            throw new YangParserException("Invalid yang-library non-container " + libData);
        }
        final EffectiveModelContext schemaContext = bindLibrary(entry.getKey(), (ContainerNode) libData);
        if (schemaMounts == null) {
            return new EmptyMountPointContext(schemaContext);
        }
        final NormalizedNode mountData;
        try {
            mountData = schemaMounts.normalizeTo(schemaContext);
        } catch (IOException e) {
            throw new YangParserException("Failed to interpret schema-mount data", e);
        }
        if (!(mountData instanceof ContainerNode)) {
            throw new YangParserException("Invalid schema-mount non-container " + mountData);
        }
        return createMountPointContext(schemaContext, (ContainerNode) mountData);
    }
    throw new YangParserException("Failed to interpret " + libraryContainers);
}
Also used : ContainerName(org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.ContainerName) MountPointChild(org.opendaylight.yangtools.rfc8528.data.api.MountPointChild) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) IOException(java.io.IOException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 3 with MountPointContext

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointContext in project netconf by opendaylight.

the class NetconfDevice method createMountPointContext.

private ListenableFuture<MountPointContext> createMountPointContext(final EffectiveModelContext schemaContext, final BaseSchema baseSchema, final NetconfDeviceCommunicator listener) {
    final MountPointContext emptyContext = new EmptyMountPointContext(schemaContext);
    if (schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isEmpty()) {
        return Futures.immediateFuture(emptyContext);
    }
    // Create a temporary RPC invoker and acquire the mount point tree
    LOG.debug("{}: Acquiring available mount points", id);
    final NetconfDeviceRpc deviceRpc = new NetconfDeviceRpc(schemaContext, listener, new NetconfMessageTransformer(emptyContext, false, baseSchema));
    return Futures.transform(deviceRpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_GET_QNAME, Builders.containerBuilder().withNodeIdentifier(NETCONF_GET_NODEID).withChild(NetconfMessageTransformUtil.toFilterStructure(RFC8528_SCHEMA_MOUNTS, schemaContext)).build()), rpcResult -> processSchemaMounts(rpcResult, emptyContext), MoreExecutors.directExecutor());
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)

Example 4 with MountPointContext

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointContext in project netconf by opendaylight.

the class DeviceMountPointContext method create.

static MountPointContext create(final MountPointContext emptyContext, final ContainerNode mountData) {
    final Optional<DataContainerChild> optMountPoint = mountData.findChildByArg(MOUNT_POINT);
    if (optMountPoint.isEmpty()) {
        LOG.debug("mount-point list not present in {}", mountData);
        return emptyContext;
    }
    final EffectiveModelContext schemaContext = emptyContext.getEffectiveModelContext();
    final DataContainerChild mountPoint = optMountPoint.get();
    checkArgument(mountPoint instanceof MapNode, "mount-point list %s is not a MapNode", mountPoint);
    final Map<MountPointIdentifier, NetconfMountPointContextFactory> mountPoints = new HashMap<>();
    for (MapEntryNode entry : ((MapNode) mountPoint).body()) {
        final String moduleName = entry.findChildByArg(MODULE).map(mod -> {
            checkArgument(mod instanceof LeafNode, "Unexpected module leaf %s", mod);
            final Object value = mod.body();
            checkArgument(value instanceof String, "Unexpected module leaf value %s", value);
            return (String) value;
        }).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry));
        final Iterator<? extends Module> it = schemaContext.findModules(moduleName).iterator();
        checkArgument(it.hasNext(), "Failed to find a module named %s", moduleName);
        final QNameModule module = it.next().getQNameModule();
        final MountPointIdentifier mountId = MountPointIdentifier.of(QName.create(module, entry.findChildByArg(LABEL).map(lbl -> {
            checkArgument(lbl instanceof LeafNode, "Unexpected label leaf %s", lbl);
            final Object value = lbl.body();
            checkArgument(value instanceof String, "Unexpected label leaf value %s", value);
            return (String) value;
        }).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry))));
        final DataContainerChild child = entry.findChildByArg(SCHEMA_REF).orElseThrow(() -> new IllegalArgumentException("Missing schema-ref choice in " + entry));
        checkArgument(child instanceof ChoiceNode, "Unexpected schema-ref choice %s", child);
        final ChoiceNode schemaRef = (ChoiceNode) child;
        final Optional<DataContainerChild> maybeShared = schemaRef.findChildByArg(SHARED_SCHEMA);
        if (maybeShared.isEmpty()) {
            LOG.debug("Ignoring non-shared mountpoint entry {}", entry);
            continue;
        }
        mountPoints.put(mountId, new NetconfMountPointContextFactory(schemaContext));
    }
    return new DeviceMountPointContext(schemaContext, mountPoints);
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) SchemaMountConstants(org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MountPointIdentifier(org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MountPointContextFactory(org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory) AbstractEffectiveModelContextProvider(org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) Immutable(org.opendaylight.yangtools.concepts.Immutable) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Module(org.opendaylight.yangtools.yang.model.api.Module) ImmutableMap(com.google.common.collect.ImmutableMap) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) QName(org.opendaylight.yangtools.yang.common.QName) Optional(java.util.Optional) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NonNull(org.eclipse.jdt.annotation.NonNull) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) HashMap(java.util.HashMap) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) MountPointIdentifier(org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 5 with MountPointContext

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointContext in project yangtools by opendaylight.

the class MountPointData method write.

void write(@NonNull final NormalizedNodeStreamWriter writer) throws IOException {
    final StreamWriterMountPointExtension mountWriter = writer.getExtensions().getInstance(StreamWriterMountPointExtension.class);
    if (mountWriter == null) {
        LOG.debug("Writer {} does not support mount points, ignoring data in {}", writer, getIdentifier());
        return;
    }
    final MountPointContext mountCtx;
    try {
        mountCtx = contextFactory.createContext(yangLib, schemaMounts);
    } catch (YangParserException e) {
        throw new IOException("Failed to resolve mount point " + getIdentifier(), e);
    }
    try (NormalizedNodeStreamWriter nestedWriter = mountWriter.startMountPoint(getIdentifier(), mountCtx)) {
        for (MountPointChild child : children) {
            child.writeTo(nestedWriter, mountCtx);
        }
    }
}
Also used : NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) MountPointChild(org.opendaylight.yangtools.rfc8528.data.api.MountPointChild) IOException(java.io.IOException) StreamWriterMountPointExtension(org.opendaylight.yangtools.rfc8528.data.api.StreamWriterMountPointExtension) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException)

Aggregations

MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)5 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 NetconfDeviceRpc (org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc)2 NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)2 Immutable (org.opendaylight.yangtools.concepts.Immutable)2 MountPointChild (org.opendaylight.yangtools.rfc8528.data.api.MountPointChild)2 MountPointContextFactory (org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory)2 MountPointIdentifier (org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier)2 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)2 SchemaMountConstants (org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants)2 QName (org.opendaylight.yangtools.yang.common.QName)2 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)2 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)2