Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22 synchronize endpoints wrt esdl encoding #24

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/omotes_rest/apis/api_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class JobInput:
Schema: ClassVar[Type[Schema]] = Schema

job_name: str = "job name"
workflow_type: str = "Draft Design - Quickscan Validation"
workflow_type: str = "grow_optimizer_no_heat_losses"
user_name: str = "user name"
input_esdl: str = "input ESDL base64string"
project_name: str = "project name"
Expand Down
18 changes: 17 additions & 1 deletion src/omotes_rest/apis/job.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import logging
import uuid

Expand Down Expand Up @@ -38,6 +39,10 @@ class JobAPI(MethodView):
@api.response(200, JobStatusResponse.Schema())
def post(self, job_input: JobInput) -> JobStatusResponse:
"""Start new job: 'input_params_dict' can have lists and (nested) dicts as values."""
esdlstr_bytes = job_input.input_esdl.encode("utf-8")
esdlstr_base64_bytes = base64.b64decode(esdlstr_bytes)
esdl_str = esdlstr_base64_bytes.decode("utf-8")
job_input.input_esdl = esdl_str
return current_app.rest_if.submit_job(job_input)

@api.response(200, JobSummary.Schema(many=True))
Expand All @@ -53,7 +58,16 @@ class JobFromIdAPI(MethodView):
@api.response(200, JobResponse.Schema())
def get(self, job_id: str) -> JobRest | None:
"""Return job details."""
return current_app.rest_if.get_job(uuid.UUID(job_id))
job = current_app.rest_if.get_job(uuid.UUID(job_id))
if job:
input_esdl = job.input_esdl
if input_esdl:
job.input_esdl = base64.b64encode(bytes(input_esdl, "utf-8")).decode("utf-8")

output_esdl = job.output_esdl
if output_esdl:
job.output_esdl = base64.b64encode(bytes(output_esdl, "utf-8")).decode("utf-8")
return job

@api.response(200, JobDeleteResponse.Schema())
def delete(self, job_id: str) -> JobDeleteResponse:
Expand Down Expand Up @@ -102,6 +116,8 @@ def get(self, job_id: str) -> JobResultResponse:
"""Return job result with output ESDL (can be None)."""
job_uuid = uuid.UUID(job_id)
output_esdl = current_app.rest_if.get_job_output_esdl(job_uuid)
if output_esdl:
output_esdl = base64.b64encode(bytes(output_esdl, "utf-8")).decode("utf-8")
return JobResultResponse(job_id=job_uuid, output_esdl=output_esdl)


Expand Down
Loading