Author: smohanty
Date: Sun Jun 9 21:50:55 2013
New Revision: 1491302
URL: http://svn.apache.org/r1491302
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/trunk/ambari-server/src/main/python/ambari-server.py
incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1491302&r1=1491301&r2=1491302&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Sun
Jun 9 21:50:55 2013
@@ -105,6 +105,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}\'"']
@@ -176,6 +177,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"
@@ -885,7 +889,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):
@@ -941,6 +985,8 @@ def setup(args):
print_error_msg ('Error while configuring connection properties.
Exiting')
sys.exit(retcode)
+ check_jdbc_drivers(args)
+
print 'Checking JDK...'
@@ -1274,6 +1320,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"
@@ -1283,6 +1330,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
@@ -1350,7 +1398,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()
@@ -1386,6 +1434,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])
@@ -1403,6 +1452,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)
@@ -1432,6 +1482,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:
@@ -1495,6 +1546,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()
@@ -1518,6 +1570,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/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1491302&r1=1491301&r2=1491302&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
Sun Jun 9 21:50:55 2013
@@ -1106,8 +1106,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()
@@ -1119,6 +1119,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