Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Make Java optional in CLI and check JAVA_BIN #3521

Merged
merged 1 commit into from
May 1, 2020
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
2 changes: 0 additions & 2 deletions heron/tools/admin/src/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ def check_environment():
Check whether the environment variables are set
:return:
'''
if not config.check_java_home_set():
sys.exit(1)

if not config.check_release_file_exists():
sys.exit(1)
Expand Down
7 changes: 6 additions & 1 deletion heron/tools/cli/src/python/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ def heron_class(class_name, lib_jars, extra_jars=None, args=None, java_defines=N
# the class locally.
java_opts = ['-D' + opt for opt in java_defines]

java_path = config.get_java_path()
if java_path is None:
err_context = "Neither JAVA_BIN or JAVA_HOME are set"
return SimpleResult(Status.InvocationError, err_context)

# Construct the command line for the sub process to run
# Because of the way Python execute works,
# the java opts must be passed as part of the list
all_args = [config.get_java_path(), "-client", "-Xmx1g"] + \
all_args = [java_path, "-client", "-Xmx1g"] + \
java_opts + \
["-cp", config.get_classpath(extra_jars + lib_jars)]

Expand Down
3 changes: 0 additions & 3 deletions heron/tools/cli/src/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ def check_environment():
Check whether the environment variables are set
:return:
'''
if not config.check_java_home_set():
sys.exit(1)

if not config.check_release_file_exists():
sys.exit(1)

Expand Down
24 changes: 7 additions & 17 deletions heron/tools/common/src/python/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,24 +424,14 @@ def parse_override_config(namespace):

def get_java_path():
"""Get the path of java executable"""
java_bin = os.environ.get("JAVA_BIN")
if java_bin:
return java_bin
java_home = os.environ.get("JAVA_HOME")
return os.path.join(java_home, BIN_DIR, "java")


def check_java_home_set():
"""Check if the java home set"""
# check if environ variable is set
if "JAVA_HOME" not in os.environ:
Log.error("JAVA_HOME not set")
return False

# check if the value set is correct
java_path = get_java_path()
if os.path.isfile(java_path) and os.access(java_path, os.X_OK):
return True

Log.error("JAVA_HOME/bin/java either does not exist or not an executable")
return False
if java_home:
return os.path.join(java_home, BIN_DIR, "java")
# this could use shutil.which("java") when python2 support is dropped
return None


def check_release_file_exists():
Expand Down