[YANGTOOLS-1341] Rework yang-repo-api in terms of java.nio Created: 01/Oct/21 Updated: 18/Jan/24 |
|
| Status: | Confirmed |
| Project: | yangtools |
| Component/s: | parser |
| Affects Version/s: | None |
| Fix Version/s: | 14.0.0, 13.0.2 |
| Type: | Epic | Priority: | Highest |
| Reporter: | Robert Varga | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | pt | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Epic Name: | YANG Filesystem | ||||||||
| Description |
|
we have a very much free-standing yang-repo-api, which has a weird placement between being user-facing and internal. This is centered around SchemaSourceRepresentation: @Beta public interface SchemaSourceRepresentation extends Identifiable<SourceIdentifier>, Immutable { @Override SourceIdentifier getIdentifier(); /** * Return the concrete representation type. * * @return The type of representation. */ @NonNull Class<? extends SchemaSourceRepresentation> getType(); /** * Return the symbolic name, if available. This name has no semantic meaning beyond being useful for debugging * by humans. * * @return Symbolic name, if available */ Optional<String> getSymbolicName(); } which is a type-safe baseline for things like YangTextFileSchemaSource, which little more than a ByteSource, i.e. an API-enriched Supplier<InputStream>. What it has is some additional metadata related to import/include statement handling, so that these can be cross-related. Most of the metadata is static, some is actually validated against the actual content. That metadata is encapsulated in SourceIdentifier, which is an internable concepts.Identifier composed of a String name and an optional Revision. There is a SemVer version which adds an optional concepts.SemVer, which is our try at versions based on OpenConfig. Reactor side of SemVer is scary, but I think the logic could use some amount of decoupling before we decide what to do with it. Now we are typically already interfacing java.nio, for example YangTextFileSchemaSource actually does:
@Override
public InputStream openStream() throws IOException {
return Files.newInputStream(file.toPath());
}
So at the very least it would be nice if we started talking java.nio.file.Path instead of java.io.File() – hence Now if we look at other YangTextFileSchemaSource implementations, these are just a number of variations on how the input stream is supplied and perhaps passing some more information from the upper layer. There is a provision to supply that content potentially lazily, which really all about connecting to a Path (or a URI) and retrieving the stream there. So now we have something which is a java.nio.file.Path implementation providing metadata and binary content – which fits exactly with how a file system operates: it provides a set of files and those files have attributes. It can additionally provide other services as well, if we provide utilities similar to java.nio.file.Files and our implementation of Path to hold the attached data, we just expose SchemaSourceRepresentation as something you can acquire from the appropriate java.nio.file.attribute.AttributeView. |
| Comments |
| Comment by Robert Varga [ 30/Nov/21 ] |
|
There is also another data point, which is RFC8525 model of how modules and submodules are organized. In that world submodule names are only unique within a module. This model also further constrains effective module resolution, as it allows only a single revision of a module to be implemented, while multiple module revisions may be 'import-only'. We will need to somehow reconcile the two views (random files and YANG Library pre-organized) so they can be fed into the parser with the expected results coming out. |
| Comment by Robert Varga [ 30/Nov/21 ] |
|
Since the YANG Library view is explicit in what modules are import-only vs. which are implemented, we need the solution here to cover the requirements of |
| Comment by Robert Varga [ 05/Jan/24 ] |
|
At the end of the day, we do have a proper construct in yang-parser-api, which is YangLibModuleSet and YangLibResolver. A chunk of this work relates to YANGTOOLS-1150, which ends up moving quite a few things around – most notably introducing SourceInfo, which is a light-weight information about how a particular SchemaSource is supposed to link to other sources. What we now need is three things:
|