org.opensearch.migrations.VersionMatchers Maven / Gradle / Ivy
package org.opensearch.migrations;
import java.util.function.Predicate;
import lombok.experimental.UtilityClass;
@UtilityClass
public class VersionMatchers {
public static final Predicate isES_6_X = VersionMatchers.matchesMajorVersion(Version.fromString("ES 6.8"));
public static final Predicate isES_7_X = VersionMatchers.matchesMajorVersion(Version.fromString("ES 7.10"));
public static final Predicate isES_7_10 = VersionMatchers.matchesMinorVersion(Version.fromString("ES 7.10.2"));
public static final Predicate equalOrGreaterThanES_7_10 = VersionMatchers.equalOrGreaterThanMinorVersion(Version.fromString("ES 7.10"));
public static final Predicate isOS_1_X = VersionMatchers.matchesMajorVersion(Version.fromString("OS 1.0.0"));
public static final Predicate isOS_2_X = VersionMatchers.matchesMajorVersion(Version.fromString("OS 2.0.0"));
private static Predicate compatibleFlavor(final Flavor flavor) {
return other -> {
if (other == null) {
return false;
}
if (other.isOpenSearch() && flavor.isOpenSearch()) {
return true;
}
return other == flavor;
};
}
private static Predicate matchesMajorVersion(final Version version) {
return other -> {
if (other == null) {
return false;
}
var flavorMatches = compatibleFlavor(other.getFlavor()).test(version.getFlavor());
var majorVersionNumberMatches = version.getMajor() == other.getMajor();
return flavorMatches && majorVersionNumberMatches;
};
}
private static Predicate matchesMinorVersion(final Version version) {
return other -> matchesMajorVersion(version)
.and(other2 -> version.getMinor() == other2.getMinor())
.test(other);
}
private static Predicate equalOrGreaterThanMinorVersion(final Version version) {
return other -> matchesMajorVersion(version)
.and(other2 -> version.getMinor() <= other2.getMinor())
.test(other);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy