Clarify missing java error message (#46160)
Since the bundled jdk was added to Elasticsearch, there are now 2 ways java can be missing. Either JAVA_HOME is set but does not exist, or the bundled jdk does not exist. This commit improves the error messages in those two cases, and also ensures our tests cover both cases.
This commit is contained in:
parent
5cfcd7c458
commit
bd5f64848e
|
@ -38,6 +38,7 @@ ES_CLASSPATH="$ES_HOME/lib/*"
|
||||||
# now set the path to java
|
# now set the path to java
|
||||||
if [ ! -z "$JAVA_HOME" ]; then
|
if [ ! -z "$JAVA_HOME" ]; then
|
||||||
JAVA="$JAVA_HOME/bin/java"
|
JAVA="$JAVA_HOME/bin/java"
|
||||||
|
JAVA_TYPE="JAVA_HOME"
|
||||||
else
|
else
|
||||||
if [ "$(uname -s)" = "Darwin" ]; then
|
if [ "$(uname -s)" = "Darwin" ]; then
|
||||||
# OSX has a different structure
|
# OSX has a different structure
|
||||||
|
@ -45,10 +46,11 @@ else
|
||||||
else
|
else
|
||||||
JAVA="$ES_HOME/jdk/bin/java"
|
JAVA="$ES_HOME/jdk/bin/java"
|
||||||
fi
|
fi
|
||||||
|
JAVA_TYPE="bundled jdk"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -x "$JAVA" ]; then
|
if [ ! -x "$JAVA" ]; then
|
||||||
echo "could not find java in JAVA_HOME or bundled at $JAVA" >&2
|
echo "could not find java in $JAVA_TYPE at $JAVA" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,15 @@ if "%1" == "nojava" (
|
||||||
|
|
||||||
if defined JAVA_HOME (
|
if defined JAVA_HOME (
|
||||||
set JAVA="%JAVA_HOME%\bin\java.exe"
|
set JAVA="%JAVA_HOME%\bin\java.exe"
|
||||||
|
set JAVA_TYPE=JAVA_HOME
|
||||||
) else (
|
) else (
|
||||||
set JAVA="%ES_HOME%\jdk\bin\java.exe"
|
set JAVA="%ES_HOME%\jdk\bin\java.exe"
|
||||||
set JAVA_HOME="%ES_HOME%\jdk"
|
set JAVA_HOME="%ES_HOME%\jdk"
|
||||||
|
set JAVA_TYPE=bundled jdk
|
||||||
)
|
)
|
||||||
|
|
||||||
if not exist %JAVA% (
|
if not exist !JAVA! (
|
||||||
echo "could not find java in JAVA_HOME or bundled at %ES_HOME%\jdk" >&2
|
echo "could not find java in !JAVA_TYPE! at !JAVA!" >&2
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class ArchiveTests extends PackagingTestCase {
|
||||||
assertThat(r.stdout, isEmptyString());
|
assertThat(r.stdout, isEmptyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test30NoJava() throws Exception {
|
public void test30MissingBundledJdk() throws Exception {
|
||||||
final Installation.Executables bin = installation.executables();
|
final Installation.Executables bin = installation.executables();
|
||||||
sh.getEnv().remove("JAVA_HOME");
|
sh.getEnv().remove("JAVA_HOME");
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class ArchiveTests extends PackagingTestCase {
|
||||||
// ask for elasticsearch version to quickly exit if java is actually found (ie test failure)
|
// ask for elasticsearch version to quickly exit if java is actually found (ie test failure)
|
||||||
final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString() + " -v");
|
final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString() + " -v");
|
||||||
assertThat(runResult.exitCode, is(1));
|
assertThat(runResult.exitCode, is(1));
|
||||||
assertThat(runResult.stderr, containsString("could not find java in JAVA_HOME or bundled"));
|
assertThat(runResult.stderr, containsString("could not find java in bundled jdk"));
|
||||||
} finally {
|
} finally {
|
||||||
if (distribution().hasJdk) {
|
if (distribution().hasJdk) {
|
||||||
mv(relocatedJdk, installation.bundledJdk);
|
mv(relocatedJdk, installation.bundledJdk);
|
||||||
|
@ -95,6 +95,17 @@ public class ArchiveTests extends PackagingTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test31BadJavaHome() throws Exception {
|
||||||
|
final Installation.Executables bin = installation.executables();
|
||||||
|
sh.getEnv().put("JAVA_HOME", "doesnotexist");
|
||||||
|
|
||||||
|
// ask for elasticsearch version to quickly exit if java is actually found (ie test failure)
|
||||||
|
final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString() + " -v");
|
||||||
|
assertThat(runResult.exitCode, is(1));
|
||||||
|
assertThat(runResult.stderr, containsString("could not find java in JAVA_HOME"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void test40CreateKeystoreManually() throws Exception {
|
public void test40CreateKeystoreManually() throws Exception {
|
||||||
final Installation.Executables bin = installation.executables();
|
final Installation.Executables bin = installation.executables();
|
||||||
|
|
||||||
|
|
|
@ -117,20 +117,27 @@ public class WindowsServiceTests extends PackagingTestCase {
|
||||||
sh.run(serviceScript + " remove");
|
sh.run(serviceScript + " remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test13InstallMissingJava() throws IOException {
|
public void test13InstallMissingBundledJdk() throws IOException {
|
||||||
final Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
|
final Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mv(installation.bundledJdk, relocatedJdk);
|
mv(installation.bundledJdk, relocatedJdk);
|
||||||
Result result = sh.runIgnoreExitCode(serviceScript + " install");
|
Result result = sh.runIgnoreExitCode(serviceScript + " install");
|
||||||
assertThat(result.exitCode, equalTo(1));
|
assertThat(result.exitCode, equalTo(1));
|
||||||
assertThat(result.stderr, containsString("could not find java in JAVA_HOME or bundled"));
|
assertThat(result.stderr, containsString("could not find java in bundled jdk"));
|
||||||
} finally {
|
} finally {
|
||||||
mv(relocatedJdk, installation.bundledJdk);
|
mv(relocatedJdk, installation.bundledJdk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test14RemoveNotInstalled() {
|
public void test14InstallBadJavaHome() throws IOException {
|
||||||
|
sh.getEnv().put("JAVA_HOME", "doesnotexist");
|
||||||
|
Result result = sh.runIgnoreExitCode(serviceScript + " install");
|
||||||
|
assertThat(result.exitCode, equalTo(1));
|
||||||
|
assertThat(result.stderr, containsString("could not find java in JAVA_HOME"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test15RemoveNotInstalled() {
|
||||||
Result result = assertFailure(serviceScript + " remove", 1);
|
Result result = assertFailure(serviceScript + " remove", 1);
|
||||||
assertThat(result.stdout, containsString("Failed removing '" + DEFAULT_ID + "' service"));
|
assertThat(result.stdout, containsString("Failed removing '" + DEFAULT_ID + "' service"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class ServerUtils {
|
||||||
|
|
||||||
} catch (HttpHostConnectException e) {
|
} catch (HttpHostConnectException e) {
|
||||||
// we want to retry if the connection is refused
|
// we want to retry if the connection is refused
|
||||||
LOG.debug("Got connection refused when waiting for cluster health", e);
|
LOG.info("Got connection refused when waiting for cluster health", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeElapsed = System.currentTimeMillis() - startTime;
|
timeElapsed = System.currentTimeMillis() - startTime;
|
||||||
|
|
Loading…
Reference in New Issue