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

✨ Expose /licensed-items endpoint in api server #6958

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
829eae9
db layer licensed items purchase
matusdrobuliak66 Dec 9, 2024
a975a63
rut part
matusdrobuliak66 Dec 10, 2024
fc62c0d
merge master
matusdrobuliak66 Dec 10, 2024
78ef2cc
renaming tests
matusdrobuliak66 Dec 10, 2024
a6f49cd
rpc interface
matusdrobuliak66 Dec 10, 2024
f5de79b
RUT unit tests
matusdrobuliak66 Dec 10, 2024
acd4c88
RUT unit tests
matusdrobuliak66 Dec 10, 2024
317cf1d
RUT unit tests
matusdrobuliak66 Dec 10, 2024
932fb00
webserver part
matusdrobuliak66 Dec 10, 2024
06f5743
webserver part
matusdrobuliak66 Dec 10, 2024
dbd1ffe
open api specs
matusdrobuliak66 Dec 10, 2024
6bec5ff
webserver part tests
matusdrobuliak66 Dec 10, 2024
754cd58
Merge branch 'master' into introduce-vip-models-pricing-4-part
matusdrobuliak66 Dec 10, 2024
3755dce
open api specs
matusdrobuliak66 Dec 10, 2024
8f264b1
Merge branch 'introduce-vip-models-pricing-4-part' of github.com:matu…
matusdrobuliak66 Dec 10, 2024
4185852
fix type
matusdrobuliak66 Dec 10, 2024
4c31cd0
fix type
matusdrobuliak66 Dec 10, 2024
530fda0
fix type
matusdrobuliak66 Dec 10, 2024
00d40bd
fix type
matusdrobuliak66 Dec 10, 2024
fa3c648
Merge branch 'master' into introduce-vip-models-pricing-4-part
matusdrobuliak66 Dec 10, 2024
12ebf32
Merge branch 'master' into introduce-vip-models-pricing-4-part
matusdrobuliak66 Dec 11, 2024
969f982
review @pcrespov
matusdrobuliak66 Dec 11, 2024
138412e
adding purchase item functionality
matusdrobuliak66 Dec 11, 2024
7e9de14
open api specs
matusdrobuliak66 Dec 11, 2024
4f1c5d6
improve error handling
matusdrobuliak66 Dec 11, 2024
26f9c57
open api specs
matusdrobuliak66 Dec 11, 2024
583b2b4
fix import
matusdrobuliak66 Dec 11, 2024
4a1008f
fix import
matusdrobuliak66 Dec 11, 2024
776806b
fix typecheck
matusdrobuliak66 Dec 11, 2024
fadfa1f
fix typecheck
matusdrobuliak66 Dec 11, 2024
e1337f0
Merge branch 'master' into introduce-vip-models-pricing-5-part
matusdrobuliak66 Dec 11, 2024
0766313
contract between webserver and api server
matusdrobuliak66 Dec 11, 2024
f09fb33
Merge branch 'master' into introduce-vip-models-pricing-5-part
matusdrobuliak66 Dec 11, 2024
a851dd1
add rabbitmq_rpc client to api-server
bisgaard-itis Dec 11, 2024
08484fb
Merge branch 'master' into 6948-expose-licensing-endpoints-api-server
bisgaard-itis Dec 11, 2024
6ba9ca5
Merge remote-tracking branch 'matusdrobuliak66/introduce-vip-models-p…
bisgaard-itis Dec 11, 2024
1cfbfc7
start adding first endpoint
bisgaard-itis Dec 11, 2024
c715cdf
minor change
bisgaard-itis Dec 11, 2024
c3fd714
Merge branch 'master' into 6948-expose-licensing-endpoints-api-server
bisgaard-itis Dec 12, 2024
a41e126
services -> services_http
bisgaard-itis Dec 12, 2024
deed91a
start developing an webapi rpc client
bisgaard-itis Dec 12, 2024
6d220d3
webserver.py -> webserver_http.py
bisgaard-itis Dec 12, 2024
a027ecf
connect pieces to expose licensed items
bisgaard-itis Dec 12, 2024
cefc23e
start adding test
bisgaard-itis Dec 12, 2024
542b80b
mock backend with pydantic model example
bisgaard-itis Dec 12, 2024
51ef078
require input input names in exception mapper
bisgaard-itis Dec 12, 2024
044199e
handle rpc client exceptions
bisgaard-itis Dec 12, 2024
3577938
update openapi spes
bisgaard-itis Dec 12, 2024
2cdaab8
Merge branch 'master' into 6948-expose-licensing-endpoints-api-server
bisgaard-itis Dec 12, 2024
0bd8e4f
fix import
bisgaard-itis Dec 12, 2024
582fb9b
ensure relative imports
bisgaard-itis Dec 12, 2024
9e173b9
fix exception detail
bisgaard-itis Dec 12, 2024
3512611
@pcrespov @matusdrobuliak66 remove /page in endpoint
bisgaard-itis Dec 12, 2024
115a60f
@pcrespov rename rpc client to _client
bisgaard-itis Dec 12, 2024
f87ccb4
@pcrespov move model_config below fields
bisgaard-itis Dec 12, 2024
87f5b57
@pcrespov name -> display_name
bisgaard-itis Dec 12, 2024
30eb799
hide endpoint from openapi.json @pcrespov @matusdrobuliak66
bisgaard-itis Dec 12, 2024
19728f5
Merge branch 'master' into 6948-expose-licensing-endpoints-api-server
bisgaard-itis Dec 12, 2024
f040401
make mypy happy
bisgaard-itis Dec 12, 2024
85fdb00
add __init__.py
bisgaard-itis Dec 12, 2024
7afde22
fix pylint
bisgaard-itis Dec 13, 2024
f80853a
small fix
bisgaard-itis Dec 13, 2024
8a52ec3
fix unit api-server tests
bisgaard-itis Dec 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from models_library.licensed_items import LicensedItemID, LicensedResourceType
from models_library.resource_tracker import PricingPlanId
from pydantic import PositiveInt
from pydantic import ConfigDict, PositiveInt

from ._base import OutputSchema

Expand All @@ -15,6 +15,20 @@ class LicensedItemGet(OutputSchema):
pricing_plan_id: PricingPlanId
created_at: datetime
modified_at: datetime
model_config = ConfigDict(
json_schema_extra={
"examples": [
{
"licensed_item_id": "0362b88b-91f8-4b41-867c-35544ad1f7a1",
"name": "best-model",
"licensed_resource_type": f"{LicensedResourceType.VIP_MODEL}",
"pricing_plan_id": "15",
"created_at": "2024-12-12 09:59:26.422140",
"modified_at": "2024-12-12 09:59:26.422140",
}
]
}
)


class LicensedItemGetPage(NamedTuple):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
from servicelib.aiohttp.application_setup import ApplicationSetupError
from servicelib.fastapi.dependencies import get_app
from servicelib.rabbitmq import RabbitMQClient
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
from tenacity import before_sleep_log, retry, stop_after_delay, wait_fixed

from ...services.log_streaming import LogDistributor
from ...services_http.log_streaming import LogDistributor

_MAX_WAIT_FOR_LOG_DISTRIBUTOR_SECONDS: Final[int] = 10

_logger = logging.getLogger(__name__)


def get_rabbitmq_rpc_client(
app: Annotated[FastAPI, Depends(get_app)]
) -> RabbitMQRPCClient:
assert app.state.rabbitmq_rpc_client # nosec
return cast(RabbitMQRPCClient, app.state.rabbitmq_rpc_client)


def get_rabbitmq_client(app: Annotated[FastAPI, Depends(get_app)]) -> RabbitMQClient:
assert app.state.rabbitmq_client # nosec
return cast(RabbitMQClient, app.state.rabbitmq_client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ..._constants import MSG_BACKEND_SERVICE_UNAVAILABLE
from ...core.settings import ApplicationSettings, WebServerSettings
from ...services.webserver import AuthSession
from ...services_http.webserver import AuthSession
from .application import get_app, get_settings
from .authentication import Identity, get_active_user_email, get_current_identity

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Annotated, cast

from fastapi import Depends, FastAPI
from servicelib.fastapi.dependencies import get_app

from ...services_rpc.wb_api_server import WbApiRpcClient


async def get_wb_api_rpc_client(
app: Annotated[FastAPI, Depends(get_app)]
) -> WbApiRpcClient:
assert app.state.wb_api_rpc_client # nosec
return cast(WbApiRpcClient, app.state.wb_api_rpc_client)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .routes import (
files,
health,
licensed_items,
meta,
solvers,
solvers_jobs,
Expand Down Expand Up @@ -40,6 +41,9 @@ def create_router(settings: ApplicationSettings):
router.include_router(studies_jobs.router, tags=["studies"], prefix="/studies")
router.include_router(wallets.router, tags=["wallets"], prefix="/wallets")
router.include_router(_credits.router, tags=["credits"], prefix="/credits")
router.include_router(
licensed_items.router, tags=["licensed-items"], prefix="/licensed-items"
)

# NOTE: multiple-files upload is currently disabled
# Web form to upload files at http://localhost:8000/v0/upload-form-view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import APIRouter, Depends, status

from ...models.schemas.model_adapter import GetCreditPriceLegacy
from ..dependencies.webserver import AuthSession, get_webserver_session
from ..dependencies.webserver_http import AuthSession, get_webserver_session
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION

router = APIRouter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
FileUploadData,
UploadLinks,
)
from ...services.storage import StorageApi, StorageFileMetaData, to_file_api_model
from ...services_http.storage import StorageApi, StorageFileMetaData, to_file_api_model
from ..dependencies.authentication import get_current_user_id
from ..dependencies.services import get_api_client
from ._common import API_SERVER_DEV_FEATURES_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

from ..._meta import API_VERSION, PROJECT_NAME
from ...core.health_checker import ApiServerHealthChecker, get_health_checker
from ...services.catalog import CatalogApi
from ...services.director_v2 import DirectorV2Api
from ...services.storage import StorageApi
from ...services.webserver import WebserverApi
from ...services_http.catalog import CatalogApi
from ...services_http.director_v2 import DirectorV2Api
from ...services_http.storage import StorageApi
from ...services_http.webserver import WebserverApi
from ..dependencies.application import get_reverse_url_mapper
from ..dependencies.services import get_api_client

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Annotated, Any

from fastapi import APIRouter, Depends, status

from ...api.dependencies.authentication import get_product_name
from ...api.dependencies.webserver_rpc import get_wb_api_rpc_client
from ...exceptions.service_errors_utils import DEFAULT_BACKEND_SERVICE_STATUS_CODES
from ...models.pagination import Page, PaginationParams
from ...models.schemas.model_adapter import LicensedItemGet
from ...services_rpc.wb_api_server import WbApiRpcClient

router = APIRouter()

_LICENSE_ITEMS_STATUS_CODES: dict[int | str, dict[str, Any]] = {
**DEFAULT_BACKEND_SERVICE_STATUS_CODES,
}


@router.get(
"",
response_model=Page[LicensedItemGet],
status_code=status.HTTP_200_OK,
responses=_LICENSE_ITEMS_STATUS_CODES,
description="Get all licensed items",
include_in_schema=False,
)
async def get_licensed_items(
page_params: Annotated[PaginationParams, Depends()],
web_api_rpc: Annotated[WbApiRpcClient, Depends(get_wb_api_rpc_client)],
product_name: Annotated[str, Depends(get_product_name)],
):
return await web_api_rpc.get_licensed_items(
product_name=product_name, page_params=page_params
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from ...models.schemas.errors import ErrorGet
from ...models.schemas.model_adapter import ServicePricingPlanGetLegacy
from ...models.schemas.solvers import Solver, SolverKeyId, SolverPort
from ...services.catalog import CatalogApi
from ...services_http.catalog import CatalogApi
from ..dependencies.application import get_reverse_url_mapper
from ..dependencies.authentication import get_current_user_id, get_product_name
from ..dependencies.services import get_api_client
from ..dependencies.webserver import AuthSession, get_webserver_session
from ..dependencies.webserver_http import AuthSession, get_webserver_session
from ._common import API_SERVER_DEV_FEATURES_ENABLED
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
JobStatus,
)
from ...models.schemas.solvers import Solver, SolverKeyId
from ...services.catalog import CatalogApi
from ...services.director_v2 import DirectorV2Api
from ...services.jobs import replace_custom_metadata, start_project, stop_project
from ...services.solver_job_models_converters import (
from ...services_http.catalog import CatalogApi
from ...services_http.director_v2 import DirectorV2Api
from ...services_http.jobs import replace_custom_metadata, start_project, stop_project
from ...services_http.solver_job_models_converters import (
create_job_from_project,
create_jobstatus_from_task,
create_new_project_for_job,
)
from ..dependencies.application import get_reverse_url_mapper
from ..dependencies.authentication import get_current_user_id, get_product_name
from ..dependencies.services import get_api_client
from ..dependencies.webserver import AuthSession, get_webserver_session
from ..dependencies.webserver_http import AuthSession, get_webserver_session
from ._constants import (
FMSG_CHANGELOG_ADDED_IN_VERSION,
FMSG_CHANGELOG_CHANGED_IN_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@
WalletGetWithAvailableCreditsLegacy,
)
from ...models.schemas.solvers import SolverKeyId
from ...services.catalog import CatalogApi
from ...services.director_v2 import DirectorV2Api
from ...services.jobs import (
from ...services_http.catalog import CatalogApi
from ...services_http.director_v2 import DirectorV2Api
from ...services_http.jobs import (
get_custom_metadata,
raise_if_job_not_associated_with_solver,
)
from ...services.log_streaming import LogDistributor, LogStreamer
from ...services.solver_job_models_converters import create_job_from_project
from ...services.solver_job_outputs import ResultsTypes, get_solver_output_results
from ...services.storage import StorageApi, to_file_api_model
from ...services_http.log_streaming import LogDistributor, LogStreamer
from ...services_http.solver_job_models_converters import create_job_from_project
from ...services_http.solver_job_outputs import ResultsTypes, get_solver_output_results
from ...services_http.storage import StorageApi, to_file_api_model
from ..dependencies.application import get_reverse_url_mapper
from ..dependencies.authentication import get_current_user_id, get_product_name
from ..dependencies.database import Engine, get_db_engine
from ..dependencies.rabbitmq import get_log_check_timeout, get_log_distributor
from ..dependencies.services import get_api_client
from ..dependencies.webserver import AuthSession, get_webserver_session
from ..dependencies.webserver_http import AuthSession, get_webserver_session
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION
from .solvers_jobs import (
JOBS_STATUS_CODES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
from models_library.api_schemas_webserver.projects import ProjectGet
from models_library.projects import ProjectID
from models_library.projects_nodes_io import NodeID
from simcore_service_api_server.api.routes._constants import (
FMSG_CHANGELOG_NEW_IN_VERSION,
)

from ...api.routes._constants import FMSG_CHANGELOG_NEW_IN_VERSION
from ...models.pagination import OnePage, Page, PaginationParams
from ...models.schemas.errors import ErrorGet
from ...models.schemas.studies import Study, StudyID, StudyPort
from ...services.webserver import AuthSession
from ..dependencies.webserver import get_webserver_session
from ...services_http.webserver import AuthSession
from ..dependencies.webserver_http import get_webserver_session

_logger = logging.getLogger(__name__)
router = APIRouter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from ...api.dependencies.authentication import get_current_user_id
from ...api.dependencies.services import get_api_client
from ...api.dependencies.webserver import get_webserver_session
from ...exceptions.backend_errors import ProjectAlreadyStartedError
from ...models.pagination import Page, PaginationParams
from ...models.schemas.errors import ErrorGet
Expand All @@ -32,22 +31,23 @@
JobStatus,
)
from ...models.schemas.studies import JobLogsMap, Study, StudyID
from ...services.director_v2 import DirectorV2Api
from ...services.jobs import (
from ...services_http.director_v2 import DirectorV2Api
from ...services_http.jobs import (
get_custom_metadata,
replace_custom_metadata,
start_project,
stop_project,
)
from ...services.solver_job_models_converters import create_jobstatus_from_task
from ...services.storage import StorageApi
from ...services.study_job_models_converters import (
from ...services_http.solver_job_models_converters import create_jobstatus_from_task
from ...services_http.storage import StorageApi
from ...services_http.study_job_models_converters import (
create_job_from_study,
create_job_outputs_from_project_outputs,
get_project_and_file_inputs_from_job_inputs,
)
from ...services.webserver import AuthSession
from ...services_http.webserver import AuthSession
from ..dependencies.application import get_reverse_url_mapper
from ..dependencies.webserver_http import get_webserver_session
from ._common import API_SERVER_DEV_FEATURES_ENABLED
from ._constants import FMSG_CHANGELOG_CHANGED_IN_VERSION, FMSG_CHANGELOG_NEW_IN_VERSION
from .solvers_jobs import JOBS_STATUS_CODES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from ...exceptions.service_errors_utils import DEFAULT_BACKEND_SERVICE_STATUS_CODES
from ...models.schemas.errors import ErrorGet
from ...models.schemas.profiles import Profile, ProfileUpdate
from ...services.webserver import AuthSession
from ..dependencies.webserver import get_webserver_session
from ...services_http.webserver import AuthSession
from ..dependencies.webserver_http import get_webserver_session

_logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ...exceptions.service_errors_utils import DEFAULT_BACKEND_SERVICE_STATUS_CODES
from ...models.schemas.errors import ErrorGet
from ...models.schemas.model_adapter import WalletGetWithAvailableCreditsLegacy
from ..dependencies.webserver import AuthSession, get_webserver_session
from ..dependencies.webserver_http import AuthSession, get_webserver_session
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION

_logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from .._meta import API_VERSION, API_VTAG, APP_NAME
from ..api.root import create_router
from ..api.routes.health import router as health_router
from ..services import catalog, director_v2, storage, webserver
from ..services.rabbitmq import setup_rabbitmq
from ..services_http import catalog, director_v2, storage, webserver
from ..services_http.rabbitmq import setup_rabbitmq
from ._prometheus_instrumentation import setup_prometheus_instrumentation
from .events import create_start_app_handler, create_stop_app_handler
from .openapi import override_openapi_method, use_route_names_as_operation_ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from .._meta import PROJECT_NAME
from ..models.schemas.jobs import JobID, JobLog
from ..services.log_streaming import LogDistributor
from ..services_http.log_streaming import LogDistributor

METRICS_NAMESPACE: Final[str] = PROJECT_NAME.replace("-", "_")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from httpx import HTTPError as HttpxException
from simcore_service_api_server.exceptions.backend_errors import BaseBackEndError
from starlette import status
from starlette.exceptions import HTTPException

from ..._constants import MSG_INTERNAL_ERROR_USER_FRIENDLY_TEMPLATE
from ...exceptions.backend_errors import BaseBackEndError
from ..custom_errors import CustomBaseError
from ..log_streaming_errors import LogStreamingBaseError
from ._custom_errors import custom_error_handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from simcore_service_api_server.exceptions.backend_errors import BaseBackEndError
from starlette.requests import Request
from starlette.responses import JSONResponse

from ...exceptions.backend_errors import BaseBackEndError
from ._utils import create_error_json_response


Expand Down
Loading
Loading