Beispiel #1
0
def main(options, args, parser):
    # set silent
    set_silent(options.silent)

    # debug mode
    set_debug_mode_from_options(options)
    init_debug(options)

    #perform checks

    options.warnings = []

    if are_cmd_line_db_args_blank(options):
        options.must_set_database_options = True
    elif not are_cmd_line_db_args_valid(options):
        parser.error(
            'All database options should be set. Please see help for the options.'
        )
    else:
        options.must_set_database_options = False

    #correct database
    fix_database_options(options, parser)

    if len(args) == 0:
        print parser.print_help()
        parser.error("No action entered")

    action_map = create_user_action_map(args, options)

    action = args[0]

    try:
        action_obj = action_map[action]
    except KeyError:
        parser.error("Invalid action: " + action)

    matches = 0
    for args_number_required in action_obj.possible_args_numbers:
        matches += int(len(args) == args_number_required)

    if matches == 0:
        print parser.print_help()
        possible_args = ' or '.join(
            str(x) for x in action_obj.possible_args_numbers)
        parser.error("Invalid number of arguments. Entered: " +
                     str(len(args)) + ", required: " + possible_args)

    options.exit_message = "Ambari Server '%s' completed successfully." % action

    try:
        action_obj.execute()

        if action_obj.need_restart:
            pstatus, pid = is_server_runing()
            if pstatus:
                print 'NOTE: Restart Ambari Server to apply changes' + \
                      ' ("ambari-server restart|stop+start")'

        if options.warnings:
            for warning in options.warnings:
                print_warning_msg(warning)
                pass
            options.exit_message = "Ambari Server '%s' completed with warnings." % action
            pass
    except FatalException as e:
        if e.reason is not None:
            print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format(
                e.code, e.reason))
        sys.exit(e.code)
    except NonFatalException as e:
        options.exit_message = "Ambari Server '%s' completed with warnings." % action
        if e.reason is not None:
            print_warning_msg(e.reason)

    if options.exit_message is not None:
        print options.exit_message
Beispiel #2
0
def main(options, args, parser):
  # set silent
  set_silent(options.silent)

  # debug mode
  set_debug_mode_from_options(options)
  init_debug(options)

  #perform checks

  options.warnings = []

  if are_cmd_line_db_args_blank(options):
    options.must_set_database_options = True
  elif not are_cmd_line_db_args_valid(options):
    parser.error('All database options should be set. Please see help for the options.')
  else:
    options.must_set_database_options = False

  #correct database
  fix_database_options(options, parser)

  if len(args) == 0:
    print parser.print_help()
    parser.error("No action entered")

  action_map = create_user_action_map(args, options)

  action = args[0]

  try:
    action_obj = action_map[action]
  except KeyError:
    parser.error("Invalid action: " + action)

  matches = 0
  for args_number_required in action_obj.possible_args_numbers:
    matches += int(len(args) == args_number_required)

  if matches == 0:
    print parser.print_help()
    possible_args = ' or '.join(str(x) for x in action_obj.possible_args_numbers)
    parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args)

  options.exit_message = "Ambari Server '%s' completed successfully." % action

  try:
    action_obj.execute()

    if action_obj.need_restart:
      pstatus, pid = is_server_runing()
      if pstatus:
        print 'NOTE: Restart Ambari Server to apply changes' + \
              ' ("ambari-server restart|stop+start")'

    if options.warnings:
      for warning in options.warnings:
        print_warning_msg(warning)
        pass
      options.exit_message = "Ambari Server '%s' completed with warnings." % action
      pass
  except FatalException as e:
    if e.reason is not None:
      print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format(e.code, e.reason))
    sys.exit(e.code)
  except NonFatalException as e:
    options.exit_message = "Ambari Server '%s' completed with warnings." % action
    if e.reason is not None:
      print_warning_msg(e.reason)

  if options.exit_message is not None:
    print options.exit_message
Beispiel #3
0
def main(options, args, parser):
  init_logging()

  # set silent
  set_silent(options.silent)

  # debug mode
  set_debug_mode_from_options(options)
  init_debug(options)

  #perform checks

  options.warnings = []

  if len(args) == 0:
    print parser.print_help()
    parser.error("No action entered")

  action_map = create_user_action_map(args, options)

  action = args[0]

  try:
    action_obj = action_map[action]
  except KeyError:
    parser.error("Invalid action: " + action)

  if action == SETUP_ACTION:
    if are_cmd_line_db_args_blank(options):
      options.must_set_database_options = True
    elif not are_cmd_line_db_args_valid(options):
      parser.error('All database options should be set. Please see help for the options.')
    else:
      options.must_set_database_options = False

    #correct database
    fix_database_options(options, parser)

  matches = 0
  for args_number_required in action_obj.possible_args_numbers:
    matches += int(len(args) == args_number_required)

  if matches == 0:
    print parser.print_help()
    possible_args = ' or '.join(str(x) for x in action_obj.possible_args_numbers)
    parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args)

  options.exit_message = "Ambari Server '%s' completed successfully." % action
  options.exit_code = None

  try:
    if action in _action_option_dependence_map:
      required, optional = _action_option_dependence_map[action]
      for opt_str, opt_dest in required:
        if hasattr(options, opt_dest) and getattr(options, opt_dest) is None:
          print "Missing option {0} for action {1}".format(opt_str, action)
          print_action_arguments_help(action)
          print "Run ambari-server.py --help to see detailed description of each option"
          raise FatalException(1, "Missing option")
    action_obj.execute()

    if action_obj.need_restart:
      pstatus, pid = is_server_runing()
      if pstatus:
        print 'NOTE: Restart Ambari Server to apply changes' + \
              ' ("ambari-server restart|stop+start")'

    if options.warnings:
      for warning in options.warnings:
        print_warning_msg(warning)
        pass
      options.exit_message = "Ambari Server '%s' completed with warnings." % action
      pass
  except FatalException as e:
    if e.reason is not None:
      print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format(e.code, e.reason))
      logger.exception(str(e))
    sys.exit(e.code)
  except NonFatalException as e:
    options.exit_message = "Ambari Server '%s' completed with warnings." % action
    if e.reason is not None:
      print_warning_msg(e.reason)

  if options.exit_message is not None:
    print options.exit_message

  if options.exit_code is not None:  # not all actions may return a system exit code
    sys.exit(options.exit_code)
Beispiel #4
0
def main(options, args, parser):
    # init logger
    properties = get_ambari_properties()
    python_log_level = logging.INFO
    python_log_name = "ambari-server-command.log"

    custom_log_level = properties["server.python.log.level"]

    if custom_log_level:
        if custom_log_level == "INFO":
            python_log_level = logging.INFO
        if custom_log_level == "DEBUG":
            python_log_level = logging.DEBUG

    custom_log_name = properties["server.python.log.name"]

    if custom_log_name:
        python_log_name = custom_log_name

    python_log = os.path.join(configDefaults.OUT_DIR, python_log_name)

    setup_logging(logger, python_log, python_log_level)

    # set silent
    set_silent(options.silent)

    # debug mode
    set_debug_mode_from_options(options)
    init_debug(options)

    #perform checks

    options.warnings = []

    if are_cmd_line_db_args_blank(options):
        options.must_set_database_options = True
    elif not are_cmd_line_db_args_valid(options):
        parser.error(
            'All database options should be set. Please see help for the options.'
        )
    else:
        options.must_set_database_options = False

    #correct database
    fix_database_options(options, parser)

    if len(args) == 0:
        print parser.print_help()
        parser.error("No action entered")

    action_map = create_user_action_map(args, options)

    action = args[0]

    try:
        action_obj = action_map[action]
    except KeyError:
        parser.error("Invalid action: " + action)

    matches = 0
    for args_number_required in action_obj.possible_args_numbers:
        matches += int(len(args) == args_number_required)

    if matches == 0:
        print parser.print_help()
        possible_args = ' or '.join(
            str(x) for x in action_obj.possible_args_numbers)
        parser.error("Invalid number of arguments. Entered: " +
                     str(len(args)) + ", required: " + possible_args)

    options.exit_message = "Ambari Server '%s' completed successfully." % action
    options.exit_code = None

    try:
        action_obj.execute()

        if action_obj.need_restart:
            pstatus, pid = is_server_runing()
            if pstatus:
                print 'NOTE: Restart Ambari Server to apply changes' + \
                      ' ("ambari-server restart|stop+start")'

        if options.warnings:
            for warning in options.warnings:
                print_warning_msg(warning)
                pass
            options.exit_message = "Ambari Server '%s' completed with warnings." % action
            pass
    except FatalException as e:
        if e.reason is not None:
            print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format(
                e.code, e.reason))
            logger.exception(str(e))
        sys.exit(e.code)
    except NonFatalException as e:
        options.exit_message = "Ambari Server '%s' completed with warnings." % action
        if e.reason is not None:
            print_warning_msg(e.reason)

    if options.exit_message is not None:
        print options.exit_message

    if options.exit_code is not None:  # not all actions may return a system exit code
        sys.exit(options.exit_code)