Skip to content
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

Remove JavaVersion, use builtin Runtime.Version to deal with runtime versions #3006

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions libs/core/src/main/java/org/opensearch/bootstrap/JarHell.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opensearch.common.io.PathUtils;

import java.io.IOException;
import java.lang.Runtime.Version;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -250,7 +251,9 @@ private static void checkManifest(Manifest manifest, Path jar) {
}

public static void checkVersionFormat(String targetVersion) {
if (!JavaVersion.isValid(targetVersion)) {
try {
Version.parse(targetVersion);
} catch (final IllegalArgumentException ex) {
throw new IllegalStateException(
String.format(
Locale.ROOT,
Expand All @@ -267,16 +270,10 @@ public static void checkVersionFormat(String targetVersion) {
* required by {@code resource} is compatible with the current installation.
*/
public static void checkJavaVersion(String resource, String targetVersion) {
JavaVersion version = JavaVersion.parse(targetVersion);
if (JavaVersion.current().compareTo(version) < 0) {
Version version = Version.parse(targetVersion);
if (Runtime.version().compareTo(version) < 0) {
throw new IllegalStateException(
String.format(
Locale.ROOT,
"%s requires Java %s:, your system: %s",
resource,
targetVersion,
JavaVersion.current().toString()
)
String.format(Locale.ROOT, "%s requires Java %s:, your system: %s", resource, targetVersion, Runtime.version().toString())
);
}
}
Expand Down
146 changes: 0 additions & 146 deletions libs/core/src/main/java/org/opensearch/bootstrap/JavaVersion.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.lang.Runtime.Version;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -156,12 +157,12 @@ public void testXmlBeansLeniency() throws Exception {

public void testRequiredJDKVersionTooOld() throws Exception {
Path dir = createTempDir();
List<Integer> current = JavaVersion.current().getVersion();
List<Integer> current = Runtime.version().version();
List<Integer> target = new ArrayList<>(current.size());
for (int i = 0; i < current.size(); i++) {
target.add(current.get(i) + 1);
}
JavaVersion targetVersion = JavaVersion.parse(Strings.collectionToDelimitedString(target, "."));
Version targetVersion = Version.parse(Strings.collectionToDelimitedString(target, "."));

Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
Expand All @@ -173,7 +174,7 @@ public void testRequiredJDKVersionTooOld() throws Exception {
fail("did not get expected exception");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("requires Java " + targetVersion.toString()));
assertTrue(e.getMessage().contains("your system: " + JavaVersion.current().toString()));
assertTrue(e.getMessage().contains("your system: " + Runtime.version().toString()));
}
}

Expand Down Expand Up @@ -209,7 +210,7 @@ public void testRequiredJDKVersionIsOK() throws Exception {
}

public void testValidVersions() {
String[] versions = new String[] { "1.7", "1.7.0", "0.1.7", "1.7.0.80" };
String[] versions = new String[] { "12-ea", "13.0.2.3-ea", "14-something", "11.0.2-21002", "11.0.14.1+1", "17.0.2+8" };
for (String version : versions) {
try {
JarHell.checkVersionFormat(version);
Expand All @@ -220,7 +221,7 @@ public void testValidVersions() {
}

public void testInvalidVersions() {
String[] versions = new String[] { "", "1.7.0_80", "1.7." };
String[] versions = new String[] { "", "1.7.0_80", "1.7.", "11.2+something-else" };
for (String version : versions) {
try {
JarHell.checkVersionFormat(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
package org.opensearch.core.internal.net;

import org.apache.lucene.util.Constants;
import org.opensearch.bootstrap.JavaVersion;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.test.OpenSearchTestCase;

import java.lang.Runtime.Version;

public class NetUtilsTests extends OpenSearchTestCase {

public void testExtendedSocketOptions() {
assumeTrue("JDK possibly not supported", Constants.JVM_NAME.contains("HotSpot") || Constants.JVM_NAME.contains("OpenJDK"));
assumeTrue("JDK version not supported", JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0);
assumeTrue("JDK version not supported", Runtime.version().compareTo(Version.parse("11")) >= 0);
assumeTrue("Platform possibly not supported", IOUtils.LINUX || IOUtils.MAC_OS_X);
assertNotNull(NetUtils.getTcpKeepIdleSocketOptionOrNull());
assertNotNull(NetUtils.getTcpKeepIntervalSocketOptionOrNull());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

package org.opensearch.common.ssl;

import org.opensearch.bootstrap.JavaVersion;

import javax.crypto.Cipher;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
Expand Down Expand Up @@ -361,7 +359,6 @@ private <V> List<V> resolveListSetting(String key, Function<String, V> parser, L

private static List<String> loadDefaultCiphers() {
final boolean has256BitAES = has256BitAES();
final boolean useGCM = JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0;
final boolean tlsV13Supported = DEFAULT_PROTOCOLS.contains("TLSv1.3");
List<String> ciphers = new ArrayList<>();
if (tlsV13Supported) { // TLSv1.3 cipher has PFS, AEAD, hardware support
Expand All @@ -370,19 +367,18 @@ private static List<String> loadDefaultCiphers() {
}
ciphers.add("TLS_AES_128_GCM_SHA256");
}
if (useGCM) { // PFS, AEAD, hardware support
if (has256BitAES) {
ciphers.addAll(
Arrays.asList(
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
)
);
} else {
ciphers.addAll(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
}
// use GCM: PFS, AEAD, hardware support
if (has256BitAES) {
ciphers.addAll(
Arrays.asList(
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
)
);
} else {
ciphers.addAll(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
}

// PFS, hardware support
Expand Down Expand Up @@ -410,13 +406,11 @@ private static List<String> loadDefaultCiphers() {
);
}

// AEAD, hardware support
if (useGCM) {
if (has256BitAES) {
ciphers.addAll(Arrays.asList("TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"));
} else {
ciphers.add("TLS_RSA_WITH_AES_128_GCM_SHA256");
}
// use GCM: AEAD, hardware support
if (has256BitAES) {
ciphers.addAll(Arrays.asList("TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"));
} else {
ciphers.add("TLS_RSA_WITH_AES_128_GCM_SHA256");
}

// hardware support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.ingest.common;

import org.opensearch.bootstrap.JavaVersion;
import org.opensearch.common.time.DateFormatter;
import org.opensearch.common.time.DateUtils;
import org.opensearch.test.OpenSearchTestCase;
Expand Down Expand Up @@ -96,10 +95,6 @@ public void testParseJavaDefaultYear() {
}

public void testParseWeekBased() {
assumeFalse(
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
JavaVersion.current().equals(JavaVersion.parse("8"))
);
String format = randomFrom("YYYY-ww");
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
Function<String, ZonedDateTime> javaFunction = DateFormat.Java.getFunction(format, timezone, Locale.ROOT);
Expand All @@ -108,10 +103,6 @@ public void testParseWeekBased() {
}

public void testParseWeekBasedWithLocale() {
assumeFalse(
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
JavaVersion.current().equals(JavaVersion.parse("8"))
);
String format = randomFrom("YYYY-ww");
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
Function<String, ZonedDateTime> javaFunction = DateFormat.Java.getFunction(format, timezone, Locale.US);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.painless;

import org.apache.lucene.util.Constants;
import org.opensearch.bootstrap.JavaVersion;
import org.hamcrest.Matcher;

import java.lang.invoke.MethodHandle;
Expand All @@ -55,11 +54,7 @@ protected String valueCtorCall(String valueType, int size) {

@Override
protected Matcher<String> outOfBoundsExceptionMessageMatcher(int index, int size) {
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0) {
return equalTo(Integer.toString(index));
} else {
return equalTo("Index " + Integer.toString(index) + " out of bounds for length " + Integer.toString(size));
}
return equalTo("Index " + Integer.toString(index) + " out of bounds for length " + Integer.toString(size));
}

public void testArrayLengthHelper() throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.opensearch.Version;
import org.opensearch.action.ActionListener;
import org.opensearch.bootstrap.JavaVersion;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.io.stream.NamedWriteableRegistry;
import org.opensearch.common.network.NetworkService;
Expand Down Expand Up @@ -121,10 +120,7 @@ public void testConnectException() throws UnknownHostException {
}

public void testDefaultKeepAliveSettings() throws IOException {
assumeTrue(
"setting default keepalive options not supported on this platform",
(IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0
);
assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X));
try (
MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)
Expand Down
Loading