Skip to content

Commit 57bd64a

Browse files
authored
Deprecate the no-jdk distributions (#64275)
This commit adds logging to indicate that the no-jdk distributions are deprecated and will be removed in a future release.
1 parent 1c0380d commit 57bd64a

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

distribution/src/bin/elasticsearch-env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ ES_DISTRIBUTION_FLAVOR=${es.distribution.flavor}
9292
ES_DISTRIBUTION_TYPE=${es.distribution.type}
9393
ES_BUNDLED_JDK=${es.bundled_jdk}
9494

95+
if [[ "$ES_BUNDLED_JDK" == "false" ]]; then
96+
echo "warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release" >&2
97+
fi
98+
9599
if [[ "$ES_DISTRIBUTION_TYPE" == "docker" ]]; then
96100
# Allow environment variables to be set by creating a file with the
97101
# contents, and setting an environment variable with the suffix _FILE to

distribution/src/bin/elasticsearch-env.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ set ES_DISTRIBUTION_FLAVOR=${es.distribution.flavor}
2929
set ES_DISTRIBUTION_TYPE=${es.distribution.type}
3030
set ES_BUNDLED_JDK=${es.bundled_jdk}
3131

32+
if "%ES_BUNDLED_JDK%" == "false" (
33+
echo "warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release" >&2
34+
)
35+
3236
cd /d "%ES_HOME%"
3337

3438
rem now set the path to java, pass "nojava" arg to skip setting JAVA_HOME and JAVA

server/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.elasticsearch.common.inject.ModulesBuilder;
7171
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
7272
import org.elasticsearch.common.lease.Releasables;
73+
import org.elasticsearch.common.logging.DeprecationLogger;
7374
import org.elasticsearch.common.logging.HeaderWarning;
7475
import org.elasticsearch.common.logging.NodeAndClusterIdStateListener;
7576
import org.elasticsearch.common.network.NetworkAddress;
@@ -252,10 +253,15 @@ public class Node implements Closeable {
252253
private final Lifecycle lifecycle = new Lifecycle();
253254

254255
/**
255-
* Logger initialized in the ctor because if it were initialized statically
256-
* then it wouldn't get the node name.
256+
* This logger instance is an instance field as opposed to a static field. This ensures that the field is not
257+
* initialized until an instance of Node is constructed, which is sure to happen after the logging infrastructure
258+
* has been initialized to include the hostname. If this field were static, then it would be initialized when the
259+
* class initializer runs. Alas, this happens too early, before logging is initialized as this class is referred to
260+
* in InternalSettingsPreparer#finalizeSettings, which runs when creating the Environment, before logging is
261+
* initialized.
257262
*/
258-
private final Logger logger;
263+
private final Logger logger = LogManager.getLogger(Node.class);
264+
private final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(Node.class);
259265
private final Injector injector;
260266
private final Environment environment;
261267
private final NodeEnvironment nodeEnvironment;
@@ -280,7 +286,6 @@ public Node(Environment environment) {
280286
*/
281287
protected Node(final Environment initialEnvironment,
282288
Collection<Class<? extends Plugin>> classpathPlugins, boolean forbidPrivateIndexSettings) {
283-
logger = LogManager.getLogger(Node.class);
284289
final List<Closeable> resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error
285290
boolean success = false;
286291
try {
@@ -307,6 +312,9 @@ protected Node(final Environment initialEnvironment,
307312
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), jvmInfo.getUsingBundledJdk());
308313
} else {
309314
logger.info("JVM home [{}]", System.getProperty("java.home"));
315+
deprecationLogger.deprecate(
316+
"no-jdk",
317+
"no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release");
310318
}
311319
logger.info("JVM arguments {}", Arrays.toString(jvmInfo.getInputArguments()));
312320
if (Build.CURRENT.isProductionRelease() == false) {

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import org.elasticsearch.index.analysis.TokenFilterFactory;
9999
import org.elasticsearch.index.analysis.TokenizerFactory;
100100
import org.elasticsearch.indices.analysis.AnalysisModule;
101+
import org.elasticsearch.monitor.jvm.JvmInfo;
101102
import org.elasticsearch.plugins.AnalysisPlugin;
102103
import org.elasticsearch.plugins.Plugin;
103104
import org.elasticsearch.script.MockScriptEngine;
@@ -408,7 +409,17 @@ private void ensureNoWarnings() {
408409
//appropriate test
409410
try {
410411
final List<String> warnings = threadContext.getResponseHeaders().get("Warning");
411-
assertNull("unexpected warning headers", warnings);
412+
if (warnings != null && JvmInfo.jvmInfo().getBundledJdk() == false) {
413+
// unit tests do not run with the bundled JDK, if there are warnings we need to filter the no-jdk deprecation warning
414+
final List<String> filteredWarnings = warnings
415+
.stream()
416+
.filter(k -> k.contains(
417+
"no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release") == false)
418+
.collect(Collectors.toList());
419+
assertThat("unexpected warning headers", filteredWarnings, empty());
420+
} else {
421+
assertNull("unexpected warning headers", warnings);
422+
}
412423
} finally {
413424
resetDeprecationLogger();
414425
}

0 commit comments

Comments
 (0)