Skip to content

Commit

Permalink
automatic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
iris-garden committed Jan 9, 2024
1 parent 9399fd6 commit 97b15b3
Show file tree
Hide file tree
Showing 477 changed files with 23,398 additions and 23,447 deletions.
428 changes: 214 additions & 214 deletions auth/auth/auth.py

Large diffs are not rendered by default.

250 changes: 125 additions & 125 deletions auth/auth/driver/driver.py

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions auth/auth/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ def http_response(self):

class EmptyLoginID(AuthUserError):
def __init__(self, username):
super().__init__(f"Login id for user '{username}' must be a non-empty string.", 'error')
super().__init__(f"Login id for user '{username}' must be a non-empty string.", "error")


class DuplicateLoginID(AuthUserError):
def __init__(self, username, login_id):
super().__init__(f"Login id '{login_id}' already exists for user '{username}'.", 'error')
super().__init__(f"Login id '{login_id}' already exists for user '{username}'.", "error")


class DuplicateUsername(AuthUserError):
def __init__(self, username, login_id):
super().__init__(f"Username '{username}' already exists with login id '{login_id}'.", 'error')
super().__init__(f"Username '{username}' already exists with login id '{login_id}'.", "error")


class InvalidUsername(AuthUserError):
def __init__(self, username):
super().__init__(f"Invalid username '{username}'. Must be a non-empty alphanumeric string.", 'error')
super().__init__(f"Invalid username '{username}'. Must be a non-empty alphanumeric string.", "error")


class InvalidType(AuthUserError):
def __init__(self, field_name, input, expected_type):
super().__init__(f"Expected '{field_name}' is of type {expected_type}. Found type {type(input)}", 'error')
super().__init__(f"Expected '{field_name}' is of type {expected_type}. Found type {type(input)}", "error")


class MultipleUserTypes(AuthUserError):
def __init__(self, username):
super().__init__(f"User '{username}' cannot be both a developer and a service account.", 'error')
super().__init__(f"User '{username}' cannot be both a developer and a service account.", "error")


class MultipleExistingUsers(AuthUserError):
def __init__(self, username, login_id):
super().__init__(
f"Multiple users with user name '{username}' and login id '{login_id}' appear in the database.",
'error',
"error",
)

def http_response(self):
Expand All @@ -54,12 +54,12 @@ def http_response(self):

class UnknownUser(AuthUserError):
def __init__(self, username):
super().__init__(f"Unknown user '{username}'.", 'error')
super().__init__(f"Unknown user '{username}'.", "error")

def http_response(self):
return web.HTTPNotFound(reason=self.message)


class PreviouslyDeletedUser(AuthUserError):
def __init__(self, username):
super().__init__(f"User '{username}' has already been deleted.", 'error')
super().__init__(f"User '{username}' has already been deleted.", "error")
12 changes: 6 additions & 6 deletions auth/setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import find_packages, setup

setup(
name='auth',
version='0.0.1',
url='https://github.com/hail-is/hail.git',
author='Hail Team',
author_email='hail@broadinstitute.org',
description='Authentication service',
name="auth",
version="0.0.1",
url="https://github.com/hail-is/hail.git",
author="Hail Team",
author_email="hail@broadinstitute.org",
description="Authentication service",
packages=find_packages(),
include_package_data=True,
)
120 changes: 60 additions & 60 deletions batch/batch/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,121 +10,121 @@
from .exceptions import NonExistentBatchError, OpenBatchError
from .utils import coalesce

log = logging.getLogger('batch')
log = logging.getLogger("batch")


def cost_breakdown_to_dict(cost_breakdown: Dict[str, float]) -> List[CostBreakdownEntry]:
return [{'resource': resource, 'cost': cost} for resource, cost in cost_breakdown.items()]
return [{"resource": resource, "cost": cost} for resource, cost in cost_breakdown.items()]


def batch_record_to_dict(record: Dict[str, Any]) -> Dict[str, Any]:
if record['state'] == 'open':
state = 'open'
elif record['n_failed'] > 0:
state = 'failure'
elif record['cancelled'] or record['n_cancelled'] > 0:
state = 'cancelled'
elif record['state'] == 'complete':
assert record['n_succeeded'] == record['n_jobs']
state = 'success'
if record["state"] == "open":
state = "open"
elif record["n_failed"] > 0:
state = "failure"
elif record["cancelled"] or record["n_cancelled"] > 0:
state = "cancelled"
elif record["state"] == "complete":
assert record["n_succeeded"] == record["n_jobs"]
state = "success"
else:
state = 'running'
state = "running"

def _time_msecs_str(t):
if t:
return time_msecs_str(t)
return None

time_created = _time_msecs_str(record['time_created'])
time_closed = _time_msecs_str(record['time_closed'])
time_completed = _time_msecs_str(record['time_completed'])
time_created = _time_msecs_str(record["time_created"])
time_closed = _time_msecs_str(record["time_closed"])
time_completed = _time_msecs_str(record["time_completed"])

if record['time_created'] and record['time_completed']:
duration_ms = record['time_completed'] - record['time_created']
if record["time_created"] and record["time_completed"]:
duration_ms = record["time_completed"] - record["time_created"]
duration = humanize_timedelta_msecs(duration_ms)
else:
duration_ms = None
duration = None

if record['cost_breakdown'] is not None:
record['cost_breakdown'] = cost_breakdown_to_dict(json.loads(record['cost_breakdown']))
if record["cost_breakdown"] is not None:
record["cost_breakdown"] = cost_breakdown_to_dict(json.loads(record["cost_breakdown"]))

d = {
'id': record['id'],
'user': record['user'],
'billing_project': record['billing_project'],
'token': record['token'],
'state': state,
'complete': record['state'] == 'complete',
'closed': record['state'] != 'open',
'n_jobs': record['n_jobs'],
'n_completed': record['n_completed'],
'n_succeeded': record['n_succeeded'],
'n_failed': record['n_failed'],
'n_cancelled': record['n_cancelled'],
'time_created': time_created,
'time_closed': time_closed,
'time_completed': time_completed,
'duration_ms': duration_ms,
'duration': duration,
'msec_mcpu': record['msec_mcpu'],
'cost': coalesce(record['cost'], 0),
'cost_breakdown': record['cost_breakdown'],
"id": record["id"],
"user": record["user"],
"billing_project": record["billing_project"],
"token": record["token"],
"state": state,
"complete": record["state"] == "complete",
"closed": record["state"] != "open",
"n_jobs": record["n_jobs"],
"n_completed": record["n_completed"],
"n_succeeded": record["n_succeeded"],
"n_failed": record["n_failed"],
"n_cancelled": record["n_cancelled"],
"time_created": time_created,
"time_closed": time_closed,
"time_completed": time_completed,
"duration_ms": duration_ms,
"duration": duration,
"msec_mcpu": record["msec_mcpu"],
"cost": coalesce(record["cost"], 0),
"cost_breakdown": record["cost_breakdown"],
}

attributes = json.loads(record['attributes'])
attributes = json.loads(record["attributes"])
if attributes:
d['attributes'] = attributes
d["attributes"] = attributes

return d


def job_record_to_dict(record: Dict[str, Any], name: Optional[str]) -> JobListEntryV1Alpha:
format_version = BatchFormatVersion(record['format_version'])
format_version = BatchFormatVersion(record["format_version"])

db_status = record['status']
db_status = record["status"]
if db_status:
db_status = json.loads(db_status)
exit_code, duration = format_version.get_status_exit_code_duration(db_status)
else:
exit_code = None
duration = None

if record['cost_breakdown'] is not None:
record['cost_breakdown'] = cost_breakdown_to_dict(json.loads(record['cost_breakdown']))
if record["cost_breakdown"] is not None:
record["cost_breakdown"] = cost_breakdown_to_dict(json.loads(record["cost_breakdown"]))

return {
'batch_id': record['batch_id'],
'job_id': record['job_id'],
'name': name,
'user': record['user'],
'billing_project': record['billing_project'],
'state': record['state'],
'exit_code': exit_code,
'duration': duration,
'cost': coalesce(record['cost'], 0),
'msec_mcpu': record['msec_mcpu'],
'cost_breakdown': record['cost_breakdown'],
"batch_id": record["batch_id"],
"job_id": record["job_id"],
"name": name,
"user": record["user"],
"billing_project": record["billing_project"],
"state": record["state"],
"exit_code": exit_code,
"duration": duration,
"cost": coalesce(record["cost"], 0),
"msec_mcpu": record["msec_mcpu"],
"cost_breakdown": record["cost_breakdown"],
}


async def cancel_batch_in_db(db, batch_id):
@transaction(db)
async def cancel(tx):
record = await tx.execute_and_fetchone(
'''
"""
SELECT `state` FROM batches
WHERE id = %s AND NOT deleted
FOR UPDATE;
''',
""",
(batch_id,),
)
if not record:
raise NonExistentBatchError(batch_id)

if record['state'] == 'open':
if record["state"] == "open":
raise OpenBatchError(batch_id)

await tx.just_execute('CALL cancel_batch(%s);', (batch_id,))
await tx.just_execute("CALL cancel_batch(%s);", (batch_id,))

await cancel()
26 changes: 13 additions & 13 deletions batch/batch/batch_configuration.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os

KUBERNETES_TIMEOUT_IN_SECONDS = float(os.environ.get('KUBERNETES_TIMEOUT_IN_SECONDS', 5.0))
REFRESH_INTERVAL_IN_SECONDS = int(os.environ.get('REFRESH_INTERVAL_IN_SECONDS', 5 * 60))
DEFAULT_NAMESPACE = os.environ['HAIL_DEFAULT_NAMESPACE']
SCOPE = os.environ['HAIL_SCOPE']
KUBERNETES_TIMEOUT_IN_SECONDS = float(os.environ.get("KUBERNETES_TIMEOUT_IN_SECONDS", 5.0))
REFRESH_INTERVAL_IN_SECONDS = int(os.environ.get("REFRESH_INTERVAL_IN_SECONDS", 5 * 60))
DEFAULT_NAMESPACE = os.environ["HAIL_DEFAULT_NAMESPACE"]
SCOPE = os.environ["HAIL_SCOPE"]

CLOUD = os.environ['CLOUD']
DOCKER_ROOT_IMAGE = os.environ['HAIL_DOCKER_ROOT_IMAGE']
DOCKER_PREFIX = os.environ['HAIL_DOCKER_PREFIX']
CLOUD = os.environ["CLOUD"]
DOCKER_ROOT_IMAGE = os.environ["HAIL_DOCKER_ROOT_IMAGE"]
DOCKER_PREFIX = os.environ["HAIL_DOCKER_PREFIX"]

KUBERNETES_SERVER_URL = os.environ['KUBERNETES_SERVER_URL']
INTERNAL_GATEWAY_IP = os.environ['INTERNAL_GATEWAY_IP']
BATCH_STORAGE_URI = os.environ['HAIL_BATCH_STORAGE_URI']
HAIL_SHA = os.environ['HAIL_SHA']
HAIL_SHOULD_PROFILE = os.environ.get('HAIL_SHOULD_PROFILE') is not None
KUBERNETES_SERVER_URL = os.environ["KUBERNETES_SERVER_URL"]
INTERNAL_GATEWAY_IP = os.environ["INTERNAL_GATEWAY_IP"]
BATCH_STORAGE_URI = os.environ["HAIL_BATCH_STORAGE_URI"]
HAIL_SHA = os.environ["HAIL_SHA"]
HAIL_SHOULD_PROFILE = os.environ.get("HAIL_SHOULD_PROFILE") is not None

MACHINE_NAME_PREFIX = f'batch-worker-{DEFAULT_NAMESPACE}-'
MACHINE_NAME_PREFIX = f"batch-worker-{DEFAULT_NAMESPACE}-"
Loading

0 comments on commit 97b15b3

Please sign in to comment.