You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2018/11/21 06:36:55 UTC
[ambari] branch trunk updated: AMBARI-24916. Add setup-jdbc command
(#2634)
This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new ae3d9aa AMBARI-24916. Add setup-jdbc command (#2634)
ae3d9aa is described below
commit ae3d9aa3abfa589a568a77e4c7cf0c7656bdfc65
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Wed Nov 21 07:36:49 2018 +0100
AMBARI-24916. Add setup-jdbc command (#2634)
---
ambari-server/sbin/ambari-server | 4 +++
ambari-server/src/main/python/ambari-server.py | 31 +++++++++++-------
.../src/main/python/ambari_server/serverSetup.py | 8 ++---
.../src/main/python/ambari_server/setupActions.py | 1 +
ambari-server/src/test/python/TestAmbariServer.py | 38 +++++++++++-----------
5 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/ambari-server/sbin/ambari-server b/ambari-server/sbin/ambari-server
index 3289ff8..4d0c334 100755
--- a/ambari-server/sbin/ambari-server
+++ b/ambari-server/sbin/ambari-server
@@ -133,6 +133,10 @@ case "${1:-}" in
echo -e "Updating jce policy"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" "$@"
;;
+ setup-jdbc)
+ echo -e "Setting up JDBC driver"
+ $PYTHON "$AMBARI_PYTHON_EXECUTABLE" "$@"
+ ;;
setup-pam)
echo -e "Setting up PAM properties..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" "$@"
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index 8cfa147..4cf7325 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -41,13 +41,13 @@ from ambari_server.enableStack import enable_stack_version
from ambari_server.hostUpdate import update_host_names
from ambari_server.kerberos_setup import setup_kerberos
from ambari_server.serverConfiguration import configDefaults, get_ambari_properties, PID_NAME
-from ambari_server.serverSetup import reset, setup, setup_jce_policy
+from ambari_server.serverSetup import reset, setup, setup_jce_policy, setup_jdbc
from ambari_server.serverUpgrade import upgrade, set_current
from ambari_server.serverUtils import is_server_runing, refresh_stack_hash, wait_for_server_to_stop
from ambari_server.setupActions import BACKUP_ACTION, LDAP_SETUP_ACTION, LDAP_SYNC_ACTION, PSTART_ACTION, \
REFRESH_STACK_HASH_ACTION, RESET_ACTION, RESTORE_ACTION, UPDATE_HOST_NAMES_ACTION, CHECK_DATABASE_ACTION, \
SETUP_ACTION, SETUP_SECURITY_ACTION, RESTART_ACTION, START_ACTION, STATUS_ACTION, STOP_ACTION, UPGRADE_ACTION, \
- SETUP_JCE_ACTION, SET_CURRENT_ACTION, ENABLE_STACK_ACTION, SETUP_SSO_ACTION, \
+ SETUP_JCE_ACTION, SETUP_JDBC_ACTION, SET_CURRENT_ACTION, ENABLE_STACK_ACTION, SETUP_SSO_ACTION, \
DB_PURGE_ACTION, INSTALL_MPACK_ACTION, UNINSTALL_MPACK_ACTION, UPGRADE_MPACK_ACTION, PAM_SETUP_ACTION, \
MIGRATE_LDAP_PAM_ACTION, KERBEROS_SETUP_ACTION
from ambari_server.setupHttps import setup_https, setup_truststore
@@ -455,6 +455,21 @@ def init_action_parser(action, parser):
# -h reserved for help
@OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
+def add_jdbc_parser_options(parser):
+ add_parser_options('--jdbc-driver', dest="jdbc_driver", default=None, parser=parser,
+ help="Specifies the path to the JDBC driver JAR file or archive " \
+ "with all required files(jdbc jar, libraries and etc), for the " \
+ "database type specified with the --jdbc-db option. " \
+ "Used only with --jdbc-db option. Archive is supported only for" \
+ " sqlanywhere database.",
+ required_for_actions = (SETUP_JDBC_ACTION,))
+ add_parser_options('--jdbc-db', dest="jdbc_db", default=None, parser=parser,
+ help="Specifies the database type [postgres|mysql|mssql|oracle|hsqldb|sqlanywhere] for the " \
+ "JDBC driver specified with the --jdbc-driver option. Used only with --jdbc-driver option.",
+ required_for_actions = (SETUP_JDBC_ACTION,))
+
+
+@OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
def init_setup_parser_options(parser):
database_group = optparse.OptionGroup(parser, 'Database options (command need to include all options)')
database_group.add_option('--database', default=None, help="Database to use embedded|oracle|mysql|mssql|postgres|sqlanywhere", dest="dbms")
@@ -467,15 +482,7 @@ def init_setup_parser_options(parser):
parser.add_option_group(database_group)
jdbc_group = optparse.OptionGroup(parser, 'JDBC options (command need to include all options)')
- jdbc_group.add_option('--jdbc-driver', default=None, help="Specifies the path to the JDBC driver JAR file or archive " \
- "with all required files(jdbc jar, libraries and etc), for the " \
- "database type specified with the --jdbc-db option. " \
- "Used only with --jdbc-db option. Archive is supported only for" \
- " sqlanywhere database." ,
- dest="jdbc_driver")
- jdbc_group.add_option('--jdbc-db', default=None, help="Specifies the database type [postgres|mysql|mssql|oracle|hsqldb|sqlanywhere] for the " \
- "JDBC driver specified with the --jdbc-driver option. Used only with --jdbc-driver option.",
- dest="jdbc_db")
+ add_jdbc_parser_options(jdbc_group)
parser.add_option_group(jdbc_group)
other_group = optparse.OptionGroup(parser, 'Other options')
@@ -815,6 +822,7 @@ def create_user_action_map(args, options):
action_map = {
SETUP_ACTION: UserAction(setup, options),
SETUP_JCE_ACTION : UserActionPossibleArgs(setup_jce_policy, [2], args),
+ SETUP_JDBC_ACTION : UserAction(setup_jdbc, options),
START_ACTION: UserAction(start, options),
STOP_ACTION: UserAction(stop, options),
RESTART_ACTION: UserAction(restart, options),
@@ -847,6 +855,7 @@ def init_action_parser(action, parser):
action_parser_map = {
SETUP_ACTION: init_setup_parser_options,
SETUP_JCE_ACTION: init_empty_parser_options,
+ SETUP_JDBC_ACTION: add_jdbc_parser_options,
START_ACTION: init_start_parser_options,
STOP_ACTION: init_empty_parser_options,
RESTART_ACTION: init_start_parser_options,
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py b/ambari-server/src/main/python/ambari_server/serverSetup.py
index a32ac38..1a8a766 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -915,7 +915,7 @@ def configure_os_settings():
def _check_jdbc_options(options):
return (options.jdbc_driver is not None and options.jdbc_db is not None)
-def proceedJDBCProperties(args):
+def setup_jdbc(args):
if not os.path.isfile(args.jdbc_driver):
err = "File {0} does not exist!".format(args.jdbc_driver)
raise FatalException(1, err)
@@ -1164,7 +1164,7 @@ def setup(options):
# proceed jdbc properties if they were set
if _check_jdbc_options(options):
- proceedJDBCProperties(options)
+ setup_jdbc(options)
return
(retcode, err) = disable_security_enhancements()
@@ -1180,10 +1180,6 @@ def setup(options):
print configDefaults.MESSAGE_CHECK_FIREWALL
check_firewall()
- # proceed jdbc properties if they were set
- if _check_jdbc_options(options):
- proceedJDBCProperties(options)
-
print 'Checking JDK...'
try:
download_and_install_jdk(options)
diff --git a/ambari-server/src/main/python/ambari_server/setupActions.py b/ambari-server/src/main/python/ambari_server/setupActions.py
index 61d20af..5917a83 100644
--- a/ambari-server/src/main/python/ambari_server/setupActions.py
+++ b/ambari-server/src/main/python/ambari_server/setupActions.py
@@ -29,6 +29,7 @@ UPGRADE_ACTION = "upgrade"
REFRESH_STACK_HASH_ACTION = "refresh-stack-hash"
STATUS_ACTION = "status"
SETUP_HTTPS_ACTION = "setup-https"
+SETUP_JDBC_ACTION = "setup-jdbc"
LDAP_SETUP_ACTION = "setup-ldap"
SETUP_SSO_ACTION = "setup-sso"
LDAP_SYNC_ACTION = "sync-ldap"
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 14f3387..9c4e704 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -99,7 +99,7 @@ with patch.object(platform, "linux_distribution", return_value = MagicMock(retur
COMMON_SERVICES_PATH_PROPERTY, WEBAPP_DIR_PROPERTY, SHARED_RESOURCES_DIR, BOOTSTRAP_SCRIPT, \
CUSTOM_ACTION_DEFINITIONS, BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY, MPACKS_STAGING_PATH_PROPERTY, STACK_JAVA_VERSION
from ambari_server.serverUtils import is_server_runing, refresh_stack_hash
- from ambari_server.serverSetup import check_selinux, check_ambari_user, proceedJDBCProperties, SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \
+ from ambari_server.serverSetup import check_selinux, check_ambari_user, setup_jdbc, SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \
download_and_install_jdk, prompt_db_properties, setup, \
AmbariUserChecks, JDKSetup, reset, setup_jce_policy, expand_jce_zip_file, check_ambari_java_version_is_valid
from ambari_server.serverUpgrade import upgrade, run_schema_upgrade, move_user_custom_actions, find_and_copy_custom_services
@@ -3689,7 +3689,7 @@ class TestAmbariServer(TestCase):
@patch("ambari_server.serverSetup.check_jdbc_drivers")
@patch("ambari_server.serverSetup.disable_security_enhancements")
@patch("ambari_server.serverSetup.is_root")
- @patch("ambari_server.serverSetup.proceedJDBCProperties")
+ @patch("ambari_server.serverSetup.setup_jdbc")
@patch("ambari_server.serverSetup.extract_views")
@patch("ambari_server.serverSetup.adjust_directory_permissions")
@patch("ambari_server.serverSetup.service_setup")
@@ -3697,7 +3697,7 @@ class TestAmbariServer(TestCase):
@patch("ambari_server.serverSetup.expand_jce_zip_file")
@patch("ambari_server.serverSetup.write_gpl_license_accepted")
def test_setup_linux(self, write_gpl_license_accepted_mock, expand_jce_zip_file_mock, read_ambari_user_mock,
- service_setup_mock, adjust_dirs_mock, extract_views_mock, proceedJDBCProperties_mock, is_root_mock,
+ service_setup_mock, adjust_dirs_mock, extract_views_mock, setup_jdbc_mock, is_root_mock,
disable_security_enhancements_mock, check_jdbc_drivers_mock, check_ambari_user_mock,
download_jdk_mock, configure_os_settings_mock, get_ambari_properties_mock,
get_YN_input_mock, gvsi_mock, gvsi_1_mock,
@@ -3901,7 +3901,7 @@ class TestAmbariServer(TestCase):
setup(args)
- self.assertTrue(proceedJDBCProperties_mock.called)
+ self.assertTrue(setup_jdbc_mock.called)
self.assertFalse(disable_security_enhancements_mock.called)
self.assertFalse(check_ambari_user_mock.called)
@@ -3930,14 +3930,14 @@ class TestAmbariServer(TestCase):
@patch("ambari_server.serverSetup.check_jdbc_drivers")
@patch("ambari_server.serverSetup.disable_security_enhancements")
@patch("ambari_server.serverSetup.is_root")
- @patch("ambari_server.serverSetup.proceedJDBCProperties")
+ @patch("ambari_server.serverSetup.setup_jdbc")
@patch("ambari_server.serverSetup.extract_views")
@patch("ambari_server.serverSetup.adjust_directory_permissions")
@patch("ambari_server.serverSetup.service_setup")
@patch("ambari_server.serverSetup.read_ambari_user")
@patch("ambari_server.serverSetup.expand_jce_zip_file")
def test_setup_windows(self, expand_jce_zip_file_mock, read_ambari_user_mock,
- service_setup_mock, adjust_dirs_mock, extract_views_mock, proceedJDBCProperties_mock, is_root_mock,
+ service_setup_mock, adjust_dirs_mock, extract_views_mock, setup_jdbc_mock, is_root_mock,
disable_security_enhancements_mock, check_jdbc_drivers_mock, check_ambari_user_mock, check_firewall_mock,
download_jdk_mock, configure_os_settings_mock, get_ambari_properties_mock,
get_YN_input_mock, gvsi_mock, gvsi_1_mock,
@@ -4063,7 +4063,7 @@ class TestAmbariServer(TestCase):
setup(args)
- self.assertTrue(proceedJDBCProperties_mock.called)
+ self.assertTrue(setup_jdbc_mock.called)
self.assertFalse(disable_security_enhancements_mock.called)
self.assertFalse(check_ambari_user_mock.called)
pass
@@ -4984,7 +4984,7 @@ class TestAmbariServer(TestCase):
@patch("os.remove")
@patch("os.symlink")
@patch("shutil.copy")
- def test_proceedJDBCProperties(self, copy_mock, os_symlink_mock, os_remove_mock, lexists_mock, exists_mock,
+ def test_setup_jdbc(self, copy_mock, os_symlink_mock, os_remove_mock, lexists_mock, exists_mock,
get_ambari_properties_mock, isfile_mock):
args = MagicMock()
@@ -4994,7 +4994,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("File test jdbc does not exist!", e.reason)
fail = True
@@ -5006,7 +5006,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("Unsupported database name incorrect db. Please see help for more information.", e.reason)
fail = True
@@ -5018,7 +5018,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("Error getting ambari properties", e.reason)
fail = True
@@ -5030,7 +5030,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("Error getting ambari properties", e.reason)
fail = True
@@ -5045,7 +5045,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
fail = True
self.assertTrue(fail)
@@ -5064,7 +5064,7 @@ class TestAmbariServer(TestCase):
copy_mock.side_effect = side_effect
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
fail = True
self.assertTrue(fail)
@@ -5081,7 +5081,7 @@ class TestAmbariServer(TestCase):
copy_mock.side_effect = None
isfile_mock.side_effect = [True, False]
- proceedJDBCProperties(args)
+ setup_jdbc(args)
self.assertTrue(os_remove_mock.called)
self.assertTrue(os_symlink_mock.called)
self.assertTrue(copy_mock.called)
@@ -5098,7 +5098,7 @@ class TestAmbariServer(TestCase):
@patch("os.remove")
@patch("os.symlink")
@patch("shutil.copy")
- def test_proceedJDBCProperties(self, copy_mock, os_symlink_mock, os_remove_mock, lexists_mock, exists_mock,
+ def test_setup_jdbc(self, copy_mock, os_symlink_mock, os_remove_mock, lexists_mock, exists_mock,
get_ambari_properties_mock, isfile_mock):
args = MagicMock()
@@ -5108,7 +5108,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("File test jdbc does not exist!", e.reason)
fail = True
@@ -5120,7 +5120,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("Unsupported database name incorrect db. Please see help for more information.", e.reason)
fail = True
@@ -5132,7 +5132,7 @@ class TestAmbariServer(TestCase):
fail = False
try:
- proceedJDBCProperties(args)
+ setup_jdbc(args)
except FatalException as e:
self.assertEquals("Error getting ambari properties", e.reason)
fail = True