16
16
from gitlab .v4 .objects .projects import Project as GitlabProject
17
17
from kubernetes .client import V1ObjectMeta , V1Secret
18
18
from marshmallow import ValidationError
19
- from sanic import Request , empty , exceptions , json
19
+ from sanic import Request , empty , json
20
20
from sanic .log import logger
21
21
from sanic .response import HTTPResponse , JSONResponse
22
22
from sanic_ext import validate
75
75
)
76
76
from renku_data_services .notebooks .errors .intermittent import AnonymousUserPatchError , PVDisabledError
77
77
from renku_data_services .notebooks .errors .programming import ProgrammingError
78
- from renku_data_services .notebooks .errors .user import MissingResourceError , UserInputError
78
+ from renku_data_services .notebooks .errors .user import MissingResourceError
79
79
from renku_data_services .notebooks .util .kubernetes_ import (
80
80
find_container ,
81
81
renku_1_make_server_name ,
@@ -161,7 +161,7 @@ async def _user_server(
161
161
) -> JSONResponse :
162
162
server = await self .nb_config .k8s_client .get_server (server_name , user .id )
163
163
if server is None :
164
- raise MissingResourceError (message = f"The server { server_name } does not exist." )
164
+ raise errors . MissingResourceError (message = f"The server { server_name } does not exist." )
165
165
server = UserServerManifest (server , self .nb_config .sessions .default_image )
166
166
return json (NotebookResponse ().dump (server ))
167
167
@@ -350,14 +350,14 @@ async def launch_notebook_helper(
350
350
if is_image_private and internal_gitlab_user .access_token :
351
351
image_repo = image_repo .with_oauth2_token (internal_gitlab_user .access_token )
352
352
if not image_repo .image_exists (parsed_image ):
353
- raise MissingResourceError (
353
+ raise errors . MissingResourceError (
354
354
message = (
355
355
f"Cannot start the session because the following the image { image } does not "
356
356
"exist or the user does not have the permissions to access it."
357
357
)
358
358
)
359
359
else :
360
- raise UserInputError (message = "Cannot determine which Docker image to use." )
360
+ raise errors . ValidationError (message = "Cannot determine which Docker image to use." )
361
361
362
362
parsed_server_options : ServerOptions | None = None
363
363
if resource_class_id is not None :
@@ -385,7 +385,7 @@ async def launch_notebook_helper(
385
385
# The old style API was used, try to find a matching class from the CRC service
386
386
parsed_server_options = await nb_config .crc_validator .find_acceptable_class (user , requested_server_options )
387
387
if parsed_server_options is None :
388
- raise UserInputError (
388
+ raise errors . ValidationError (
389
389
message = "Cannot find suitable server options based on your request and "
390
390
"the available resource classes." ,
391
391
detail = "You are receiving this error because you are using the old API for "
@@ -397,8 +397,8 @@ async def launch_notebook_helper(
397
397
default_resource_class = await nb_config .crc_validator .get_default_class ()
398
398
max_storage_gb = default_resource_class .max_storage
399
399
if storage is not None and storage > max_storage_gb :
400
- raise UserInputError (
401
- "The requested storage amount is higher than the "
400
+ raise errors . ValidationError (
401
+ message = "The requested storage amount is higher than the "
402
402
f"allowable maximum for the default resource class of { max_storage_gb } GB."
403
403
)
404
404
if storage is None :
@@ -434,14 +434,16 @@ async def launch_notebook_helper(
434
434
)
435
435
)
436
436
except ValidationError as e :
437
- raise UserInputError ( f"Couldn't load cloud storage config: { str (e )} " )
437
+ raise errors . ValidationError ( message = f"Couldn't load cloud storage config: { str (e )} " )
438
438
mount_points = set (s .mount_folder for s in storages if s .mount_folder and s .mount_folder != "/" )
439
439
if len (mount_points ) != len (storages ):
440
- raise UserInputError (
441
- "Storage mount points must be set, can't be at the root of the project and must be unique."
440
+ raise errors . ValidationError (
441
+ message = "Storage mount points must be set, can't be at the root of the project and must be unique."
442
442
)
443
443
if any (s1 .mount_folder .startswith (s2 .mount_folder ) for s1 in storages for s2 in storages if s1 != s2 ):
444
- raise UserInputError ("Cannot mount a cloud storage into the mount point of another cloud storage." )
444
+ raise errors .ValidationError (
445
+ message = "Cannot mount a cloud storage into the mount point of another cloud storage."
446
+ )
445
447
446
448
repositories = repositories or []
447
449
@@ -479,7 +481,7 @@ async def launch_notebook_helper(
479
481
)
480
482
481
483
if len (server .safe_username ) > 63 :
482
- raise UserInputError (
484
+ raise errors . ValidationError (
483
485
message = "A username cannot be longer than 63 characters, "
484
486
f"your username is { len (server .safe_username )} characters long." ,
485
487
detail = "This can occur if your username has been changed manually or by an admin." ,
@@ -557,7 +559,9 @@ async def _patch_server(
557
559
state = PatchServerStatusEnum .from_api_state (body .state ) if body .state is not None else None
558
560
resource_class_id = patch_body .resource_class_id
559
561
if server and not (currently_hibernated or currently_failing ) and resource_class_id :
560
- raise UserInputError ("The resource class can be changed only if the server is hibernated or failing" )
562
+ raise errors .ValidationError (
563
+ message = "The resource class can be changed only if the server is hibernated or failing"
564
+ )
561
565
562
566
if resource_class_id :
563
567
parsed_server_options = await self .nb_config .crc_validator .validate_class_storage (
@@ -704,12 +708,9 @@ def stop_server(self) -> BlueprintFactoryResponse:
704
708
705
709
@authenticate (self .authenticator )
706
710
async def _stop_server (
707
- request : Request , user : AnonymousAPIUser | AuthenticatedAPIUser , server_name : str
711
+ _ : Request , user : AnonymousAPIUser | AuthenticatedAPIUser , server_name : str
708
712
) -> HTTPResponse :
709
- try :
710
- await self .nb_config .k8s_client .delete_server (server_name , safe_username = user .id )
711
- except MissingResourceError as err :
712
- raise exceptions .NotFound (message = err .message )
713
+ await self .nb_config .k8s_client .delete_server (server_name , safe_username = user .id )
713
714
return HTTPResponse (status = 204 )
714
715
715
716
return "/notebooks/servers/<server_name>" , ["DELETE" ], _stop_server
@@ -748,7 +749,7 @@ async def _server_logs(
748
749
)
749
750
return json (ServerLogs ().dump (logs ))
750
751
except MissingResourceError as err :
751
- raise exceptions . NotFound (message = err .message )
752
+ raise errors . MissingResourceError (message = err .message )
752
753
753
754
return "/notebooks/logs/<server_name>" , ["GET" ], _server_logs
754
755
0 commit comments