Skip to content

Commit

Permalink
Merge branch 'master' into introduce-vip-models-pricing-6-part
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 authored Dec 13, 2024
2 parents 6abf9bd + e97f83b commit a99b7cd
Show file tree
Hide file tree
Showing 74 changed files with 1,043 additions and 489 deletions.
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
3 changes: 1 addition & 2 deletions scripts/maintenance/migrate_project/src/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import Optional

import typer
from db import (
Expand All @@ -15,7 +14,7 @@
def main(config: Path = typer.Option(..., exists=True)):
assert config.exists() # nosec
settings = Settings.load_from_file(config)
typer.echo(f"Detected settings:\n{settings.json(indent=2)}\n")
typer.echo(f"Detected settings:\n{settings.model_dump_json(indent=2)}\n")

r_clone_config_path = assemble_config_file(
# source
Expand Down
4 changes: 3 additions & 1 deletion scripts/maintenance/migrate_project/src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ class Config:
if __name__ == "__main__":
# produces an empty configuration to be saved as starting point
print(
Settings.model_validate(Settings.Config.schema_extra["example"]).json(indent=2)
Settings.model_validate(
Settings.Config.schema_extra["example"]
).model_dump_json(indent=2)
)
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

0 comments on commit a99b7cd

Please sign in to comment.