-
Notifications
You must be signed in to change notification settings - Fork 30
✨ Introduce license item checkout & release functionality (🗃️) #6960
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
Merged
matusdrobuliak66
merged 34 commits into
ITISFoundation:master
from
matusdrobuliak66:introduce-vip-models-pricing-6-part
Dec 18, 2024
Merged
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9c815b8
renaming wallets to credit account for frontend
matusdrobuliak66 6abf9bd
fix rut export CSV usage
matusdrobuliak66 a99b7cd
Merge branch 'master' into introduce-vip-models-pricing-6-part
matusdrobuliak66 abccfab
Merge branch 'master' into introduce-vip-models-pricing-6-part
matusdrobuliak66 e060492
implement rut part of checkout/release license
matusdrobuliak66 200b1db
implement rut part of checkout/release license
matusdrobuliak66 7406371
adding tests to rut
matusdrobuliak66 c4e56df
checkout release functionality
matusdrobuliak66 504d2c8
webserver functionality
matusdrobuliak66 7839e46
Merge branch 'master' into introduce-vip-models-pricing-6-part
matusdrobuliak66 68068fb
improve playwright e2e test
matusdrobuliak66 5dd8efa
Merge branch 'master' into introduce-vip-models-pricing-6-part
matusdrobuliak66 b803038
merge master
matusdrobuliak66 3f30f05
add get and list license usages
matusdrobuliak66 c0d5c8e
wire checkout and release in webserver
matusdrobuliak66 4c269c3
wire checkout and release in webserver
matusdrobuliak66 4eaaf16
wire checkout and release in webserver
matusdrobuliak66 34d4577
adding unit tests in webserver
matusdrobuliak66 4826fa8
renaming
matusdrobuliak66 1eaba29
renaming
matusdrobuliak66 a43626d
renaming
matusdrobuliak66 7a1dcf7
renaming
matusdrobuliak66 2a0b64f
renaming
matusdrobuliak66 f8c6567
imporve error handling
matusdrobuliak66 f38de47
fix api server
matusdrobuliak66 a150857
fix failing tests
matusdrobuliak66 043b78b
Merge branch 'master' into introduce-vip-models-pricing-6-part
matusdrobuliak66 8b41ebf
fix available tests
matusdrobuliak66 de312d3
fix mypy
matusdrobuliak66 68ee78c
fix e2e tests
matusdrobuliak66 7e8313c
Merge branch 'master' into introduce-vip-models-pricing-6-part
matusdrobuliak66 1ee8886
review @sanderegg
matusdrobuliak66 84eb893
review @pcrespov
matusdrobuliak66 69b0dcd
fix test
matusdrobuliak66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...library/src/models_library/api_schemas_resource_usage_tracker/licensed_items_checkouts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from datetime import datetime | ||
from typing import NamedTuple | ||
|
||
from models_library.licensed_items import LicensedItemID | ||
from models_library.products import ProductName | ||
from models_library.resource_tracker import ServiceRunId | ||
from models_library.resource_tracker_licensed_items_checkouts import ( | ||
LicensedItemCheckoutID, | ||
) | ||
from models_library.users import UserID | ||
from models_library.wallets import WalletID | ||
from pydantic import BaseModel, ConfigDict, PositiveInt | ||
|
||
|
||
class LicensedItemCheckoutGet(BaseModel): | ||
licensed_item_checkout_id: LicensedItemCheckoutID | ||
licensed_item_id: LicensedItemID | ||
wallet_id: WalletID | ||
user_id: UserID | ||
product_name: ProductName | ||
service_run_id: ServiceRunId | ||
started_at: datetime | ||
stopped_at: datetime | None | ||
num_of_seats: int | ||
|
||
model_config = ConfigDict( | ||
json_schema_extra={ | ||
"examples": [ | ||
{ | ||
"licensed_item_checkout_id": "beb16d18-d57d-44aa-a638-9727fa4a72ef", | ||
"licensed_item_id": "303942ef-6d31-4ba8-afbe-dbb1fce2a953", | ||
"wallet_id": 1, | ||
"user_id": 1, | ||
"product_name": "osparc", | ||
"service_run_id": "run_1", | ||
"started_at": "2023-01-11 13:11:47.293595", | ||
"stopped_at": "2023-01-11 13:11:47.293595", | ||
"num_of_seats": 1, | ||
} | ||
] | ||
} | ||
) | ||
|
||
|
||
class LicensedItemsCheckoutsPage(NamedTuple): | ||
items: list[LicensedItemCheckoutGet] | ||
total: PositiveInt |
27 changes: 27 additions & 0 deletions
27
packages/models-library/src/models_library/api_schemas_webserver/licensed_items_checkouts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from datetime import datetime | ||
from typing import NamedTuple | ||
|
||
from pydantic import PositiveInt | ||
|
||
from ..licensed_items import LicensedItemID | ||
from ..products import ProductName | ||
from ..resource_tracker_licensed_items_checkouts import LicensedItemCheckoutID | ||
from ..users import UserID | ||
from ..wallets import WalletID | ||
from ._base import OutputSchema | ||
|
||
|
||
class LicensedItemCheckoutGet(OutputSchema): | ||
licensed_item_checkout_id: LicensedItemCheckoutID | ||
licensed_item_id: LicensedItemID | ||
wallet_id: WalletID | ||
user_id: UserID | ||
product_name: ProductName | ||
started_at: datetime | ||
stopped_at: datetime | None | ||
num_of_seats: int | ||
|
||
|
||
class LicensedItemUsageGetPage(NamedTuple): | ||
items: list[LicensedItemCheckoutGet] | ||
total: PositiveInt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/models-library/src/models_library/resource_tracker_licensed_items_checkouts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from typing import TypeAlias | ||
from uuid import UUID | ||
|
||
LicensedItemCheckoutID: TypeAlias = UUID |
28 changes: 28 additions & 0 deletions
28
...abase/src/simcore_postgres_database/migration/versions/3720518f82a7_modify_licenses_db.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""modify licenses DB | ||
|
||
Revision ID: 3720518f82a7 | ||
Revises: 77ac824a77ff | ||
Create Date: 2024-12-13 12:46:38.302027+00:00 | ||
|
||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "3720518f82a7" | ||
down_revision = "77ac824a77ff" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.drop_column("resource_tracker_licensed_items_usage", "licensed_item_id") | ||
op.add_column( | ||
"resource_tracker_licensed_items_usage", | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sa.Column("licensed_item_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
) | ||
|
||
|
||
def downgrade(): | ||
... |
134 changes: 134 additions & 0 deletions
134
...c/simcore_postgres_database/migration/versions/aa6da21a0055_rename_usages_to_checkouts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
"""rename usages to checkouts | ||
|
||
Revision ID: aa6da21a0055 | ||
Revises: 3720518f82a7 | ||
Create Date: 2024-12-17 13:47:09.304574+00:00 | ||
|
||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "aa6da21a0055" | ||
down_revision = "3720518f82a7" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"resource_tracker_licensed_items_checkouts", | ||
sa.Column( | ||
"licensed_item_checkout_id", | ||
postgresql.UUID(as_uuid=True), | ||
server_default=sa.text("gen_random_uuid()"), | ||
nullable=False, | ||
), | ||
sa.Column("licensed_item_id", postgresql.UUID(as_uuid=True), nullable=True), | ||
sa.Column("wallet_id", sa.BigInteger(), nullable=False), | ||
sa.Column("user_id", sa.BigInteger(), nullable=False), | ||
sa.Column("user_email", sa.String(), nullable=True), | ||
sa.Column("product_name", sa.String(), nullable=False), | ||
sa.Column("service_run_id", sa.String(), nullable=True), | ||
sa.Column("started_at", sa.DateTime(timezone=True), nullable=False), | ||
sa.Column("stopped_at", sa.DateTime(timezone=True), nullable=True), | ||
sa.Column("num_of_seats", sa.SmallInteger(), nullable=False), | ||
sa.Column( | ||
"modified", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["product_name", "service_run_id"], | ||
[ | ||
"resource_tracker_service_runs.product_name", | ||
"resource_tracker_service_runs.service_run_id", | ||
], | ||
name="resource_tracker_license_checkouts_service_run_id_fkey", | ||
onupdate="CASCADE", | ||
ondelete="RESTRICT", | ||
), | ||
sa.PrimaryKeyConstraint("licensed_item_checkout_id"), | ||
) | ||
op.create_index( | ||
op.f("ix_resource_tracker_licensed_items_checkouts_wallet_id"), | ||
"resource_tracker_licensed_items_checkouts", | ||
["wallet_id"], | ||
unique=False, | ||
) | ||
op.drop_index( | ||
"ix_resource_tracker_licensed_items_usage_wallet_id", | ||
table_name="resource_tracker_licensed_items_usage", | ||
) | ||
op.drop_table("resource_tracker_licensed_items_usage") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"resource_tracker_licensed_items_usage", | ||
sa.Column( | ||
"licensed_item_usage_id", | ||
postgresql.UUID(), | ||
server_default=sa.text("gen_random_uuid()"), | ||
autoincrement=False, | ||
nullable=False, | ||
), | ||
sa.Column("wallet_id", sa.BIGINT(), autoincrement=False, nullable=False), | ||
sa.Column("user_id", sa.BIGINT(), autoincrement=False, nullable=False), | ||
sa.Column("user_email", sa.VARCHAR(), autoincrement=False, nullable=True), | ||
sa.Column("product_name", sa.VARCHAR(), autoincrement=False, nullable=False), | ||
sa.Column("service_run_id", sa.VARCHAR(), autoincrement=False, nullable=True), | ||
sa.Column( | ||
"started_at", | ||
postgresql.TIMESTAMP(timezone=True), | ||
autoincrement=False, | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"stopped_at", | ||
postgresql.TIMESTAMP(timezone=True), | ||
autoincrement=False, | ||
nullable=True, | ||
), | ||
sa.Column("num_of_seats", sa.SMALLINT(), autoincrement=False, nullable=False), | ||
sa.Column( | ||
"modified", | ||
postgresql.TIMESTAMP(timezone=True), | ||
server_default=sa.text("now()"), | ||
autoincrement=False, | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"licensed_item_id", postgresql.UUID(), autoincrement=False, nullable=False | ||
), | ||
sa.ForeignKeyConstraint( | ||
["product_name", "service_run_id"], | ||
[ | ||
"resource_tracker_service_runs.product_name", | ||
"resource_tracker_service_runs.service_run_id", | ||
], | ||
name="resource_tracker_license_checkouts_service_run_id_fkey", | ||
onupdate="CASCADE", | ||
ondelete="RESTRICT", | ||
), | ||
sa.PrimaryKeyConstraint( | ||
"licensed_item_usage_id", name="resource_tracker_licensed_items_usage_pkey" | ||
), | ||
) | ||
op.create_index( | ||
"ix_resource_tracker_licensed_items_usage_wallet_id", | ||
"resource_tracker_licensed_items_usage", | ||
["wallet_id"], | ||
unique=False, | ||
) | ||
op.drop_index( | ||
op.f("ix_resource_tracker_licensed_items_checkouts_wallet_id"), | ||
table_name="resource_tracker_licensed_items_checkouts", | ||
) | ||
op.drop_table("resource_tracker_licensed_items_checkouts") | ||
# ### end Alembic commands ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...s/service-library/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from common_library.errors_classes import OsparcErrorMixin | ||
|
||
|
||
class LicensesBaseError(OsparcErrorMixin, Exception): | ||
... | ||
|
||
|
||
class NotEnoughAvailableSeatsError(LicensesBaseError): | ||
msg_template = "Not enough available seats. Current available seats {available_num_of_seats} for license item {license_item_id}" | ||
|
||
|
||
class CanNotCheckoutNotEnoughAvailableSeatsError(LicensesBaseError): | ||
msg_template = "Can not checkout license item {licensed_item_id} with num of seats {num_of_seats}. Currently available seats {available_num_of_seats}" | ||
|
||
|
||
class CanNotCheckoutServiceIsNotRunningError(LicensesBaseError): | ||
msg_template = "Can not checkout license item {licensed_item_id} as dynamic service is not running. Current service {service_run}" | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class LicensedItemCheckoutNotFoundError(LicensesBaseError): | ||
msg_template = "Licensed item checkout {licensed_item_checkout_id} not found." | ||
|
||
|
||
LICENSES_ERRORS = ( | ||
NotEnoughAvailableSeatsError, | ||
CanNotCheckoutNotEnoughAvailableSeatsError, | ||
CanNotCheckoutServiceIsNotRunningError, | ||
LicensedItemCheckoutNotFoundError, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.