Skip to content

Commit cf0ade0

Browse files
authored
Merge pull request #55 from ecmwf-projects/555-update-post-process-execution
Refactorization
2 parents 7da57f6 + 3554793 commit cf0ade0

File tree

7 files changed

+106
-110
lines changed

7 files changed

+106
-110
lines changed

ogc_api_processes_fastapi/clients.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import fastapi
2121

22-
from . import responses
22+
from . import models
2323

2424

2525
class BaseClient(abc.ABC):
@@ -28,7 +28,7 @@ class BaseClient(abc.ABC):
2828
@abc.abstractmethod
2929
def get_processes(
3030
self, limit: Optional[int] = fastapi.Query(None)
31-
) -> responses.ProcessList:
31+
) -> models.ProcessList:
3232
"""Get all available processes.
3333
3434
Called with `GET /processes`.
@@ -40,15 +40,15 @@ def get_processes(
4040
4141
Returns
4242
-------
43-
responses.ProcessList
43+
models.ProcessList
4444
List of available processes summaries.
4545
"""
4646
...
4747

4848
@abc.abstractmethod
4949
def get_process(
5050
self, process_id: str = fastapi.Path(...)
51-
) -> responses.ProcessDescription:
51+
) -> models.ProcessDescription:
5252
"""Get description of the process identified by `process_id`.
5353
5454
Called with `GET /processes/{process_id}`.
@@ -60,7 +60,7 @@ def get_process(
6060
6161
Returns
6262
-------
63-
responses.schema["ProcessDescription"]
63+
models.ProcessDescription
6464
Description of the process.
6565
6666
Raises
@@ -75,7 +75,7 @@ def post_process_execution(
7575
self,
7676
process_id: str = fastapi.Path(...),
7777
execution_content: Dict[str, Any] = fastapi.Body(...),
78-
) -> responses.StatusInfo:
78+
) -> models.StatusInfo:
7979
"""Post request for execution of the process identified by `process_id`.
8080
8181
Called with `POST /processes/{process_id}/execution`.
@@ -90,7 +90,7 @@ def post_process_execution(
9090
9191
Returns
9292
-------
93-
responses.StatusInfo
93+
models.StatusInfo
9494
Information on the status of the submitted job.
9595
9696
Raises
@@ -106,7 +106,7 @@ def get_jobs(
106106
processID: Optional[List[str]] = fastapi.Query(None),
107107
status: Optional[List[str]] = fastapi.Query(None),
108108
limit: Optional[int] = fastapi.Query(10, ge=1, le=10000),
109-
) -> responses.JobList:
109+
) -> models.JobList:
110110
"""Get the list of submitted jobs.
111111
112112
Called with `GET /jobs`.
@@ -127,12 +127,12 @@ def get_jobs(
127127
128128
Returns
129129
-------
130-
responses.JobList
130+
models.JobList
131131
List of jobs.
132132
"""
133133

134134
@abc.abstractmethod
135-
def get_job(self, job_id: str = fastapi.Path(...)) -> responses.StatusInfo:
135+
def get_job(self, job_id: str = fastapi.Path(...)) -> models.StatusInfo:
136136
"""Get status information of the job identified by `job_id`.
137137
138138
Called with `GET /jobs/{job_id}`.
@@ -144,7 +144,7 @@ def get_job(self, job_id: str = fastapi.Path(...)) -> responses.StatusInfo:
144144
145145
Returns
146146
-------
147-
responses.StatusInfo
147+
models.StatusInfo
148148
Information on the status of the job.
149149
150150
Raises
@@ -155,7 +155,7 @@ def get_job(self, job_id: str = fastapi.Path(...)) -> responses.StatusInfo:
155155
...
156156

157157
@abc.abstractmethod
158-
def get_job_results(self, job_id: str = fastapi.Path(...)) -> responses.Results:
158+
def get_job_results(self, job_id: str = fastapi.Path(...)) -> models.Results:
159159
"""Get results of the job identified by `job_id`.
160160
161161
Called with `GET /jobs/{job_id}/results`.
@@ -167,7 +167,7 @@ def get_job_results(self, job_id: str = fastapi.Path(...)) -> responses.Results:
167167
168168
Returns
169169
-------
170-
responses.Results
170+
models.Results
171171
Job results.
172172
173173
Raises
@@ -182,7 +182,7 @@ def get_job_results(self, job_id: str = fastapi.Path(...)) -> responses.Results:
182182
...
183183

184184
@abc.abstractmethod
185-
def delete_job(self, job_id: str = fastapi.Path(...)) -> responses.StatusInfo:
185+
def delete_job(self, job_id: str = fastapi.Path(...)) -> models.StatusInfo:
186186
"""Cancel the job identified by `job_id`.
187187
188188
Called with `DELETE /jobs/{job_id}`.
@@ -194,7 +194,7 @@ def delete_job(self, job_id: str = fastapi.Path(...)) -> responses.StatusInfo:
194194
195195
Returns
196196
-------
197-
responses.StatusInfo
197+
models.StatusInfo
198198
Information on the status of the job.
199199
200200
Raises

ogc_api_processes_fastapi/endpoints.py

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
import fastapi
77

8-
from . import clients, responses
8+
from . import clients, models
99

1010

1111
def create_links_to_job(
12-
request: fastapi.Request, job: responses.StatusInfo
13-
) -> List[responses.Link]:
12+
request: fastapi.Request, job: models.StatusInfo
13+
) -> List[models.Link]:
1414
"""Create links to attach to provided the job.
1515
1616
Parameters
1717
----------
18-
job : schema["StatusInfo"]
18+
job : models.StatusInfo
1919
Job to create links for.
2020
2121
Returns
2222
-------
23-
List[responses.Link]
23+
List[models.Link]
2424
Links to attach to job.
2525
"""
2626
rel_job_link = "self"
@@ -29,7 +29,7 @@ def create_links_to_job(
2929
rel_job_link = "monitor"
3030
title_job_link = "job status info"
3131
links = [
32-
responses.Link(
32+
models.Link(
3333
href=urllib.parse.urljoin(str(request.base_url), f"jobs/{job.jobID}"),
3434
rel=rel_job_link,
3535
type="application/json",
@@ -38,7 +38,7 @@ def create_links_to_job(
3838
]
3939
if job.status.value in ("successful", "failed"):
4040
links.append(
41-
responses.Link(
41+
models.Link(
4242
href=urllib.parse.urljoin(
4343
str(request.base_url), f"jobs/{job.jobID}/results"
4444
),
@@ -50,8 +50,8 @@ def create_links_to_job(
5050

5151
def create_self_link(
5252
request_url: str, title: Optional[str] = None, type: Optional[str] = None
53-
) -> responses.Link:
54-
self_link = responses.Link(href=str(request_url), rel="self")
53+
) -> models.Link:
54+
self_link = models.Link(href=str(request_url), rel="self")
5555
if type:
5656
self_link.type = type
5757
if title:
@@ -60,8 +60,8 @@ def create_self_link(
6060

6161

6262
def create_page_link(
63-
request_url: str, page: str, pagination_qs: responses.PaginationQueryParameters
64-
) -> responses.Link:
63+
request_url: str, page: str, pagination_qs: models.PaginationQueryParameters
64+
) -> models.Link:
6565
if page not in ("next", "prev"):
6666
raise ValueError(f"{page} is not a valid value for ``page`` parameter")
6767
request_parsed = urllib.parse.urlsplit(request_url)
@@ -72,13 +72,13 @@ def create_page_link(
7272
query_string = urllib.parse.urlencode(queries_page, doseq=True)
7373
parsed_page_request = request_parsed._replace(query=query_string)
7474
url_page = parsed_page_request.geturl()
75-
link_page = responses.Link(href=url_page, rel=page)
75+
link_page = models.Link(href=url_page, rel=page)
7676
return link_page
7777

7878

7979
def create_pagination_links(
80-
request_url: str, pagination_qs: Optional[responses.PaginationQueryParameters]
81-
) -> List[responses.Link]:
80+
request_url: str, pagination_qs: Optional[models.PaginationQueryParameters]
81+
) -> List[models.Link]:
8282
pagination_links = []
8383
if pagination_qs:
8484
if pagination_qs.next:
@@ -92,32 +92,32 @@ def create_pagination_links(
9292

9393
def create_get_landing_page_endpoint(
9494
client: clients.BaseClient,
95-
) -> Callable[[fastapi.Request], responses.LandingPage]:
95+
) -> Callable[[fastapi.Request], models.LandingPage]:
9696
def get_landing_page(
9797
request: fastapi.Request,
98-
) -> responses.LandingPage:
98+
) -> models.LandingPage:
9999
"""Get the API landing page."""
100100
links = [
101-
responses.Link(
101+
models.Link(
102102
href=urllib.parse.urljoin(str(request.base_url), "openapi.json"),
103103
rel="service-desc",
104104
type="application/vnd.oai.openapi+json;version=3.0",
105105
title="OpenAPI service description",
106106
),
107-
responses.Link(
107+
models.Link(
108108
href=urllib.parse.urljoin(str(request.base_url), "conformance"),
109109
rel="http://www.opengis.net/def/rel/ogc/1.0/conformance",
110110
type="application/json",
111111
title="Conformance declaration",
112112
),
113-
responses.Link(
113+
models.Link(
114114
href=urllib.parse.urljoin(str(request.base_url), "processes"),
115115
rel="http://www.opengis.net/def/rel/ogc/1.0/processes",
116116
type="application/json",
117117
title="Metadata about the processes",
118118
),
119119
]
120-
landing_page = responses.LandingPage(links=links)
120+
landing_page = models.LandingPage(links=links)
121121

122122
return landing_page
123123

@@ -126,10 +126,10 @@ def get_landing_page(
126126

127127
def create_get_conformance_endpoint(
128128
client: clients.BaseClient,
129-
) -> Callable[[fastapi.Request], responses.ConfClass]:
130-
def get_conformance(request: fastapi.Request) -> responses.ConfClass:
129+
) -> Callable[[fastapi.Request], models.ConfClass]:
130+
def get_conformance(request: fastapi.Request) -> models.ConfClass:
131131
"""Get the API conformance declaration page."""
132-
conformance = responses.ConfClass(
132+
conformance = models.ConfClass(
133133
conformsTo=[
134134
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/core",
135135
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/ogc-process-description",
@@ -146,11 +146,11 @@ def get_conformance(request: fastapi.Request) -> responses.ConfClass:
146146

147147
def create_get_processes_endpoint(
148148
client: clients.BaseClient,
149-
) -> Callable[[fastapi.Request], responses.ProcessList]:
149+
) -> Callable[[fastapi.Request], models.ProcessList]:
150150
def get_processes(
151151
request: fastapi.Request,
152-
process_list: responses.ProcessList = fastapi.Depends(client.get_processes),
153-
) -> responses.ProcessList:
152+
process_list: models.ProcessList = fastapi.Depends(client.get_processes),
153+
) -> models.ProcessList:
154154
"""Get the list of available processes.
155155
156156
The list of processes contains a summary of each process
@@ -159,7 +159,7 @@ def get_processes(
159159
"""
160160
for process in process_list.processes:
161161
process.links = [
162-
responses.Link(
162+
models.Link(
163163
href=urllib.parse.urljoin(
164164
str(request.base_url), f"processes/{process.id}"
165165
),
@@ -184,11 +184,11 @@ def get_processes(
184184

185185
def create_get_process_endpoint(
186186
client: clients.BaseClient,
187-
) -> Callable[[fastapi.Request], responses.ProcessDescription]:
187+
) -> Callable[[fastapi.Request], models.ProcessDescription]:
188188
def get_process(
189189
request: fastapi.Request,
190-
process: responses.ProcessDescription = fastapi.Depends(client.get_process),
191-
) -> responses.ProcessDescription:
190+
process: models.ProcessDescription = fastapi.Depends(client.get_process),
191+
) -> models.ProcessDescription:
192192
"""Get the description of a specific process.
193193
194194
The list of processes contains a summary of each process
@@ -197,7 +197,7 @@ def get_process(
197197
"""
198198
process.links = [
199199
create_self_link(str(request.url)),
200-
responses.Link(
200+
models.Link(
201201
href=urllib.parse.urljoin(
202202
str(request.base_url), f"processes/{process.id}/execution"
203203
),
@@ -214,18 +214,16 @@ def get_process(
214214

215215
def create_post_process_execution_endpoint(
216216
client: clients.BaseClient,
217-
) -> Callable[[fastapi.Request, fastapi.Response], responses.StatusInfo]:
217+
) -> Callable[[fastapi.Request, fastapi.Response], models.StatusInfo]:
218218
def post_process_execution(
219219
request: fastapi.Request,
220220
response: fastapi.Response,
221-
status_info: responses.StatusInfo = fastapi.Depends(
222-
client.post_process_execution
223-
),
224-
) -> responses.StatusInfo:
221+
status_info: models.StatusInfo = fastapi.Depends(client.post_process_execution),
222+
) -> models.StatusInfo:
225223
"""Create a new job."""
226224
status_info.links = [
227225
create_self_link(str(request.url)),
228-
responses.Link(
226+
models.Link(
229227
href=urllib.parse.urljoin(
230228
str(request.base_url), f"jobs/{status_info.jobID}"
231229
),
@@ -245,11 +243,11 @@ def post_process_execution(
245243

246244
def create_get_jobs_endpoint(
247245
client: clients.BaseClient,
248-
) -> Callable[[fastapi.Request], responses.JobList]:
246+
) -> Callable[[fastapi.Request], models.JobList]:
249247
def get_jobs(
250248
request: fastapi.Request,
251-
job_list: responses.JobList = fastapi.Depends(client.get_jobs),
252-
) -> responses.JobList:
249+
job_list: models.JobList = fastapi.Depends(client.get_jobs),
250+
) -> models.JobList:
253251
"""Show the list of submitted jobs."""
254252
for job in job_list.jobs:
255253
job.links = create_links_to_job(job=job, request=request)
@@ -269,11 +267,11 @@ def get_jobs(
269267

270268
def create_get_job_endpoint(
271269
client: clients.BaseClient,
272-
) -> Callable[[fastapi.Request], responses.StatusInfo]:
270+
) -> Callable[[fastapi.Request], models.StatusInfo]:
273271
def get_job(
274272
request: fastapi.Request,
275-
job: responses.StatusInfo = fastapi.Depends(client.get_job),
276-
) -> responses.StatusInfo:
273+
job: models.StatusInfo = fastapi.Depends(client.get_job),
274+
) -> models.StatusInfo:
277275
"""Show the status of a job."""
278276
job.links = create_links_to_job(job=job, request=request)
279277

@@ -284,10 +282,10 @@ def get_job(
284282

285283
def create_get_job_results_endpoint(
286284
client: clients.BaseClient,
287-
) -> Callable[[], responses.Results]:
285+
) -> Callable[[], models.Results]:
288286
def get_job_results(
289-
job_results: responses.Results = fastapi.Depends(client.get_job_results),
290-
) -> responses.Results:
287+
job_results: models.Results = fastapi.Depends(client.get_job_results),
288+
) -> models.Results:
291289
"""Show results of a job."""
292290
return job_results
293291

@@ -296,10 +294,10 @@ def get_job_results(
296294

297295
def create_delete_job_endpoint(
298296
client: clients.BaseClient,
299-
) -> Callable[[], responses.StatusInfo]:
297+
) -> Callable[[], models.StatusInfo]:
300298
def delete_job(
301-
job: responses.StatusInfo = fastapi.Depends(client.delete_job),
302-
) -> responses.StatusInfo:
299+
job: models.StatusInfo = fastapi.Depends(client.delete_job),
300+
) -> models.StatusInfo:
303301
"""Cancel a job."""
304302
return job
305303

0 commit comments

Comments
 (0)