Example #1
0
def main():
    '''
  Run the command
  :return:
  '''
    # verify if the environment variables are correctly set
    check_environment()

    # create the argument parser
    parser = create_parser()

    # if no argument is provided, print help and exit
    if len(sys.argv[1:]) == 0:
        parser.print_help()
        return 0

    # insert the boolean values for some of the options
    sys.argv = config.insert_bool_values(sys.argv)

    try:
        # parse the args
        args, unknown_args = parser.parse_known_args()
    except ValueError as ex:
        Log.error("Error while parsing arguments: %s", str(ex))
        Log.debug(traceback.format_exc())
        sys.exit(1)

    command_line_args = vars(args)

    # command to be execute
    command = command_line_args['subcommand']

    # file resources to be cleaned when exit
    files = []

    if command not in ('help', 'version'):
        log.set_logging_level(command_line_args)
        command_line_args = extract_common_args(command, parser,
                                                command_line_args)
        # bail out if args are empty
        if not command_line_args:
            return 1
        # register dirs cleanup function during exit
        files.append(command_line_args['override_config_file'])

    atexit.register(cleanup, files)

    # print the input parameters, if verbose is enabled
    Log.debug(command_line_args)

    start = time.time()
    resp = run(command, parser, command_line_args, unknown_args)
    response.render(resp)
    end = time.time()

    if command not in ('help', 'version'):
        sys.stdout.flush()
        Log.info('Elapsed time: %.3fs.', (end - start))

    return 0 if response.isAllSuccessful(resp) else 1
Example #2
0
def main():
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser()

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # command to be execute
  command = command_line_args['subcommand']

  # file resources to be cleaned when exit
  files = []

  if command not in ('help', 'version'):
    log.set_logging_level(command_line_args)
    command_line_args = extract_common_args(command, parser, command_line_args)
    # bail out if args are empty
    if not command_line_args:
      return 1
    # register dirs cleanup function during exit
    files.append(command_line_args['override_config_file'])

  atexit.register(cleanup, files)

  # print the input parameters, if verbose is enabled
  Log.debug(command_line_args)

  start = time.time()
  resp = run(command, parser, command_line_args, unknown_args)
  response.render(resp)
  end = time.time()

  if command not in ('help', 'version'):
    sys.stdout.flush()
    Log.info('Elapsed time: %.3fs.', (end - start))

  return 0 if response.isAllSuccessful(resp) else 1
Example #3
0
def main():
    """ main """
    # create the parser and parse the arguments
    (parser, _) = create_parsers()
    (args, remaining) = parser.parse_known_args()

    if remaining == ['help']:
        parser.print_help()
        parser.exit()

    elif remaining == ['version']:
        common_config.print_build_info()
        parser.exit()

    elif remaining != []:
        Log.error('Invalid subcommand')
        sys.exit(1)

    namespace = vars(args)

    log.set_logging_level(namespace)

    # set Tornado global option
    define_options(namespace['port'], namespace['config_file'])

    config = Config(create_tracker_config(namespace))

    # create Tornado application
    application = Application(config)

    # pylint: disable=unused-argument
    # SIGINT handler:
    # 1. stop all the running zkstatemanager and filestatemanagers
    # 2. stop the Tornado IO loop
    def signal_handler(signum, frame):
        # start a new line after ^C character because this looks nice
        print('\n', end='')
        application.stop()
        tornado.ioloop.IOLoop.instance().stop()

    # associate SIGINT and SIGTERM with a handler
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    Log.info("Running on port: %d", namespace['port'])
    if namespace["config_file"]:
        Log.info("Using config file: %s", namespace['config_file'])
    Log.info("Using state manager:\n" + str(config))

    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(namespace['port'])

    tornado.ioloop.IOLoop.instance().start()
Example #4
0
def main():
  """ main """
  # create the parser and parse the arguments
  (parser, _) = create_parsers()
  (args, remaining) = parser.parse_known_args()

  if remaining == ['help']:
    parser.print_help()
    parser.exit()

  elif remaining == ['version']:
    common_config.print_build_info()
    parser.exit()

  elif remaining != []:
    Log.error('Invalid subcommand')
    sys.exit(1)

  namespace = vars(args)

  log.set_logging_level(namespace)

  # set Tornado global option
  define_options(namespace['port'], namespace['config_file'])

  config = Config(create_tracker_config(namespace))

  # create Tornado application
  application = Application(config)

  # pylint: disable=unused-argument
  # SIGINT handler:
  # 1. stop all the running zkstatemanager and filestatemanagers
  # 2. stop the Tornado IO loop
  def signal_handler(signum, frame):
    # start a new line after ^C character because this looks nice
    print('\n', end='')
    application.stop()
    tornado.ioloop.IOLoop.instance().stop()

  # associate SIGINT and SIGTERM with a handler
  signal.signal(signal.SIGINT, signal_handler)
  signal.signal(signal.SIGTERM, signal_handler)

  Log.info("Running on port: %d", namespace['port'])
  if namespace["config_file"]:
    Log.info("Using config file: %s", namespace['config_file'])
  Log.info("Using state manager:\n" + str(config))

  http_server = tornado.httpserver.HTTPServer(application)
  http_server.listen(namespace['port'])

  tornado.ioloop.IOLoop.instance().start()
Example #5
0
def main(args):
    """ main """
    # create the argument parser
    parser = create_parser()

    # if no argument is provided, print help and exit
    if not args:
        parser.print_help()
        return 0

    # insert the boolean values for some of the options
    all_args = parse.insert_bool_values(args)

    # parse the args
    args, unknown_args = parser.parse_known_args(args=all_args)
    command_line_args = vars(args)
    command = command_line_args['subcommand']

    if unknown_args:
        Log.error('Unknown argument: %s', unknown_args[0])
        # show help message
        command_line_args['help-command'] = command
        command = 'help'

    if command not in ['help', 'version']:
        opts.set_tracker_url(command_line_args)
        log.set_logging_level(command_line_args)
        if command not in ['topologies', 'clusters']:
            command_line_args = extract_common_args(command, parser,
                                                    command_line_args)
        if not command_line_args:
            return 1
        Log.info("Using tracker URL: %s", command_line_args["tracker_url"])

    # timing command execution
    start = time.time()
    ret = run(command, parser, command_line_args, unknown_args)
    end = time.time()

    if command != 'help':
        sys.stdout.flush()
        Log.info('Elapsed time: %.3fs.', (end - start))

    return 0 if ret else 1
Example #6
0
def main(args):
  """ main """
  # create the argument parser
  parser = create_parser()

  # if no argument is provided, print help and exit
  if not args:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  all_args = parse.insert_bool_values(args)

  # parse the args
  args, unknown_args = parser.parse_known_args(args=all_args)
  command_line_args = vars(args)
  command = command_line_args['subcommand']

  if unknown_args:
    Log.error('Unknown argument: %s' % unknown_args[0])
    # show help message
    command_line_args['help-command'] = command
    command = 'help'

  if command not in ['help', 'version']:
    opts.set_tracker_url(command_line_args)
    log.set_logging_level(command_line_args)
    if command not in ['topologies', 'clusters']:
      command_line_args = extract_common_args(command, parser, command_line_args)
    if not command_line_args:
      return 1
    Log.info("Using tracker URL: %s", command_line_args["tracker_url"])

  # timing command execution
  start = time.time()
  ret = run(command, parser, command_line_args, unknown_args)
  end = time.time()

  if command != 'help':
    sys.stdout.flush()
    Log.info('Elapsed time: %.3fs.' % (end - start))

  return 0 if ret else 1
Example #7
0
def execute(handlers):
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser(handlers)

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # set log level
  log.set_logging_level(command_line_args)
  Log.debug("Input Command Line Args: %s", command_line_args)

  # command to be execute
  command = command_line_args['subcommand']

  # print the input parameters, if verbose is enabled
  Log.debug("Processed Command Line Args: %s", command_line_args)

  results = run(handlers, command, parser, command_line_args, unknown_args)

  return 0 if result.is_successful(results) else 1
Example #8
0
def execute(handlers, local_commands):
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser(handlers)

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # set log level
  log.set_logging_level(command_line_args)
  Log.debug("Input Command Line Args: %s", command_line_args)

# command to be execute
  command = command_line_args['subcommand']
  is_local_command = command in local_commands

  if command == 'version':
    results = run(handlers, command, parser, command_line_args, unknown_args)
    return 0 if result.is_successful(results) else 1

  if not is_local_command:
    log.set_logging_level(command_line_args)
    Log.debug("Input Command Line Args: %s", command_line_args)

    # determine the mode of deployment
    command_line_args = extract_common_args(command, parser, command_line_args)
    command_line_args = deployment_mode(command, parser, command_line_args)

    # bail out if args are empty
    if not command_line_args:
      return 1

    # register dirs cleanup function during exit
    if command_line_args['deploy_mode'] == config.DIRECT_MODE and command != "version":
      cleaned_up_files.append(command_line_args['override_config_file'])
      atexit.register(cleanup, cleaned_up_files)

  # print the input parameters, if verbose is enabled
  Log.debug("Processed Command Line Args: %s", command_line_args)

  start = time.time()
  results = run(handlers, command, parser, command_line_args, unknown_args)
  if not is_local_command:
    result.render(results)
  end = time.time()

  if not is_local_command:
    sys.stdout.flush()
    Log.debug('Elapsed time: %.3fs.', (end - start))

  return 0 if result.is_successful(results) else 1
Example #9
0
def execute(handlers, local_commands):
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser(handlers)

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # set log level
  log.set_logging_level(command_line_args)
  Log.debug("Input Command Line Args: %s", command_line_args)

# command to be execute
  command = command_line_args['subcommand']
  is_local_command = command in local_commands

  if command == 'version':
    results = run(handlers, command, parser, command_line_args, unknown_args)
    return 0 if result.is_successful(results) else 1

  if not is_local_command:
    log.set_logging_level(command_line_args)
    Log.debug("Input Command Line Args: %s", command_line_args)

    # determine the mode of deployment
    command_line_args = extract_common_args(command, parser, command_line_args)
    command_line_args = deployment_mode(command, parser, command_line_args)

    # bail out if args are empty
    if not command_line_args:
      return 1

    # register dirs cleanup function during exit
    if command_line_args['deploy_mode'] == config.DIRECT_MODE and command != "version":
      cleaned_up_files.append(command_line_args['override_config_file'])
      atexit.register(cleanup, cleaned_up_files)

  # print the input parameters, if verbose is enabled
  Log.debug("Processed Command Line Args: %s", command_line_args)

  start = time.time()
  results = run(handlers, command, parser, command_line_args, unknown_args)
  if not is_local_command:
    result.render(results)
  end = time.time()

  if not is_local_command:
    sys.stdout.flush()
    Log.debug('Elapsed time: %.3fs.', (end - start))

  return 0 if result.is_successful(results) else 1