Пример #1
0
def cli(
    config_file: str,
    stmgr_type: str,
    name: str,
    rootpath: str,
    tunnelhost: str,
    hostport: str,
    port: int,
    verbose: bool,
) -> None:
  """
  A HTTP service for serving data about clusters.

  The statemanager's config from the given config file can be overrided using
  options on this executable.

  """

  log.configure(logging.DEBUG if verbose else logging.INFO)

  # set Tornado global option
  define_options(port, config_file)

  stmgr_override = {
      "type": stmgr_type,
      "name": name,
      "rootpath": rootpath,
      "tunnelhost": tunnelhost,
      "hostport": hostport,
  }
  config = Config(create_tracker_config(config_file, stmgr_override))

  # 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", port)
  if config_file:
    Log.info("Using config file: %s", config_file)
  Log.info(f"Using state manager:\n{config}")

  http_server = tornado.httpserver.HTTPServer(application)
  http_server.listen(port)

  tornado.ioloop.IOLoop.instance().start()
Пример #2
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()
Пример #3
0
  def __init__(self):

    AsyncHTTPClient.configure(None, defaults=dict(request_timeout=120.0))
    config = Config(options.config_file)
    self.tracker = Tracker(config)
    self.tracker.synch_topologies()
    tornadoHandlers = [
        (r"/", handlers.MainHandler),
        (r"/clusters", handlers.ClustersHandler, {"tracker":self.tracker}),
        (r"/topologies", handlers.TopologiesHandler, {"tracker":self.tracker}),
        (r"/topologies/states", handlers.StatesHandler, {"tracker":self.tracker}),
        (r"/topologies/info", handlers.TopologyHandler, {"tracker":self.tracker}),
        (r"/topologies/logicalplan", handlers.LogicalPlanHandler, {"tracker":self.tracker}),
        (r"/topologies/containerfiledata", handlers.ContainerFileDataHandler,
         {"tracker":self.tracker}),
        (r"/topologies/containerfilestats",
         handlers.ContainerFileStatsHandler, {"tracker":self.tracker}),
        (r"/topologies/physicalplan", handlers.PhysicalPlanHandler, {"tracker":self.tracker}),
        # Deprecated. See https://github.com/twitter/heron/issues/1754
        (r"/topologies/executionstate", handlers.ExecutionStateHandler, {"tracker":self.tracker}),
        (r"/topologies/schedulerlocation", handlers.SchedulerLocationHandler,
         {"tracker":self.tracker}),
        (r"/topologies/metadata", handlers.MetaDataHandler, {"tracker":self.tracker}),
        (r"/topologies/runtimestate", handlers.RuntimeStateHandler, {"tracker":self.tracker}),
        (r"/topologies/metrics", handlers.MetricsHandler, {"tracker":self.tracker}),
        (r"/topologies/metricstimeline", handlers.MetricsTimelineHandler, {"tracker":self.tracker}),
        (r"/topologies/metricsquery", handlers.MetricsQueryHandler, {"tracker":self.tracker}),
        (r"/topologies/exceptions", handlers.ExceptionHandler, {"tracker":self.tracker}),
        (r"/topologies/exceptionsummary", handlers.ExceptionSummaryHandler,
         {"tracker":self.tracker}),
        (r"/machines", handlers.MachinesHandler, {"tracker":self.tracker}),
        (r"/topologies/pid", handlers.PidHandler, {"tracker":self.tracker}),
        (r"/topologies/jstack", handlers.JstackHandler, {"tracker":self.tracker}),
        (r"/topologies/jmap", handlers.JmapHandler, {"tracker":self.tracker}),
        (r"/topologies/histo", handlers.MemoryHistogramHandler, {"tracker":self.tracker}),
        (r"(.*)", handlers.DefaultHandler),
    ]

    settings = dict(
        debug=True,
        serve_traceback=True,
        static_path=os.path.dirname(__file__)
    )
    tornado.web.Application.__init__(self, tornadoHandlers, **settings)
    Log.info("Tracker has started")
Пример #4
0
def cli(
    config_file: str,
    stmgr_type: str,
    name: str,
    rootpath: str,
    tunnelhost: str,
    hostport: str,
    port: int,
    verbose: bool,
) -> None:
    """
  A HTTP service for serving data about clusters.

  The statemanager's config from the given config file can be overrided using
  options on this executable.

  """

    log_level = logging.DEBUG if verbose else logging.INFO
    log.configure(log_level)

    stmgr_override = {
        "type": stmgr_type,
        "name": name,
        "rootpath": rootpath,
        "tunnelhost": tunnelhost,
        "hostport": hostport,
    }
    config = Config(create_tracker_config(config_file, stmgr_override))

    state.tracker = Tracker(config)
    state.tracker.sync_topologies()
    # this only returns when interrupted
    uvicorn.run(app, host="0.0.0.0", port=port, log_level=log_level)
    state.tracker.stop_sync()

    # non-daemon threads linger and stop the process for quitting, so signal
    # for cleaning up
    os.kill(os.getpid(), signal.SIGKILL)