ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [1/2] ambari git commit: AMBARI-15426. changing jdk version being used by HDP does not work (aonishuk)
Date Wed, 16 Mar 2016 15:29:58 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 345a52a27 -> dbcca75bd
  refs/heads/trunk 8eb7f6cd0 -> e4418ee38


AMBARI-15426. changing jdk version being used by HDP does not work (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e4418ee3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e4418ee3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e4418ee3

Branch: refs/heads/trunk
Commit: e4418ee382aadc20d50a830ff19331d0da54739b
Parents: 8eb7f6c
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Wed Mar 16 17:29:45 2016 +0200
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Wed Mar 16 17:29:45 2016 +0200

----------------------------------------------------------------------
 .../custom_actions/scripts/check_host.py        |  9 ++++--
 .../before-ANY/scripts/shared_initialization.py | 34 ++++++++++++--------
 .../test/python/custom_actions/TestCheckHost.py |  1 +
 .../2.0.6/hooks/before-ANY/test_before_any.py   |  7 +++-
 4 files changed, 33 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e4418ee3/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/check_host.py b/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
index 09b2c05..9b79290 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
@@ -25,6 +25,7 @@ import re
 import subprocess
 import socket
 import getpass
+import tempfile
 
 from resource_management.libraries.functions import packages_analyzer
 from resource_management.libraries.functions.default import default
@@ -344,14 +345,14 @@ class CheckHost(Script):
           db_connection_check_structured_output = {"exit_code" : 1, "message": message}
           return db_connection_check_structured_output
       else:
-        tmp_java_dir = format("{tmp_dir}/jdk")
+        tmp_java_dir = tempfile.mkdtemp(prefix="jdk_tmp_", dir=tmp_dir)
         sudo = AMBARI_SUDO_BINARY
         if jdk_name.endswith(".bin"):
           chmod_cmd = ("chmod", "+x", jdk_download_target)
-          install_cmd = format("mkdir -p {tmp_java_dir} && cd {tmp_java_dir} &&
echo A | {jdk_download_target} -noregister && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
+          install_cmd = format("cd {tmp_java_dir} && echo A | {jdk_download_target}
-noregister && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
         elif jdk_name.endswith(".gz"):
           chmod_cmd = ("chmod","a+x", java_dir)
-          install_cmd = format("mkdir -p {tmp_java_dir} && cd {tmp_java_dir} &&
tar -xf {jdk_download_target} && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
+          install_cmd = format("cd {tmp_java_dir} && tar -xf {jdk_download_target}
&& {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
         try:
           Directory(java_dir)
           Execute(chmod_cmd, not_if = format("test -e {java_exec}"), sudo = True)
@@ -363,6 +364,8 @@ class CheckHost(Script):
           print message
           db_connection_check_structured_output = {"exit_code" : 1, "message": message}
           return db_connection_check_structured_output
+        finally:
+          Directory(tmp_java_dir, action="delete")
 
     # download DBConnectionVerification.jar from ambari-server resources
     try:

http://git-wip-us.apache.org/repos/asf/ambari/blob/e4418ee3/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-ANY/scripts/shared_initialization.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-ANY/scripts/shared_initialization.py
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-ANY/scripts/shared_initialization.py
index f5556fb..ed6c36c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-ANY/scripts/shared_initialization.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-ANY/scripts/shared_initialization.py
@@ -20,6 +20,7 @@ limitations under the License.
 import os
 import re
 import getpass
+import tempfile
 from copy import copy
 from resource_management.libraries.functions.version import compare_versions
 from resource_management import *
@@ -179,7 +180,6 @@ def setup_java():
 
     jdk_curl_target = format("{tmp_dir}/{jdk_name}")
     java_dir = os.path.dirname(params.java_home)
-    tmp_java_dir = format("{tmp_dir}/jdk")
 
     if not params.jdk_name:
       return
@@ -193,22 +193,28 @@ def setup_java():
          not_if = format("test -f {jdk_curl_target}")
     )
 
-    if params.jdk_name.endswith(".bin"):
-      chmod_cmd = ("chmod", "+x", jdk_curl_target)
-      install_cmd = format("mkdir -p {tmp_java_dir} && cd {tmp_java_dir} &&
echo A | {jdk_curl_target} -noregister && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
-    elif params.jdk_name.endswith(".gz"):
-      chmod_cmd = ("chmod","a+x", java_dir)
-      install_cmd = format("mkdir -p {tmp_java_dir} && cd {tmp_java_dir} &&
tar -xf {jdk_curl_target} && {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
+    tmp_java_dir = tempfile.mkdtemp(prefix="jdk_tmp_", dir=params.tmp_dir)
 
-    Directory(java_dir
-    )
+    try:
+      if params.jdk_name.endswith(".bin"):
+        chmod_cmd = ("chmod", "+x", jdk_curl_target)
+        install_cmd = format("cd {tmp_java_dir} && echo A | {jdk_curl_target} -noregister
&& {sudo} cp -rp {tmp_java_dir}/* {java_dir}")
+      elif params.jdk_name.endswith(".gz"):
+        chmod_cmd = ("chmod","a+x", java_dir)
+        install_cmd = format("cd {tmp_java_dir} && tar -xf {jdk_curl_target} &&
{sudo} cp -rp {tmp_java_dir}/* {java_dir}")
+
+      Directory(java_dir
+      )
 
-    Execute(chmod_cmd,
-            sudo = True,
-            )
+      Execute(chmod_cmd,
+              sudo = True,
+              )
+
+      Execute(install_cmd,
+              )
 
-    Execute(install_cmd,
-            )
+    finally:
+      Directory(tmp_java_dir, action="delete")
 
     File(format("{java_home}/bin/java"),
          mode=0755,

http://git-wip-us.apache.org/repos/asf/ambari/blob/e4418ee3/ambari-server/src/test/python/custom_actions/TestCheckHost.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestCheckHost.py b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
index c82c70d..8bc1774 100644
--- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py
+++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
@@ -67,6 +67,7 @@ class TestCheckHost(TestCase):
                                                                                 "exit_code"
: 1}})
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch("tempfile.mkdtemp", new = MagicMock(return_value='/tmp/jdk_tmp_dir'))
   @patch.object(Script, 'get_config')
   @patch.object(Script, 'get_tmp_dir')
   @patch("check_host.download_file")

http://git-wip-us.apache.org/repos/asf/ambari/blob/e4418ee3/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
index a7eb9b1..a3567d5 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
@@ -30,6 +30,7 @@ class TestHookBeforeInstall(RMFTestCase):
 
   @patch("os.path.isfile")
   @patch.object(getpass, "getuser", new = MagicMock(return_value='some_user'))
+  @patch("tempfile.mkdtemp", new = MagicMock(return_value='/tmp/jdk_tmp_dir'))
   @patch("os.path.exists")
   def test_hook_default(self, os_path_exists_mock, os_path_isfile_mock):
 
@@ -196,8 +197,12 @@ class TestHookBeforeInstall(RMFTestCase):
     self.assertResourceCalled('Execute', ('chmod', 'a+x', u'/usr/jdk64'),
                               sudo = True
                               )
-    self.assertResourceCalled('Execute', 'mkdir -p /tmp/jdk && cd /tmp/jdk &&
tar -xf /tmp/jdk-7u67-linux-x64.tar.gz && ambari-sudo.sh cp -rp /tmp/jdk/* /usr/jdk64'
+    self.assertResourceCalled('Execute', 'cd /tmp/jdk_tmp_dir && tar -xf /tmp/jdk-7u67-linux-x64.tar.gz
&& ambari-sudo.sh cp -rp /tmp/jdk_tmp_dir/* /usr/jdk64'
                               )
+    self.assertResourceCalled('Directory', '/tmp/jdk_tmp_dir',
+                              action = ['delete']
+                              )
+
     self.assertResourceCalled('File', '/usr/jdk64/jdk1.7.0_45/bin/java',
                               mode = 0755,
                               cd_access = "a",


Mime
View raw message