Skip to content

Commit d2733e2

Browse files
authored
Merge pull request #195 from hubmapconsortium/main
DEV sync
2 parents 363d00d + d030c59 commit d2733e2

File tree

8 files changed

+66
-26
lines changed

8 files changed

+66
-26
lines changed

src/example_config.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
"user_authentication": "main_auth",
3131
"passthrough_domain": "127.0.0.1:8000",
3232
"connection_details": {},
33-
"parameter_mapping": [
34-
{
33+
"parameter_mapping": {
3534
"num_cpus": "cpus_per_task",
3635
"memory_mb": "memory_per_node",
3736
"time_limit_min": "time_limit"
38-
}
39-
]
37+
}
4038
}
4139
},
4240
"available_job_types": {

src/tests/github_test_config.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
"user_authentication": "test_auth",
2828
"passthrough_domain": "127.0.0.1:8000",
2929
"connection_details": {},
30-
"parameter_mapping": [
31-
{
30+
"parameter_mapping": {
3231
"num_cpus": "cpus_per_task",
3332
"memory_mb": "memory_per_node",
3433
"time_limit_min": "time_limit"
35-
}
36-
]
34+
}
3735
}
3836
},
3937
"available_job_types": {

src/tests/unittests/test_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,22 +661,22 @@ def test_workspace_custom_params_validation_required(self):
661661
"job_type": "test_job",
662662
"job_details": {},
663663
}
664-
response = self.client.put(
664+
response_bad = self.client.put(
665665
reverse("workspaces_put_type", args=[self.workspace.id, "start"]),
666666
body,
667667
)
668668
self.assertValidResponse(
669-
response,
669+
response_bad,
670670
status.HTTP_422_UNPROCESSABLE_ENTITY,
671671
success=False,
672672
message="Invalid resource options found: ['Missing required: test_param']",
673673
)
674674
body["resource_options"] = {"test_param": "test"}
675-
response = self.client.put(
675+
response_good = self.client.put(
676676
reverse("workspaces_put_type", args=[self.workspace.id, "start"]),
677677
body,
678678
)
679-
self.assertValidResponse(response, status.HTTP_200_OK, success=True)
679+
self.assertValidResponse(response_good, status.HTTP_200_OK, success=True)
680680
self.assertEqual(
681681
apps.get_app_config("user_workspaces_server").parameters.pop(), test_param
682682
)

src/user_workspaces_server/controllers/resources/abstract_resource.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ def validate_options(self, resource_options: dict) -> bool:
4848
logging.error(f"Validation errors: {validator.errors}")
4949
raise ValidationException(f"Invalid resource options found: {validator.errors}")
5050
return validator.is_valid
51+
52+
def translate_option_name(self, option: str) -> str:
53+
return self.config.get("parameter_mapping", {}).get(option)
54+
55+
def translate_options(self, resource_options: dict) -> dict:
56+
translated_options = {}
57+
for option_name, option_value in resource_options.items():
58+
if updated_option_name := self.translate_option_name(option_name):
59+
translated_options[updated_option_name] = option_value
60+
61+
return translated_options

src/user_workspaces_server/controllers/resources/slurm_api_resource.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,10 @@ def get_user_token(self, external_user):
226226

227227
def translate_options(self, resource_options):
228228
# Should translate the options into a format that can be used by the resource
229-
updated_options = {}
230-
for option_name, option_value in resource_options.items():
231-
if updated_option_name := self.translate_option_name(option_name):
232-
updated_options[updated_option_name] = option_value
233-
229+
translated_options = super().translate_options(resource_options)
234230
gpu_enabled = resource_options.get("gpu_enabled", False)
235231
if isinstance(gpu_enabled, bool) and gpu_enabled:
236-
updated_options["tres_per_job"] = "gres/gpu=1"
232+
translated_options["tres_per_job"] = "gres/gpu=1"
237233
if gpu_partition := self.config.get("gpu_partition"):
238-
updated_options["partition"] = gpu_partition
239-
return updated_options
240-
241-
def translate_option_name(self, option: str) -> str:
242-
return self.config.get("parameter_mapping", {}).get(option)
234+
translated_options["partition"] = gpu_partition
235+
return translated_options

src/user_workspaces_server/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
from django.urls import include, path
1818

19-
from user_workspaces_server.views import parameter_view
20-
2119
from . import ws_consumers
2220
from .views import (
2321
job_type_view,
2422
job_view,
23+
parameter_view,
2524
passthrough_view,
2625
shared_workspace_view,
2726
status_view,

src/user_workspaces_server/views/workspace_view.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def put(self, request, workspace_id, put_type=None):
274274

275275
if not resource.validate_options(resource_options):
276276
raise ParseError("Invalid resource options found.")
277+
translated_options = resource.translate_options(resource_options)
277278

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

@@ -287,7 +288,7 @@ def put(self, request, workspace_id, put_type=None):
287288
"request_job_details": job_details,
288289
"current_job_details": {},
289290
},
290-
"resource_options": resource_options,
291+
"resource_options": translated_options,
291292
"resource_name": type(resource).__name__,
292293
"status": "pending",
293294
"resource_job_id": -1,

user-workspaces-spec.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,33 @@ components:
198198
type: string
199199
success:
200200
type: boolean
201+
ParametersResponse:
202+
type: object
203+
properties:
204+
parameters:
205+
type: array
206+
items:
207+
type: object
208+
properties:
209+
display_name:
210+
type: string
211+
description:
212+
type: string
213+
variable_name:
214+
type: string
215+
default_value:
216+
type: integer
217+
validation:
218+
type: object
219+
properties:
220+
type:
221+
type: string
222+
min:
223+
type: integer
224+
max:
225+
type: integer
226+
required:
227+
type: boolean
201228
paths:
202229
'/workspaces/':
203230
get:
@@ -457,7 +484,20 @@ paths:
457484
application/json:
458485
schema:
459486
$ref: '#/components/schemas/JobTypeResponse'
487+
'/parameters/':
488+
get:
489+
tags:
490+
- Parameters
491+
summary: Get the parameters that may be passed in JSON body of request.
492+
responses:
493+
"200":
494+
description: successful operation
495+
content:
496+
application/json:
497+
schema:
498+
$ref: '#/components/schemas/ParametersResponse'
460499
tags:
461500
- name: Workspaces
462501
- name: Jobs
463502
- name: JobTypes
503+
- name: Parameters

0 commit comments

Comments
 (0)