Skip to content

Commit

Permalink
updated api documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gesinaphillips committed Jan 31, 2025
1 parent c13fffa commit 93c9dda
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,17 @@ def validate_options(self, resource_options: dict) -> bool:
logging.error(f"Validation errors: {validator.errors}")
raise ValidationException(f"Invalid resource options found: {validator.errors}")
return validator.is_valid

def translate_option_name(self, option: str) -> str:
return self.config.get("parameter_mapping", {}).get(option)

def translate_options(self, resource_options: dict) -> dict:
return self.translated_options(resource_options)

def translated_options(self, resource_options: dict) -> dict:
translated_options = {}
for option_name, option_value in resource_options.items():
if updated_option_name := self.translate_option_name(option_name):
translated_options[updated_option_name] = option_value

return translated_options
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,10 @@ def get_user_token(self, external_user):

def translate_options(self, resource_options):
# Should translate the options into a format that can be used by the resource
updated_options = {}
for option_name, option_value in resource_options.items():
if updated_option_name := self.translate_option_name(option_name):
updated_options[updated_option_name] = option_value

translated_options = self.translated_options(resource_options)
gpu_enabled = resource_options.get("gpu_enabled", False)
if isinstance(gpu_enabled, bool) and gpu_enabled:
updated_options["tres_per_job"] = "gres/gpu=1"
translated_options["tres_per_job"] = "gres/gpu=1"
if gpu_partition := self.config.get("gpu_partition"):
updated_options["partition"] = gpu_partition
return updated_options

def translate_option_name(self, option: str) -> str:
return self.config.get("parameter_mapping", {}).get(option)
translated_options["partition"] = gpu_partition
return translated_options
3 changes: 2 additions & 1 deletion src/user_workspaces_server/views/workspace_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def put(self, request, workspace_id, put_type=None):

if not resource.validate_options(resource_options):
raise ParseError("Invalid resource options found.")
translated_options = resource.translate_options(resource_options)

# TODO: Check whether user has permission for this resource (and resource storage).

Expand All @@ -276,7 +277,7 @@ def put(self, request, workspace_id, put_type=None):
"request_job_details": job_details,
"current_job_details": {},
},
"resource_options": resource_options,
"resource_options": translated_options,
"resource_name": type(resource).__name__,
"status": "pending",
"resource_job_id": -1,
Expand Down
40 changes: 40 additions & 0 deletions user-workspaces-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@ components:
type: string
success:
type: boolean
ParametersResponse:
type: object
properties:
parameters:
type: array
items:
type: object
properties:
display_name:
type: string
description:
type: string
variable_name:
type: string
default_value:
type: integer
validation:
type: object
properties:
type:
type: string
min:
type: integer
max:
type: integer
required:
type: boolean
paths:
'/workspaces/':
get:
Expand Down Expand Up @@ -457,7 +484,20 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/JobTypeResponse'
'/parameters/':
get:
tags:
- Parameters
summary: Get the parameters that may be passed in JSON body of request.
responses:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ParametersResponse'
tags:
- name: Workspaces
- name: Jobs
- name: JobTypes
- name: Parameters

0 comments on commit 93c9dda

Please sign in to comment.