Skip to content

Commit 386e899

Browse files
committed
update get_solver_release to use rpc interface
1 parent e133506 commit 386e899

File tree

1 file changed

+45
-15
lines changed
  • services/api-server/src/simcore_service_api_server/api/routes

1 file changed

+45
-15
lines changed

services/api-server/src/simcore_service_api_server/api/routes/solvers.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from operator import attrgetter
44
from typing import Annotated, Any
55

6+
from common_library.pagination_tools import iter_pagination_params
67
from fastapi import APIRouter, Depends, HTTPException, status
7-
from grpc import services
88
from httpx import HTTPStatusError
99
from models_library.api_schemas_catalog.services import ServiceListFilters
10+
from models_library.rest_pagination import MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE
1011
from models_library.services_enums import ServiceType
1112
from pydantic import ValidationError
1213
from simcore_service_api_server.services_rpc.catalog import CatalogService
@@ -30,6 +31,9 @@
3031
create_route_description,
3132
)
3233

34+
DEFAULT_PAGINATION_LIMIT = MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE - 1
35+
36+
3337
_logger = logging.getLogger(__name__)
3438

3539
_SOLVER_STATUS_CODES: dict[int | str, dict[str, Any]] = {
@@ -77,7 +81,7 @@ async def list_solvers(
7781
):
7882
"""Lists all available solvers (latest version)"""
7983

80-
services, page_info = await catalog_service.list_latest_releases(
84+
services, _ = await catalog_service.list_latest_releases(
8185
user_id=user_id,
8286
product_name=product_name,
8387
filters=ServiceListFilters(service_type=ServiceType.COMPUTATIONAL),
@@ -110,26 +114,52 @@ async def get_solvers_page(
110114
response_model=list[Solver],
111115
summary="Lists All Releases",
112116
responses=_SOLVER_STATUS_CODES,
117+
description=create_route_description(
118+
base="Lists all released solvers (not just latest version)",
119+
deprecated=True,
120+
alternative="GET /v0/solvers/releases/page",
121+
changelog=[
122+
FMSG_CHANGELOG_NEW_IN_VERSION.format("0.5.0", ""),
123+
FMSG_CHANGELOG_REMOVED_IN_VERSION_FORMAT.format(
124+
"0.7",
125+
"This endpoint is deprecated and will be removed in a future version",
126+
),
127+
],
128+
),
113129
)
114130
async def list_solvers_releases(
115131
user_id: Annotated[int, Depends(get_current_user_id)],
116-
catalog_client: Annotated[CatalogApi, Depends(get_api_client(CatalogApi))],
132+
catalog_service: Annotated[CatalogService, Depends()],
117133
url_for: Annotated[Callable, Depends(get_reverse_url_mapper)],
118134
product_name: Annotated[str, Depends(get_product_name)],
119135
):
120-
"""Lists all released solvers i.e. all released versions
121136

122-
SEE get_solvers_releases_page for a paginated version of this function
123-
"""
124-
assert await catalog_client.is_responsive() # nosec
125-
126-
services = await catalog_client.list_services(
127-
user_id=user_id,
128-
product_name=product_name,
129-
predicate=None,
130-
type_filter="COMPUTATIONAL",
131-
)
132-
solvers = [service.to_solver() for service in services]
137+
latest_releases = []
138+
for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT):
139+
services, page_meta = await catalog_service.list_latest_releases(
140+
user_id=user_id,
141+
product_name=product_name,
142+
offset=page_params.offset,
143+
limit=page_params.limit,
144+
filters=ServiceListFilters(service_type=ServiceType.COMPUTATIONAL),
145+
)
146+
page_params.total_number_of_items = page_meta.total
147+
latest_releases.extend(services)
148+
149+
all_releases = []
150+
for service in latest_releases:
151+
for page_params in iter_pagination_params(limit=DEFAULT_PAGINATION_LIMIT):
152+
services, page_meta = await catalog_service.list_release_history(
153+
product_name=product_name,
154+
user_id=user_id,
155+
service_key=service.id,
156+
offset=page_params.offset,
157+
limit=page_params.limit,
158+
)
159+
page_params.total_number_of_items = page_meta.total
160+
all_releases.extend(services)
161+
162+
solvers = [Solver.create_from_service(service) for service in all_releases]
133163

134164
for solver in solvers:
135165
solver.url = url_for(

0 commit comments

Comments
 (0)