mirror of
https://github.com/wassname/ray.git
synced 2026-08-03 13:10:57 +08:00
[autoscaler] Cleanup Logging (#2709)
Moves Autoscaler onto Python `logging` module.
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import logging
|
||||
import time
|
||||
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
@@ -29,10 +30,12 @@ DEFAULT_SERVICE_ACCOUNT_ROLES = ("roles/storage.objectAdmin",
|
||||
MAX_POLLS = 12
|
||||
POLL_INTERVAL = 5
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def wait_for_crm_operation(operation):
|
||||
"""Poll for cloud resource manager operation until finished."""
|
||||
print("Waiting for operation {} to finish...".format(operation))
|
||||
logger.info("Waiting for operation {} to finish...".format(operation))
|
||||
|
||||
for _ in range(MAX_POLLS):
|
||||
result = crm.operations().get(name=operation["name"]).execute()
|
||||
@@ -40,7 +43,7 @@ def wait_for_crm_operation(operation):
|
||||
raise Exception(result["error"])
|
||||
|
||||
if "done" in result and result["done"]:
|
||||
print("Done.")
|
||||
logger.info("Done.")
|
||||
break
|
||||
|
||||
time.sleep(POLL_INTERVAL)
|
||||
@@ -50,7 +53,8 @@ def wait_for_crm_operation(operation):
|
||||
|
||||
def wait_for_compute_global_operation(project_name, operation):
|
||||
"""Poll for global compute operation until finished."""
|
||||
print("Waiting for operation {} to finish...".format(operation["name"]))
|
||||
logger.info("Waiting for operation {} to finish...".format(
|
||||
operation["name"]))
|
||||
|
||||
for _ in range(MAX_POLLS):
|
||||
result = compute.globalOperations().get(
|
||||
@@ -61,7 +65,7 @@ def wait_for_compute_global_operation(project_name, operation):
|
||||
raise Exception(result["error"])
|
||||
|
||||
if result["status"] == "DONE":
|
||||
print("Done.")
|
||||
logger.info("Done.")
|
||||
break
|
||||
|
||||
time.sleep(POLL_INTERVAL)
|
||||
@@ -154,7 +158,7 @@ def _configure_iam_role(config):
|
||||
service_account = _get_service_account(email, config)
|
||||
|
||||
if service_account is None:
|
||||
print("Creating new service account {}".format(
|
||||
logger.info("Creating new service account {}".format(
|
||||
DEFAULT_SERVICE_ACCOUNT_ID))
|
||||
|
||||
service_account = _create_service_account(
|
||||
@@ -227,7 +231,7 @@ def _configure_key_pair(config):
|
||||
|
||||
# Create a key since it doesn't exist locally or in GCP
|
||||
if not key_found and not os.path.exists(private_key_path):
|
||||
print("Creating new key pair {}".format(key_name))
|
||||
logger.info("Creating new key pair {}".format(key_name))
|
||||
public_key, private_key = generate_rsa_key_pair()
|
||||
|
||||
_create_project_ssh_key_pair(project, public_key, ssh_user)
|
||||
@@ -252,8 +256,8 @@ def _configure_key_pair(config):
|
||||
"Private key file {} not found for user {}"
|
||||
"".format(private_key_path, ssh_user))
|
||||
|
||||
print("Private key not specified in config, using {}"
|
||||
"".format(private_key_path))
|
||||
logger.info("Private key not specified in config, using {}"
|
||||
"".format(private_key_path))
|
||||
|
||||
config["auth"]["ssh_private_key"] = private_key_path
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import print_function
|
||||
from uuid import uuid4
|
||||
import time
|
||||
|
||||
import logging
|
||||
from googleapiclient import discovery
|
||||
|
||||
from ray.autoscaler.node_provider import NodeProvider
|
||||
@@ -14,10 +15,13 @@ from ray.autoscaler.gcp.config import MAX_POLLS, POLL_INTERVAL
|
||||
INSTANCE_NAME_MAX_LEN = 64
|
||||
INSTANCE_NAME_UUID_LEN = 8
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def wait_for_compute_zone_operation(compute, project_name, operation, zone):
|
||||
"""Poll for compute zone operation until finished."""
|
||||
print("Waiting for operation {} to finish...".format(operation["name"]))
|
||||
logger.info("Waiting for operation {} to finish...".format(
|
||||
operation["name"]))
|
||||
|
||||
for _ in range(MAX_POLLS):
|
||||
result = compute.zoneOperations().get(
|
||||
@@ -27,7 +31,7 @@ def wait_for_compute_zone_operation(compute, project_name, operation, zone):
|
||||
raise Exception(result["error"])
|
||||
|
||||
if result["status"] == "DONE":
|
||||
print("Done.")
|
||||
logger.info("Done.")
|
||||
break
|
||||
|
||||
time.sleep(POLL_INTERVAL)
|
||||
|
||||
Reference in New Issue
Block a user