You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2015/09/01 17:43:02 UTC
[2/2] ambari git commit: AMBARI-12944. Make it configurable to select
which DB type is the default Ambari DB. (mpapirkovskyy)
AMBARI-12944. Make it configurable to select which DB type is the default Ambari DB. (mpapirkovskyy)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7680d7e7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7680d7e7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7680d7e7
Branch: refs/heads/trunk
Commit: 7680d7e74dbb20ac7b40692d96f11206397ad4c9
Parents: 9a05ae6
Author: Myroslav Papirkovskyy <mp...@hortonworks.com>
Authored: Tue Sep 1 18:15:58 2015 +0300
Committer: Myroslav Papirkovskyy <mp...@hortonworks.com>
Committed: Tue Sep 1 18:42:40 2015 +0300
----------------------------------------------------------------------
.../GenerateStackDefinition.py | 10 +++++
.../configs/SAPHD.json | 3 +-
.../python/ambari_server/dbConfiguration.py | 29 ++++++++++--
.../python/ambari_server/serverConfiguration.py | 2 +
.../main/python/ambari_server/serverSetup.py | 46 +++++++++++++++-----
.../src/test/python/TestAmbariServer.py | 30 ++++++++++---
6 files changed, 100 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/7680d7e7/ambari-common/src/main/python/pluggable_stack_definition/GenerateStackDefinition.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/pluggable_stack_definition/GenerateStackDefinition.py b/ambari-common/src/main/python/pluggable_stack_definition/GenerateStackDefinition.py
index 79cf362..f1f9381 100644
--- a/ambari-common/src/main/python/pluggable_stack_definition/GenerateStackDefinition.py
+++ b/ambari-common/src/main/python/pluggable_stack_definition/GenerateStackDefinition.py
@@ -583,14 +583,24 @@ class GeneratorHelper(object):
with open(source_ambari_properties, 'r') as in_file:
with open(target_ambari_properties, 'w') as out_file:
+ replaced_properties = []
for line in in_file:
property = line.split('=')[0]
if property in propertyMap:
out_file.write('='.join([property, propertyMap[property]]))
out_file.write(os.linesep)
+ replaced_properties.append(property)
else:
out_file.write(line)
+ if len(propertyMap) - len(replaced_properties) > 0:
+ out_file.write(os.linesep) #make sure we don't break last entry from original properties
+
+ for key in propertyMap:
+ if key not in replaced_properties:
+ out_file.write('='.join([key, propertyMap[key]]))
+ out_file.write(os.linesep)
+
def copy_custom_actions(self):
original_folder = os.path.join(self.resources_folder, 'custom_actions')
target_folder = os.path.join(self.output_folder, 'custom_actions')
http://git-wip-us.apache.org/repos/asf/ambari/blob/7680d7e7/ambari-common/src/main/python/pluggable_stack_definition/configs/SAPHD.json
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/pluggable_stack_definition/configs/SAPHD.json b/ambari-common/src/main/python/pluggable_stack_definition/configs/SAPHD.json
index 176f4c5..37de54d 100644
--- a/ambari-common/src/main/python/pluggable_stack_definition/configs/SAPHD.json
+++ b/ambari-common/src/main/python/pluggable_stack_definition/configs/SAPHD.json
@@ -20,7 +20,8 @@
"jdk1.8.url" : "http://DOWNLOAD_NOT_SUPPORTED",
"jdk1.7.jcpol-url" : "http://DOWNLOAD_NOT_SUPPORTED",
"jdk1.8.jcpol-url" : "http://DOWNLOAD_NOT_SUPPORTED",
- "rolling.upgrade.min.stack" : "SAPHD-0.9"
+ "rolling.upgrade.min.stack" : "SAPHD-0.9",
+ "server.setup.default.dbms" : "sqlanywhere"
},
"common-services": [
{
http://git-wip-us.apache.org/repos/asf/ambari/blob/7680d7e7/ambari-server/src/main/python/ambari_server/dbConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration.py b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
index d870036..4b76781 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
@@ -27,7 +27,7 @@ from ambari_commons.os_family_impl import OsFamilyImpl
from ambari_commons.str_utils import cbool
from ambari_server.serverConfiguration import decrypt_password_for_alias, get_ambari_properties, get_is_secure, \
get_resources_location, get_value_from_properties, is_alias_string, \
- JDBC_PASSWORD_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, PRESS_ENTER_MSG
+ JDBC_PASSWORD_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, PRESS_ENTER_MSG, DEFAULT_DBMS_PROPERTY
from ambari_server.userInput import get_validated_string_input
@@ -280,6 +280,12 @@ class DBMSConfigFactory(object):
def get_supported_jdbc_drivers(self):
return []
+ def force_dbms_setup(self):
+ return False
+
+ def get_default_dbms_name(self):
+ return ""
+
#
# Database configuration factory for Windows
#
@@ -372,6 +378,13 @@ class DBMSConfigFactoryLinux(DBMSConfigFactory):
"Enter choice ({0}): "
self.JDK_VALID_CHOICES_PATTERN = "^[{0}]$"
+ def force_dbms_setup(self):
+ dbms_name = self.get_default_dbms_name()
+ if dbms_name.strip():
+ return True
+ else:
+ return False
+
def select_dbms(self, options):
try:
dbms_index = options.database_index
@@ -437,13 +450,22 @@ class DBMSConfigFactoryLinux(DBMSConfigFactory):
def get_supported_jdbc_drivers(self):
return self.DRIVER_KEYS_LIST
+ def get_default_dbms_name(self):
+ properties = get_ambari_properties()
+ default_dbms_name = get_value_from_properties(properties, DEFAULT_DBMS_PROPERTY, "").strip().lower()
+ if default_dbms_name not in self.DBMS_KEYS_LIST:
+ return ""
+ else:
+ return default_dbms_name
+
def _get_default_dbms_index(self, options):
+ default_dbms_name = self.get_default_dbms_name()
try:
dbms_name = options.dbms
if not dbms_name:
- dbms_name = ""
+ dbms_name = default_dbms_name
except AttributeError:
- dbms_name = ""
+ dbms_name = default_dbms_name
try:
persistence_type = options.persistence_type
if not persistence_type:
@@ -531,3 +553,4 @@ def get_jdbc_driver_path(options, properties):
factory = DBMSConfigFactory()
dbms = factory.create(options, properties)
return dbms._get_default_driver_path(properties)
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/7680d7e7/ambari-server/src/main/python/ambari_server/serverConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverConfiguration.py b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
index 03da9f9..bc78d68 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -128,6 +128,8 @@ JDBC_RCA_URL_PROPERTY = "server.jdbc.rca.url"
JDBC_RCA_USER_NAME_PROPERTY = "server.jdbc.rca.user.name"
JDBC_RCA_PASSWORD_FILE_PROPERTY = "server.jdbc.rca.user.passwd"
+DEFAULT_DBMS_PROPERTY = "server.setup.default.dbms"
+
JDBC_RCA_PASSWORD_ALIAS = "ambari.db.password"
### # Windows-specific # ###
http://git-wip-us.apache.org/repos/asf/ambari/blob/7680d7e7/ambari-server/src/main/python/ambari_server/serverSetup.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py b/ambari-server/src/main/python/ambari_server/serverSetup.py
index 67f67a7..b3e6e21 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -84,7 +84,7 @@ JDBC_DB_OPTION_VALUES = get_supported_jdbc_drivers()
# Setup security prerequisites
#
-def verify_setup_allowed():
+def verify_setup_allowed(options):
if get_silent():
properties = get_ambari_properties()
if properties == -1:
@@ -99,6 +99,29 @@ def verify_setup_allowed():
"and Master Key not persisted."
print "Ambari Server 'setup' exiting."
return 1
+
+ factory = DBMSConfigFactory()
+ default_dbms = factory.get_default_dbms_name()
+ if default_dbms:
+ valid = True
+ if options.dbms is not None \
+ and options.database_host is not None \
+ and options.database_port is not None \
+ and options.database_name is not None \
+ and options.database_username is not None \
+ and options.database_password is not None:
+
+ if default_dbms == "sqlanywhere" and options.sqla_server_name is None:
+ valid = False
+
+ else:
+ valid = False
+
+ if not valid:
+ print "ERROR: Cannot run silent setup without database connection properties provided."
+ print "Ambari Server 'setup' exiting."
+ return 2
+
return 0
@@ -637,10 +660,10 @@ class JDKSetup(object):
# Base implementation, overriden in the subclasses
def _install_jdk(self, java_inst_file, java_home_dir):
pass
-
+
def adjust_jce_permissions(self, jdk_path):
pass
-
+
# Base implementation, overriden in the subclasses
def _ensure_java_home_env_var_is_set(self, java_home_dir):
pass
@@ -771,7 +794,7 @@ class JDKSetupLinux(JDKSetup):
def _ensure_java_home_env_var_is_set(self, java_home_dir):
#No way to do this in Linux. Best we can is to set the process environment variable.
os.environ[JAVA_HOME] = java_home_dir
-
+
def adjust_jce_permissions(self, jdk_path):
ambari_user = read_ambari_user()
cmd = self.SET_JCE_PERMISSIONS.format(ambari_user, jdk_path,configDefaults.JDK_SECURITY_DIR)
@@ -890,13 +913,16 @@ def _cache_jdbc_driver(args):
# Ask user for database connection properties
def prompt_db_properties(options):
- ok = False
- if options.must_set_database_options:
- ok = get_YN_input("Enter advanced database configuration [y/n] (n)? ", False)
+ factory = DBMSConfigFactory()
- print 'Configuring database...'
+ if not factory.force_dbms_setup():
+ ok = False
+ if options.must_set_database_options:
+ ok = get_YN_input("Enter advanced database configuration [y/n] (n)? ", False)
+ else:
+ ok = True
- factory = DBMSConfigFactory()
+ print 'Configuring database...'
options.must_set_database_options = ok
options.database_index = factory.select_dbms(options)
@@ -1049,7 +1075,7 @@ def setup(options):
print "Nothing was done. Ambari Setup already performed and cannot re-run setup in silent mode. Use \"ambari-server setup\" command without -s option to change Ambari setup."
sys.exit(0)
- retcode = verify_setup_allowed()
+ retcode = verify_setup_allowed(options)
if not retcode == 0:
raise FatalException(1, None)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7680d7e7/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 7b913e1..6467cd8 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -18,6 +18,7 @@ limitations under the License.
from stacks.utils.RMFTestCase import *
import sys
+import traceback
import os
import datetime
import errno
@@ -2925,7 +2926,8 @@ class TestAmbariServer(TestCase):
pass
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
- def test_prompt_db_properties_default(self):
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
+ def test_prompt_db_properties_default(self, get_ambari_properties_mock):
args = MagicMock()
args.must_set_database_options = False
@@ -2938,6 +2940,8 @@ class TestAmbariServer(TestCase):
del args.database_password
del args.persistence_type
+ get_ambari_properties_mock.return_value = Properties()
+
prompt_db_properties(args)
self.assertEqual(args.database_index, 0)
@@ -4130,6 +4134,7 @@ class TestAmbariServer(TestCase):
@patch("ambari_server.serverConfiguration.write_property")
@patch("ambari_server.serverConfiguration.get_validated_string_input")
@patch("os.environ")
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
@patch("ambari_server.setupSecurity.get_ambari_properties")
@patch("ambari_server.serverSetup.get_ambari_properties")
@patch("ambari_server.serverConfiguration.get_ambari_properties")
@@ -4157,7 +4162,7 @@ class TestAmbariServer(TestCase):
find_jdk_mock, check_database_name_property_mock, search_file_mock,
popenMock, openMock, pexistsMock,
get_ambari_properties_mock, get_ambari_properties_2_mock, get_ambari_properties_3_mock,
- get_ambari_properties_4_mock, os_environ_mock,
+ get_ambari_properties_4_mock, get_ambari_properties_5_mock, os_environ_mock,
get_validated_string_input_method, write_property_method,
os_chmod_method, get_is_secure_mock, get_is_persisted_mock,
save_master_key_method, get_master_key_location_method,
@@ -4202,7 +4207,7 @@ class TestAmbariServer(TestCase):
p = Properties()
p.process_pair(SECURITY_IS_ENCRYPTION_ENABLED, 'False')
- get_ambari_properties_4_mock.return_value = \
+ get_ambari_properties_5_mock.return_value = get_ambari_properties_4_mock.return_value = \
get_ambari_properties_3_mock.return_value = get_ambari_properties_2_mock.return_value = \
get_ambari_properties_mock.return_value = p
get_is_secure_mock.return_value = False
@@ -5707,7 +5712,8 @@ class TestAmbariServer(TestCase):
@patch("ambari_server.serverSetup.get_YN_input")
@patch("ambari_server.dbConfiguration.get_validated_string_input")
@patch("ambari_server.dbConfiguration_linux.print_info_msg")
- def test_prompt_db_properties(self, print_info_msg_mock,
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
+ def test_prompt_db_properties(self, get_ambari_properties_mock, print_info_msg_mock,
get_validated_string_input_mock, get_YN_input_mock):
def reset_mocks():
get_validated_string_input_mock.reset_mock()
@@ -5727,6 +5733,7 @@ class TestAmbariServer(TestCase):
return args
args = reset_mocks()
+ get_ambari_properties_mock.return_value = Properties()
set_silent(False)
@@ -6122,6 +6129,7 @@ class TestAmbariServer(TestCase):
@not_for_platform(PLATFORM_WINDOWS)
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
@patch("ambari_server.dbConfiguration_linux.get_ambari_properties")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
@patch("ambari_server.dbConfiguration.print_error_msg")
@@ -6135,12 +6143,13 @@ class TestAmbariServer(TestCase):
@patch("shutil.copy")
def test_ensure_jdbc_drivers_installed(self, shutil_copy_mock, os_symlink_mock, os_remove_mock, lexists_mock, isdir_mock, glob_mock,
raw_input_mock, print_warning_msg, print_error_msg_mock, print_error_msg_2_mock,
- get_ambari_properties_mock):
+ get_ambari_properties_mock, get_ambari_properties_2_mock):
out = StringIO.StringIO()
sys.stdout = out
def reset_mocks():
get_ambari_properties_mock.reset_mock()
+ get_ambari_properties_2_mock.reset_mock()
shutil_copy_mock.reset_mock()
print_error_msg_mock.reset_mock()
print_warning_msg.reset_mock()
@@ -6164,7 +6173,7 @@ class TestAmbariServer(TestCase):
props = Properties()
props.process_pair(RESOURCES_DIR_PROPERTY, resources_dir)
- get_ambari_properties_mock.return_value = props
+ get_ambari_properties_2_mock.return_value = get_ambari_properties_mock.return_value = props
factory = DBMSConfigFactory()
@@ -7992,7 +8001,9 @@ class TestAmbariServer(TestCase):
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("ambari_server.dbConfiguration_linux.run_os_command")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
def test_change_objects_owner_both(self,
+ get_ambari_properties_mock,
print_error_msg_mock,
run_os_command_mock):
args = MagicMock()
@@ -8010,6 +8021,7 @@ class TestAmbariServer(TestCase):
stdout = " stdout "
stderr = " stderr "
run_os_command_mock.return_value = 1, stdout, stderr
+ get_ambari_properties_mock.return_value = Properties()
set_verbose(True)
self.assertRaises(FatalException, change_objects_owner, args)
@@ -8021,7 +8033,9 @@ class TestAmbariServer(TestCase):
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("ambari_server.dbConfiguration_linux.run_os_command")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
def test_change_objects_owner_only_stdout(self,
+ get_ambari_properties_mock,
print_error_msg_mock,
run_os_command_mock):
args = MagicMock()
@@ -8038,6 +8052,7 @@ class TestAmbariServer(TestCase):
stdout = " stdout "
stderr = ""
run_os_command_mock.return_value = 1, stdout, stderr
+ get_ambari_properties_mock.return_value = Properties()
set_verbose(True)
self.assertRaises(FatalException, change_objects_owner, args)
@@ -8048,7 +8063,9 @@ class TestAmbariServer(TestCase):
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("ambari_server.dbConfiguration_linux.run_os_command")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
+ @patch("ambari_server.dbConfiguration.get_ambari_properties")
def test_change_objects_owner_only_stderr(self,
+ get_ambari_properties_mock,
print_error_msg_mock,
run_os_command_mock):
args = MagicMock()
@@ -8065,6 +8082,7 @@ class TestAmbariServer(TestCase):
stdout = ""
stderr = " stderr "
run_os_command_mock.return_value = 1, stdout, stderr
+ get_ambari_properties_mock.return_value = Properties()
set_verbose(True)
self.assertRaises(FatalException, change_objects_owner, args)