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);
}
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);
}
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());
}
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);
}
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);
}
}
}
Aggregations