Repository: ambari Updated Branches: refs/heads/branch-2.5 8b5883316 -> dd33b2391
AMBARI-20026 Ambari server start returns prematurely before extracting views. (dsen) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dd33b239 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dd33b239 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dd33b239 Branch: refs/heads/branch-2.5 Commit: dd33b239176fe05ccad5e59442d2a04e24cf15a1 Parents: 8b58833 Author: Dmytro Sen <d...@apache.org> Authored: Wed Feb 15 19:07:19 2017 +0200 Committer: Dmytro Sen <d...@apache.org> Committed: Wed Feb 15 19:07:19 2017 +0200 ---------------------------------------------------------------------- .../python/ambari_server/serverConfiguration.py | 13 +++++ .../src/main/python/ambari_server/utils.py | 21 ++++++++ .../src/main/python/ambari_server_main.py | 56 +++++++++++--------- .../src/test/python/TestAmbariServer.py | 4 +- 4 files changed, 69 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/dd33b239/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 d3bfa70..d5d3baa 100644 --- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py +++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py @@ -694,6 +694,19 @@ def get_master_key_location(properties): keyLocation = properties[SECURITY_KEYS_DIR] return keyLocation +def get_ambari_server_ui_port(properties): + ambari_server_ui_port = CLIENT_API_PORT + client_api_port = properties.get_property(CLIENT_API_PORT_PROPERTY) + if client_api_port: + ambari_server_ui_port = client_api_port + api_ssl = properties.get_property(SSL_API) + if api_ssl and str(api_ssl).lower() == "true": + ambari_server_ui_port = DEFAULT_SSL_API_PORT + ssl_api_port = properties.get_property(SSL_API_PORT) + if ssl_api_port: + ambari_server_ui_port = ssl_api_port + return ambari_server_ui_port + # Copy file to /tmp and save with file.# (largest # is latest file) def backup_file_in_temp(filePath): if filePath is not None: http://git-wip-us.apache.org/repos/asf/ambari/blob/dd33b239/ambari-server/src/main/python/ambari_server/utils.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari_server/utils.py b/ambari-server/src/main/python/ambari_server/utils.py index f65ceed..6408285 100644 --- a/ambari-server/src/main/python/ambari_server/utils.py +++ b/ambari-server/src/main/python/ambari_server/utils.py @@ -28,6 +28,8 @@ import subprocess import logging import platform from ambari_commons import OSConst,OSCheck +from ambari_commons.logging_utils import print_error_msg +from ambari_commons.exceptions import FatalException logger = logging.getLogger(__name__) @@ -155,6 +157,25 @@ def get_live_pids_count(pids): """ return len([pid for pid in pids if pid_exists(pid)]) +def wait_for_ui_start(ambari_server_ui_port, timeout=1): + + tstart = time.time() + while int(time.time()-tstart) <= timeout: + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(1) + sock.connect(('localhost', ambari_server_ui_port)) + print "\nServer started listening on " + str(ambari_server_ui_port) + return True + except Exception as e: + #print str(e) + pass + + sys.stdout.write('.') + sys.stdout.flush() + time.sleep(1) + + return False def get_symlink_path(path_to_link): """ http://git-wip-us.apache.org/repos/asf/ambari/blob/dd33b239/ambari-server/src/main/python/ambari_server_main.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari_server_main.py b/ambari-server/src/main/python/ambari_server_main.py index df1b0a1..c7ae48a 100644 --- a/ambari-server/src/main/python/ambari_server_main.py +++ b/ambari-server/src/main/python/ambari_server_main.py @@ -32,7 +32,7 @@ from ambari_server.ambariPath import AmbariPath from ambari_server.dbConfiguration import ensure_dbms_is_running, ensure_jdbc_driver_is_installed from ambari_server.serverConfiguration import configDefaults, find_jdk, get_ambari_properties, \ get_conf_dir, get_is_persisted, get_is_secure, get_java_exe_path, get_original_master_key, read_ambari_user, \ - get_is_active_instance, update_properties, \ + get_is_active_instance, update_properties, get_ambari_server_ui_port, \ PID_NAME, SECURITY_KEY_ENV_VAR_NAME, SECURITY_MASTER_KEY_LOCATION, \ SETUP_OR_UPGRADE_MSG, check_database_name_property, parse_properties_file, get_missing_properties from ambari_server.serverUtils import refresh_stack_hash @@ -40,7 +40,7 @@ from ambari_server.setupHttps import get_fqdn from ambari_server.setupSecurity import generate_env, \ ensure_can_start_under_current_user from ambari_server.utils import check_reverse_lookup, save_pid, locate_file, locate_all_file_paths, looking_for_pid, \ - save_main_pid_ex, check_exitcode, get_live_pids_count + save_main_pid_ex, check_exitcode, get_live_pids_count, wait_for_ui_start from ambari_server.serverClassPath import ServerClassPath logger = logging.getLogger(__name__) @@ -102,8 +102,9 @@ SERVER_START_CMD_DEBUG_WINDOWS = "{0} " \ "-cp {3} " \ "org.apache.ambari.server.controller.AmbariServer" -SERVER_START_TIMEOUT = 5 +SERVER_START_TIMEOUT = 5 #seconds SERVER_START_RETRIES = 4 +WEB_UI_INIT_TIME = 50 #seconds SERVER_PING_TIMEOUT_WINDOWS = 5 SERVER_PING_ATTEMPTS_WINDOWS = 4 @@ -203,6 +204,11 @@ def wait_for_server_start(pidFile, scmStatus): @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT) def wait_for_server_start(pidFile, scmStatus): + properties = get_ambari_properties() + if properties == -1: + err ="Error getting ambari properties" + raise FatalException(-1, err) + #wait for server process for SERVER_START_TIMEOUT seconds sys.stdout.write('Waiting for server start...') sys.stdout.flush() @@ -211,42 +217,44 @@ def wait_for_server_start(pidFile, scmStatus): # looking_for_pid() might return partrial pid list on slow hardware for i in range(1, SERVER_START_RETRIES): pids = looking_for_pid(SERVER_SEARCH_PATTERN, SERVER_START_TIMEOUT) - - sys.stdout.write('\n') - sys.stdout.flush() - if save_main_pid_ex(pids, pidFile, locate_all_file_paths('sh', '/bin') + locate_all_file_paths('bash', '/bin') + locate_all_file_paths('dash', '/bin'), IS_FOREGROUND): server_started = True - sys.stdout.write("Server PID determined "+AMBARI_SERVER_STARTED_SUCCESS_MSG+"\n") break else: sys.stdout.write("Unable to determine server PID. Retrying...\n") sys.stdout.flush() + exception = None + if server_started: + ambari_server_ui_port = get_ambari_server_ui_port(properties) + if not wait_for_ui_start(int(ambari_server_ui_port), WEB_UI_INIT_TIME): + exception = FatalException(1, "Server not yet listening on http port " + ambari_server_ui_port + \ + " after " + str(WEB_UI_INIT_TIME) + " seconds. Exiting.") + elif get_live_pids_count(pids) <= 0: + exitcode = check_exitcode(os.path.join(configDefaults.PID_DIR, EXITCODE_NAME)) + exception = FatalException(-1, AMBARI_SERVER_DIE_MSG.format(exitcode, configDefaults.SERVER_OUT_FILE)) + else: + exception = FatalException(-1, AMBARI_SERVER_NOT_STARTED_MSG) + if os.path.isfile(configDefaults.SERVER_OUT_FILE): if 'Database consistency check: failed' in open(configDefaults.SERVER_OUT_FILE).read(): - print "DB configs consistency check failed. Run \"ambari-server start --skip-database-check\" to skip. " \ - "You may try --auto-fix-database flag to attempt to fix issues automatically. " \ - "If you use this \"--skip-database-check\" option, do not make any changes to your cluster topology " \ - "or perform a cluster upgrade until you correct the database consistency issues. See " + \ - configDefaults.DB_CHECK_LOG + "for more details on the consistency issues." + print "DB configs consistency check failed. Run \"ambari-server start --skip-database-check\" to skip. " \ + "You may try --auto-fix-database flag to attempt to fix issues automatically. " \ + "If you use this \"--skip-database-check\" option, do not make any changes to your cluster topology " \ + "or perform a cluster upgrade until you correct the database consistency issues. See " + \ + configDefaults.DB_CHECK_LOG + " for more details on the consistency issues." elif 'Database consistency check: warning' in open(configDefaults.SERVER_OUT_FILE).read(): - print "DB configs consistency check found warnings. See " + \ - configDefaults.DB_CHECK_LOG + " for more details." + print "DB configs consistency check found warnings. See " + configDefaults.DB_CHECK_LOG + " for more details." else: - print "DB configs consistency check: no errors and warnings were found." + print "DB configs consistency check: no errors and warnings were found." else: - sys.stdout.write(configDefaults.SERVER_OUT_FILE + " does not exist") + sys.stdout.write(configDefaults.SERVER_OUT_FILE + " does not exist") + + if exception: + raise exception - if server_started: - return - elif get_live_pids_count(pids) <= 0: - exitcode = check_exitcode(os.path.join(configDefaults.PID_DIR, EXITCODE_NAME)) - raise FatalException(-1, AMBARI_SERVER_DIE_MSG.format(exitcode, configDefaults.SERVER_OUT_FILE)) - else: - raise FatalException(-1, AMBARI_SERVER_NOT_STARTED_MSG) def server_process_main(options, scmStatus=None): properties = get_ambari_properties() http://git-wip-us.apache.org/repos/asf/ambari/blob/dd33b239/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 8692030..ed99533 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -4392,6 +4392,7 @@ class TestAmbariServer(TestCase): @patch("sys.stdout.flush") @patch("sys.stdout.write") @patch("ambari_server_main.looking_for_pid") + @patch("ambari_server_main.wait_for_ui_start") @patch("ambari_server_main.save_main_pid_ex") @patch("ambari_server_main.check_exitcode") @patch("os.makedirs") @@ -4441,7 +4442,7 @@ class TestAmbariServer(TestCase): save_master_key_method, get_master_key_location_method, os_chown_mock, is_server_running_mock, locate_file_mock, os_makedirs_mock, check_exitcode_mock, save_main_pid_ex_mock, - looking_for_pid_mock, stdout_write_mock, stdout_flush_mock, + wait_for_ui_start_mock, looking_for_pid_mock, stdout_write_mock, stdout_flush_mock, get_is_active_instance_mock): def reset_mocks(): @@ -4478,6 +4479,7 @@ class TestAmbariServer(TestCase): "exe": "/test", "cmd": "test arg" }] + wait_for_ui_start_mock.return_value = True check_exitcode_mock.return_value = 0 p = Properties()