-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Abstract version features checking to work with non-semantic versions #137199
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 5 commits
65bc193
56dbefa
a43053a
d85d889
fd3285c
8162162
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 |
|---|---|---|
|
|
@@ -26,27 +26,47 @@ | |
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.function.BiConsumer; | ||
| import java.util.function.Predicate; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static java.util.Collections.emptySet; | ||
|
|
||
| class ESRestTestFeatureService implements TestFeatureService { | ||
| public class ESRestTestFeatureService implements TestFeatureService { | ||
ldematte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * In order to migrate from version checks to cluster feature checks, | ||
| * we provide synthetic features derived from versions, e.g. "gte_v8.0.0". | ||
| */ | ||
| private static final Pattern VERSION_FEATURE_PATTERN = Pattern.compile("gte_v(\\d+\\.\\d+\\.\\d+)"); | ||
|
|
||
| private final Collection<Version> nodeVersions; | ||
| public interface VersionFeaturesPredicate { | ||
| boolean test(Version featureVersion, boolean any); | ||
| } | ||
|
|
||
| public static VersionFeaturesPredicate fromSemanticVersions(Set<String> nodesVersions) { | ||
| Set<Version> semanticNodeVersions = nodesVersions.stream() | ||
| .map(ESRestTestCase::parseLegacyVersion) | ||
| .flatMap(Optional::stream) | ||
| .collect(Collectors.toSet()); | ||
| if (semanticNodeVersions.isEmpty()) { | ||
| // Nodes do not have a semantic version (e.g. serverless). | ||
| // We assume the cluster is on the "latest version", and all is supported. | ||
| return ((featureVersion, any) -> true); | ||
|
||
| } | ||
|
|
||
| return (featureVersion, any) -> checkCollection(semanticNodeVersions, nodeVersion -> nodeVersion.onOrAfter(featureVersion), any); | ||
| } | ||
|
|
||
| private final VersionFeaturesPredicate versionFeaturesPredicate; | ||
| private final Collection<Set<String>> nodeFeatures; | ||
|
|
||
| ESRestTestFeatureService(Set<Version> nodeVersions, Collection<Set<String>> nodeFeatures) { | ||
| this.nodeVersions = nodeVersions; | ||
| ESRestTestFeatureService(VersionFeaturesPredicate versionFeaturesPredicate, Collection<Set<String>> nodeFeatures) { | ||
| this.versionFeaturesPredicate = versionFeaturesPredicate; | ||
| this.nodeFeatures = nodeFeatures; | ||
| } | ||
|
|
||
|
|
@@ -88,7 +108,7 @@ public boolean clusterHasFeature(String featureId, boolean any) { | |
| ); | ||
| } | ||
|
|
||
| return checkCollection(nodeVersions, v -> v.onOrAfter(extractedVersion), any); | ||
| return versionFeaturesPredicate.test(extractedVersion, any); | ||
|
||
| } | ||
|
|
||
| if (hasFeatureMetadata()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.