From 67e6f9a2a517b86b88c22deb5a79ee665159f2ca Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:51:45 +0100 Subject: [PATCH] cleanup --- .../models/comp_runs.py | 15 ++++----------- .../modules/clusters_keeper.py | 1 - .../modules/comp_scheduler/_manager.py | 2 -- .../modules/comp_scheduler/_utils.py | 4 ++-- .../modules/db/repositories/comp_runs.py | 10 +--------- .../src/simcore_service_director_v2/utils/db.py | 15 --------------- 6 files changed, 7 insertions(+), 40 deletions(-) diff --git a/services/director-v2/src/simcore_service_director_v2/models/comp_runs.py b/services/director-v2/src/simcore_service_director_v2/models/comp_runs.py index f3fedc6a9f9..c2ced79e336 100644 --- a/services/director-v2/src/simcore_service_director_v2/models/comp_runs.py +++ b/services/director-v2/src/simcore_service_director_v2/models/comp_runs.py @@ -2,7 +2,7 @@ from contextlib import suppress from typing import TypeAlias -from models_library.clusters import DEFAULT_CLUSTER_ID, ClusterID +from models_library.clusters import ClusterID from models_library.projects import ProjectID from models_library.projects_nodes_io import NodeID from models_library.projects_state import RunningState @@ -70,13 +70,6 @@ def convert_result_from_state_type_enum_if_needed(cls, v): return RunningState(DB_TO_RUNNING_STATE[StateType(v)]) return v - @field_validator("cluster_id", mode="before") - @classmethod - def convert_null_to_default_cluster_id(cls, v): - if v is None: - v = DEFAULT_CLUSTER_ID - return v - @field_validator("created", "modified", "started", "ended") @classmethod def ensure_utc(cls, v: datetime.datetime | None) -> datetime.datetime | None: @@ -100,7 +93,7 @@ def convert_null_to_empty_metadata(cls, v): "run_id": 432, "project_uuid": "65fee9d2-e030-452c-a29c-45d288577ca5", "user_id": 132, - "cluster_id": 0, + "cluster_id": None, "iteration": 42, "result": "UNKNOWN", "started": None, @@ -116,7 +109,7 @@ def convert_null_to_empty_metadata(cls, v): "run_id": 432, "project_uuid": "65fee9d2-e030-452c-a29c-45d288577ca5", "user_id": 132, - "cluster_id": None, # this default to DEFAULT_CLUSTER_ID + "cluster_id": None, "iteration": 42, "result": "NOT_STARTED", "started": None, @@ -132,7 +125,7 @@ def convert_null_to_empty_metadata(cls, v): "run_id": 43243, "project_uuid": "65fee9d2-e030-452c-a29c-45d288577ca5", "user_id": 132, - "cluster_id": 123, + "cluster_id": None, "iteration": 12, "result": "SUCCESS", "created": "2021-03-01T13:07:34.191610", diff --git a/services/director-v2/src/simcore_service_director_v2/modules/clusters_keeper.py b/services/director-v2/src/simcore_service_director_v2/modules/clusters_keeper.py index 2e62c414d86..01f5586fc35 100644 --- a/services/director-v2/src/simcore_service_director_v2/modules/clusters_keeper.py +++ b/services/director-v2/src/simcore_service_director_v2/modules/clusters_keeper.py @@ -48,7 +48,6 @@ async def get_or_create_on_demand_cluster( owner=user_id, endpoint=returned_cluster.endpoint, authentication=returned_cluster.authentication, - access_rights={}, ) except RemoteMethodNotRegisteredError as exc: # no clusters-keeper, that is not going to work! diff --git a/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_manager.py b/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_manager.py index 6abadf9139e..09d9a49169e 100644 --- a/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_manager.py +++ b/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_manager.py @@ -4,7 +4,6 @@ import networkx as nx from aiopg.sa import Engine from fastapi import FastAPI -from models_library.clusters import DEFAULT_CLUSTER_ID from models_library.projects import ProjectID from models_library.users import UserID from servicelib.background_task import start_periodic_task, stop_periodic_task @@ -55,7 +54,6 @@ async def run_new_pipeline( new_run = await CompRunsRepository.instance(db_engine).create( user_id=user_id, project_id=project_id, - cluster_id=DEFAULT_CLUSTER_ID, metadata=run_metadata, use_on_demand_clusters=use_on_demand_clusters, ) diff --git a/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_utils.py b/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_utils.py index 0458b159811..9d2722e3b6c 100644 --- a/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_utils.py +++ b/services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_utils.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from fastapi import FastAPI from models_library.docker import DockerGenericTag @@ -13,10 +13,10 @@ from models_library.users import UserID from servicelib.redis import RedisClientSDK from settings_library.redis import RedisDatabase -from simcore_service_director_v2.modules.redis import get_redis_client_manager from ...models.comp_runs import Iteration from ...models.comp_tasks import CompTaskAtDB +from ..redis import get_redis_client_manager SCHEDULED_STATES: set[RunningState] = { RunningState.PUBLISHED, diff --git a/services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py b/services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py index 13e01a4276f..46cc7669cde 100644 --- a/services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py +++ b/services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py @@ -5,7 +5,6 @@ import arrow import sqlalchemy as sa from aiopg.sa.result import RowProxy -from models_library.clusters import DEFAULT_CLUSTER_ID, ClusterID from models_library.projects import ProjectID from models_library.projects_state import RunningState from models_library.users import UserID @@ -43,10 +42,6 @@ ("clusters", "cluster_id"), ), } -_DEFAULT_FK_CONSTRAINT_TO_ERROR: Final[tuple[type[DirectorError], tuple]] = ( - DirectorError, - (), -) class CompRunsRepository(BaseRepository): @@ -154,7 +149,6 @@ async def create( *, user_id: UserID, project_id: ProjectID, - cluster_id: ClusterID, iteration: PositiveInt | None = None, metadata: RunMetadataDict, use_on_demand_clusters: bool, @@ -178,9 +172,7 @@ async def create( .values( user_id=user_id, project_uuid=f"{project_id}", - cluster_id=( - cluster_id if cluster_id != DEFAULT_CLUSTER_ID else None - ), + cluster_id=None, iteration=iteration, result=RUNNING_STATE_TO_DB[RunningState.PUBLISHED], started=datetime.datetime.now(tz=datetime.UTC), diff --git a/services/director-v2/src/simcore_service_director_v2/utils/db.py b/services/director-v2/src/simcore_service_director_v2/utils/db.py index af944c11dff..43e3a371089 100644 --- a/services/director-v2/src/simcore_service_director_v2/utils/db.py +++ b/services/director-v2/src/simcore_service_director_v2/utils/db.py @@ -1,9 +1,6 @@ import logging -from typing import Any -from common_library.serialization import model_dump_with_secrets from fastapi import FastAPI -from models_library.clusters import BaseCluster from models_library.projects_state import RunningState from simcore_postgres_database.models.comp_pipeline import StateType @@ -28,17 +25,5 @@ _logger = logging.getLogger(__name__) -def to_clusters_db(cluster: BaseCluster, *, only_update: bool) -> dict[str, Any]: - db_model: dict[str, Any] = model_dump_with_secrets( - cluster, - show_secrets=True, - by_alias=True, - exclude={"id", "access_rights"}, - exclude_unset=only_update, - exclude_none=only_update, - ) - return db_model - - def get_repository(app: FastAPI, repo_type: type[RepoType]) -> RepoType: return get_base_repository(engine=app.state.engine, repo_type=repo_type)