Skip to content

Commit 641ddb4

Browse files
authored
Merge branch 'master' into feature/listenToProjectDocumentWS
2 parents 4585ae4 + ef83d12 commit 641ddb4

File tree

29 files changed

+1230
-1254
lines changed

29 files changed

+1230
-1254
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# mypy: disable-error-code=truthy-function
22
from typing import Annotated, Any, Literal, TypeAlias
33

4-
from models_library.groups import GroupID
5-
from models_library.projects import ProjectID
6-
from models_library.services_history import ServiceRelease
74
from pydantic import ConfigDict, Field
85

96
from ..access_rights import ExecutableAccessRights
107
from ..api_schemas_directorv2.dynamic_services import RetrieveDataOut
118
from ..basic_types import PortInt
9+
from ..groups import GroupID
10+
from ..projects import ProjectID
1211
from ..projects_nodes import InputID, InputsDict, PartialNode
1312
from ..projects_nodes_io import NodeID
1413
from ..services import ServiceKey, ServicePortKey, ServiceVersion
1514
from ..services_enums import ServiceState
15+
from ..services_history import ServiceRelease
1616
from ..services_resources import ServiceResourcesDict
1717
from ._base import InputSchemaWithoutCamelCase, OutputSchema
1818

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
"""
2-
Ownership and access rights
2+
Ownership and access rights
33
"""
44

55
from enum import Enum
6+
from typing import Annotated
67

78
from pydantic import BaseModel, ConfigDict, Field
8-
from pydantic.types import PositiveInt
99

1010
from .basic_types import IDStr
11-
from .users import FirstNameStr, LastNameStr
11+
from .users import UserID
1212

1313

14-
class GroupIDStr(IDStr):
15-
...
14+
class GroupIDStr(IDStr): ...
1615

1716

1817
class AccessEnum(str, Enum):
@@ -22,26 +21,23 @@ class AccessEnum(str, Enum):
2221

2322

2423
class AccessRights(BaseModel):
25-
read: bool = Field(..., description="has read access")
26-
write: bool = Field(..., description="has write access")
27-
delete: bool = Field(..., description="has deletion rights")
24+
read: Annotated[bool, Field(description="has read access")]
25+
write: Annotated[bool, Field(description="has write access")]
26+
delete: Annotated[bool, Field(description="has deletion rights")]
2827

2928
model_config = ConfigDict(extra="forbid")
3029

3130

3231
class Owner(BaseModel):
33-
user_id: PositiveInt = Field(..., description="Owner's user id")
34-
first_name: FirstNameStr | None = Field(..., description="Owner's first name")
35-
last_name: LastNameStr | None = Field(..., description="Owner's last name")
32+
user_id: Annotated[UserID, Field(description="Owner's user id")]
3633

3734
model_config = ConfigDict(
3835
extra="forbid",
3936
json_schema_extra={
4037
"examples": [
41-
# NOTE: None and empty string are both defining an undefined value
42-
{"user_id": 1, "first_name": None, "last_name": None},
43-
{"user_id": 2, "first_name": "", "last_name": ""},
44-
{"user_id": 3, "first_name": "John", "last_name": "Smith"},
38+
{"user_id": 1},
39+
{"user_id": 42},
40+
{"user_id": 666},
4541
]
4642
},
4743
)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ class ProjectLocked(BaseModel):
195195
"status": ProjectStatus.OPENED,
196196
"owner": {
197197
"user_id": 123,
198-
"first_name": "Johnny",
199-
"last_name": "Cash",
200198
},
201199
},
202200
]

packages/pytest-simcore/src/pytest_simcore/socketio_client.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pytest
1010
import socketio
1111
from aiohttp.test_utils import TestClient
12+
from pytest_simcore.helpers.logging_tools import log_context
1213
from servicelib.aiohttp import status
1314
from yarl import URL
1415

@@ -56,18 +57,19 @@ async def create_socketio_connection(
5657
security_cookie_factory: Callable[[TestClient | None], Awaitable[str]],
5758
client_session_id_factory: Callable[[], str],
5859
) -> AsyncIterable[
59-
Callable[[str | None, TestClient | None], Awaitable[socketio.AsyncClient]]
60+
Callable[
61+
[str | None, TestClient | None], Awaitable[tuple[socketio.AsyncClient, str]]
62+
]
6063
]:
6164
clients: list[socketio.AsyncClient] = []
6265

6366
async def _connect(
6467
client_session_id: str | None = None, client: TestClient | None = None
65-
) -> socketio.AsyncClient:
68+
) -> tuple[socketio.AsyncClient, str]:
6669
if client_session_id is None:
6770
client_session_id = client_session_id_factory()
6871

6972
sio = socketio.AsyncClient(ssl_verify=False)
70-
# enginio 3.10.0 introduced ssl verification
7173
assert client_session_id
7274
url = str(
7375
URL(socketio_url_factory(client)).with_query(
@@ -80,21 +82,27 @@ async def _connect(
8082
# WARNING: engineio fails with empty cookies. Expects "key=value"
8183
headers.update({"Cookie": cookie})
8284

83-
print(f"--> Connecting socketio client to {url} ...")
84-
await sio.connect(url, headers=headers, wait_timeout=10)
85-
assert sio.sid
86-
print("... connection done")
85+
with log_context(logging.INFO, f"socketio_client: connecting to {url}"):
86+
print(f"--> Connecting socketio client to {url} ...")
87+
sio.on(
88+
"connect",
89+
handler=lambda: logger.info("Connected successfully with %s", sio.sid),
90+
)
91+
sio.on(
92+
"disconnect",
93+
handler=lambda: logger.info("Disconnected from %s", sio.sid),
94+
)
95+
await sio.connect(url, headers=headers, wait_timeout=10)
96+
assert sio.sid
8797
clients.append(sio)
88-
return sio
98+
return sio, client_session_id
8999

90100
yield _connect
91101

92102
# cleans up clients produce by _connect(*) calls
93103
for sio in clients:
94104
if sio.connected:
95-
print(f"<--Disconnecting socketio client {sio}")
96-
await sio.disconnect()
97-
await sio.wait()
98-
print(f"... disconnection from {sio} done.")
99-
assert not sio.connected
100-
assert not sio.sid
105+
with log_context(logging.INFO, f"socketio_client: disconnecting {sio}"):
106+
await sio.disconnect()
107+
await sio.wait()
108+
assert not sio.connected

services/web/server/src/simcore_service_webserver/dynamic_scheduler/api.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from models_library.services import ServicePortKey
2525
from models_library.users import UserID
2626
from pydantic import NonNegativeInt
27-
from pydantic.types import PositiveInt
2827
from servicelib.progress_bar import ProgressBarData
2928
from servicelib.rabbitmq import RabbitMQClient, RPCServerError
3029
from servicelib.rabbitmq.rpc_interfaces.dynamic_scheduler import services
@@ -94,13 +93,13 @@ async def stop_dynamic_service(
9493

9594
async def _post_progress_message(
9695
rabbitmq_client: RabbitMQClient,
97-
user_id: PositiveInt,
98-
project_id: str,
96+
user_id: UserID,
97+
project_id: ProjectID,
9998
report: ProgressReport,
10099
) -> None:
101100
progress_message = ProgressRabbitMessageProject(
102101
user_id=user_id,
103-
project_id=ProjectID(project_id),
102+
project_id=project_id,
104103
progress_type=ProgressType.PROJECT_CLOSING,
105104
report=report,
106105
)
@@ -111,14 +110,14 @@ async def _post_progress_message(
111110
async def stop_dynamic_services_in_project(
112111
app: web.Application,
113112
*,
114-
user_id: PositiveInt,
115-
project_id: str,
113+
user_id: UserID,
114+
project_id: ProjectID,
116115
simcore_user_agent: str,
117116
save_state: bool,
118117
) -> None:
119118
"""Stops all dynamic services in the project"""
120119
running_dynamic_services = await list_dynamic_services(
121-
app, user_id=user_id, project_id=ProjectID(project_id)
120+
app, user_id=user_id, project_id=project_id
122121
)
123122

124123
async with AsyncExitStack() as stack:

services/web/server/src/simcore_service_webserver/exporter/_handlers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from ..projects._projects_service import create_user_notification_cb
1919
from ..redis import get_redis_lock_manager_client_sdk
2020
from ..security.decorators import permission_required
21-
from ..users import users_service
2221
from ._formatter.archive import get_sds_archive_path
2322
from .exceptions import SDSException
2423
from .utils import CleanupFileResponse
@@ -51,10 +50,7 @@ async def export_project(request: web.Request):
5150
get_redis_lock_manager_client_sdk(request.app),
5251
project_uuid=project_uuid,
5352
status=ProjectStatus.EXPORTING,
54-
owner=Owner(
55-
user_id=user_id,
56-
**await users_service.get_user_fullname(request.app, user_id=user_id),
57-
),
53+
owner=Owner(user_id=user_id),
5854
notification_cb=create_user_notification_cb(
5955
user_id, ProjectID(f"{project_uuid}"), request.app
6056
),

services/web/server/src/simcore_service_webserver/garbage_collector/_core.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from aiohttp import web
66
from servicelib.logging_utils import log_catch, log_context
77

8-
from ..resource_manager.registry import RedisResourceRegistry, get_registry
8+
from ..resource_manager.registry import get_registry
99
from ._core_disconnected import remove_disconnected_user_resources
1010
from ._core_guests import remove_users_manually_marked_as_guests
1111
from ._core_orphans import remove_orphaned_services
@@ -34,24 +34,31 @@ async def collect_garbage(app: web.Application):
3434
The field `garbage_collection_interval_seconds` defines the interval at which this
3535
function will be called.
3636
"""
37-
registry: RedisResourceRegistry = get_registry(app)
37+
registry = get_registry(app)
3838

39-
with log_catch(_logger, reraise=False), log_context(
40-
_logger, logging.INFO, "Step 1: Removes disconnected user sessions"
39+
with (
40+
log_catch(_logger, reraise=False),
41+
log_context(
42+
_logger, logging.INFO, "Step 1: Removes disconnected user sessions"
43+
),
4144
):
4245
# Triggers signal to close possible pending opened projects
4346
# Removes disconnected GUEST users after they finished their sessions
4447
await remove_disconnected_user_resources(registry, app)
4548

46-
with log_catch(_logger, reraise=False), log_context(
47-
_logger, logging.INFO, "Step 2: Removes users manually marked for removal"
49+
with (
50+
log_catch(_logger, reraise=False),
51+
log_context(
52+
_logger, logging.INFO, "Step 2: Removes users manually marked for removal"
53+
),
4854
):
4955
# if a user was manually marked as GUEST it needs to be
5056
# removed together with all the associated projects
5157
await remove_users_manually_marked_as_guests(registry, app)
5258

53-
with log_catch(_logger, reraise=False), log_context(
54-
_logger, logging.INFO, "Step 3: Removes orphaned services"
59+
with (
60+
log_catch(_logger, reraise=False),
61+
log_context(_logger, logging.INFO, "Step 3: Removes orphaned services"),
5562
):
5663
# For various reasons, some services remain pending after
5764
# the projects are closed or the user was disconencted.

0 commit comments

Comments
 (0)