-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Update transport version directory structure #132891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
76c8eca
ec31471
6982230
61c9a03
ed7a2bb
33c9aae
85ecfa4
f3581d6
0bc2815
62c6935
0666f3b
4816d31
6d3c5ed
9f4f49f
f9e417e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ | |
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
@@ -113,6 +112,7 @@ public static TransportVersion fromBufferedReader( | |
| String component, | ||
| String path, | ||
| boolean nameInFile, | ||
| boolean ignoreName, | ||
| BufferedReader bufferedReader, | ||
| Integer latest | ||
| ) { | ||
|
|
@@ -128,7 +128,14 @@ public static TransportVersion fromBufferedReader( | |
| if (parts.length < (nameInFile ? 2 : 1)) { | ||
| throw new IllegalStateException("invalid transport version file format [" + toComponentPath(component, path) + "]"); | ||
| } | ||
| String name = nameInFile ? parts[0] : path.substring(path.lastIndexOf('/') + 1, path.length() - 4); | ||
| String name = null; | ||
| if (ignoreName == false) { | ||
| if (nameInFile) { | ||
| name = parts[0]; | ||
| } else { | ||
| name = path.substring(path.lastIndexOf('/') + 1, path.length() - 4); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: I'm not a fan of "magic numbers" (4) here or elsewhere, I'd rather this reference a constant if only purely to improve readability and maintainability. Not blocking - your call. |
||
| } | ||
| } | ||
| List<Integer> ids = new ArrayList<>(); | ||
| for (int i = nameInFile ? 1 : 0; i < parts.length; ++i) { | ||
| try { | ||
|
|
@@ -156,7 +163,7 @@ public static TransportVersion fromBufferedReader( | |
| } | ||
| } | ||
|
|
||
| public static Map<String, TransportVersion> collectFromInputStreams( | ||
| public static List<TransportVersion> collectFromInputStreams( | ||
| String component, | ||
| Function<String, InputStream> nameToStream, | ||
| String latestFileName | ||
|
|
@@ -165,32 +172,32 @@ public static Map<String, TransportVersion> collectFromInputStreams( | |
| component, | ||
| "/transport/latest/" + latestFileName, | ||
| nameToStream, | ||
| (c, p, br) -> fromBufferedReader(c, p, true, br, Integer.MAX_VALUE) | ||
| (c, p, br) -> fromBufferedReader(c, p, true, false, br, Integer.MAX_VALUE) | ||
| ); | ||
| if (latest != null) { | ||
| List<String> versionFilesNames = parseFromBufferedReader( | ||
| List<String> versionRelativePaths = parseFromBufferedReader( | ||
| component, | ||
| "/transport/defined/manifest.txt", | ||
| "/transport/definitions/manifest.txt", | ||
| nameToStream, | ||
| (c, p, br) -> br.lines().filter(line -> line.isBlank() == false).toList() | ||
| ); | ||
| if (versionFilesNames != null) { | ||
| Map<String, TransportVersion> transportVersions = new HashMap<>(); | ||
| for (String versionFileName : versionFilesNames) { | ||
| if (versionRelativePaths != null) { | ||
| List<TransportVersion> transportVersions = new ArrayList<>(); | ||
| for (String versionRelativePath : versionRelativePaths) { | ||
| TransportVersion transportVersion = parseFromBufferedReader( | ||
| component, | ||
| "/transport/defined/" + versionFileName, | ||
| "/transport/definitions/" + versionRelativePath, | ||
| nameToStream, | ||
| (c, p, br) -> fromBufferedReader(c, p, false, br, latest.id()) | ||
| (c, p, br) -> fromBufferedReader(c, p, false, versionRelativePath.startsWith("initial/"), br, latest.id()) | ||
| ); | ||
| if (transportVersion != null) { | ||
| transportVersions.put(versionFileName.substring(0, versionFileName.length() - 4), transportVersion); | ||
| transportVersions.add(transportVersion); | ||
| } | ||
| } | ||
| return transportVersions; | ||
| } | ||
| } | ||
| return Map.of(); | ||
| return List.of(); | ||
| } | ||
|
|
||
| private static String toComponentPath(String component, String path) { | ||
|
|
@@ -228,7 +235,23 @@ public static TransportVersion fromId(int id) { | |
| public static TransportVersion fromName(String name) { | ||
| TransportVersion known = VersionsHolder.ALL_VERSIONS_BY_NAME.get(name); | ||
| if (known == null) { | ||
| throw new IllegalStateException("unknown transport version [" + name + "]"); | ||
| List<String> versionRelativePaths = parseFromBufferedReader( | ||
| "<server>", | ||
| "/transport/definitions/manifest.txt", | ||
| TransportVersion.class::getResourceAsStream, | ||
| (c, p, br) -> br.lines().filter(line -> line.isBlank() == false).toList() | ||
| ); | ||
| throw new IllegalStateException( | ||
| "\nunknown transport version [" | ||
| + name | ||
| + "];" | ||
| + "\nknown names [" | ||
| + VersionsHolder.ALL_VERSIONS_BY_NAME | ||
|
||
| + "]" | ||
| + "\nrelative paths" | ||
| + versionRelativePaths | ||
| + "\n" | ||
| ); | ||
| } | ||
| return known; | ||
| } | ||
|
|
@@ -419,12 +442,15 @@ private static class VersionsHolder { | |
| static { | ||
| // collect all the transport versions from server and es modules/plugins (defined in server) | ||
| List<TransportVersion> allVersions = new ArrayList<>(TransportVersions.DEFINED_VERSIONS); | ||
| Map<String, TransportVersion> allVersionsByName = collectFromInputStreams( | ||
| List<TransportVersion> streamVersions = collectFromInputStreams( | ||
| "<server>", | ||
| TransportVersion.class::getResourceAsStream, | ||
| Version.CURRENT.major + "." + Version.CURRENT.minor + ".csv" | ||
| ); | ||
| addTransportVersions(allVersionsByName.values(), allVersions).sort(TransportVersion::compareTo); | ||
| Map<String, TransportVersion> allVersionsByName = streamVersions.stream() | ||
| .filter(tv -> tv.name() != null) | ||
| .collect(Collectors.toMap(TransportVersion::name, v -> v)); | ||
| addTransportVersions(streamVersions, allVersions).sort(TransportVersion::compareTo); | ||
|
|
||
| // set version lookup by release before adding serverless versions | ||
| // serverless versions should not affect release version | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe flip this to positive logic, like "recordName" or "captureName"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to
isNamed