Ver Fonte

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

Vitaly Brodetskyi há 11 anos atrás
pai
commit
b625ae435b

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

@@ -124,12 +124,20 @@ class CheckHost(Script):
     db_connection_url = config['commandParams']['db_connection_url']
     user_name = config['commandParams']['user_name']
     user_passwd = config['commandParams']['user_passwd']
-  
+    java_exec = os.path.join(java64_home, "bin","java")
+
+    if ('jdk_name' not in config['commandParams'] or config['commandParams']['jdk_name'] == None \
+        or config['commandParams']['jdk_name'] == '') and not os.path.isfile(java_exec):
+      message = "Custom java is not available on host. Please install it. Java home should be the same as on server. " \
+                "\n"
+      print message
+      db_connection_check_structured_output = {"exit_code" : "1", "message": message}
+      return db_connection_check_structured_output
+
     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_exec = os.path.join(java64_home, "bin","java")
     java_dir = os.path.dirname(java64_home)
 
     # download DBConnectionVerification.jar from ambari-server resources

+ 15 - 0
ambari-server/src/test/python/TestCheckHost.py

@@ -148,6 +148,21 @@ class TestCheckHost(TestCase):
     self.assertEquals(structured_out_mock.call_args[0][0], {'db_connection_check':
                                         {'message': 'DB connection check completed successfully!', 'exit_code': '0'}})
 
+    #test jdk_name and java home are not available
+    mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
+                                                   "java_home" : "test_java_home",
+                                                   "ambari_server_host" : "test_host",
+                                                   "jdk_location" : "test_jdk_location",
+                                                   "db_connection_url" : "test_db_connection_url",
+                                                   "user_name" : "test_user_name",
+                                                   "user_passwd" : "test_user_passwd",
+                                                   "db_name" : "postgresql"}}
+
+    isfile_mock.return_value = False
+    checkHost.actionexecute(None)
+    self.assertEquals(structured_out_mock.call_args[0][0], {'db_connection_check': {'message': 'Custom java is not ' \
+            'available on host. Please install it. Java home should be the same as on server. \n', 'exit_code': '1'}})
+
 
 
   @patch("socket.gethostbyname")