Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frode-aarstad committed Nov 28, 2024
1 parent 080ce06 commit 3187e0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
22 changes: 13 additions & 9 deletions src/everest/detached/jobs/everest_server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -237,16 +241,16 @@ 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", 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.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.app.include_router(self.router)

Expand Down Expand Up @@ -326,7 +330,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 {}
Expand All @@ -345,14 +348,15 @@ 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)
Expand Down
17 changes: 9 additions & 8 deletions src/everest/detached/jobs/everserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -156,24 +159,22 @@ 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)

Expand All @@ -185,7 +186,7 @@ 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

Expand Down
5 changes: 5 additions & 0 deletions src/everest/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
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"

0 comments on commit 3187e0c

Please sign in to comment.