Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed May 16, 2024
1 parent 3e0d699 commit 6902510
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
4 changes: 2 additions & 2 deletions renku_notebooks/api/classes/data_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def validate_class_storage(
if storage > res_class.get("max_storage"):
raise InvalidComputeResourceError(message="The requested storage surpasses the maximum value allowed.")
options = ServerOptions.from_resource_class(res_class)
options.idle_threshold = pool.get("idle_threshold")
options.hibernation_threshold = pool.get("hibernation_threshold")
options.idle_threshold_seconds = pool.get("idle_threshold")
options.hibernation_threshold_seconds = pool.get("hibernation_threshold")
options.set_storage(storage, gigabytes=True)
quota = pool.get("quota")
if quota is not None and isinstance(quota, dict):
Expand Down
8 changes: 4 additions & 4 deletions renku_notebooks/api/classes/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ def __init__(
self.gl_project_name = f"{self.namespace}/{self.project}"
self.is_image_private = is_image_private

if self.server_options.idle_threshold is not None:
self.idle_seconds_threshold = self.server_options.idle_threshold
if self.server_options.idle_threshold_seconds is not None:
self.idle_seconds_threshold = self.server_options.idle_threshold_seconds
else:
self.idle_seconds_threshold: int = (
config.sessions.culling.registered.idle_seconds
if isinstance(self._user, RegisteredUser)
else config.sessions.culling.anonymous.idle_seconds
)

if self.server_options.hibernation_threshold is not None:
self.hibernated_seconds_threshold: int = self.server_options.hibernation_threshold
if self.server_options.hibernation_threshold_seconds is not None:
self.hibernated_seconds_threshold: int = self.server_options.hibernation_threshold_seconds
else:
self.hibernated_seconds_threshold: int = (
config.sessions.culling.registered.hibernated_seconds
Expand Down
34 changes: 14 additions & 20 deletions renku_notebooks/api/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ def version():
"cloudstorageEnabled": config.cloud_storage.enabled,
"cloudstorageClass": config.cloud_storage.storage_class,
"sshEnabled": config.ssh_enabled,
"registeredUsersIdleThreshold": culling.registered.idle_seconds,
"registeredUsersHibernationThreshold": culling.registered.hibernated_seconds,
"anonymousUsersIdleThreshold": culling.anonymous.idle_seconds,
"anonymousUsersHibernationThreshold": culling.anonymous.hibernated_seconds,
"defaultCullingThresholds": {
"registered": {
"idle": culling.registered.idle_seconds,
"hibernation": culling.registered.hibernated_seconds,
},
"anonymous": {
"idle": culling.anonymous.idle_seconds,
"hibernation": culling.anonymous.hibernated_seconds,
},
},
},
}
],
Expand Down Expand Up @@ -112,28 +118,18 @@ def user_servers(user, **query_params):
- servers
"""
servers = [
UserServerManifest(s)
for s in config.k8s.client.list_servers(user.safe_username)
]
servers = [UserServerManifest(s) for s in config.k8s.client.list_servers(user.safe_username)]
filter_attrs = list(filter(lambda x: x[1] is not None, query_params.items()))
filtered_servers = {}
ann_prefix = config.session_get_endpoint_annotations.renku_annotation_prefix
for server in servers:
if all(
[
server.annotations.get(f"{ann_prefix}{key}") == value
for key, value in filter_attrs
]
):
if all([server.annotations.get(f"{ann_prefix}{key}") == value for key, value in filter_attrs]):
filtered_servers[server.server_name] = server
return ServersGetResponse().dump({"servers": filtered_servers})


@bp.route("servers/<server_name>", methods=["GET"])
@use_args(
{"server_name": fields.Str(required=True)}, location="view_args", as_kwargs=True
)
@use_args({"server_name": fields.Str(required=True)}, location="view_args", as_kwargs=True)
@authenticated
def user_server(user, server_name):
"""Returns a user server based on its ID.
Expand Down Expand Up @@ -190,9 +186,7 @@ def launch_notebook(
server_options=None,
user_secrets=None,
):
server_name = make_server_name(
user.safe_username, namespace, project, branch, commit_sha
)
server_name = make_server_name(user.safe_username, namespace, project, branch, commit_sha)
gl_project = user.get_renku_project(f"{namespace}/{project}")
gl_project_path = gl_project.path
server_class = UserServer
Expand Down
4 changes: 2 additions & 2 deletions renku_notebooks/api/schemas/server_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class ServerOptions:
node_affinities: list[NodeAffinity] = field(default_factory=list)
tolerations: list[Toleration] = field(default_factory=list)
resource_class_id: Optional[int] = None
idle_threshold: Optional[int] = None
hibernation_threshold: Optional[int] = None
idle_threshold_seconds: Optional[int] = None
hibernation_threshold_seconds: Optional[int] = None

def __post_init__(self):
if self.default_url is None:
Expand Down
19 changes: 15 additions & 4 deletions renku_notebooks/api/schemas/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
from marshmallow import Schema, fields


class CullingThreshold(Schema):
"""Culling thresholds info."""

idle = fields.Int(required=True)
hibernation = fields.Int(required=True)


class DefaultCullingThresholds(Schema):
"""Culling thresholds for this deployment."""

registered = fields.Nested(CullingThreshold, required=True)
anonymous = fields.Nested(CullingThreshold, required=True)


class NotebooksServiceInfo(Schema):
"""Various notebooks service info."""

anonymousSessionsEnabled = fields.Boolean(required=True)
cloudstorageEnabled = fields.Boolean(required=True)
sshEnabled = fields.Boolean(required=True)
registeredUsersIdleThreshold = fields.Int(required=True)
registeredUsersHibernationThreshold = fields.Int(required=True)
anonymousUsersIdleThreshold = fields.Int(required=True)
anonymousUsersHibernationThreshold = fields.Int(required=True)
defaultCullingThresholds = fields.Nested(DefaultCullingThresholds, required=True)


class NotebooksServiceVersions(Schema):
Expand Down

0 comments on commit 6902510

Please sign in to comment.