mirror of
https://github.com/kemko/nomad.git
synced 2026-01-11 04:45:42 +03:00
drivers/java: restore 0.8.7 java version detection (#5317)
Restore 0.8.x behavior where java driver is marked as detected when `java -version` exits with 0 but returns unexpected output. Furthermore, we restore behavior when `java -version` where we parse the first three lines of `java -version` but ignore rest. If `java -version` returns less than 3 lines, Nomad 0.8.7 would panic. In this implementation, we'd still mark java as detected but returns empty version. The 0.8.7 logic for detecting java version is found in https://github.com/hashicorp/nomad/blob/v0.8.7/client/driver/java.go#L132-L172 . I punt on revamping how we can be more resilient to java -version syntax, and aimed for preserving existing behavior instead.
This commit is contained in:
@@ -18,14 +18,15 @@ func javaVersionInfo() (version, runtime, vm string, err error) {
|
||||
cmd.Stderr = &out
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to check java version: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
version, runtime, vm, err = parseJavaVersionOutput(out.String())
|
||||
version, runtime, vm = parseJavaVersionOutput(out.String())
|
||||
return
|
||||
}
|
||||
|
||||
func parseJavaVersionOutput(infoString string) (version, runtime, vm string, err error) {
|
||||
func parseJavaVersionOutput(infoString string) (version, runtime, vm string) {
|
||||
infoString = strings.TrimSpace(infoString)
|
||||
|
||||
lines := strings.Split(infoString, "\n")
|
||||
@@ -33,8 +34,9 @@ func parseJavaVersionOutput(infoString string) (version, runtime, vm string, err
|
||||
lines = lines[1:]
|
||||
}
|
||||
|
||||
if len(lines) != 3 {
|
||||
return "", "", "", fmt.Errorf("unexpected java version info output, expected 3 lines but got: %v", infoString)
|
||||
if len(lines) < 3 {
|
||||
// unexpected output format, don't attempt to parse output for version
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
versionString := strings.TrimSpace(lines[0])
|
||||
@@ -44,5 +46,5 @@ func parseJavaVersionOutput(infoString string) (version, runtime, vm string, err
|
||||
versionString = match[1]
|
||||
}
|
||||
|
||||
return versionString, strings.TrimSpace(lines[1]), strings.TrimSpace(lines[2]), nil
|
||||
return versionString, strings.TrimSpace(lines[1]), strings.TrimSpace(lines[2])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user