This is an automated email from the ASF dual-hosted git repository.

nicknezis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-heron.git


The following commit(s) were added to refs/heads/master by this push:
     new cf08e71  Make Java optional in CLI and check JAVA_BIN (#3521)
cf08e71 is described below

commit cf08e71f95c2a2dd0f464d3250698c72b42d2a0c
Author: Oliver Bristow <[email protected]>
AuthorDate: Sat May 2 00:44:11 2020 +0100

    Make Java optional in CLI and check JAVA_BIN (#3521)
---
 heron/tools/admin/src/python/main.py          |  2 --
 heron/tools/cli/src/python/execute.py         |  7 ++++++-
 heron/tools/cli/src/python/main.py            |  3 ---
 heron/tools/common/src/python/utils/config.py | 24 +++++++-----------------
 4 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/heron/tools/admin/src/python/main.py 
b/heron/tools/admin/src/python/main.py
index 4b27601..4986d30 100644
--- a/heron/tools/admin/src/python/main.py
+++ b/heron/tools/admin/src/python/main.py
@@ -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)
diff --git a/heron/tools/cli/src/python/execute.py 
b/heron/tools/cli/src/python/execute.py
index ba2d982..9534d1c 100644
--- a/heron/tools/cli/src/python/execute.py
+++ b/heron/tools/cli/src/python/execute.py
@@ -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)]
 
diff --git a/heron/tools/cli/src/python/main.py 
b/heron/tools/cli/src/python/main.py
index a8257c0..c37ce09 100644
--- a/heron/tools/cli/src/python/main.py
+++ b/heron/tools/cli/src/python/main.py
@@ -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)
 
diff --git a/heron/tools/common/src/python/utils/config.py 
b/heron/tools/common/src/python/utils/config.py
index 42d395f..83afb24 100644
--- a/heron/tools/common/src/python/utils/config.py
+++ b/heron/tools/common/src/python/utils/config.py
@@ -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():

Reply via email to