Beispiel #1
0
def run(command, parser, args, unknown_args):
  '''
  :param command:
  :param parser:
  :param args:
  :param unknown_args:
  :return:
  '''
  config.print_build_info()
  return True
Beispiel #2
0
def run(command, parser, args, unknown_args):
  '''
  :param command:
  :param parser:
  :param args:
  :param unknown_args:
  :return:
  '''
  config.print_build_info()
  return SimpleResult(Status.Ok)
Beispiel #3
0
def run(command, parser, cl_args, unknown_args):
    '''
  :param command:
  :param parser:
  :param args:
  :param unknown_args:
  :return:
  '''
    cluster = cl_args['cluster']

    # server mode
    if cluster:
        config_file = config.heron_rc_file()
        client_confs = {}

        # Read the cluster definition, if not found
        client_confs = cdefs.read_server_mode_cluster_definition(
            cluster, cl_args, config_file)

        if not client_confs[cluster]:
            Log.error(
                'Neither service url nor %s cluster definition in %s file',
                cluster, config_file)
            return SimpleResult(Status.HeronError)

        # if cluster definition exists, but service_url is not set, it is an error
        if not 'service_url' in client_confs[cluster]:
            Log.error('No service url for %s cluster in %s', cluster,
                      config_file)
            sys.exit(1)

        service_endpoint = cl_args['service_url']
        service_apiurl = service_endpoint + rest.ROUTE_SIGNATURES[command][1]
        service_method = rest.ROUTE_SIGNATURES[command][0]

        try:
            r = service_method(service_apiurl)
            if r.status_code != requests.codes.ok:
                Log.error(r.json().get(
                    'message',
                    f"Unknown error from API server {r.status_code}"))
            sorted_items = sorted(list(r.json().items()),
                                  key=lambda tup: tup[0])
            for key, value in sorted_items:
                print(f"{key} : {value}")
        except (requests.exceptions.ConnectionError,
                requests.exceptions.HTTPError) as err:
            Log.error(err)
            return SimpleResult(Status.HeronError)
    else:
        config.print_build_info()

    return SimpleResult(Status.Ok)
Beispiel #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()
Beispiel #5
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()
Beispiel #6
0
def main():
    '''
  :param argv:
  :return:
  '''
    log.configure(logging.DEBUG)
    tornado.log.enable_pretty_logging()

    # create the parser and parse the arguments
    (parser, child_parser) = args.create_parsers()
    (parsed_args, remaining) = parser.parse_known_args()

    if remaining:
        r = child_parser.parse_args(args=remaining, namespace=parsed_args)
        namespace = vars(r)
        if 'version' in namespace:
            common_config.print_build_info(zipped_pex=True)
        else:
            parser.print_help()
        parser.exit()

    # log additional information
    command_line_args = vars(parsed_args)

    Log.info("Listening at http://%s:%d%s", command_line_args['address'],
             command_line_args['port'], command_line_args['base_url'])
    Log.info("Using tracker url: %s", command_line_args['tracker_url'])

    # pass the options to tornado and start the ui server
    define_options(command_line_args['address'], command_line_args['port'],
                   command_line_args['tracker_url'],
                   command_line_args['base_url'])
    http_server = tornado.httpserver.HTTPServer(
        Application(command_line_args['base_url']))
    http_server.listen(command_line_args['port'],
                       address=command_line_args['address'])

    # pylint: disable=unused-argument
    # stop Tornado IO loop
    def signal_handler(signum, frame):
        # start a new line after ^C character because this looks nice
        print '\n',
        Log.debug('SIGINT received. Stopping UI')
        tornado.ioloop.IOLoop.instance().stop()

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

    # start Tornado IO loop
    tornado.ioloop.IOLoop.instance().start()
Beispiel #7
0
def main():
  '''
  :param argv:
  :return:
  '''
  log.configure(logging.DEBUG)
  tornado.log.enable_pretty_logging()

  # create the parser and parse the arguments
  (parser, child_parser) = args.create_parsers()
  (parsed_args, remaining) = parser.parse_known_args()

  if remaining:
    r = child_parser.parse_args(args=remaining, namespace=parsed_args)
    namespace = vars(r)
    if 'version' in namespace:
      common_config.print_build_info(zipped_pex=True)
    else:
      parser.print_help()
    parser.exit()

  # log additional information
  command_line_args = vars(parsed_args)

  Log.info("Listening at http://%s:%d%s", command_line_args['address'],
           command_line_args['port'], command_line_args['base_url'])
  Log.info("Using tracker url: %s", command_line_args['tracker_url'])

  # pass the options to tornado and start the ui server
  define_options(command_line_args['address'],
                 command_line_args['port'],
                 command_line_args['tracker_url'],
                 command_line_args['base_url'])
  http_server = tornado.httpserver.HTTPServer(Application(command_line_args['base_url']))
  http_server.listen(command_line_args['port'], address=command_line_args['address'])

  # pylint: disable=unused-argument
  # stop Tornado IO loop
  def signal_handler(signum, frame):
    # start a new line after ^C character because this looks nice
    print('\n', end='')
    Log.debug('SIGINT received. Stopping UI')
    tornado.ioloop.IOLoop.instance().stop()

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

  # start Tornado IO loop
  tornado.ioloop.IOLoop.instance().start()
Beispiel #8
0
def run(command, parser, cl_args, unknown_args):
  '''
  :param command:
  :param parser:
  :param args:
  :param unknown_args:
  :return:
  '''
  cluster = cl_args['cluster']

  # server mode
  if cluster:
    config_file = config.heron_rc_file()
    client_confs = dict()

    # Read the cluster definition, if not found
    client_confs = cdefs.read_server_mode_cluster_definition(cluster, cl_args, config_file)

    if not client_confs[cluster]:
      Log.error('Neither service url nor %s cluster definition in %s file', cluster, config_file)
      return SimpleResult(Status.HeronError)

    # if cluster definition exists, but service_url is not set, it is an error
    if not 'service_url' in client_confs[cluster]:
      Log.error('No service url for %s cluster in %s', cluster, config_file)
      sys.exit(1)

    service_endpoint = cl_args['service_url']
    service_apiurl = service_endpoint + rest.ROUTE_SIGNATURES[command][1]
    service_method = rest.ROUTE_SIGNATURES[command][0]

    try:
      r = service_method(service_apiurl)
      if r.status_code != requests.codes.ok:
        Log.error(r.json().get('message', "Unknown error from api server %d" % r.status_code))
      sorted_items = sorted(r.json().items(), key=lambda tup: tup[0])
      for key, value in sorted_items:
        print("%s : %s" % (key, value))
    except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as err:
      Log.error(err)
      return SimpleResult(Status.HeronError)
  else:
    config.print_build_info()

  return SimpleResult(Status.Ok)
Beispiel #9
0
def run(command, parser, known_args, unknown_args):
  """ run command """
  config.print_build_info()
  return True
Beispiel #10
0
def run(command, parser, known_args, unknown_args):
    """ run command """
    config.print_build_info()
    return True
Beispiel #11
0
def show_version(_, __, value):
    if value:
        config.print_build_info()
        sys.exit(0)