This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch branch-feature-jdk11
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-jdk11 by this
push:
new b6309a8 AMBARI-24730. Support Java 9+ in Ambari Server setup (#2427)
b6309a8 is described below
commit b6309a8160151387510875a6d27c340da58eb626
Author: Gabor Boros <[email protected]>
AuthorDate: Sat Oct 6 07:36:54 2018 +0200
AMBARI-24730. Support Java 9+ in Ambari Server setup (#2427)
---
.../src/main/python/ambari_server/serverSetup.py | 18 +++++++++++++++---
ambari-server/src/test/python/TestAmbariServer.py | 4 ++--
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py
b/ambari-server/src/main/python/ambari_server/serverSetup.py
index a32ac38..b91d8eb 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -80,7 +80,7 @@ UNTAR_JDK_ARCHIVE = "tar --no-same-owner -xvf {0}"
JDK_PROMPT = "[{0}] {1}\n"
JDK_VALID_CHOICES = "^[{0}{1:d}]$"
-JDK_VERSION_CHECK_CMD = """{0} -version 2>&1 | grep -i version | sed
's/.*version ".*\.\(.*\)\..*"/\\1/; 1q' 2>&1"""
+JDK_VERSION_CHECK_CMD = """{0} -version 2>&1 | grep -i version 2>&1"""
def get_supported_jdbc_drivers():
factory = DBMSConfigFactory()
@@ -1272,6 +1272,17 @@ def setup_jce_policy(args):
print 'NOTE: Restart Ambari Server to apply changes' + \
' ("ambari-server restart|stop|start")'
+def get_java_major_version(cmd_out):
+ version_short = re.split("[java|openjdk|.*] version", cmd_out)[1].split("
")[1][1:-1]
+ if re.match("^1\.[0-9].*", version_short): # 1.8.0_112
+ return version_short.split(".")[1]
+ elif re.match("^[1-9][0-9]*\.[0-9].*", version_short): # 10.0.2
+ return version_short.split(".")[0]
+ elif re.match("^[1-9][0-9]*$", version_short): # 11
+ return version_short
+ elif re.match("^[1-9][0-9]*-.*$", version_short): # 12-ea
+ return version_short.split("-")[0]
+
def check_ambari_java_version_is_valid(java_home, java_bin, min_version,
properties):
"""
Check that ambari uses the proper (minimum) JDK with a shell command.
@@ -1292,11 +1303,12 @@ def check_ambari_java_version_is_valid(java_home,
java_bin, min_version, propert
err = "Checking JDK version command returned with exit code %s" %
process.returncode
raise FatalException(process.returncode, err)
else:
- actual_jdk_version = int(out)
+ java_major_version = get_java_major_version(out)
+ actual_jdk_version = int(java_major_version)
print 'JDK version found: {0}'.format(actual_jdk_version)
if actual_jdk_version < min_version:
print 'Minimum JDK version is {0} for Ambari. Setup JDK again only for
Ambari Server.'.format(min_version)
- properties.process_pair(STACK_JAVA_VERSION, out)
+ properties.process_pair(STACK_JAVA_VERSION, java_major_version)
result = False
else:
print 'Minimum JDK version is {0} for Ambari. Skipping to setup
different JDK for Ambari Server.'.format(min_version)
diff --git a/ambari-server/src/test/python/TestAmbariServer.py
b/ambari-server/src/test/python/TestAmbariServer.py
index affea57..52224d4 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -3150,7 +3150,7 @@ class TestAmbariServer(TestCase):
# case 1: jdk7 is picked for stacks
properties = Properties()
p = MagicMock()
- p.communicate.return_value = ('7', None)
+ p.communicate.return_value = ('java version "1.7.0_80"', None)
p.returncode = 0
popenMock.return_value = p
result = check_ambari_java_version_is_valid('/usr/jdk64/jdk_1.7.0/',
'java', 8, properties)
@@ -3159,7 +3159,7 @@ class TestAmbariServer(TestCase):
# case 2: jdk8 is picked for stacks
properties = Properties()
- p.communicate.return_value = ('8', None)
+ p.communicate.return_value = ('java version "1.8.0_112"', None)
p.returncode = 0
result = check_ambari_java_version_is_valid('/usr/jdk64/jdk_1.8.0/',
'java', 8, properties)
self.assertFalse(properties.get_property(STACK_JAVA_VERSION))