From 2eb364c5bae95620cb00191ded50298e04d2f67f Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 3 Dec 2024 09:48:04 +0100 Subject: [PATCH 1/7] added new scheduling mode --- .env-devel | 1 + services/docker-compose.yml | 1 + .../api/rpc/_services.py | 27 ++------ .../core/settings.py | 14 +++++ .../services/scheduler/__init__.py | 7 +++ .../services/scheduler/_interface.py | 61 +++++++++++++++++++ .../status_monitor/_deferred_get_status.py | 6 +- 7 files changed, 92 insertions(+), 25 deletions(-) create mode 100644 services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py create mode 100644 services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py diff --git a/.env-devel b/.env-devel index 7703fa8082a..0a0dfe497e4 100644 --- a/.env-devel +++ b/.env-devel @@ -126,6 +126,7 @@ DIRECTOR_V2_TRACING={} # DYNAMIC_SCHEDULER ---- DYNAMIC_SCHEDULER_LOGLEVEL=DEBUG DYNAMIC_SCHEDULER_PROFILING=1 +DYNAMIC_SCHEDULER_SCHEDULING_MODE=VIA_DIRECTOR_V2 DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT=01:00:00 DYNAMIC_SCHEDULER_TRACING={} diff --git a/services/docker-compose.yml b/services/docker-compose.yml index 691e544b0c0..acdfc813f00 100644 --- a/services/docker-compose.yml +++ b/services/docker-compose.yml @@ -562,6 +562,7 @@ services: REDIS_PASSWORD: ${REDIS_PASSWORD} DIRECTOR_V2_HOST: ${DIRECTOR_V2_HOST} DIRECTOR_V2_PORT: ${DIRECTOR_V2_PORT} + DYNAMIC_SCHEDULER_SCHEDULING_MODE: ${DYNAMIC_SCHEDULER_SCHEDULING_MODE} DYNAMIC_SCHEDULER_LOGLEVEL: ${DYNAMIC_SCHEDULER_LOGLEVEL} DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT: ${DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT} DYNAMIC_SCHEDULER_PROFILING: ${DYNAMIC_SCHEDULER_PROFILING} diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py index 65fc96dd660..560e47d2bde 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py @@ -12,9 +12,7 @@ ServiceWasNotFoundError, ) -from ...core.settings import ApplicationSettings -from ...services.director_v2 import DirectorV2Client -from ...services.service_tracker import set_request_as_running, set_request_as_stopped +from ...services import scheduler router = RPCRouter() @@ -23,23 +21,16 @@ async def get_service_status( app: FastAPI, *, node_id: NodeID ) -> NodeGet | DynamicServiceGet | NodeGetIdle: - director_v2_client = DirectorV2Client.get_from_app_state(app) - response: NodeGet | DynamicServiceGet | NodeGetIdle = ( - await director_v2_client.get_status(node_id) - ) - return response + return await scheduler.get_service_status(app, node_id=node_id) @router.expose() async def run_dynamic_service( app: FastAPI, *, dynamic_service_start: DynamicServiceStart ) -> NodeGet | DynamicServiceGet: - director_v2_client = DirectorV2Client.get_from_app_state(app) - response: NodeGet | DynamicServiceGet = ( - await director_v2_client.run_dynamic_service(dynamic_service_start) + return await scheduler.run_dynamic_service( + app, dynamic_service_start=dynamic_service_start ) - await set_request_as_running(app, dynamic_service_start) - return response @router.expose( @@ -51,12 +42,6 @@ async def run_dynamic_service( async def stop_dynamic_service( app: FastAPI, *, dynamic_service_stop: DynamicServiceStop ) -> None: - director_v2_client = DirectorV2Client.get_from_app_state(app) - settings: ApplicationSettings = app.state.settings - await director_v2_client.stop_dynamic_service( - node_id=dynamic_service_stop.node_id, - simcore_user_agent=dynamic_service_stop.simcore_user_agent, - save_state=dynamic_service_stop.save_state, - timeout=settings.DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT, + return await scheduler.stop_dynamic_service( + app, dynamic_service_stop=dynamic_service_stop ) - await set_request_as_stopped(app, dynamic_service_stop) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py index e577a806712..8486c512bdf 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py @@ -1,4 +1,5 @@ import datetime +from enum import StrEnum from typing import Annotated from pydantic import AliasChoices, Field, TypeAdapter, field_validator @@ -14,6 +15,11 @@ from .._meta import API_VERSION, API_VTAG, PROJECT_NAME +class SchedulingMode(StrEnum): + INTERNAL = "INTERNAL" + VIA_DIRECTOR_V2 = "VIA_DIRECTOR_V2" + + class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings): """Base settings of any osparc service's app""" @@ -68,6 +74,14 @@ class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings): ), ) + DYNAMIC_SCHEDULER_SCHEDULING_MODE: SchedulingMode = Field( + SchedulingMode.VIA_DIRECTOR_V2, + description=( + "this is a way to switch between different dynamic schedulers for the new style services" + # NOTE: this option should be removed when the scheduling will be done via this service + ), + ) + @field_validator("DYNAMIC_SCHEDULER_LOGLEVEL", mode="before") @classmethod def _validate_log_level(cls, value: str) -> str: diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py new file mode 100644 index 00000000000..e81fd5a26fc --- /dev/null +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py @@ -0,0 +1,7 @@ +from ._interface import get_service_status, run_dynamic_service, stop_dynamic_service + +__all__: tuple[str, ...] = ( + "get_service_status", + "run_dynamic_service", + "stop_dynamic_service", +) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py new file mode 100644 index 00000000000..3e1b4c8bdf2 --- /dev/null +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py @@ -0,0 +1,61 @@ +from fastapi import FastAPI +from models_library.api_schemas_directorv2.dynamic_services import DynamicServiceGet +from models_library.api_schemas_dynamic_scheduler.dynamic_services import ( + DynamicServiceStart, + DynamicServiceStop, +) +from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle +from models_library.projects_nodes_io import NodeID + +from ...core.settings import ApplicationSettings, SchedulingMode +from ...services.director_v2 import DirectorV2Client +from ...services.service_tracker import set_request_as_running, set_request_as_stopped + + +async def get_service_status( + app: FastAPI, *, node_id: NodeID +) -> NodeGet | DynamicServiceGet | NodeGetIdle: + settings: ApplicationSettings = app.state.settings + if settings.DYNAMIC_SCHEDULER_SCHEDULING_MODE == SchedulingMode.INTERNAL: + raise NotImplementedError + + director_v2_client = DirectorV2Client.get_from_app_state(app) + response: NodeGet | DynamicServiceGet | NodeGetIdle = ( + await director_v2_client.get_status(node_id) + ) + return response + + +async def run_dynamic_service( + app: FastAPI, *, dynamic_service_start: DynamicServiceStart +) -> NodeGet | DynamicServiceGet: + settings: ApplicationSettings = app.state.settings + if settings.DYNAMIC_SCHEDULER_SCHEDULING_MODE == SchedulingMode.INTERNAL: + raise NotImplementedError + + director_v2_client = DirectorV2Client.get_from_app_state(app) + response: NodeGet | DynamicServiceGet = ( + await director_v2_client.run_dynamic_service(dynamic_service_start) + ) + + await set_request_as_running(app, dynamic_service_start) + return response + + +async def stop_dynamic_service( + app: FastAPI, *, dynamic_service_stop: DynamicServiceStop +) -> None: + settings: ApplicationSettings = app.state.settings + if settings.DYNAMIC_SCHEDULER_SCHEDULING_MODE == SchedulingMode.INTERNAL: + raise NotImplementedError + + director_v2_client = DirectorV2Client.get_from_app_state(app) + settings: ApplicationSettings = app.state.settings + await director_v2_client.stop_dynamic_service( + node_id=dynamic_service_stop.node_id, + simcore_user_agent=dynamic_service_stop.simcore_user_agent, + save_state=dynamic_service_stop.save_state, + timeout=settings.DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT, + ) + + await set_request_as_stopped(app, dynamic_service_stop) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py index f710204504c..e9dcded6e71 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py @@ -12,8 +12,7 @@ from servicelib.deferred_tasks import BaseDeferredHandler, TaskUID from servicelib.deferred_tasks._base_deferred_handler import DeferredContext -from .. import service_tracker -from ..director_v2 import DirectorV2Client +from .. import scheduler, service_tracker from ..notifier import notify_service_status_change _logger = logging.getLogger(__name__) @@ -47,9 +46,8 @@ async def run( app: FastAPI = context["app"] node_id: NodeID = context["node_id"] - director_v2_client: DirectorV2Client = DirectorV2Client.get_from_app_state(app) service_status: NodeGet | RunningDynamicServiceDetails | NodeGetIdle = ( - await director_v2_client.get_status(node_id) + await scheduler.get_service_status(app, node_id=node_id) ) _logger.debug( "Service status type=%s, %s", type(service_status), service_status From f626572d8c227b4a69e96a23ab6e95ac348ea565 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 3 Dec 2024 09:50:07 +0100 Subject: [PATCH 2/7] restructured modules --- .../api/rpc/_services.py | 8 ++++---- .../services/scheduler/__init__.py | 7 ------- .../{scheduler/_interface.py => scheduler_interface.py} | 6 +++--- .../services/status_monitor/_deferred_get_status.py | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) delete mode 100644 services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py rename services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/{scheduler/_interface.py => scheduler_interface.py} (91%) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py index 560e47d2bde..76a8e30ceec 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rpc/_services.py @@ -12,7 +12,7 @@ ServiceWasNotFoundError, ) -from ...services import scheduler +from ...services import scheduler_interface router = RPCRouter() @@ -21,14 +21,14 @@ async def get_service_status( app: FastAPI, *, node_id: NodeID ) -> NodeGet | DynamicServiceGet | NodeGetIdle: - return await scheduler.get_service_status(app, node_id=node_id) + return await scheduler_interface.get_service_status(app, node_id=node_id) @router.expose() async def run_dynamic_service( app: FastAPI, *, dynamic_service_start: DynamicServiceStart ) -> NodeGet | DynamicServiceGet: - return await scheduler.run_dynamic_service( + return await scheduler_interface.run_dynamic_service( app, dynamic_service_start=dynamic_service_start ) @@ -42,6 +42,6 @@ async def run_dynamic_service( async def stop_dynamic_service( app: FastAPI, *, dynamic_service_stop: DynamicServiceStop ) -> None: - return await scheduler.stop_dynamic_service( + return await scheduler_interface.stop_dynamic_service( app, dynamic_service_stop=dynamic_service_stop ) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py deleted file mode 100644 index e81fd5a26fc..00000000000 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from ._interface import get_service_status, run_dynamic_service, stop_dynamic_service - -__all__: tuple[str, ...] = ( - "get_service_status", - "run_dynamic_service", - "stop_dynamic_service", -) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py similarity index 91% rename from services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py rename to services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py index 3e1b4c8bdf2..0d65d4730f6 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler/_interface.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py @@ -7,9 +7,9 @@ from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle from models_library.projects_nodes_io import NodeID -from ...core.settings import ApplicationSettings, SchedulingMode -from ...services.director_v2 import DirectorV2Client -from ...services.service_tracker import set_request_as_running, set_request_as_stopped +from ..core.settings import ApplicationSettings, SchedulingMode +from .director_v2 import DirectorV2Client +from .service_tracker import set_request_as_running, set_request_as_stopped async def get_service_status( diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py index e9dcded6e71..c093fdd93d1 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/status_monitor/_deferred_get_status.py @@ -12,7 +12,7 @@ from servicelib.deferred_tasks import BaseDeferredHandler, TaskUID from servicelib.deferred_tasks._base_deferred_handler import DeferredContext -from .. import scheduler, service_tracker +from .. import scheduler_interface, service_tracker from ..notifier import notify_service_status_change _logger = logging.getLogger(__name__) @@ -47,7 +47,7 @@ async def run( node_id: NodeID = context["node_id"] service_status: NodeGet | RunningDynamicServiceDetails | NodeGetIdle = ( - await scheduler.get_service_status(app, node_id=node_id) + await scheduler_interface.get_service_status(app, node_id=node_id) ) _logger.debug( "Service status type=%s, %s", type(service_status), service_status From 3cb6e9af1cb47438adfc967cf8e9ac10264b6390 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 3 Dec 2024 10:00:03 +0100 Subject: [PATCH 3/7] extended tests --- .../unit/api_rpc/test_api_rpc__services.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py index 7ee876e9e4b..b07da825c6a 100644 --- a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py +++ b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py @@ -20,6 +20,7 @@ from models_library.users import UserID from pydantic import TypeAdapter from pytest_mock import MockerFixture +from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict from pytest_simcore.helpers.typing_env import EnvVarsDict from servicelib.rabbitmq import RabbitMQRPCClient, RPCServerError from servicelib.rabbitmq.rpc_interfaces.dynamic_scheduler import services @@ -29,6 +30,7 @@ ) from settings_library.rabbit import RabbitSettings from settings_library.redis import RedisSettings +from simcore_service_dynamic_scheduler.core.settings import SchedulingMode pytest_simcore_core_services_selection = [ "redis", @@ -133,13 +135,32 @@ def mock_director_v2_service_state( yield None +@pytest.fixture( + params=[ + SchedulingMode.VIA_DIRECTOR_V2, + # NOTE: enable below when INTERNAL scheduler is impelmented + # SchedulingMode.INTERNAL, + ] +) +def scheduling_mode(request: pytest.FixtureRequest) -> SchedulingMode: + return request.param + + @pytest.fixture def app_environment( + monkeypatch: pytest.MonkeyPatch, app_environment: EnvVarsDict, rabbit_service: RabbitSettings, redis_service: RedisSettings, + scheduling_mode: SchedulingMode, ) -> EnvVarsDict: - return app_environment + return setenvs_from_dict( + monkeypatch, + { + **app_environment, + "DYNAMIC_SCHEDULER_SCHEDULING_MODE": scheduling_mode, + }, + ) @pytest.fixture From f7e586338b0a77bb1962cafee862aaed49bd5f55 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 3 Dec 2024 10:15:11 +0100 Subject: [PATCH 4/7] fixed broken test --- .../tests/unit/api_rpc/test_api_rpc__services.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py index b07da825c6a..cfb972be9f8 100644 --- a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py +++ b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py @@ -148,19 +148,19 @@ def scheduling_mode(request: pytest.FixtureRequest) -> SchedulingMode: @pytest.fixture def app_environment( - monkeypatch: pytest.MonkeyPatch, app_environment: EnvVarsDict, rabbit_service: RabbitSettings, redis_service: RedisSettings, scheduling_mode: SchedulingMode, + monkeypatch: pytest.MonkeyPatch, ) -> EnvVarsDict: - return setenvs_from_dict( + setenvs_from_dict( monkeypatch, { - **app_environment, "DYNAMIC_SCHEDULER_SCHEDULING_MODE": scheduling_mode, }, ) + return app_environment @pytest.fixture From c130e8b32ebc5a3f58f63711d84ec90905d55646 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 3 Dec 2024 11:46:06 +0100 Subject: [PATCH 5/7] renamed env var --- .env-devel | 2 +- services/docker-compose.yml | 2 +- .../core/settings.py | 10 ++-------- .../services/scheduler_interface.py | 8 ++++---- .../tests/unit/api_rpc/test_api_rpc__services.py | 13 ++++++------- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.env-devel b/.env-devel index 0a0dfe497e4..7f39e419b62 100644 --- a/.env-devel +++ b/.env-devel @@ -126,7 +126,7 @@ DIRECTOR_V2_TRACING={} # DYNAMIC_SCHEDULER ---- DYNAMIC_SCHEDULER_LOGLEVEL=DEBUG DYNAMIC_SCHEDULER_PROFILING=1 -DYNAMIC_SCHEDULER_SCHEDULING_MODE=VIA_DIRECTOR_V2 +DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER=0 DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT=01:00:00 DYNAMIC_SCHEDULER_TRACING={} diff --git a/services/docker-compose.yml b/services/docker-compose.yml index acdfc813f00..887d8844ade 100644 --- a/services/docker-compose.yml +++ b/services/docker-compose.yml @@ -562,7 +562,7 @@ services: REDIS_PASSWORD: ${REDIS_PASSWORD} DIRECTOR_V2_HOST: ${DIRECTOR_V2_HOST} DIRECTOR_V2_PORT: ${DIRECTOR_V2_PORT} - DYNAMIC_SCHEDULER_SCHEDULING_MODE: ${DYNAMIC_SCHEDULER_SCHEDULING_MODE} + DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER: ${DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER} DYNAMIC_SCHEDULER_LOGLEVEL: ${DYNAMIC_SCHEDULER_LOGLEVEL} DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT: ${DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT} DYNAMIC_SCHEDULER_PROFILING: ${DYNAMIC_SCHEDULER_PROFILING} diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py index 8486c512bdf..6d43bd4c6e9 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/core/settings.py @@ -1,5 +1,4 @@ import datetime -from enum import StrEnum from typing import Annotated from pydantic import AliasChoices, Field, TypeAdapter, field_validator @@ -15,11 +14,6 @@ from .._meta import API_VERSION, API_VTAG, PROJECT_NAME -class SchedulingMode(StrEnum): - INTERNAL = "INTERNAL" - VIA_DIRECTOR_V2 = "VIA_DIRECTOR_V2" - - class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings): """Base settings of any osparc service's app""" @@ -74,8 +68,8 @@ class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings): ), ) - DYNAMIC_SCHEDULER_SCHEDULING_MODE: SchedulingMode = Field( - SchedulingMode.VIA_DIRECTOR_V2, + DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER: bool = Field( + default=False, description=( "this is a way to switch between different dynamic schedulers for the new style services" # NOTE: this option should be removed when the scheduling will be done via this service diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py index 0d65d4730f6..41cb8b0827f 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py @@ -7,7 +7,7 @@ from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle from models_library.projects_nodes_io import NodeID -from ..core.settings import ApplicationSettings, SchedulingMode +from ..core.settings import ApplicationSettings from .director_v2 import DirectorV2Client from .service_tracker import set_request_as_running, set_request_as_stopped @@ -16,7 +16,7 @@ async def get_service_status( app: FastAPI, *, node_id: NodeID ) -> NodeGet | DynamicServiceGet | NodeGetIdle: settings: ApplicationSettings = app.state.settings - if settings.DYNAMIC_SCHEDULER_SCHEDULING_MODE == SchedulingMode.INTERNAL: + if settings.DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER: raise NotImplementedError director_v2_client = DirectorV2Client.get_from_app_state(app) @@ -30,7 +30,7 @@ async def run_dynamic_service( app: FastAPI, *, dynamic_service_start: DynamicServiceStart ) -> NodeGet | DynamicServiceGet: settings: ApplicationSettings = app.state.settings - if settings.DYNAMIC_SCHEDULER_SCHEDULING_MODE == SchedulingMode.INTERNAL: + if settings.DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER: raise NotImplementedError director_v2_client = DirectorV2Client.get_from_app_state(app) @@ -46,7 +46,7 @@ async def stop_dynamic_service( app: FastAPI, *, dynamic_service_stop: DynamicServiceStop ) -> None: settings: ApplicationSettings = app.state.settings - if settings.DYNAMIC_SCHEDULER_SCHEDULING_MODE == SchedulingMode.INTERNAL: + if settings.DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER: raise NotImplementedError director_v2_client = DirectorV2Client.get_from_app_state(app) diff --git a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py index cfb972be9f8..c72ac4ed2ce 100644 --- a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py +++ b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py @@ -30,7 +30,6 @@ ) from settings_library.rabbit import RabbitSettings from settings_library.redis import RedisSettings -from simcore_service_dynamic_scheduler.core.settings import SchedulingMode pytest_simcore_core_services_selection = [ "redis", @@ -137,12 +136,12 @@ def mock_director_v2_service_state( @pytest.fixture( params=[ - SchedulingMode.VIA_DIRECTOR_V2, - # NOTE: enable below when INTERNAL scheduler is impelmented - # SchedulingMode.INTERNAL, + False, + # NOTE: enable below when INTERNAL scheduler is implemented + # True, ] ) -def scheduling_mode(request: pytest.FixtureRequest) -> SchedulingMode: +def use_internal_scheduler(request: pytest.FixtureRequest) -> bool: return request.param @@ -151,13 +150,13 @@ def app_environment( app_environment: EnvVarsDict, rabbit_service: RabbitSettings, redis_service: RedisSettings, - scheduling_mode: SchedulingMode, + use_internal_scheduler: bool, monkeypatch: pytest.MonkeyPatch, ) -> EnvVarsDict: setenvs_from_dict( monkeypatch, { - "DYNAMIC_SCHEDULER_SCHEDULING_MODE": scheduling_mode, + "DYNAMIC_SCHEDULER_USE_INTERNAL_SCHEDULER": f"{use_internal_scheduler}", }, ) return app_environment From c219c8eeaf421c8ad8bd9257eb904fa2ddd05b72 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Thu, 5 Dec 2024 06:34:10 +0100 Subject: [PATCH 6/7] add xfail for option --- .../tests/unit/api_rpc/test_api_rpc__services.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py index c72ac4ed2ce..ddd8bfd6e2d 100644 --- a/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py +++ b/services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py @@ -137,8 +137,12 @@ def mock_director_v2_service_state( @pytest.fixture( params=[ False, - # NOTE: enable below when INTERNAL scheduler is implemented - # True, + pytest.param( + True, + marks=pytest.mark.xfail( + reason="INTERNAL scheduler implementation is missing" + ), + ), ] ) def use_internal_scheduler(request: pytest.FixtureRequest) -> bool: From af041a974c6db57c074dcb888978cd40a26d1fb4 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Thu, 5 Dec 2024 06:54:14 +0100 Subject: [PATCH 7/7] mypy --- .../services/scheduler_interface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py index 41cb8b0827f..1d4bcdd112b 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/scheduler_interface.py @@ -50,7 +50,6 @@ async def stop_dynamic_service( raise NotImplementedError director_v2_client = DirectorV2Client.get_from_app_state(app) - settings: ApplicationSettings = app.state.settings await director_v2_client.stop_dynamic_service( node_id=dynamic_service_stop.node_id, simcore_user_agent=dynamic_service_stop.simcore_user_agent,