Browse Source

AMBARI-5956. DB connection check error if jdk_name does not exist.(vbrodetskyi)

Vitaly Brodetskyi 10 years ago
parent
commit
5214ea465e

+ 4 - 4
ambari-server/src/main/resources/custom_actions/check_host.py

@@ -136,14 +136,13 @@ class CheckHost(Script):
 
     environment = { "no_proxy": format("{ambari_server_hostname}") }
     artifact_dir = "/tmp/HDP-artifacts/"
-    jdk_name = config['commandParams']['jdk_name']
-    jdk_curl_target = format("{artifact_dir}/{jdk_name}")
     java_dir = os.path.dirname(java64_home)
 
-    # download DBConnectionVerification.jar from ambari-server resources
-
+    # download and install java if it doesn't exists
     if not os.path.isfile(java_exec):
       try:
+        jdk_name = config['commandParams']['jdk_name']
+        jdk_curl_target = format("{artifact_dir}/{jdk_name}")
         Execute(format("mkdir -p {artifact_dir} ; curl -kf "
                 "--retry 10 {jdk_location}/{jdk_name} -o {jdk_curl_target}"),
                 path = ["/bin","/usr/bin/"],
@@ -169,6 +168,7 @@ class CheckHost(Script):
         db_connection_check_structured_output = {"exit_code" : 1, "message": message}
         return db_connection_check_structured_output
 
+    # download DBConnectionVerification.jar from ambari-server resources
     try:
       cmd = format("/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf "
                    "--retry 5 {jdk_location}{check_db_connection_jar_name} "

+ 4 - 4
ambari-server/src/test/python/TestCheckHost.py

@@ -83,10 +83,10 @@ class TestCheckHost(TestCase):
                      'DBConnectionVerification.jar from Ambari Server resources. Check network access to Ambari ' \
                      'Server.\ntest exception', 'exit_code': 1}})
     
-    self.assertEquals(format_mock.call_args_list[2][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
+    self.assertEquals(format_mock.call_args_list[1][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
                       "--retry 5 {jdk_location}{check_db_connection_jar_name} -o {check_db_connection_jar_name}'")
     
-    self.assertEquals(format_mock.call_args_list[3][0][0], "[ -f /usr/lib/ambari-agent/{check_db_connection_jar_name}]")
+    self.assertEquals(format_mock.call_args_list[2][0][0], "[ -f /usr/lib/ambari-agent/{check_db_connection_jar_name}]")
 
     # test, download jdbc driver failed
     mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
@@ -111,10 +111,10 @@ class TestCheckHost(TestCase):
                   'Server host to make the JDBC driver available for download and to enable testing '
                   'the database connection.\n')
     self.assertEquals(structured_out_mock.call_args[0][0]['db_connection_check']['exit_code'], 1)
-    self.assertEquals(format_mock.call_args_list[4][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
+    self.assertEquals(format_mock.call_args_list[3][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
                                                             "--retry 5 {jdbc_url} -o {jdbc_name}'")
     
-    self.assertEquals(format_mock.call_args_list[5][0][0], "[ -f /usr/lib/ambari-agent/{jdbc_name}]")
+    self.assertEquals(format_mock.call_args_list[4][0][0], "[ -f /usr/lib/ambari-agent/{jdbc_name}]")
 
     # test, no connection to remote db
     mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",