Skip to content

Commit b338774

Browse files
Merge remote-tracking branch 'upstream/master' into is6880/hash-api-key-secret
2 parents d1da32a + d0f485b commit b338774

File tree

114 files changed

+3175
-661
lines changed

Some content is hidden

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

114 files changed

+3175
-661
lines changed

api/specs/web-server/_computations.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
from typing import Annotated
22

3+
from _common import as_query
34
from fastapi import APIRouter, Depends, status
45
from models_library.api_schemas_webserver.computations import (
56
ComputationGet,
67
ComputationPathParams,
8+
ComputationRunRestGet,
79
ComputationStart,
810
ComputationStarted,
11+
ComputationTaskRestGet,
912
)
1013
from models_library.generics import Envelope
1114
from simcore_service_webserver._meta import API_VTAG
15+
from simcore_service_webserver.director_v2._controller.computations_rest import (
16+
ComputationRunListQueryParams,
17+
ComputationTaskListQueryParams,
18+
ComputationTaskPathParams,
19+
)
1220

1321
router = APIRouter(
1422
prefix=f"/{API_VTAG}",
@@ -53,3 +61,22 @@ async def start_computation(
5361
status_code=status.HTTP_204_NO_CONTENT,
5462
)
5563
async def stop_computation(_path: Annotated[ComputationPathParams, Depends()]): ...
64+
65+
66+
@router.get(
67+
"/computations/-/iterations/latest",
68+
response_model=Envelope[list[ComputationRunRestGet]],
69+
)
70+
async def list_computations_latest_iteration(
71+
_query: Annotated[as_query(ComputationRunListQueryParams), Depends()],
72+
): ...
73+
74+
75+
@router.get(
76+
"/computations/{project_id}/iterations/latest/tasks",
77+
response_model=Envelope[list[ComputationTaskRestGet]],
78+
)
79+
async def list_computations_latest_iteration_tasks(
80+
_query: Annotated[as_query(ComputationTaskListQueryParams), Depends()],
81+
_path: Annotated[ComputationTaskPathParams, Depends()],
82+
): ...

packages/models-library/src/models_library/api_schemas_directorv2/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
from typing import Final
2+
3+
from pydantic import TypeAdapter
4+
5+
from ..rabbitmq_basic_types import RPCNamespace
16
from . import clusters, dynamic_services
27

38
assert clusters # nosec
49
assert dynamic_services # nosec
510

11+
12+
DIRECTOR_V2_RPC_NAMESPACE: Final[RPCNamespace] = TypeAdapter(
13+
RPCNamespace
14+
).validate_python("director-v2")
15+
16+
617
__all__: tuple[str, ...] = (
718
"clusters",
819
"dynamic_services",
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from datetime import datetime
2+
from typing import Annotated, Any, NamedTuple
3+
4+
from pydantic import (
5+
BaseModel,
6+
BeforeValidator,
7+
ConfigDict,
8+
PositiveInt,
9+
)
10+
11+
from ..projects import ProjectID
12+
from ..projects_nodes_io import NodeID
13+
from ..projects_state import RunningState
14+
15+
16+
class ComputationRunRpcGet(BaseModel):
17+
project_uuid: ProjectID
18+
iteration: int
19+
state: RunningState
20+
info: dict[str, Any]
21+
submitted_at: datetime
22+
started_at: datetime | None
23+
ended_at: datetime | None
24+
25+
model_config = ConfigDict(
26+
json_schema_extra={
27+
"examples": [
28+
{
29+
"project_uuid": "beb16d18-d57d-44aa-a638-9727fa4a72ef",
30+
"iteration": 1,
31+
"state": "SUCCESS",
32+
"info": {
33+
"wallet_id": 9866,
34+
"user_email": "[email protected]",
35+
"wallet_name": "test",
36+
"product_name": "osparc",
37+
"project_name": "test",
38+
"project_metadata": {
39+
"parent_node_id": "12e0c8b2-bad6-40fb-9948-8dec4f65d4d9",
40+
"parent_node_name": "UJyfwFVYySnPCaLuQIaz",
41+
"parent_project_id": "beb16d18-d57d-44aa-a638-9727fa4a72ef",
42+
"parent_project_name": "qTjDmYPxeqAWfCKCQCYF",
43+
"root_parent_node_id": "37176e84-d977-4993-bc49-d76fcfc6e625",
44+
"root_parent_node_name": "UEXExIZVPeFzGRmMglPr",
45+
"root_parent_project_id": "beb16d18-d57d-44aa-a638-9727fa4a72ef",
46+
"root_parent_project_name": "FuDpjjFIyeNTWRUWCuKo",
47+
},
48+
"node_id_names_map": {},
49+
"simcore_user_agent": "agent",
50+
},
51+
"submitted_at": "2023-01-11 13:11:47.293595",
52+
"started_at": "2023-01-11 13:11:47.293595",
53+
"ended_at": "2023-01-11 13:11:47.293595",
54+
}
55+
]
56+
}
57+
)
58+
59+
60+
class ComputationRunRpcGetPage(NamedTuple):
61+
items: list[ComputationRunRpcGet]
62+
total: PositiveInt
63+
64+
65+
def _none_to_zero_float_pre_validator(value: Any):
66+
if value is None:
67+
return 0.0
68+
return value
69+
70+
71+
class ComputationTaskRpcGet(BaseModel):
72+
project_uuid: ProjectID
73+
node_id: NodeID
74+
state: RunningState
75+
progress: Annotated[float, BeforeValidator(_none_to_zero_float_pre_validator)]
76+
image: dict[str, Any]
77+
started_at: datetime | None
78+
ended_at: datetime | None
79+
80+
model_config = ConfigDict(
81+
json_schema_extra={
82+
"examples": [
83+
{
84+
"project_uuid": "beb16d18-d57d-44aa-a638-9727fa4a72ef",
85+
"node_id": "12e0c8b2-bad6-40fb-9948-8dec4f65d4d9",
86+
"state": "SUCCESS",
87+
"progress": 0.0,
88+
"image": {
89+
"name": "simcore/services/comp/ti-solutions-optimizer",
90+
"tag": "1.0.19",
91+
"node_requirements": {"CPU": 8.0, "RAM": 25769803776},
92+
},
93+
"started_at": "2023-01-11 13:11:47.293595",
94+
"ended_at": "2023-01-11 13:11:47.293595",
95+
}
96+
]
97+
}
98+
)
99+
100+
101+
class ComputationTaskRpcGetPage(NamedTuple):
102+
items: list[ComputationTaskRpcGet]
103+
total: PositiveInt

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

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
from typing import Annotated
1+
from datetime import datetime
2+
from typing import Annotated, Any
23

34
from common_library.basic_types import DEFAULT_FACTORY
4-
from pydantic import BaseModel, Field
5+
from pydantic import (
6+
BaseModel,
7+
ConfigDict,
8+
Field,
9+
)
510

611
from ..api_schemas_directorv2.computations import (
712
ComputationGet as _DirectorV2ComputationGet,
813
)
14+
from ..basic_types import IDStr
915
from ..projects import CommitID, ProjectID
10-
from ._base import InputSchemaWithoutCamelCase, OutputSchemaWithoutCamelCase
16+
from ..projects_nodes_io import NodeID
17+
from ..projects_state import RunningState
18+
from ..rest_ordering import OrderBy, create_ordering_query_model_class
19+
from ..rest_pagination import PageQueryParameters
20+
from ._base import (
21+
InputSchemaWithoutCamelCase,
22+
OutputSchema,
23+
OutputSchemaWithoutCamelCase,
24+
)
1125

1226

1327
class ComputationPathParams(BaseModel):
@@ -41,3 +55,71 @@ class ComputationStarted(OutputSchemaWithoutCamelCase):
4155
json_schema_extra={"default": []},
4256
),
4357
] = DEFAULT_FACTORY
58+
59+
60+
### Computation Run
61+
62+
63+
ComputationRunListOrderParams = create_ordering_query_model_class(
64+
ordering_fields={
65+
"submitted_at",
66+
"started_at",
67+
"ended_at",
68+
"state",
69+
},
70+
default=OrderBy(field=IDStr("submitted_at")),
71+
ordering_fields_api_to_column_map={
72+
"submitted_at": "created",
73+
"started_at": "started",
74+
"ended_at": "ended",
75+
},
76+
)
77+
78+
79+
class ComputationRunListQueryParams(
80+
PageQueryParameters,
81+
ComputationRunListOrderParams, # type: ignore[misc, valid-type]
82+
): ...
83+
84+
85+
class ComputationRunRestGet(OutputSchema):
86+
project_uuid: ProjectID
87+
iteration: int
88+
state: RunningState
89+
info: dict[str, Any]
90+
submitted_at: datetime
91+
started_at: datetime | None
92+
ended_at: datetime | None
93+
94+
95+
### Computation Task
96+
97+
98+
class ComputationTaskPathParams(BaseModel):
99+
project_id: ProjectID
100+
model_config = ConfigDict(populate_by_name=True, extra="forbid")
101+
102+
103+
ComputationTaskListOrderParams = create_ordering_query_model_class(
104+
ordering_fields={
105+
"started_at",
106+
},
107+
default=OrderBy(field=IDStr("started_at")),
108+
ordering_fields_api_to_column_map={"started_at": "start"},
109+
)
110+
111+
112+
class ComputationTaskListQueryParams(
113+
PageQueryParameters,
114+
ComputationTaskListOrderParams, # type: ignore[misc, valid-type]
115+
): ...
116+
117+
118+
class ComputationTaskRestGet(OutputSchema):
119+
project_uuid: ProjectID
120+
node_id: NodeID
121+
state: RunningState
122+
progress: float
123+
image: dict[str, Any]
124+
started_at: datetime | None
125+
ended_at: datetime | None

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Models both project and node states
2+
Models both project and node states
33
"""
44

55
from enum import Enum, unique
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""add indexes to comp tables
2+
3+
Revision ID: f65f7786cd4b
4+
Revises: cf8f743fd0b7
5+
Create Date: 2025-04-17 12:44:27.577984+00:00
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "f65f7786cd4b"
14+
down_revision = "cf8f743fd0b7"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_index("ix_comp_runs_user_id", "comp_runs", ["user_id"], unique=False)
22+
op.create_index(
23+
"ix_comp_tasks_project_id", "comp_tasks", ["project_id"], unique=False
24+
)
25+
op.drop_index("idx_projects_last_change_date_desc", table_name="projects")
26+
op.create_index(
27+
"idx_projects_last_change_date_desc",
28+
"projects",
29+
["last_change_date"],
30+
unique=False,
31+
postgresql_using="btree",
32+
postgresql_ops={"last_change_date": "DESC"},
33+
)
34+
# ### end Alembic commands ###
35+
36+
37+
def downgrade():
38+
# ### commands auto generated by Alembic - please adjust! ###
39+
op.drop_index(
40+
"idx_projects_last_change_date_desc",
41+
table_name="projects",
42+
postgresql_using="btree",
43+
postgresql_ops={"last_change_date": "DESC"},
44+
)
45+
op.create_index(
46+
"idx_projects_last_change_date_desc",
47+
"projects",
48+
[sa.text("last_change_date DESC")],
49+
unique=False,
50+
)
51+
op.drop_index("ix_comp_tasks_project_id", table_name="comp_tasks")
52+
op.drop_index("ix_comp_runs_user_id", table_name="comp_runs")
53+
# ### end Alembic commands ###

packages/postgres-database/src/simcore_postgres_database/models/comp_runs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@
9999
doc="the run uses on demand clusters",
100100
),
101101
sa.UniqueConstraint("project_uuid", "user_id", "iteration"),
102+
sa.Index("ix_comp_runs_user_id", "user_id"),
102103
)

packages/postgres-database/src/simcore_postgres_database/models/comp_tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class NodeClass(enum.Enum):
110110
),
111111
# ------
112112
sa.UniqueConstraint("project_id", "node_id", name="project_node_uniqueness"),
113+
sa.Index("ix_comp_tasks_project_id", "project_id"),
113114
)
114115

115116
register_modified_datetime_auto_update_trigger(comp_tasks)

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/director_v2/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)