1+ from enum import Enum
12from typing import Any , Dict , List , Optional
23
34from fastapi import APIRouter , Depends , HTTPException
@@ -99,6 +100,13 @@ class SetJobStatusBody(RunnerEndpointBody):
99100 command_params : SetJobStatusCmdParams
100101
101102
103+ class RunnerEndpointsCategory (str , Enum ):
104+ SET_JOB_STATUS = "SET_JOB_STATUS"
105+ CREATE_EXPERIMENT = "CREATE_EXPERIMENT"
106+ RUNNER_RUN = "RUNNER_RUN"
107+ UPDATE_EXPERIMENT_DETAILS = "UPDATE_EXPERIMENT_DETAILS"
108+
109+
102110def _endpoint_enabled (endpoint_name : str ) -> bool :
103111 config = read_config_file ()
104112 endpoints = config .get ("RUNNER_CONFIGURATION" , {}).get ("ENDPOINTS" , {})
@@ -114,7 +122,7 @@ async def set_job_status(
114122 """
115123 Set the job status for an experiment using the specified runner profile.
116124 """
117- if not _endpoint_enabled (" SET_JOB_STATUS" ):
125+ if not _endpoint_enabled (RunnerEndpointsCategory . SET_JOB_STATUS . value ):
118126 raise HTTPException (
119127 status_code = 403 ,
120128 detail = "The set-job-status endpoint is currently disabled." ,
@@ -166,7 +174,7 @@ async def run_experiment(
166174 """
167175 Run an experiment using the specified runner profile.
168176 """
169- if not _endpoint_enabled (" RUNNER_RUN" ):
177+ if not _endpoint_enabled (RunnerEndpointsCategory . RUNNER_RUN . value ):
170178 raise HTTPException (
171179 status_code = 403 ,
172180 detail = "The run-experiment endpoint is currently disabled." ,
@@ -218,7 +226,7 @@ async def get_runner_run_status(
218226 """
219227 Get the status of the runner run for a given experiment ID.
220228 """
221- if not _endpoint_enabled (" RUNNER_RUN" ):
229+ if not _endpoint_enabled (RunnerEndpointsCategory . RUNNER_RUN . value ):
222230 raise HTTPException (
223231 status_code = 403 ,
224232 detail = "The get-runner-run-status endpoint is currently disabled." ,
@@ -264,7 +272,7 @@ async def stop_experiment(
264272 """
265273 Stop an experiment using the specified runner profile.
266274 """
267- if not _endpoint_enabled (" RUNNER_RUN" ):
275+ if not _endpoint_enabled (RunnerEndpointsCategory . RUNNER_RUN . value ):
268276 raise HTTPException (
269277 status_code = 403 ,
270278 detail = "The stop-experiment endpoint is currently disabled." ,
@@ -310,7 +318,7 @@ async def create_experiment(
310318 """
311319 Create an experiment using the specified runner profile.
312320 """
313- if not _endpoint_enabled (" CREATE_EXPERIMENT" ):
321+ if not _endpoint_enabled (RunnerEndpointsCategory . CREATE_EXPERIMENT . value ):
314322 raise HTTPException (
315323 status_code = 403 ,
316324 detail = "The create-experiment endpoint is currently disabled." ,
@@ -352,3 +360,59 @@ async def create_experiment(
352360 "expid" : expid ,
353361 "message" : f"Experiment { expid } created successfully." ,
354362 }
363+
364+
365+ class UpdateExperimentBody (RunnerEndpointBody ):
366+ expid : str
367+ description : str
368+
369+
370+ @router .post (
371+ "/command/update-experiment-description" , name = "Update experiment description"
372+ )
373+ async def update_experiment_description (
374+ body : UpdateExperimentBody ,
375+ user_id : Optional [str ] = Depends (auth_token_dependency ()),
376+ ) -> Dict [str , Any ]:
377+ """
378+ Update the description of an experiment using the specified runner profile.
379+ """
380+ if not _endpoint_enabled (RunnerEndpointsCategory .UPDATE_EXPERIMENT_DETAILS .value ):
381+ raise HTTPException (
382+ status_code = 403 ,
383+ detail = "The update-experiment-description endpoint is currently disabled." ,
384+ )
385+
386+ expid = body .expid
387+ description = body .description
388+
389+ logger .info (
390+ f"Updating description for experiment { expid } using profile { body .profile_name } "
391+ )
392+
393+ try :
394+ profile = process_profile (body .profile_name , body .profile_params )
395+ logger .debug (
396+ f"Processing profile: { body .profile_name } . Profile data: { profile } "
397+ )
398+
399+ runner_type , module_loader_type , modules = (
400+ profile .get ("RUNNER_TYPE" ),
401+ profile .get ("MODULE_LOADER_TYPE" ),
402+ profile .get ("MODULES" ),
403+ )
404+
405+ runner_extra_params = get_runner_extra_params (profile )
406+
407+ module_loader = get_module_loader (module_loader_type , modules )
408+ runner = get_runner (runner_type , module_loader , ** runner_extra_params )
409+ await runner .update_description (expid , description )
410+ except Exception as exc :
411+ raise HTTPException (
412+ status_code = 500 ,
413+ detail = f"Failed to update description for experiment { expid } : { exc } " ,
414+ )
415+
416+ return {
417+ "message" : f"Description for experiment { expid } updated successfully." ,
418+ }
0 commit comments