Exemple #1
0
def main(
        ctx: typer.Context,
        _: bool = typer.Option(None, "--version", "-v", callback=version_callback, is_eager=True),
        debug: bool = typer.Option(False, "--debug", "-d"),
        config_dir: str = typer.Option(State.FUNCX_DIR, "--config_dir", "-c", help="override default config dir")
):
    # Note: no docstring here; the docstring for @app.callback is used as a help message for overall app.
    # Sets up global variables in the State wrapper (debug flag, config dir, default config file).
    # For commands other than `init`, we ensure the existence of the config directory and file.

    global logger
    funcx.set_stream_logger(level=logging.DEBUG if debug else logging.INFO)
    logger = logging.getLogger('funcx')
    logger.debug("Command: {}".format(ctx.invoked_subcommand))

    # Set global state variables, to avoid passing them around as arguments all the time
    State.DEBUG = debug
    State.FUNCX_DIR = config_dir
    State.FUNCX_CONFIG_FILE = os.path.join(State.FUNCX_DIR, FUNCX_CONFIG_FILE_NAME)

    # Otherwise, we ensure that configs exist
    if not os.path.exists(State.FUNCX_CONFIG_FILE):
        logger.info(f"No existing configuration found at {State.FUNCX_CONFIG_FILE}. Initializing...")
        init_endpoint()

    logger.debug("Loading config files from {}".format(State.FUNCX_DIR))

    funcx_config = SourceFileLoader('global_config', State.FUNCX_CONFIG_FILE).load_module()
    State.FUNCX_CONFIG = funcx_config.global_options
Exemple #2
0
import argparse
import time

import funcx
from funcx import set_stream_logger
from funcx.sdk.client import FuncXClient
from funcx.serialize import FuncXSerializer

fxs = FuncXSerializer()

set_stream_logger()


def sum_yadu_new01(event):
    return sum(event)


"""
@funcx.register(description="...")
def sum_yadu_new01(event):
    return sum(event)
"""


def test(fxc, ep_id):
    fn_uuid = fxc.register_function(
        sum_yadu_new01,
        description="New sum function defined without string spec")
    print("FN_UUID : ", fn_uuid)

    task_id = fxc.run([1, 2, 3, 9001], endpoint_id=ep_id, function_id=fn_uuid)
Exemple #3
0
import argparse

import funcx
from funcx_endpoint.endpoint.utils.config import Config
from funcx_endpoint.executors.high_throughput.interchange import Interchange

funcx.set_stream_logger()

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-a", "--address", required=True, help="Address")
    parser.add_argument("-c", "--client_ports", required=True, help="ports")
    args = parser.parse_args()
    config = Config()

    ic = Interchange(
        client_address=args.address,
        client_ports=[int(i) for i in args.client_ports.split(",")],
    )
    ic.start()
    print("Interchange started")
Exemple #4
0
def cli_run():
    """ Entry point for funcx-endpoint
    """
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(dest='command')
    parser.add_argument("-v",
                        "--version",
                        help="Print Endpoint version information")
    parser.add_argument("-d",
                        "--debug",
                        action='store_true',
                        help="Enables debug logging")
    parser.add_argument("-c",
                        "--config_dir",
                        default='{}/.funcx'.format(pathlib.Path.home()),
                        help="Path to funcx config directory")

    # Init Endpoint
    init = subparsers.add_parser(
        'init',
        help='Sets up starter config files to help start running endpoints')
    init.add_argument(
        "-f",
        "--force",
        action='store_true',
        help=
        "Force re-initialization of config with this flag.\nWARNING: This will wipe your current config"
    )

    # Configure an endpoint
    configure = subparsers.add_parser('configure',
                                      help='Configures an endpoint')
    configure.add_argument(
        "--config",
        default=None,
        help=
        "Path to config file to be used as template rather than the funcX default"
    )
    configure.add_argument("name",
                           help="Name of the endpoint to configure for")

    # Start an endpoint
    start = subparsers.add_parser('start', help='Starts an endpoint')
    start.add_argument("name", help="Name of the endpoint to start")
    start.add_argument("--endpoint_uuid",
                       help="The UUID for the endpoint to register with",
                       default=None,
                       required=False)

    # Stop an endpoint
    stop = subparsers.add_parser('stop', help='Stops an active endpoint')
    stop.add_argument("name", help="Name of the endpoint to stop")

    # List all endpoints
    subparsers.add_parser('list', help='Lists all endpoints')

    args = parser.parse_args()

    funcx.set_stream_logger(
        level=logging.DEBUG if args.debug else logging.INFO)
    global logger
    logger = logging.getLogger('funcx')

    if args.version:
        logger.info("FuncX version: {}".format(funcx.__version__))

    logger.debug("Command: {}".format(args.command))

    args.config_file = os.path.join(args.config_dir, 'config.py')

    if args.command == "init":
        if args.force:
            logger.debug("Forcing re-authentication via GlobusAuth")
        funcx_client = FuncXClient(force_login=args.force)
        init_endpoint(args)
        return

    if not os.path.exists(args.config_file):
        logger.critical(
            "Missing a config file at {}. Critical error. Exiting.".format(
                args.config_file))
        logger.info(
            "Please run the following to create the appropriate config files : \n $> funcx-endpoint init"
        )
        exit(-1)

    if args.command == "init":
        init_endpoint(args)
        exit(-1)

    logger.debug("Loading config files from {}".format(args.config_dir))

    import importlib.machinery
    global_config = importlib.machinery.SourceFileLoader(
        'global_config', args.config_file).load_module()

    if args.command == "configure":
        configure_endpoint(args,
                           config_file=args.config,
                           global_config=global_config.global_options)

    elif args.command == "start":
        start_endpoint(args, global_config=global_config.global_options)

    elif args.command == "stop":
        stop_endpoint(args, global_config=global_config.global_options)

    elif args.command == "list":
        list_endpoints(args)