diff --git a/python/ray/scripts/scripts.py b/python/ray/scripts/scripts.py index 01e97092b..bfe83a127 100644 --- a/python/ray/scripts/scripts.py +++ b/python/ray/scripts/scripts.py @@ -15,6 +15,8 @@ from ray.autoscaler.commands import (attach_cluster, exec_cluster, import ray.ray_constants as ray_constants import ray.utils +logger = logging.getLogger(__name__) + def check_no_existing_redis_clients(node_ip_address, redis_client): # The client table prefix must be kept in sync with the file @@ -41,11 +43,25 @@ def check_no_existing_redis_clients(node_ip_address, redis_client): @click.group() -def cli(): - pass +@click.option( + "--logging-level", + required=False, + default=ray_constants.LOGGER_LEVEL, + type=str, + help=ray_constants.LOGGER_LEVEL_HELP) +@click.option( + "--logging-format", + required=False, + default=ray_constants.LOGGER_FORMAT, + type=str, + help=ray_constants.LOGGER_FORMAT_HELP) +def cli(logging_level, logging_format): + level = logging.getLevelName(logging_level.upper()) + logging.basicConfig(level=level, format=logging_format) + logger.setLevel(level) -@click.command() +@cli.command() @click.option( "--node-ip-address", required=False, @@ -161,34 +177,17 @@ def cli(): is_flag=True, default=False, help="do not redirect non-worker stdout and stderr to files") -@click.option( - "--logging-level", - required=False, - default=ray_constants.LOGGER_LEVEL, - type=str, - help=ray_constants.LOGGER_LEVEL_HELP) -@click.option( - "--logging-format", - required=False, - default=ray_constants.LOGGER_FORMAT, - type=str, - help=ray_constants.LOGGER_FORMAT_HELP) def start(node_ip_address, redis_address, redis_port, num_redis_shards, redis_max_clients, redis_shard_ports, object_manager_port, object_store_memory, num_workers, num_cpus, num_gpus, resources, head, no_ui, block, plasma_directory, huge_pages, autoscaling_config, - use_raylet, no_redirect_worker_output, no_redirect_output, - logging_level, logging_format): + use_raylet, no_redirect_worker_output, no_redirect_output): # Convert hostnames to numerical IP address. if node_ip_address is not None: node_ip_address = services.address_to_ip(node_ip_address) if redis_address is not None: redis_address = services.address_to_ip(redis_address) - level = logging.getLevelName(logging_level.upper()) - logging.basicConfig(level=level, format=logging_format) - logger = logging.getLogger(__name__) - if use_raylet is None and os.environ.get("RAY_USE_XRAY") == "1": # This environment variable is used in our testing setup. logger.info("Detected environment variable 'RAY_USE_XRAY'.") @@ -342,7 +341,7 @@ def start(node_ip_address, redis_address, redis_port, num_redis_shards, time.sleep(30) -@click.command() +@cli.command() def stop(): subprocess.call( [ @@ -396,7 +395,7 @@ def stop(): pass -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.option( "--no-restart", @@ -441,7 +440,7 @@ def create_or_update(cluster_config_file, min_workers, max_workers, no_restart, no_restart, restart_only, yes, cluster_name) -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.option( "--workers-only", @@ -464,7 +463,7 @@ def teardown(cluster_config_file, yes, workers_only, cluster_name): teardown_cluster(cluster_config_file, yes, workers_only, cluster_name) -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.option( "--start", @@ -481,7 +480,7 @@ def attach(cluster_config_file, start, cluster_name): attach_cluster(cluster_config_file, start, cluster_name) -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.argument("source", required=True, type=str) @click.argument("target", required=True, type=str) @@ -495,7 +494,7 @@ def rsync_down(cluster_config_file, source, target, cluster_name): rsync(cluster_config_file, source, target, cluster_name, down=True) -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.argument("source", required=True, type=str) @click.argument("target", required=True, type=str) @@ -509,7 +508,7 @@ def rsync_up(cluster_config_file, source, target, cluster_name): rsync(cluster_config_file, source, target, cluster_name, down=False) -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.argument("cmd", required=True, type=str) @click.option( @@ -541,7 +540,7 @@ def exec_cmd(cluster_config_file, cmd, screen, stop, start, cluster_name, port_forward) -@click.command() +@cli.command() @click.argument("cluster_config_file", required=True, type=str) @click.option( "--cluster-name",