Exemplo n.º 1
0
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()
    pids = []
    server_started = False
    # 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
            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 '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."
    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."
    else:
        print "DB configs consistency check: no errors and warnings were found."

    if exception:
        raise exception
Exemplo n.º 2
0
def wait_for_pid(pids, server_init_timeout, occupy_port_timeout,
                 init_web_ui_timeout, server_out_file, db_check_log,
                 properties):
    """
    Check pid for existence during timeout
  """
    from ambari_server.serverConfiguration import get_ambari_server_ui_port
    ambari_server_ui_port = int(get_ambari_server_ui_port(properties))
    server_ui_port_occupied = False
    tstart = time.time()
    pid_live = 0
    while int(time.time() - tstart) <= occupy_port_timeout and len(pids) > 0:
        sys.stdout.write('.')
        sys.stdout.flush()
        pid_live = 0
        for item in pids:
            if pid_exists(item["pid"]):
                pid_live += 1
        time.sleep(1)

        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)
            server_ui_port_occupied = True
            break
        except Exception as e:
            #print str(e)
            pass

    if 'Database consistency check: failed' in open(server_out_file).read():
        print "\nDB configs consistency check failed. Run \"ambari-server start --skip-database-check\" to skip. " \
              "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 " + \
              db_check_log + "for more details on the consistency issues."
    elif 'Database consistency check: warning' in open(server_out_file).read():
        print "\nDB configs consistency check found warnings. See " + db_check_log + " for more details."
    else:
        print "\nDB configs consistency check: no errors and warnings were found."

    if not server_ui_port_occupied:
        raise FatalException(
            1, "Server not yet listening on http port " +
            str(ambari_server_ui_port) + " after " +
            str(occupy_port_timeout + server_init_timeout) +
            " seconds. Exiting.")

    tstart = time.time()
    print "Waiting for 10 seconds, for server WEB UI initialization"
    while int(time.time() - tstart) <= init_web_ui_timeout and len(pids) > 0:
        sys.stdout.write('.')
        sys.stdout.flush()
        pid_live = 0
        for item in pids:
            if pid_exists(item["pid"]):
                pid_live += 1
        time.sleep(1)

    return pid_live
Exemplo n.º 3
0
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()
    pids = []
    pid = None
    # 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)
        pid = 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)
        if pid:
            break
        else:
            sys.stdout.write("Unable to determine server PID. Retrying...\n")
            sys.stdout.flush()

    exception = None
    if pid:
        ambari_server_ui_port = get_ambari_server_ui_port(properties)
        web_server_startup_timeout = get_web_server_startup_timeout(properties)
        waitStart = time.time()
        if not wait_for_ui_start(int(ambari_server_ui_port), pid,
                                 web_server_startup_timeout):
            waitTime = int(time.time() - waitStart)
            # Java process stopped, due to a DB check or other startup issue
            if waitTime < web_server_startup_timeout:
                exception = FatalException(-1, AMBARI_SERVER_STOPPED)
            # UI didn't come up on time
            else:
                exception = FatalException(
                    1,
                    AMBARI_SERVER_UI_TIMEOUT.format(
                        ambari_server_ui_port, web_server_startup_timeout))
    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 'DB_CHECK_ERROR' in open(configDefaults.SERVER_OUT_FILE).read():
            print "\nDB 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 'DB_CHECK_WARNING' in open(configDefaults.SERVER_OUT_FILE).read():
            print "\nDB configs consistency check found warnings. See " + configDefaults.DB_CHECK_LOG + " for more details."
        # Only presume that DB check was successful if it explicitly appears in the log. An unexpected error may prevent
        # the consistency check from running at all, so missing error/warning message in the log cannot imply the check was
        # successful
        elif 'DB_CHECK_SUCCESS' in open(configDefaults.SERVER_OUT_FILE).read():
            print "\nDB configs consistency check: no errors and warnings were found."
    else:
        sys.stdout.write(configDefaults.SERVER_OUT_FILE + " does not exist")

    if exception:
        raise exception