Skip to content

Commit 7f9be17

Browse files
author
Andrei Neagu
committed
moved inputs to services
1 parent 3472e17 commit 7f9be17

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
""" Free functions to inject dependencies in routes handlers
2-
"""
1+
"""Free functions to inject dependencies in routes handlers"""
32

43
from asyncio import Lock
54
from typing import Annotated, cast
@@ -13,10 +12,10 @@
1312
from ...core.settings import ApplicationSettings
1413
from ...models.schemas.application_health import ApplicationHealth
1514
from ...models.shared_store import SharedStore
16-
from ...modules.inputs import InputsState
1715
from ...modules.mounted_fs import MountedVolumes
1816
from ...modules.outputs import OutputsContext, OutputsManager
1917
from ...modules.prometheus_metrics import UserServicesMetrics
18+
from ...services.inputs import InputsState
2019

2120

2221
def get_application(request: Request) -> FastAPI:
@@ -28,66 +27,66 @@ def get_app_state(request: Request) -> State:
2827

2928

3029
def get_application_health(
31-
app_state: Annotated[State, Depends(get_app_state)]
30+
app_state: Annotated[State, Depends(get_app_state)],
3231
) -> ApplicationHealth:
3332
return cast(ApplicationHealth, app_state.application_health)
3433

3534

3635
def get_settings(
37-
app_state: Annotated[State, Depends(get_app_state)]
36+
app_state: Annotated[State, Depends(get_app_state)],
3837
) -> ApplicationSettings:
3938
return cast(ApplicationSettings, app_state.settings)
4039

4140

4241
def get_shared_store(
43-
app_state: Annotated[State, Depends(get_app_state)]
42+
app_state: Annotated[State, Depends(get_app_state)],
4443
) -> SharedStore:
4544
return cast(SharedStore, app_state.shared_store)
4645

4746

4847
def get_mounted_volumes(
49-
app_state: Annotated[State, Depends(get_app_state)]
48+
app_state: Annotated[State, Depends(get_app_state)],
5049
) -> MountedVolumes:
5150
return cast(MountedVolumes, app_state.mounted_volumes)
5251

5352

5453
def get_container_restart_lock(
55-
app_state: Annotated[State, Depends(get_app_state)]
54+
app_state: Annotated[State, Depends(get_app_state)],
5655
) -> Lock:
5756
return cast(Lock, app_state.container_restart_lock)
5857

5958

6059
def get_outputs_manager(
61-
app_state: Annotated[State, Depends(get_app_state)]
60+
app_state: Annotated[State, Depends(get_app_state)],
6261
) -> OutputsManager:
6362
return cast(OutputsManager, app_state.outputs_manager)
6463

6564

6665
def get_outputs_context(
67-
app_state: Annotated[State, Depends(get_app_state)]
66+
app_state: Annotated[State, Depends(get_app_state)],
6867
) -> OutputsContext:
6968
return cast(OutputsContext, app_state.outputs_context)
7069

7170

7271
def get_inputs_state(
73-
app_state: Annotated[State, Depends(get_app_state)]
72+
app_state: Annotated[State, Depends(get_app_state)],
7473
) -> InputsState:
7574
return cast(InputsState, app_state.inputs_state)
7675

7776

7877
def get_user_services_metrics(
79-
app_state: Annotated[State, Depends(get_app_state)]
78+
app_state: Annotated[State, Depends(get_app_state)],
8079
) -> UserServicesMetrics:
8180
return cast(UserServicesMetrics, app_state.user_service_metrics)
8281

8382

8483
def get_rabbitmq_client(
85-
app: Annotated[FastAPI, Depends(get_application)]
84+
app: Annotated[FastAPI, Depends(get_application)],
8685
) -> RabbitMQClient:
8786
return rabbitmq.get_rabbitmq_client(app)
8887

8988

9089
def get_rabbitmq_rpc_server(
91-
app: Annotated[FastAPI, Depends(get_application)]
90+
app: Annotated[FastAPI, Depends(get_application)],
9291
) -> RabbitMQRPCClient:
9392
return rabbitmq.get_rabbitmq_rpc_server(app)

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rest/containers_extension.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
from simcore_sdk.node_ports_v2.port_utils import is_file_type
1111

1212
from ...core.docker_utils import docker_client
13-
from ...modules.inputs import disable_inputs_pulling, enable_inputs_pulling
1413
from ...modules.mounted_fs import MountedVolumes
15-
from ...modules.outputs import (
16-
OutputsContext,
17-
disable_event_propagation,
18-
enable_event_propagation,
19-
)
14+
from ...modules.outputs import OutputsContext
15+
from ...services.inputs import disable_inputs_pulling, enable_inputs_pulling
16+
from ...services.outputs import disable_event_propagation, enable_event_propagation
2017
from ._dependencies import get_application, get_mounted_volumes, get_outputs_context
2118

2219
_logger = logging.getLogger(__name__)

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rest/containers_long_running_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from ...models.schemas.application_health import ApplicationHealth
1414
from ...models.schemas.containers import ContainersCreate
1515
from ...models.shared_store import SharedStore
16-
from ...modules.inputs import InputsState
1716
from ...modules.long_running_tasks import (
1817
task_containers_restart,
1918
task_create_service_containers,
@@ -27,6 +26,7 @@
2726
)
2827
from ...modules.mounted_fs import MountedVolumes
2928
from ...modules.outputs import OutputsManager
29+
from ...services.inputs import InputsState
3030
from ._dependencies import (
3131
get_application,
3232
get_application_health,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from fastapi import FastAPI
2+
from servicelib.rabbitmq import RPCRouter
3+
4+
from ...services.inputs import disable_inputs_pulling, enable_inputs_pulling
5+
from ...services.outputs import disable_event_propagation, enable_event_propagation
6+
7+
router = RPCRouter()
8+
9+
10+
@router.expose()
11+
async def toggle_ports_io(
12+
app: FastAPI, *, enable_outputs: bool, enable_inputs: bool
13+
) -> None:
14+
if enable_outputs:
15+
await enable_event_propagation(app)
16+
else:
17+
await disable_event_propagation(app)
18+
19+
if enable_inputs:
20+
enable_inputs_pulling(app)
21+
else:
22+
disable_inputs_pulling(app)

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rpc/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from ...core.rabbitmq import get_rabbitmq_rpc_server
66
from ...core.settings import ApplicationSettings
7-
from . import _disk, _disk_usage, _volumes
7+
from . import _containers_extension, _disk, _disk_usage, _volumes
88

99
ROUTERS: list[RPCRouter] = [
10+
_containers_extension.router,
1011
_disk_usage.router,
1112
_disk.router,
1213
_volumes.router,

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
from ..models.schemas.application_health import ApplicationHealth
2424
from ..models.shared_store import SharedStore, setup_shared_store
2525
from ..modules.attribute_monitor import setup_attribute_monitor
26-
from ..modules.inputs import setup_inputs
2726
from ..modules.mounted_fs import MountedVolumes, setup_mounted_fs
2827
from ..modules.notifications import setup_notifications
2928
from ..modules.outputs import setup_outputs
3029
from ..modules.prometheus_metrics import setup_prometheus_metrics
3130
from ..modules.resource_tracking import setup_resource_tracking
3231
from ..modules.system_monitor import setup_system_monitor
3332
from ..modules.user_services_preferences import setup_user_services_preferences
33+
from ..services.inputs import setup_inputs
3434
from .docker_compose_utils import docker_compose_down
3535
from .docker_logs import setup_background_log_fetcher
3636
from .error_handlers import http_error_handler, node_not_found_error_handler
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__all__: tuple[str, ...] = (
2+
"disable_event_propagation",
3+
"enable_event_propagation",
4+
)

0 commit comments

Comments
 (0)