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/05/22 20:05:24 UTC
git commit: AMBARI-5696. Usability: performing connectivity checks
against an external database.(vbrodetskyi)
Repository: ambari
Updated Branches:
refs/heads/trunk 4c45504be -> 199a0916a
AMBARI-5696. Usability: performing connectivity checks against an external database.(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/199a0916
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/199a0916
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/199a0916
Branch: refs/heads/trunk
Commit: 199a0916a2b5f1e6e935018865ee63888e75a257
Parents: 4c45504
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Thu May 22 18:43:55 2014 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Thu May 22 18:43:55 2014 +0300
----------------------------------------------------------------------
.../main/resources/custom_actions/check_host.py | 129 +++++++++++++++++--
1 file changed, 119 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/199a0916/ambari-server/src/main/resources/custom_actions/check_host.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/check_host.py b/ambari-server/src/main/resources/custom_actions/check_host.py
index 19628e2..e5aa920 100644
--- a/ambari-server/src/main/resources/custom_actions/check_host.py
+++ b/ambari-server/src/main/resources/custom_actions/check_host.py
@@ -20,26 +20,135 @@ Ambari Agent
"""
-import os, sys
+import os, sys, subprocess
from resource_management import *
+CHECK_JAVA_HOME = "java_home_check"
+CHECK_DB_CONNECTION = "db_connection_check"
+
+DB_NAME_MYSQL = "mysql"
+DB_NAME_ORACLE = "oracle"
+DB_NAME_POSTGRESQL = "postgresql"
+
+JDBC_DRIVER_MYSQL = "com.mysql.jdbc.Driver"
+JDBC_DRIVER_ORACLE = "oracle.jdbc.driver.OracleDriver"
+JDBC_DRIVER_POSTGRESQL = "org.postgresql.Driver"
+
+
class CheckHost(Script):
def actionexecute(self, env):
config = Script.get_config()
- java_home = config['hostLevelParams']['java_home']
+ #print "CONFIG: " + str(config)
+
+ check_execute_list = config['commandParams']['check_execute_list']
+ structured_output = {}
+
+ if CHECK_JAVA_HOME in check_execute_list:
+ java_home_check_structured_output = execute_java_home_available_check(config)
+ structured_output[CHECK_JAVA_HOME] = java_home_check_structured_output
+
+ if CHECK_DB_CONNECTION in check_execute_list:
+ db_connection_check_structured_output = execute_db_connection_check(config)
+ structured_output[CHECK_DB_CONNECTION] = db_connection_check_structured_output
+
+ self.put_structured_out(structured_output)
+
+
+def execute_java_home_available_check(config):
+ print "Java home check started."
+ java64_home = config['hostLevelParams']['java_home']
+
+ if not os.path.isfile(os.path.join(java64_home, "bin", "java")):
+ print "Java home doesn't exist!"
+ java_home_check_structured_output = {"exit_code" : "1", "message": "Java home doesn't exist!"}
+ else:
+ print "Java home exists!"
+ java_home_check_structured_output = {"exit_code" : "0", "message": "Java home exists!"}
+
+ return java_home_check_structured_output
+
+
+def execute_db_connection_check(config):
+ print "DB connection check started."
+
+ # initialize needed data
+
+ ambari_server_hostname = config['clusterHostInfo']['ambari_server_host']
+ check_db_connection_jar_name = "DBConnectionVerification.jar"
+ jdk_location = config['hostLevelParams']['jdk_location']
+ java64_home = config['hostLevelParams']['java_home']
+ db_name = config['commandParams']['db_name']
+
+ if db_name == DB_NAME_MYSQL:
+ jdbc_url = config['hostLevelParams']['mysql_jdbc_url']
+ jdbc_driver = JDBC_DRIVER_MYSQL
+ elif db_name == DB_NAME_ORACLE:
+ jdbc_url = config['hostLevelParams']['oracle_jdbc_url']
+ jdbc_driver = JDBC_DRIVER_ORACLE
+ elif db_name == DB_NAME_POSTGRESQL:
+ jdbc_url = config['hostLevelParams']['postgresql_jdbc_url']
+ jdbc_driver = JDBC_DRIVER_POSTGRESQL
+
+ path, jdbc_name = os.path.split(jdbc_url)
+ db_connection_url = config['commandParams']['db_connection_url']
+ user_name = config['commandParams']['user_name']
+ user_passwd = config['commandParams']['user_passwd']
+
+ environment = { "no_proxy": format("{ambari_server_hostname}") }
+
+ # 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} "
+ "-o {check_db_connection_jar_name}'")
+ Execute(cmd, not_if=format("[ -f /usr/lib/ambari-agent/{check_db_connection_jar_name}]"), environment = environment)
+ except Exception, e:
+ message = "Error downloading DBConnectionVerification.jar from Ambari Server resources. Check network access to " \
+ "Ambari Server.\n" + str(e)
+ print message
+ db_connection_check_structured_output = {"exit_code" : "1", "message": message}
+ return db_connection_check_structured_output
+
+ # download jdbc driver from ambari-server resources
+
+ try:
+ cmd = format("/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf "
+ "--retry 5 {jdbc_url} -o {jdbc_name}'")
+ Execute(cmd, not_if=format("[ -f /usr/lib/ambari-agent/{jdbc_name}]"), environment = environment)
+ except Exception, e:
+ message = "Error downloading JDBC connector from Ambari Server resources. Check network access to " \
+ "Ambari Server.\n" + str(e)
+ print message
+ db_connection_check_structured_output = {"exit_code" : "1", "message": message}
+ return db_connection_check_structured_output
+
+
+ # try to connect to db
+
+ db_connection_check_command = format("{java64_home}/bin/java -cp /usr/lib/ambari-agent/{check_db_connection_jar_name}:" \
+ "/usr/lib/ambari-agent/{jdbc_name} org.apache.ambari.server.DBConnectionVerification {db_connection_url} " \
+ "{user_name} {user_passwd!p} {jdbc_driver}")
- if not os.path.isfile(os.path.join(java_home, "bin", "java")):
- print "Java home not exists"
- sys.exit(1)
+ process = subprocess.Popen(db_connection_check_command,
+ stdout=subprocess.PIPE,
+ stdin=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ shell=True)
+ (stdoutdata, stderrdata) = process.communicate()
+ print "INFO stdoutdata: " + stdoutdata
+ print "INFO stderrdata: " + stderrdata
+ print "INFO returncode: " + str(process.returncode)
- print "Java home exists"
- structured_output_example = {
- 'result': 'Host check completed.'
- }
+ if process.returncode == 0:
+ db_connection_check_structured_output = {"exit_code" : "0", "message": "DB connection check completed successfully!" }
+ else:
+ db_connection_check_structured_output = {"exit_code" : "1", "message": stdoutdata }
- self.put_structured_out(structured_output_example)
+ return db_connection_check_structured_output
if __name__ == "__main__":