Author: smohanty
Date: Wed Jun 12 01:19:53 2013
New Revision: 1492031
URL: http://svn.apache.org/r1492031
Log:
AMBARI-2349. Enhance processing of ojdbc.jar before starting ambari server.
(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=1492031&r1=1492030&r2=1492031&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 Wed
Jun 12 01:19:53 2013
@@ -106,7 +106,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"
+RESOURCES_DIR_KEY="resources.dir"
SETUP_DB_CMD = ['su', '-', 'postgres',
'--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'"']
@@ -909,25 +909,36 @@ def copy_files(files, dest_dir):
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 copied 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)
+ properties = get_ambari_properties()
+
+ ## ask user twice
+ for i in range(0,2):
+ result = find_jdbc_driver(args)
+ if result == -1:
+ msg = 'WARNING: Before starting Ambari Server, ' \
+ 'the {0} JDBC driver JAR file must be copied 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
+ # check if user provided drivers
+ result = find_jdbc_driver(args)
- return 0
+ if type(result) is not int:
+ print 'Copying JDBC drivers to server resources...'
+ try:
+ resources_dir = properties[RESOURCES_DIR_KEY]
+ except KeyError:
+ print_error_msg("There is no value for " + RESOURCES_DIR_KEY + "in " +
AMBARI_PROPERTIES_FILE)
+ return -1
+ copy_files(result, resources_dir)
+ break
+ return 0
#
@@ -1595,6 +1606,24 @@ def store_local_properties(args):
return -1
return 0
+
+# Load ambari properties and return dict with values
+def get_ambari_properties():
+ conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
+ if conf_file is None:
+ print 'File %s not found in search path $%s: %s' %\
+ (AMBARI_PROPERTIES_FILE, AMBARI_CONF_VAR, get_conf_dir())
+ return -1
+ print_info_msg('Loading properties from ' + conf_file)
+
+ properties = None
+ try:
+ properties = Properties()
+ properties.load(open(conf_file))
+ except (Exception), e:
+ print 'Could not read "%s": %s' % (conf_file, e)
+ return -1
+ return properties
# Load database connection properties from conf file
def parse_properties_file(args):
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=1492031&r1=1492030&r2=1492031&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
Wed Jun 12 01:19:53 2013
@@ -1158,11 +1158,70 @@ class TestAmbariServer(TestCase):
sys.stdout = sys.__stdout__
+ @patch.object(ambari_server, "get_ambari_properties")
+ @patch.object(ambari_server, "find_jdbc_driver")
+ @patch.object(ambari_server, "copy_files")
+ @patch('__builtin__.raw_input')
+ def test_check_jdbc_drivers(self, raw_input_mock, copy_files_mock,
find_jdbc_driver_mock, get_ambari_properties_mock):
+
+ out = StringIO.StringIO()
+ sys.stdout = out
+
+ args = MagicMock()
+
+ # Check positive scenario
+ drivers_list = ['driver_file']
+ resources_dir = '/tmp'
+
+ get_ambari_properties_mock.return_value = {ambari_server.RESOURCES_DIR_KEY
: resources_dir}
+ find_jdbc_driver_mock.return_value = drivers_list
+
+ rcode = ambari_server.check_jdbc_drivers(args)
+
+ self.assertEqual(0, rcode)
+ copy_files_mock.assert_called_with(drivers_list, resources_dir)
+
+ #Check negative scenario
+ find_jdbc_driver_mock.return_value = -1
+
+ args.database = "oracle"
+
+ rcode = ambari_server.check_jdbc_drivers(args)
+
+ self.assertEqual(0, rcode)
+ #Ensure user was asked to provide drivers
+ self.assertTrue(raw_input_mock.called)
+
+ sys.stdout = sys.__stdout__
+
+
@patch.object(ambari_server, "search_file")
- def test_parse_properties_file(self, search_file_mock):
+ def test_get_ambari_properties(self, search_file_mock):
+ search_file_mock.return_value = None
+ rcode = ambari_server.get_ambari_properties()
+ self.assertEqual(rcode, -1)
+
tf1 = tempfile.NamedTemporaryFile()
search_file_mock.return_value = tf1.name
+ prop_name='name'
+ prop_value='val'
+
+ with open(tf1.name, 'w') as fout:
+ fout.write(prop_name + '=' + prop_value)
+ fout.close()
+
+ properties = ambari_server.get_ambari_properties()
+
+ self.assertEqual(properties[prop_name], prop_value)
+
+ sys.stdout = sys.__stdout__
+
+ @patch.object(ambari_server, "search_file")
+ def test_parse_properties_file(self, search_file_mock):
+
+ tf1 = tempfile.NamedTemporaryFile(mode='r')
+ search_file_mock.return_value = tf1.name
args = MagicMock()
ambari_server.parse_properties_file(args)