diff --git a/src/everest/detached/jobs/everest_server_api.py b/src/everest/detached/jobs/everest_server_api.py index 40a28a46e6c..384570cfb39 100644 --- a/src/everest/detached/jobs/everest_server_api.py +++ b/src/everest/detached/jobs/everest_server_api.py @@ -36,7 +36,11 @@ from everest.config import EverestConfig, ServerConfig from everest.detached import get_opt_status from everest.strings import ( + EXIT_CODE_ENDPOINT, + OPT_PROGRESS_ENDPOINT, + SHARED_DATA_ENDPOINT, SIM_PROGRESS_ENDPOINT, + START_ENDPOINT, STOP_ENDPOINT, ) from everest.util import makedirs_if_needed @@ -237,16 +241,22 @@ def __init__(self, everest_config: EverestConfig): self.router = APIRouter() self.router.add_api_route("/", self.get_status, methods=["GET"]) - self.router.add_api_route("/stop", self.stop, methods=["POST"]) + self.router.add_api_route("/" + STOP_ENDPOINT, self.stop, methods=["POST"]) self.router.add_api_route( - "/sim_progress", self.get_sim_progress, methods=["GET"] + "/" + SIM_PROGRESS_ENDPOINT, self.get_sim_progress, methods=["GET"] ) self.router.add_api_route( - "/opt_progress", self.get_opt_progress, methods=["GET"] + "/" + OPT_PROGRESS_ENDPOINT, self.get_opt_progress, methods=["GET"] + ) + self.router.add_api_route( + "/" + START_ENDPOINT, self.start_experiment, methods=["POST"] + ) + self.router.add_api_route( + "/" + EXIT_CODE_ENDPOINT, self.get_exit_code, methods=["GET"] + ) + self.router.add_api_route( + "/" + SHARED_DATA_ENDPOINT, self.get_state, methods=["GET"] ) - self.router.add_api_route("/start", self.start_experiment, methods=["POST"]) - self.router.add_api_route("/exit_code", self.get_exit_code, methods=["GET"]) - self.router.add_api_route("/state", self.get_state, methods=["GET"]) self.app.include_router(self.router) @@ -326,7 +336,6 @@ def get_exit_code( ) -> JSONResponse: self._log(request) self._check_user(credentials) - return JSONResponse( jsonable_encoder( self.runner.get_exit_code() if self.runner.get_exit_code() else {} @@ -345,14 +354,14 @@ def start_experiment( self, request: Request, credentials: HTTPBasicCredentials = Depends(security), - ) -> JSONResponse: + ) -> Response: self._log(request) self._check_user(credentials) self.runner = ExperimentRunner(self.everest_config, self.state) self.runner.start() - return JSONResponse("ok") + return Response("Everest experiment started", 200) def get_state( self, request: Request, credentials: HTTPBasicCredentials = Depends(security) diff --git a/src/everest/detached/jobs/everserver.py b/src/everest/detached/jobs/everserver.py index 5625cad3ddd..11c518e4d24 100755 --- a/src/everest/detached/jobs/everserver.py +++ b/src/everest/detached/jobs/everserver.py @@ -20,8 +20,11 @@ from everest.simulator import JOB_FAILURE from everest.strings import ( EVEREST, + EXIT_CODE_ENDPOINT, OPT_FAILURE_REALIZATIONS, + SHARED_DATA_ENDPOINT, SIM_PROGRESS_ENDPOINT, + START_ENDPOINT, STOP_ENDPOINT, ) from everest.util import configure_logger, version_info @@ -156,24 +159,24 @@ def main(): while not is_running: try: requests.get(url + "/", verify=cert, auth=auth, proxies=PROXY) - # check return value is_running = True except: time.sleep(1) update_everserver_status(status_path, ServerStatus.running) - # start - response = requests.post(url + "/start", verify=cert, auth=auth, proxies=PROXY) + response = requests.post( + url + "/" + START_ENDPOINT, verify=cert, auth=auth, proxies=PROXY + ) - is_running = True - while is_running: + is_done = False + while not is_done: response = requests.get( - url + "/exit_code", verify=cert, auth=auth, proxies=PROXY + url + "/" + EXIT_CODE_ENDPOINT, verify=cert, auth=auth, proxies=PROXY ) exit_code = ExitCode.model_validate_json(response.text) if exit_code.exit_code or exit_code.message: - is_running = False + is_done = True else: time.sleep(1) @@ -185,7 +188,9 @@ def main(): ) return - response = requests.get(url + "/state", verify=cert, auth=auth, proxies=PROXY) + response = requests.get( + url + "/" + SHARED_DATA_ENDPOINT, verify=cert, auth=auth, proxies=PROXY + ) if json_body := json.loads(response.text): shared_data = json_body diff --git a/src/everest/strings.py b/src/everest/strings.py index 50be1da326b..791eca51ae6 100644 --- a/src/everest/strings.py +++ b/src/everest/strings.py @@ -29,5 +29,9 @@ SIMULATOR_END = "end" SIM_PROGRESS_ENDPOINT = "sim_progress" SIM_PROGRESS_ID = "simulation_progress" +START_ENDPOINT = "start" STOP_ENDPOINT = "stop" STORAGE_DIR = "simulation_results" +STATUS_ENDPOINT = "status" +SHARED_DATA_ENDPOINT = "shared_data" +EXIT_CODE_ENDPOINT = "exit_code"