Beispiel #1
0
def start_server(args, sentry_client):
    # type: (Namespace, SentryProxy) -> None

    log_level = logging.getLevelName(logging.getLogger().level)
    logging.info("begin. log_level={}".format(log_level))

    assert not (settings.debug and settings.num_processes > 1
                ), "debug mode does not support multiple processes"

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths,
                           "grouper_fe")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    # setup database
    logging.debug("configure database session")
    database_url = args.database_url or get_database_url(settings)
    Session.configure(bind=get_db_engine(database_url))

    usecase_factory = create_graph_usecase_factory(settings, Session())
    application = create_fe_application(settings, usecase_factory,
                                        args.deployment_name)

    address = args.address or settings.address
    port = args.port or settings.port

    ssl_context = get_plugin_proxy().get_ssl_context()

    logging.info("Starting application server with %d processes on port %d",
                 settings.num_processes, port)
    server = tornado.httpserver.HTTPServer(application,
                                           ssl_options=ssl_context)
    server.bind(port, address=address)
    # When using multiple processes, the forking happens here
    server.start(settings.num_processes)

    stats.set_defaults()

    # Create the Graph and start the config / graph update threads post fork to ensure each
    # process gets updated.

    settings.start_config_thread(args.config, "fe")

    with closing(Session()) as session:
        graph = Graph()
        graph.update_from_db(session)

    refresher = DbRefreshThread(settings, graph, settings.refresh_interval,
                                sentry_client)
    refresher.daemon = True
    refresher.start()

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        tornado.ioloop.IOLoop.instance().stop()
    finally:
        print("Bye")
Beispiel #2
0
def main(sys_argv=sys.argv, start_config_thread=True):
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")

    subparsers = parser.add_subparsers(dest="command")

    for subcommand_module in [
            dump_sql,
            group,
            oneoff,
            shell,
            sync_db,
            user,
            user_proxy,
    ]:
        subcommand_module.add_parser(subparsers)

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths,
                           "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    args.func(args)
Beispiel #3
0
def start_server(args, sentry_client):
    # type: (argparse.Namespace, SentryProxy) -> None

    log_level = logging.getLevelName(logging.getLogger().level)
    logging.info("begin. log_level={}".format(log_level))

    assert not (settings.debug and settings.num_processes > 1), \
        "debug mode does not support multiple processes"

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths, "grouper_api")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    # setup database
    logging.debug("configure database session")
    database_url = args.database_url or get_database_url(settings)
    Session.configure(bind=get_db_engine(database_url))

    settings.start_config_thread(args.config, "api")

    with closing(Session()) as session:
        graph = Graph()
        graph.update_from_db(session)

    refresher = DbRefreshThread(settings, graph, settings.refresh_interval, sentry_client)
    refresher.daemon = True
    refresher.start()

    application = get_application(graph, settings, sentry_client)

    address = args.address or settings.address
    port = args.port or settings.port

    logging.info("Starting application server on port %d", port)
    server = tornado.httpserver.HTTPServer(application)
    server.bind(port, address=address)
    server.start(settings.num_processes)

    stats.set_defaults()

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        tornado.ioloop.IOLoop.instance().stop()
    finally:
        print "Bye"
Beispiel #4
0
def main(sys_argv=sys.argv, start_config_thread=True):
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c", "--config", default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v", "--verbose", action="count", default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q", "--quiet", action="count", default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V", "--version", action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")

    subparsers = parser.add_subparsers(dest="command")

    for subcommand_module in [
            dump_sql,
            group,
            oneoff,
            shell,
            sync_db,
            user,
            user_proxy,
            ]:
        subcommand_module.add_parser(subparsers)

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths, "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    args.func(args)
Beispiel #5
0
def start_processor(args, sentry_client):
    # type: (argparse.Namespace, SentryProxy) -> None

    log_level = logging.getLevelName(logging.getLogger().level)
    logging.info("begin. log_level={}".format(log_level))

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths, "grouper-background")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    # setup database
    logging.debug("configure database session")
    Session.configure(bind=get_db_engine(get_database_url(settings)))

    settings.start_config_thread(args.config, "background")

    background = BackgroundProcessor(settings, sentry_client)
    background.run()
Beispiel #6
0
def main(sys_argv=sys.argv, start_config_thread=True, session=None):
    # type: (List[str], bool, Optional[Session]) -> None
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s %s" % __version__,
        help="Display version information.",
    )

    subparsers = parser.add_subparsers(dest="command")
    CtlCommandFactory.add_all_parsers(subparsers)

    # Add parsers for legacy commands that have not been refactored.
    for subcommand_module in [
            dump_sql,
            group,
            oneoff,
            service_account,
            shell,
            sync_db,
            user_proxy,
    ]:
        subcommand_module.add_parser(subparsers)  # type: ignore

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths,
                           "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    usecase_factory = create_sql_usecase_factory(settings, session)
    command_factory = CtlCommandFactory(usecase_factory)

    # Old-style subcommands store a func in callable when setting up their arguments.  New-style
    # subcommands are handled via a factory that constructs and calls the correct object.
    if getattr(args, "func", None):
        args.func(args)
    else:
        command = command_factory.construct_command(args.command)
        command.run(args)