You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2014/01/15 16:03:44 UTC

git commit: AMBARI-3976. ambari-server setup -j option installs JDK to indicated location if it does not exist there.(vbrodetskyi)

Updated Branches:
  refs/heads/trunk 4b4351ba4 -> 1763922ec


AMBARI-3976. ambari-server setup -j option installs JDK to indicated location if it does not exist there.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: 1763922ec6f7bf0d3b96a1d342ce25a8f25489d7
Parents: 4b4351b
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Wed Jan 15 17:02:46 2014 +0200
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Wed Jan 15 17:02:46 2014 +0200

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  | 20 +++++++---
 .../src/test/python/TestAmbariServer.py         | 39 ++++++++++++++++----
 2 files changed, 47 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1763922e/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index cd34d97..743ba2c 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -1691,12 +1691,19 @@ def download_jdk(args):
   ok = False
   jcePolicyWarn = "JCE Policy files are required for configuring Kerberos security. If you plan to use Kerberos," \
          "please make sure JCE Unlimited Strength Jurisdiction Policy Files are valid on all hosts."
-  if args.java_home and os.path.exists(args.java_home):
+  if args.java_home:
+    if not os.path.exists(args.java_home):
+      err = "Path to java home " + args.java_home + " does not exists"
+      raise FatalException(1, err)
+
+    jce_policy_paths = []
     for jce_file in JCE_POLICY_FILENAMES:
       jce_policy_path = os.path.join(properties[RESOURCES_DIR_PROPERTY], jce_file)
       if os.path.exists(jce_policy_path):
-        err = "Command failed to execute. Please remove or move " + jce_policy_path + " and retry again"
-        raise FatalException(1, err)
+        jce_policy_paths.append(jce_policy_path)
+    if len(jce_policy_paths) > 0:
+      err = "Command failed to execute. Please remove or move " + str(jce_policy_paths).strip('[]') + " and retry again"
+      raise FatalException(1, err)
 
     print_warning_msg("JAVA_HOME " + args.java_home + " must be valid on ALL hosts")
     print_warning_msg(jcePolicyWarn)
@@ -1705,7 +1712,7 @@ def download_jdk(args):
     remove_property(JCE_NAME_PROPERTY)
     return 0
   else:
-    if get_JAVA_HOME():
+    if get_JAVA_HOME() and not args.jdk_location:
       change_jdk = get_YN_input("Do you want to change Oracle JDK [y/n] (n)? ", False)
       if not change_jdk:
         return 0
@@ -1716,7 +1723,10 @@ def download_jdk(args):
       err = 'Property ' + str(e) + ' is not defined at ' + conf_file
       raise FatalException(1, err)
     ##JDK location was set by user with --jdk-location key
-    if args.jdk_location and os.path.exists(args.jdk_location):
+    if args.jdk_location:
+      if not os.path.exists(args.jdk_location):
+        err = "Path to jdk " + args.jdk_location + " does not exists"
+        raise FatalException(1, err)
       path, custom_jdk_name = os.path.split(args.jdk_location)
       dest_file = resources_dir + os.sep + custom_jdk_name
       print_warning_msg("JDK must be installed on all agent hosts and JAVA_HOME must be valid on all agent hosts.")

http://git-wip-us.apache.org/repos/asf/ambari/blob/1763922e/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 6daa413..0e90d7b 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1821,6 +1821,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       pass
     # Test case: JDK already exists
     p = MagicMock()
+    args.java_home = None
+    args.jdk_location = None
     get_ambari_properties_mock.return_value = p
     p.__getitem__.return_value = "somewhere"
     get_JAVA_HOME_mock.return_value = True
@@ -1829,6 +1831,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     rcode = ambari_server.download_jdk(args)
     self.assertEqual(0, rcode)
     # Test case: java home setup
+    args.java_home = "somewhere"
     path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = False
     rcode = ambari_server.download_jdk(args)
@@ -1862,6 +1865,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       # Expected
       pass
       # Successful JDK download
+    args.java_home = None
+    path_isfileMock.return_value = False
+    args.jdk_location = None
     ambari_server.JDK_INSTALL_DIR = os.getcwd()
     run_os_command_mock.return_value = (0, "Creating jdk-1.2/jre"
                                            "Content-Length: 32000\r\n"
@@ -1876,7 +1882,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     p.__getitem__.return_value = "somewhere"
     p.__getitem__.side_effect = None
     get_YN_input_mock.return_value = False
-    ambari_server.download_jdk(MagicMock())
+    ambari_server.download_jdk(args)
     self.assertTrue(exit_mock.called)
 
     # Test case: JDK file does not exist, jdk-location argument passed
@@ -1886,7 +1892,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_YN_input_mock.reset_mock()
     get_YN_input_mock.return_value = True
     args.jdk_location = "/existing/jdk/jdk-6u31-linux-x64.bin"
-    path_existsMock.side_effect = [False, True]
+    path_existsMock.return_value = True
     ambari_server.download_jdk(args)
     self.assertTrue(write_property_mock.call_count == 1)
     self.assertTrue(remove_property_mock.call_count == 2)
@@ -1898,7 +1904,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     p.__getitem__.return_value = "somewhere"
     p.__getitem__.side_effect = None
     args.jdk_location = "/existing/jdk/file"
-    path_existsMock.side_effect = [False, True]
+    path_existsMock.return_value = True
 
     def copyfile_side_effect(s, d):
       raise Exception("TerribleException")
@@ -1911,13 +1917,14 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       # Expected
       self.assertTrue(copyfile_mock.called)
     copyfile_mock.reset_mock()
-    # Test case: jdk is already installed, ensure that JCE check is not skipped if -j option is not supplied.
+    # Test case: jdk is already installed, ensure that JCE check is skipped if -j option is not supplied.
     p = MagicMock()
+    args.jdk_location = None
     get_ambari_properties_mock.return_value = p
     p.__getitem__.return_value = "somewhere"
     get_JAVA_HOME_mock.return_value = True
     get_YN_input_mock.return_value = False
-    path_existsMock.side_effect = [False, True]
+    path_existsMock.return_value = False
     with patch.object(ambari_server, "download_jce_policy") as download_jce_policy_mock:
       rcode = ambari_server.download_jdk(args)
       self.assertFalse(download_jce_policy_mock.called)
@@ -1926,7 +1933,6 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     write_property_mock.reset_mock()
     remove_property_mock.reset_mock()
     args.java_home = "somewhere"
-    path_existsMock.return_value = True
     path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = True
     ambari_server.download_jdk(args)
@@ -1947,9 +1953,11 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       # Expected
       self.assertFalse(write_property_mock.called)
     # Test case: Setup ambari-server first time, Custom JDK selected, JDK exists
+    args.java_home = None
+    args.jdk_location = None
     write_property_mock.reset_mock()
     remove_property_mock.reset_mock()
-    path_existsMock.side_effect = [False,False,True]
+    path_existsMock.return_value = True
     get_validated_string_input_mock.return_value = "3"
     get_JAVA_HOME_mock.return_value = False
     rcode = ambari_server.download_jdk(args)
@@ -1968,6 +1976,23 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     except FatalException as fe:
       # Expected
       pass
+    #Test case: Setup ambari-server with java home passed. Path to java home doesn't not exists
+    args.java_home = "somewhere"
+    path_existsMock.return_value = False
+    try:
+      ambari_server.download_jdk(args)
+      self.fail("Should throw exception")
+    except FatalException as fe:
+      self.assertTrue("Path to java home somewhere does not exists" in fe.reason)
+    #Test case: Setup ambari-server with jdk location passed. Path to JDK doesn't not exists
+    args.java_home = None
+    args.jdk_location = "/existing/jdk/file"
+    path_existsMock.return_value = False
+    try:
+      ambari_server.download_jdk(args)
+      self.fail("Should throw exception")
+    except FatalException as fe:
+      self.assertTrue("Path to jdk /existing/jdk/file does not exists" in fe.reason)
 
 
   @patch.object(ambari_server, "run_os_command")