Пример #1
0
def fix_database_options(options, parser):
  if options.dbms == 'embedded':
    print "WARNING: HostName for postgres server " + options.database_host + \
          " will be ignored: using localhost."
    options.database_host = "localhost"
    options.dbms = 'postgres'
    options.persistence_type = 'local'
    options.database_index = 0
  elif options.dbms is not None and options.dbms not in DATABASE_NAMES:
    parser.print_help()
    parser.error("Unsupported Database " + options.dbms)
  elif options.dbms is not None:
    options.dbms = options.dbms.lower()
    options.database_index = LINUX_DBMS_KEYS_LIST.index(options.dbms)

  _validate_database_port(options, parser)

  # jdbc driver and db options validation
  if options.jdbc_driver is None and options.jdbc_db is not None:
    parser.error("Option --jdbc-db is used only in pair with --jdbc-driver")
  elif options.jdbc_driver is not None and options.jdbc_db is None:
    parser.error("Option --jdbc-driver is used only in pair with --jdbc-db")

  if options.sid_or_sname.lower() not in ["sid", "sname"]:
    print "WARNING: Valid values for sid_or_sname are 'sid' or 'sname'. Use 'sid' if the db identifier type is " \
          "Service ID. Use 'sname' if the db identifier type is Service Name"
    parser.print_help()
    exit(-1)
  else:
    options.sid_or_sname = options.sid_or_sname.lower()
Пример #2
0
def fix_database_options(options, parser):
  if options.dbms == 'embedded':
    print "WARNING: HostName for postgres server " + options.database_host + \
          " will be ignored: using localhost."
    options.database_host = "localhost"
    options.dbms = 'postgres'
    options.persistence_type = 'local'
    options.database_index = 0
  elif options.dbms is not None and options.dbms not in DATABASE_NAMES:
    parser.print_help()
    parser.error("Unsupported Database " + options.dbms)
  elif options.dbms is not None:
    options.dbms = options.dbms.lower()
    options.database_index = LINUX_DBMS_KEYS_LIST.index(options.dbms)

  _validate_database_port(options, parser)

  # jdbc driver and db options validation
  if options.jdbc_driver is None and options.jdbc_db is not None:
    parser.error("Option --jdbc-db is used only in pair with --jdbc-driver")
  elif options.jdbc_driver is not None and options.jdbc_db is None:
    parser.error("Option --jdbc-driver is used only in pair with --jdbc-db")

  if options.sid_or_sname.lower() not in ["sid", "sname"]:
    print "WARNING: Valid values for sid_or_sname are 'sid' or 'sname'. Use 'sid' if the db identifier type is " \
          "Service ID. Use 'sname' if the db identifier type is Service Name"
    parser.print_help()
    exit(-1)
  else:
    options.sid_or_sname = options.sid_or_sname.lower()
Пример #3
0
def run_mpack_install_checker(options, mpack_stacks):
    """
  Run MpackInstallChecker to validate that there is no cluster deployed with a stack that is not included in the management pack
  :param options: Options passed
  :param mpack_stacks: List of stacks included in the management pack
  :return: Output of MpackInstallChecker
  """
    properties = get_ambari_properties()
    database_type = properties[JDBC_DATABASE_PROPERTY]
    jdk_path = get_java_exe_path()

    if not jdk_path or not database_type:
        # Ambari Server has not been setup, so no cluster would be present
        return (0, "", "")

    parse_properties_file(options)
    options.database_index = LINUX_DBMS_KEYS_LIST.index(
        properties[JDBC_DATABASE_PROPERTY])
    ensure_jdbc_driver_is_installed(options, properties)

    serverClassPath = ServerClassPath(properties, options)
    class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell()

    command = MPACK_INSTALL_CHECKER_CMD.format(jdk_path, class_path,
                                               ",".join(mpack_stacks))

    ambari_user = read_ambari_user()
    current_user = ensure_can_start_under_current_user(ambari_user)
    environ = generate_env(options, ambari_user, current_user)

    return run_os_command(command, env=environ)
Пример #4
0
def check_database(options):
    logger.info("Check database consistency.")
    jdk_path = serverConfiguration.get_java_exe_path()

    if jdk_path is None:
        print_error_msg(
            "No JDK found, please run the \"setup\" "
            "command to install a JDK automatically or install any "
            "JDK manually to " + configDefaults.JDK_INSTALL_DIR)
        sys.exit(1)

    properties = serverConfiguration.get_ambari_properties()
    serverConfiguration.parse_properties_file(options)

    database_type = properties[JDBC_DATABASE_PROPERTY]
    if not database_type:
        print_error_msg("Please run \"ambari-server setup\" command"
                        " to initialize ambari db properties.")
        sys.exit(1)

    options.database_index = LINUX_DBMS_KEYS_LIST.index(
        properties[JDBC_DATABASE_PROPERTY])

    dbConfiguration.ensure_jdbc_driver_is_installed(
        options, serverConfiguration.get_ambari_properties())

    serverClassPath = ServerClassPath(
        serverConfiguration.get_ambari_properties(), options)
    class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell()

    command = CHECK_DATABASE_HELPER_CMD.format(jdk_path, class_path)

    ambari_user = serverConfiguration.read_ambari_user()
    current_user = setupSecurity.ensure_can_start_under_current_user(
        ambari_user)
    environ = setupSecurity.generate_env(options, ambari_user, current_user)

    (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ)

    if retcode > 0:
        print str(stdout)
        raise FatalException(
            1, 'Database check failed to complete. Please check ' +
            configDefaults.SERVER_LOG_FILE + ' and ' +
            configDefaults.DB_CHECK_LOG + ' for more information.')
    else:
        print str(stdout)
        if not stdout.startswith("No errors"):
            print "Ambari Server 'check-database' completed"
            sys.exit(1)
Пример #5
0
def upgrade_stack(args):
    logger.info("Upgrade stack.")
    if not is_root():
        err = 'Ambari-server upgradestack should be run with ' \
              'root-level privileges'
        raise FatalException(4, err)

    check_database_name_property()

    try:
        stack_id = args[1]
    except IndexError:
        #stack_id is mandatory
        raise FatalException("Invalid number of stack upgrade arguments")

    try:
        repo_url = args[2]
    except IndexError:
        repo_url = None

    try:
        repo_url_os = args[3]
    except IndexError:
        repo_url_os = None

    parser = optparse.OptionParser()
    parser.add_option("-d", type="int", dest="database_index")

    db = get_ambari_properties()[JDBC_DATABASE_PROPERTY]

    idx = LINUX_DBMS_KEYS_LIST.index(db)

    (options, opt_args) = parser.parse_args(["-d {0}".format(idx)])

    stack_name, stack_version = stack_id.split(STACK_NAME_VER_SEP)
    retcode = run_stack_upgrade(options, stack_name, stack_version, repo_url,
                                repo_url_os)

    if not retcode == 0:
        raise FatalException(retcode, 'Stack upgrade failed.')

    return retcode
Пример #6
0
def check_database(options):

    jdk_path = serverConfiguration.get_java_exe_path()

    if jdk_path is None:
        print_error_msg(
            "No JDK found, please run the \"setup\" "
            "command to install a JDK automatically or install any "
            "JDK manually to " + configDefaults.JDK_INSTALL_DIR)
        sys.exit(1)

    properties = serverConfiguration.get_ambari_properties()
    serverConfiguration.parse_properties_file(options)
    options.database_index = LINUX_DBMS_KEYS_LIST.index(
        properties[JDBC_DATABASE_PROPERTY])

    dbConfiguration.ensure_jdbc_driver_is_installed(
        options, serverConfiguration.get_ambari_properties())

    serverClassPath = ServerClassPath(
        serverConfiguration.get_ambari_properties(), options)
    class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell()

    command = CHECK_DATABASE_HELPER_CMD.format(jdk_path, class_path)

    ambari_user = serverConfiguration.read_ambari_user()
    current_user = setupSecurity.ensure_can_start_under_current_user(
        ambari_user)
    environ = setupSecurity.generate_env(options, ambari_user, current_user)

    (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ)
    print_info_msg("Return code from check database command, retcode = " +
                   str(retcode))

    if retcode > 0:
        print_error_msg(
            "Database check failed to complete. Please check ambari-server.log and ambari-server-check-database.log for problem."
        )
        raise FatalException(1, 'Database check failed.')
    else:
        print str(stdout)
Пример #7
0
def upgrade_stack(args):
  if not is_root():
    err = 'Ambari-server upgradestack should be run with ' \
          'root-level privileges'
    raise FatalException(4, err)

  check_database_name_property()

  try:
    stack_id = args[1]
  except IndexError:
    #stack_id is mandatory
    raise FatalException("Invalid number of stack upgrade arguments")

  try:
    repo_url = args[2]
  except IndexError:
    repo_url = None

  try:
    repo_url_os = args[3]
  except IndexError:
    repo_url_os = None

  parser = optparse.OptionParser()
  parser.add_option("-d", type="int", dest="database_index")

  db = get_ambari_properties()[JDBC_DATABASE_PROPERTY]

  idx = LINUX_DBMS_KEYS_LIST.index(db)

  (options, opt_args) = parser.parse_args(["-d {0}".format(idx)])

  stack_name, stack_version = stack_id.split(STACK_NAME_VER_SEP)
  retcode = run_stack_upgrade(options, stack_name, stack_version, repo_url, repo_url_os)

  if not retcode == 0:
    raise FatalException(retcode, 'Stack upgrade failed.')

  return retcode
Пример #8
0
def update_host_names(args, options):
    services_stopped = userInput.get_YN_input(
        "Please, confirm Ambari services are stopped [y/n] (n)? ", False)
    if not services_stopped:
        print 'Exiting...'
        sys.exit(1)

    pending_commands = userInput.get_YN_input(
        "Please, confirm there are no pending commands on cluster [y/n] (n)? ",
        False)
    if not pending_commands:
        print 'Exiting...'
        sys.exit(1)

    db_backup_done = userInput.get_YN_input(
        "Please, confirm you have made backup of the Ambari db [y/n] (n)? ",
        False)
    if not db_backup_done:
        print 'Exiting...'
        sys.exit(1)

    status, pid = serverUtils.is_server_runing()
    if status:
        raise FatalException(1, "Ambari Server should be stopped")

    try:
        host_mapping_file_path = args[1]
    except IndexError:
        #host_mapping file is mandatory
        raise FatalException(
            1,
            "Invalid number of host update arguments. Probably, you forgot to add json file with "
            "host changes.")

    if not os.path.isfile(host_mapping_file_path):
        raise FatalException(1, "Invalid file path or file doesn't exist")

    if not os.access(host_mapping_file_path, os.R_OK):
        raise FatalException(1, "File is not readable")

    jdk_path = serverConfiguration.get_java_exe_path()

    if jdk_path is None:
        print_error_msg(
            "No JDK found, please run the \"setup\" "
            "command to install a JDK automatically or install any "
            "JDK manually to " + configDefaults.JDK_INSTALL_DIR)
        sys.exit(1)

    properties = serverConfiguration.get_ambari_properties()
    serverConfiguration.parse_properties_file(options)
    options.database_index = LINUX_DBMS_KEYS_LIST.index(
        properties[JDBC_DATABASE_PROPERTY])

    dbConfiguration.ensure_jdbc_driver_is_installed(
        options, serverConfiguration.get_ambari_properties())

    serverClassPath = ServerClassPath(
        serverConfiguration.get_ambari_properties(), options)
    class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell()

    command = HOST_UPDATE_HELPER_CMD.format(jdk_path, class_path,
                                            host_mapping_file_path)

    ambari_user = serverConfiguration.read_ambari_user()
    current_user = setupSecurity.ensure_can_start_under_current_user(
        ambari_user)
    environ = setupSecurity.generate_env(options, ambari_user, current_user)

    (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ)
    print_info_msg("Return code from update host names command, retcode = " +
                   str(retcode))

    if retcode > 0:
        print_error_msg(
            "Error executing update host names, please check the server logs.")
        raise FatalException(1, 'Host names update failed.')
    else:
        print_info_msg('Host names update completed successfully')
Пример #9
0
def update_host_names(args, options):
  services_stopped = userInput.get_YN_input("Please, confirm Ambari services are stopped [y/n] (n)? ", False)
  if not services_stopped:
    print 'Exiting...'
    sys.exit(1)

  pending_commands = userInput.get_YN_input("Please, confirm there are no pending commands on cluster [y/n] (n)? ", False)
  if not pending_commands:
    print 'Exiting...'
    sys.exit(1)

  db_backup_done = userInput.get_YN_input("Please, confirm you have made backup of the Ambari db [y/n] (n)? ", False)
  if not db_backup_done:
    print 'Exiting...'
    sys.exit(1)

  status, pid = serverUtils.is_server_runing()
  if status:
    raise FatalException(1, "Ambari Server should be stopped")

  try:
    host_mapping_file_path = args[1]
  except IndexError:
    #host_mapping file is mandatory
    raise FatalException(1, "Invalid number of host update arguments. Probably, you forgot to add json file with "
                            "host changes.")

  if not os.path.isfile(host_mapping_file_path):
    raise FatalException(1, "Invalid file path or file doesn't exist")

  if not os.access(host_mapping_file_path, os.R_OK):
    raise FatalException(1, "File is not readable")

  jdk_path = serverConfiguration.get_java_exe_path()

  if jdk_path is None:
    print_error_msg("No JDK found, please run the \"setup\" "
                    "command to install a JDK automatically or install any "
                    "JDK manually to " + configDefaults.JDK_INSTALL_DIR)
    sys.exit(1)

  properties = serverConfiguration.get_ambari_properties()
  serverConfiguration.parse_properties_file(options)
  options.database_index = LINUX_DBMS_KEYS_LIST.index(properties[JDBC_DATABASE_PROPERTY])

  dbConfiguration.ensure_jdbc_driver_is_installed(options, serverConfiguration.get_ambari_properties())

  serverClassPath = ServerClassPath(serverConfiguration.get_ambari_properties(), options)
  class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell()

  command = HOST_UPDATE_HELPER_CMD.format(jdk_path, class_path, host_mapping_file_path)

  ambari_user = serverConfiguration.read_ambari_user()
  current_user = setupSecurity.ensure_can_start_under_current_user(ambari_user)
  environ = setupSecurity.generate_env(options, ambari_user, current_user)

  (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ)
  print_info_msg("Return code from update host names command, retcode = " + str(retcode))

  if retcode > 0:
    print_error_msg("Error executing update host names, please check the server logs.")
    raise FatalException(1, 'Host names update failed.')
  else:
    print_info_msg('Host names update completed successfully')