Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7f9be17
moved inputs to services
Aug 18, 2025
5d0d7be
fixed
Aug 18, 2025
27dcbd1
refactr
Aug 18, 2025
c689ed8
added tests
Aug 18, 2025
1a19df7
reverted inputs placement
Aug 18, 2025
a7e6c43
properly extracted internals
Aug 18, 2025
a674736
refactor interface
Aug 18, 2025
7c604d4
added rpc interface for create_output_dirs
Aug 18, 2025
10f15d0
extracted common interface
Aug 18, 2025
f9e757f
Merge remote-tracking branch 'upstream/master' into pr-osparc-dy-side…
Aug 28, 2025
5bee321
added API for attach/detach container extentions
Aug 28, 2025
df779bb
Merge remote-tracking branch 'upstream/master' into pr-osparc-dy-side…
Aug 28, 2025
544f8d4
extracted common containers interface
Aug 28, 2025
30e5521
removed unused code
Aug 28, 2025
100fbb7
refactored messages
Aug 28, 2025
57efa22
moved tests
Aug 28, 2025
db5a1a2
finished adding RPC interface
Aug 29, 2025
8caad07
Merge remote-tracking branch 'upstream/master' into pr-osparc-dy-side…
Aug 29, 2025
d4184f6
refactor
Aug 29, 2025
0cfd263
fixed reimports
Aug 29, 2025
c4219a8
fixed error message
Aug 29, 2025
8a625ae
fixed tests
Aug 29, 2025
a6677f7
updated descriptions and docs
Aug 29, 2025
f83db20
added docstrings
Aug 29, 2025
a557f24
updated specs
Aug 29, 2025
a5ed3a3
Merge branch 'master' into pr-osparc-dy-sidecar-ports-migrate
GitHK Aug 29, 2025
707b704
removed unused
Aug 29, 2025
19821b9
drop unused
Aug 29, 2025
e03bb8b
copilot suggestions
Aug 29, 2025
bcef2c4
Merge remote-tracking branch 'upstream/master' into pr-osparc-dy-side…
Aug 29, 2025
ff22ecc
Merge branch 'pr-osparc-dy-sidecar-ports-migrate' of github.com:GitHK…
Aug 29, 2025
90569a3
Merge remote-tracking branch 'upstream/master' into pr-osparc-dy-side…
Sep 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import logging

from models_library.projects_nodes_io import NodeID
from models_library.rabbitmq_basic_types import RPCMethodName
from models_library.services import ServiceOutput
from pydantic import TypeAdapter

from ....logging_utils import log_decorator
from ... import RabbitMQRPCClient
from ._utils import get_rpc_namespace

_logger = logging.getLogger(__name__)


@log_decorator(_logger, level=logging.DEBUG)
async def toggle_ports_io(
rabbitmq_rpc_client: RabbitMQRPCClient,
*,
node_id: NodeID,
enable_outputs: bool,
enable_inputs: bool
) -> None:
rpc_namespace = get_rpc_namespace(node_id)
result = await rabbitmq_rpc_client.request(
rpc_namespace,
TypeAdapter(RPCMethodName).validate_python("toggle_ports_io"),
enable_outputs=enable_outputs,
enable_inputs=enable_inputs,
)
assert result is None # nosec


@log_decorator(_logger, level=logging.DEBUG)
async def create_output_dirs(
rabbitmq_rpc_client: RabbitMQRPCClient,
*,
node_id: NodeID,
outputs_labels: dict[str, ServiceOutput]
) -> None:
rpc_namespace = get_rpc_namespace(node_id)
result = await rabbitmq_rpc_client.request(
rpc_namespace,
TypeAdapter(RPCMethodName).validate_python("create_output_dirs"),
outputs_labels=outputs_labels,
)
assert result is None # nosec


@log_decorator(_logger, level=logging.DEBUG)
async def attach_container_to_network(
rabbitmq_rpc_client: RabbitMQRPCClient,
*,
node_id: NodeID,
container_id: str,
network_id: str,
network_aliases: list[str]
) -> None:
rpc_namespace = get_rpc_namespace(node_id)
result = await rabbitmq_rpc_client.request(
rpc_namespace,
TypeAdapter(RPCMethodName).validate_python("attach_container_to_network"),
container_id=container_id,
network_id=network_id,
network_aliases=network_aliases,
)
assert result is None # nosec


@log_decorator(_logger, level=logging.DEBUG)
async def detach_container_from_network(
rabbitmq_rpc_client: RabbitMQRPCClient,
*,
node_id: NodeID,
container_id: str,
network_id: str
) -> None:
rpc_namespace = get_rpc_namespace(node_id)
result = await rabbitmq_rpc_client.request(
rpc_namespace,
TypeAdapter(RPCMethodName).validate_python("detach_container_from_network"),
container_id=container_id,
network_id=network_id,
)
assert result is None # nosec
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
""" Free functions to inject dependencies in routes handlers
"""
"""Free functions to inject dependencies in routes handlers"""

from asyncio import Lock
from typing import Annotated, cast

from fastapi import Depends, FastAPI, Request
Expand All @@ -10,84 +8,37 @@
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient

from ...core import rabbitmq
from ...core.settings import ApplicationSettings
from ...models.schemas.application_health import ApplicationHealth
from ...models.shared_store import SharedStore
from ...modules.inputs import InputsState
from ...modules.mounted_fs import MountedVolumes
from ...modules.outputs import OutputsContext, OutputsManager
from ...modules.prometheus_metrics import UserServicesMetrics


def get_application(request: Request) -> FastAPI:
return cast(FastAPI, request.app)


def get_app_state(request: Request) -> State:
def _get_app_state(request: Request) -> State:
return cast(State, request.app.state)


def get_application_health(
app_state: Annotated[State, Depends(get_app_state)]
app_state: Annotated[State, Depends(_get_app_state)],
) -> ApplicationHealth:
return cast(ApplicationHealth, app_state.application_health)


def get_settings(
app_state: Annotated[State, Depends(get_app_state)]
) -> ApplicationSettings:
return cast(ApplicationSettings, app_state.settings)


def get_shared_store(
app_state: Annotated[State, Depends(get_app_state)]
) -> SharedStore:
return cast(SharedStore, app_state.shared_store)


def get_mounted_volumes(
app_state: Annotated[State, Depends(get_app_state)]
) -> MountedVolumes:
return cast(MountedVolumes, app_state.mounted_volumes)


def get_container_restart_lock(
app_state: Annotated[State, Depends(get_app_state)]
) -> Lock:
return cast(Lock, app_state.container_restart_lock)


def get_outputs_manager(
app_state: Annotated[State, Depends(get_app_state)]
) -> OutputsManager:
return cast(OutputsManager, app_state.outputs_manager)


def get_outputs_context(
app_state: Annotated[State, Depends(get_app_state)]
) -> OutputsContext:
return cast(OutputsContext, app_state.outputs_context)


def get_inputs_state(
app_state: Annotated[State, Depends(get_app_state)]
) -> InputsState:
return cast(InputsState, app_state.inputs_state)


def get_user_services_metrics(
app_state: Annotated[State, Depends(get_app_state)]
app_state: Annotated[State, Depends(_get_app_state)],
) -> UserServicesMetrics:
return cast(UserServicesMetrics, app_state.user_service_metrics)


def get_rabbitmq_client(
app: Annotated[FastAPI, Depends(get_application)]
app: Annotated[FastAPI, Depends(get_application)],
) -> RabbitMQClient:
return rabbitmq.get_rabbitmq_client(app)


def get_rabbitmq_rpc_server(
app: Annotated[FastAPI, Depends(get_application)]
app: Annotated[FastAPI, Depends(get_application)],
) -> RabbitMQRPCClient:
return rabbitmq.get_rabbitmq_rpc_server(app)
Loading
Loading