Skip to content

Commit a03ed85

Browse files
♻️✨ refactoring of pricing plans (🗃️) (#4812)
1 parent a7f5940 commit a03ed85

File tree

61 files changed

+3203
-2702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3203
-2702
lines changed

api/specs/web-server/_catalog.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ServiceResourcesGet,
1111
ServiceUpdate,
1212
)
13+
from models_library.api_schemas_webserver.resource_usage import ServicePricingPlanGet
1314
from models_library.generics import Envelope
1415
from simcore_service_webserver._meta import API_VTAG
1516
from simcore_service_webserver.catalog._handlers import (
@@ -130,3 +131,15 @@ def get_service_resources(
130131
_params: Annotated[ServicePathParams, Depends()],
131132
):
132133
...
134+
135+
136+
@router.get(
137+
"/catalog/services/{service_key:path}/{service_version}/pricing-plan",
138+
response_model=Envelope[ServicePricingPlanGet],
139+
summary="Retrieve default pricing plan for provided service",
140+
tags=["pricing-plans"],
141+
)
142+
async def get_service_pricing_plan(
143+
_params: Annotated[ServicePathParams, Depends()],
144+
):
145+
...

api/specs/web-server/_resource_usage.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@
1111

1212
from _common import assert_handler_signature_against_model
1313
from fastapi import APIRouter, Query
14-
from models_library.api_schemas_webserver.resource_usage import ServiceRunGet
14+
from models_library.api_schemas_webserver.resource_usage import (
15+
PricingUnitGet,
16+
ServiceRunGet,
17+
)
1518
from models_library.generics import Envelope
19+
from models_library.resource_tracker import PricingPlanId, PricingUnitId
1620
from models_library.rest_pagination import DEFAULT_NUMBER_OF_ITEMS_PER_PAGE
1721
from models_library.wallets import WalletID
1822
from pydantic import NonNegativeInt
1923
from simcore_service_webserver._meta import API_VTAG
24+
from simcore_service_webserver.resource_usage._pricing_plans_handlers import (
25+
_GetPricingPlanUnitPathParams,
26+
)
2027
from simcore_service_webserver.resource_usage._service_runs_handlers import (
21-
_ListServicesPathParams,
28+
_ListServicesResourceUsagesPathParams,
2229
)
2330

24-
router = APIRouter(prefix=f"/{API_VTAG}", tags=["usage"])
31+
router = APIRouter(prefix=f"/{API_VTAG}")
2532

2633

2734
#
@@ -30,9 +37,10 @@
3037

3138

3239
@router.get(
33-
"/resource-usage/services",
40+
"/services/-/resource-usages",
3441
response_model=Envelope[list[ServiceRunGet]],
3542
summary="Retrieve finished and currently running user services (user and product are taken from context, optionally wallet_id parameter might be provided).",
43+
tags=["usage"],
3644
)
3745
async def list_resource_usage_services(
3846
wallet_id: WalletID = Query(None),
@@ -43,5 +51,22 @@ async def list_resource_usage_services(
4351

4452

4553
assert_handler_signature_against_model(
46-
list_resource_usage_services, _ListServicesPathParams
54+
list_resource_usage_services, _ListServicesResourceUsagesPathParams
55+
)
56+
57+
58+
@router.get(
59+
"/pricing-plans/{pricing_plan_id}/pricing-units/{pricing_unit_id}",
60+
response_model=Envelope[PricingUnitGet],
61+
summary="Retrieve detail information about pricing unit",
62+
tags=["pricing-plans"],
63+
)
64+
async def get_pricing_plan_unit(
65+
pricing_plan_id: PricingPlanId, pricing_unit_id: PricingUnitId
66+
):
67+
...
68+
69+
70+
assert_handler_signature_against_model(
71+
get_pricing_plan_unit, _GetPricingPlanUnitPathParams
4772
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from datetime import datetime
2+
from decimal import Decimal
3+
from typing import Any, ClassVar
4+
5+
from models_library.resource_tracker import (
6+
PricingPlanClassification,
7+
PricingPlanId,
8+
PricingUnitCostId,
9+
PricingUnitId,
10+
)
11+
from pydantic import BaseModel
12+
13+
14+
class PricingUnitGet(BaseModel):
15+
pricing_unit_id: PricingUnitId
16+
unit_name: str
17+
current_cost_per_unit: Decimal
18+
current_cost_per_unit_id: PricingUnitCostId
19+
default: bool
20+
specific_info: dict
21+
22+
class Config:
23+
schema_extra: ClassVar[dict[str, Any]] = {
24+
"examples": [
25+
{
26+
"pricing_unit_id": 1,
27+
"unit_name": "SMALL",
28+
"current_cost_per_unit": 5.7,
29+
"current_cost_per_unit_id": 1,
30+
"default": True,
31+
"specific_info": {},
32+
}
33+
]
34+
}
35+
36+
37+
class ServicePricingPlanGet(BaseModel):
38+
pricing_plan_id: PricingPlanId
39+
display_name: str
40+
description: str
41+
classification: PricingPlanClassification
42+
created_at: datetime
43+
pricing_plan_key: str
44+
pricing_units: list[PricingUnitGet]
45+
46+
class Config:
47+
schema_extra: ClassVar[dict[str, Any]] = {
48+
"examples": [
49+
{
50+
"pricing_plan_id": 1,
51+
"display_name": "Pricing Plan for Sleeper",
52+
"description": "Special Pricing Plan for Sleeper",
53+
"classification": "TIER",
54+
"created_at": "2023-01-11 13:11:47.293595",
55+
"pricing_plan_key": "pricing-plan-sleeper",
56+
"pricing_units": [
57+
PricingUnitGet.Config.schema_extra["examples"][0]
58+
],
59+
}
60+
]
61+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from datetime import datetime
2+
from decimal import Decimal
3+
4+
from models_library.projects import ProjectID
5+
from models_library.projects_nodes_io import NodeID
6+
from models_library.resource_tracker import (
7+
CreditTransactionStatus,
8+
ServiceRunId,
9+
ServiceRunStatus,
10+
)
11+
from models_library.services import ServiceKey, ServiceVersion
12+
from models_library.users import UserID
13+
from models_library.wallets import WalletID
14+
from pydantic import BaseModel
15+
16+
17+
class ServiceRunGet(BaseModel):
18+
service_run_id: ServiceRunId
19+
wallet_id: WalletID | None
20+
wallet_name: str | None
21+
user_id: UserID
22+
project_id: ProjectID
23+
project_name: str
24+
node_id: NodeID
25+
node_name: str
26+
service_key: ServiceKey
27+
service_version: ServiceVersion
28+
service_type: str
29+
service_resources: dict
30+
started_at: datetime
31+
stopped_at: datetime | None
32+
service_run_status: ServiceRunStatus
33+
# Cost in credits
34+
credit_cost: Decimal | None
35+
transaction_status: CreditTransactionStatus | None

packages/models-library/src/models_library/api_schemas_webserver/resource_usage.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from decimal import Decimal
33

44
from models_library.resource_tracker import (
5-
PricingDetailId,
65
PricingPlanClassification,
76
PricingPlanId,
87
ServiceRunId,
@@ -14,7 +13,7 @@
1413

1514
from ..projects import ProjectID
1615
from ..projects_nodes_io import NodeID
17-
from ..resource_tracker import ServiceRunStatus
16+
from ..resource_tracker import PricingUnitId, ServiceRunStatus
1817
from ..services import ServiceKey, ServiceVersion
1918
from ._base import OutputSchema
2019

@@ -41,18 +40,18 @@ class ServiceRunGet(
4140
service_run_status: ServiceRunStatus
4241

4342

44-
class PricingDetailMinimalGet(OutputSchema):
45-
pricing_detail_id: PricingDetailId
43+
class PricingUnitGet(OutputSchema):
44+
pricing_unit_id: PricingUnitId
4645
unit_name: str
47-
cost_per_unit: Decimal
48-
valid_from: datetime
49-
simcore_default: bool
46+
current_cost_per_unit: Decimal
47+
default: bool
5048

5149

52-
class PricingPlanGet(OutputSchema):
50+
class ServicePricingPlanGet(OutputSchema):
5351
pricing_plan_id: PricingPlanId
54-
name: str
52+
display_name: str
5553
description: str
5654
classification: PricingPlanClassification
5755
created_at: datetime
58-
details: list[PricingDetailMinimalGet]
56+
pricing_plan_key: str
57+
pricing_units: list[PricingUnitGet]

packages/models-library/src/models_library/rabbitmq_messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ class RabbitResourceTrackingStartedMessage(RabbitResourceTrackingBaseMessage):
201201
wallet_name: str | None
202202

203203
pricing_plan_id: int | None
204-
pricing_detail_id: int | None
204+
pricing_unit_id: int | None
205+
pricing_unit_cost_id: int | None
205206

206207
product_name: str
207208
simcore_user_agent: str

packages/models-library/src/models_library/resource_tracker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
ServiceRunId: TypeAlias = str
99
PricingPlanId: TypeAlias = PositiveInt
10-
PricingDetailId: TypeAlias = PositiveInt
10+
PricingUnitId: TypeAlias = PositiveInt
11+
PricingUnitCostId: TypeAlias = PositiveInt
1112
CreditTransactionId: TypeAlias = PositiveInt
1213

1314

packages/models-library/src/models_library/services_creation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class CreateServiceMetricsAdditionalParams(BaseModel):
1111
wallet_id: WalletID | None
1212
wallet_name: str | None
1313
pricing_plan_id: int | None
14-
pricing_detail_id: int | None
14+
pricing_unit_id: int | None
15+
pricing_unit_cost_id: int | None
1516
product_name: str
1617
simcore_user_agent: str
1718
user_email: str
@@ -28,7 +29,8 @@ class Config:
2829
"wallet_id": 1,
2930
"wallet_name": "a private wallet for me",
3031
"pricing_plan_id": 1,
31-
"pricing_detail_id": 1,
32+
"pricing_unit_id": 1,
33+
"pricing_unit_detail_id": 1,
3234
"product_name": "osparc",
3335
"simcore_user_agent": "undefined",
3436
"user_email": "[email protected]",

0 commit comments

Comments
 (0)