Skip to content

Commit

Permalink
Deprecate the no-jdk distributions (#64275)
Browse files Browse the repository at this point in the history
This commit adds logging to indicate that the no-jdk distributions are
deprecated and will be removed in a future release.
  • Loading branch information
jasontedor authored Oct 28, 2020
1 parent 1c0380d commit 57bd64a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions distribution/src/bin/elasticsearch-env
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ ES_DISTRIBUTION_FLAVOR=${es.distribution.flavor}
ES_DISTRIBUTION_TYPE=${es.distribution.type}
ES_BUNDLED_JDK=${es.bundled_jdk}

if [[ "$ES_BUNDLED_JDK" == "false" ]]; then
echo "warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release" >&2
fi

if [[ "$ES_DISTRIBUTION_TYPE" == "docker" ]]; then
# Allow environment variables to be set by creating a file with the
# contents, and setting an environment variable with the suffix _FILE to
Expand Down
4 changes: 4 additions & 0 deletions distribution/src/bin/elasticsearch-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ set ES_DISTRIBUTION_FLAVOR=${es.distribution.flavor}
set ES_DISTRIBUTION_TYPE=${es.distribution.type}
set ES_BUNDLED_JDK=${es.bundled_jdk}

if "%ES_BUNDLED_JDK%" == "false" (
echo "warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release" >&2
)

cd /d "%ES_HOME%"

rem now set the path to java, pass "nojava" arg to skip setting JAVA_HOME and JAVA
Expand Down
16 changes: 12 additions & 4 deletions server/src/main/java/org/elasticsearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.HeaderWarning;
import org.elasticsearch.common.logging.NodeAndClusterIdStateListener;
import org.elasticsearch.common.network.NetworkAddress;
Expand Down Expand Up @@ -252,10 +253,15 @@ public class Node implements Closeable {
private final Lifecycle lifecycle = new Lifecycle();

/**
* Logger initialized in the ctor because if it were initialized statically
* then it wouldn't get the node name.
* This logger instance is an instance field as opposed to a static field. This ensures that the field is not
* initialized until an instance of Node is constructed, which is sure to happen after the logging infrastructure
* has been initialized to include the hostname. If this field were static, then it would be initialized when the
* class initializer runs. Alas, this happens too early, before logging is initialized as this class is referred to
* in InternalSettingsPreparer#finalizeSettings, which runs when creating the Environment, before logging is
* initialized.
*/
private final Logger logger;
private final Logger logger = LogManager.getLogger(Node.class);
private final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(Node.class);
private final Injector injector;
private final Environment environment;
private final NodeEnvironment nodeEnvironment;
Expand All @@ -280,7 +286,6 @@ public Node(Environment environment) {
*/
protected Node(final Environment initialEnvironment,
Collection<Class<? extends Plugin>> classpathPlugins, boolean forbidPrivateIndexSettings) {
logger = LogManager.getLogger(Node.class);
final List<Closeable> resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error
boolean success = false;
try {
Expand All @@ -307,6 +312,9 @@ protected Node(final Environment initialEnvironment,
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), jvmInfo.getUsingBundledJdk());
} else {
logger.info("JVM home [{}]", System.getProperty("java.home"));
deprecationLogger.deprecate(
"no-jdk",
"no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release");
}
logger.info("JVM arguments {}", Arrays.toString(jvmInfo.getInputArguments()));
if (Build.CURRENT.isProductionRelease() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.plugins.AnalysisPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.MockScriptEngine;
Expand Down Expand Up @@ -408,7 +409,17 @@ private void ensureNoWarnings() {
//appropriate test
try {
final List<String> warnings = threadContext.getResponseHeaders().get("Warning");
assertNull("unexpected warning headers", warnings);
if (warnings != null && JvmInfo.jvmInfo().getBundledJdk() == false) {
// unit tests do not run with the bundled JDK, if there are warnings we need to filter the no-jdk deprecation warning
final List<String> filteredWarnings = warnings
.stream()
.filter(k -> k.contains(
"no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release") == false)
.collect(Collectors.toList());
assertThat("unexpected warning headers", filteredWarnings, empty());
} else {
assertNull("unexpected warning headers", warnings);
}
} finally {
resetDeprecationLogger();
}
Expand Down

0 comments on commit 57bd64a

Please sign in to comment.