incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject svn commit: r1491303 - in /incubator/ambari/branches/branch-1.2.4/ambari-server/src: main/python/ambari-server.py test/python/TestAmbaryServer.py
Date Sun, 09 Jun 2013 21:51:39 GMT
Author: smohanty
Date: Sun Jun  9 21:51:39 2013
New Revision: 1491303

URL: http://svn.apache.org/r1491303
Log:
AMBARI-2334. Need to make it clear that ojdbc.jar must be in place before starting server.
(Myroslav Papirkovskyy, Oleksandr Diachenko via smohanty)

Modified:
    incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
    incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py?rev=1491303&r1=1491302&r2=1491303&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
(original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
Sun Jun  9 21:51:39 2013
@@ -103,6 +103,7 @@ PID_DIR="/var/run/ambari-server"
 PID_NAME="ambari-server.pid"
 AMBARI_PROPERTIES_FILE="ambari.properties"
 AMBARI_PROPERTIES_RPMSAVE_FILE="ambari.properties.rpmsave"
+RESOURCES_DIR="/var/lib/ambari-server/resources"
 
 SETUP_DB_CMD = ['su', '-', 'postgres',
         '--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'"']
@@ -174,6 +175,9 @@ ORACLE_EXEC_ARGS = "-S '{0}/{1}@(descrip
 MYSQL_EXEC_ARGS = "--host={0} --port={1} --user={2} --password={3} {4} " \
                  "-e\"set @schema=\'{4}\'; set @username=\'{2}\'; source {5};\""
 
+JDBC_PATTERNS = {"oracle":"*ojdbc*.jar", "mysql":"*mysql*.jar"}
+DATABASE_FULL_NAMES = {"oracle":"Oracle", "mysql":"MySQL", "postgres":"PostgreSQL"}
+
 
 # jdk commands
 JDK_LOCAL_FILENAME = "jdk-6u31-linux-x64.bin"
@@ -781,7 +785,47 @@ def is_local_database(options):
     return True
   return False
 
+#Check if required jdbc drivers present
+def find_jdbc_driver(args):
+  if args.database in JDBC_PATTERNS.keys():
+    drivers = []
+    drivers.extend(glob.glob(JAVA_SHARE_PATH + os.sep + JDBC_PATTERNS[args.database]))
+    if drivers:
+      return drivers
+    return -1
+  return 0
+
+def copy_files(files, dest_dir):
+  if os.path.isdir(dest_dir):
+    for filepath in files:
+      shutil.copy(filepath, dest_dir)
+    return 0
+  else:
+    return -1
+
+def check_jdbc_drivers(args):
+  result = find_jdbc_driver(args)
+  if result == -1:
+    msg = 'WARNING: Before starting Ambari Server, ' \
+          'the {0} JDBC driver JAR file must be placed to {1}. Press enter to continue.'.format(
+      DATABASE_FULL_NAMES[args.database],
+      JAVA_SHARE_PATH
+    )
+    if not SILENT:
+      raw_input(msg)
+    else:
+      print_warning_msg(msg)
+
+  elif type(result) is not int:
+    print 'Copying JDBC drivers to server resources...'
+    copy_files(result, RESOURCES_DIR)
+    pass
+
+  return 0
+
+
 #
+
 # Setup the Ambari Server.
 #
 def setup(args):
@@ -837,6 +881,8 @@ def setup(args):
       print_error_msg ('Error while configuring connection properties. Exiting')
       sys.exit(retcode)
 
+    check_jdbc_drivers(args)
+
 
 
   print 'Checking JDK...'
@@ -1163,6 +1209,7 @@ def get_pass_file_path(conf_file):
     JDBC_PASSWORD_FILENAME)
 
 
+# Set database properties to default values
 def load_default_db_properties(args):
   args.database=DATABASE_NAMES[DATABASE_INDEX]
   args.database_host = "localhost"
@@ -1172,6 +1219,7 @@ def load_default_db_properties(args):
   args.database_password = "bigdata"
   pass
 
+# Ask user for database conenction properties
 def prompt_db_properties(args):
   global DATABASE_INDEX
 
@@ -1239,7 +1287,7 @@ def prompt_db_properties(args):
   ))
 
 
-
+# Store set of properties for remote database connection
 def store_remote_properties(args):
   conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
   properties = Properties()
@@ -1275,6 +1323,7 @@ def store_remote_properties(args):
 
   return 0
 
+# Initialize remote database schema
 def setup_remote_db(args):
 
   retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
@@ -1292,6 +1341,7 @@ def setup_remote_db(args):
 
   return 0
 
+# Get database client executable path
 def get_db_cli_tool(args):
   for tool in DATABASE_CLI_TOOLS[DATABASE_INDEX]:
     cmd =CHECK_COMMAND_EXIST_CMD.format(tool)
@@ -1321,6 +1371,7 @@ def run_in_shell(cmd):
   return process.returncode, stdoutdata, stderrdata
 
 
+#execute SQL script on remote database
 def execute_remote_script(args, scriptPath):
   tool = get_db_cli_tool(args)
   if not tool:
@@ -1384,6 +1435,7 @@ def configure_database_username_password
     print_error_msg("Connection properties not set in config file.")
 
 
+# Store local database connection properties
 def store_local_properties(args):
   conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
   properties = Properties()
@@ -1407,6 +1459,7 @@ def store_local_properties(args):
 
   return 0
 
+# Load database connection properties from conf file
 def parse_properties_file(args):
   conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
   properties = Properties()

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py?rev=1491303&r1=1491302&r2=1491303&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
(original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
Sun Jun  9 21:51:39 2013
@@ -1015,8 +1015,8 @@ class TestAmbariServer(TestCase):
   @patch.object(ambari_server, "store_remote_properties")
   @patch.object(ambari_server, "is_local_database")
   @patch.object(ambari_server, "check_iptables")
-
-  def test_setup_remote_db_wo_client(self, check_iptables_mock, is_local_db_mock,
+  @patch.object(ambari_server, "check_jdbc_drivers")
+  def test_setup_remote_db_wo_client(self, check_jdbc_drivers_mock, check_iptables_mock,
is_local_db_mock,
                                      store_remote_properties_mock, get_db_cli_tool_mock,
exit_mock):
 
     out = StringIO.StringIO()
@@ -1028,6 +1028,7 @@ class TestAmbariServer(TestCase):
     check_iptables_mock.return_value = (0, "other")
     store_remote_properties_mock.return_value = 0
     get_db_cli_tool_mock.return_value = None
+    check_jdbc_drivers_mock.return_value=0
 
     failed = False
     result = None



Mime
View raw message