From f5eb1c299dffd450e66b9a66fa2403c8478288b2 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 17 Mar 2023 14:46:00 +0100 Subject: [PATCH] webserver --- .../director_v2_core_computations.py | 4 ++-- .../exporter/formatters/formatter_v1.py | 2 +- .../projects/projects_api.py | 9 ++++++--- .../projects/projects_handlers_crud.py | 11 ++++++++--- .../studies_dispatcher/_projects.py | 2 +- .../server/tests/unit/with_dbs/01/test_director_v2.py | 8 ++++++-- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/director_v2_core_computations.py b/services/web/server/src/simcore_service_webserver/director_v2_core_computations.py index 66af38f0e2c2..346afc7a131a 100644 --- a/services/web/server/src/simcore_service_webserver/director_v2_core_computations.py +++ b/services/web/server/src/simcore_service_webserver/director_v2_core_computations.py @@ -97,7 +97,7 @@ def set_client(app: web.Application, obj: ComputationsApi): @log_decorator(logger=log) async def create_or_update_pipeline( - app: web.Application, user_id: UserID, project_id: ProjectID + app: web.Application, user_id: UserID, project_id: ProjectID, product_name: str ) -> Optional[DataType]: settings: DirectorV2Settings = get_plugin_settings(app) @@ -105,6 +105,7 @@ async def create_or_update_pipeline( body = { "user_id": user_id, "project_id": f"{project_id}", + "product_name": product_name, } # request to director-v2 try: @@ -122,7 +123,6 @@ async def create_or_update_pipeline( async def is_pipeline_running( app: web.Application, user_id: PositiveInt, project_id: UUID ) -> Optional[bool]: - # TODO: make it cheaper by /computations/{project_id}/state. First trial shows # that the efficiency gain is minimal but should be considered specially if the handler # gets heavier with time diff --git a/services/web/server/src/simcore_service_webserver/exporter/formatters/formatter_v1.py b/services/web/server/src/simcore_service_webserver/exporter/formatters/formatter_v1.py index 5fc157048eea..85db265216e0 100644 --- a/services/web/server/src/simcore_service_webserver/exporter/formatters/formatter_v1.py +++ b/services/web/server/src/simcore_service_webserver/exporter/formatters/formatter_v1.py @@ -224,7 +224,7 @@ async def add_new_project( if _project_db["uuid"] != str(project.uuid): raise ExporterException("Project uuid dose nto match after validation") - await create_or_update_pipeline(app, user_id, project.uuid) + await create_or_update_pipeline(app, user_id, project.uuid, product_name) async def _fix_node_run_hashes_based_on_old_project( diff --git a/services/web/server/src/simcore_service_webserver/projects/projects_api.py b/services/web/server/src/simcore_service_webserver/projects/projects_api.py index 8d9c30c5a0eb..d73f1b8f53d7 100644 --- a/services/web/server/src/simcore_service_webserver/projects/projects_api.py +++ b/services/web/server/src/simcore_service_webserver/projects/projects_api.py @@ -47,6 +47,7 @@ from .. import catalog_client, director_v2_api, storage_api from ..application_settings import get_settings +from ..products import get_product_name from ..resource_manager.websocket_manager import ( PROJECT_ID_KEY, UserSessionID, @@ -276,7 +277,7 @@ async def add_project_node( # also ensure the project is updated by director-v2 since services # are due to access comp_tasks at some point see [https://github.com/ITISFoundation/osparc-simcore/issues/3216] await director_v2_api.create_or_update_pipeline( - request.app, user_id, project["uuid"] + request.app, user_id, project["uuid"], product_name ) if _is_node_dynamic(service_key): @@ -352,7 +353,10 @@ async def delete_project_node( partial_workbench_data, user_id, f"{project_uuid}" ) # also ensure the project is updated by director-v2 since services - await director_v2_api.create_or_update_pipeline(request.app, user_id, project_uuid) + product_name = get_product_name(request) + await director_v2_api.create_or_update_pipeline( + request.app, user_id, project_uuid, product_name + ) async def update_project_linked_product( @@ -591,7 +595,6 @@ async def try_open_project_for_user( await get_user_name(app, user_id), notify_users=False, ): - with managed_resource(user_id, client_session_id, app) as rt: # NOTE: if max_number_of_studies_per_user is set, the same # project shall still be openable if the tab was closed diff --git a/services/web/server/src/simcore_service_webserver/projects/projects_handlers_crud.py b/services/web/server/src/simcore_service_webserver/projects/projects_handlers_crud.py index 0adc5f2b52d6..cf831e0515a3 100644 --- a/services/web/server/src/simcore_service_webserver/projects/projects_handlers_crud.py +++ b/services/web/server/src/simcore_service_webserver/projects/projects_handlers_crud.py @@ -146,6 +146,7 @@ async def create_projects(request: web.Request): request_context=req_ctx, query_params=query_params, predefined_project=predefined_project, + product_name=req_ctx.product_name, fire_and_forget=True, ) @@ -249,7 +250,8 @@ async def _create_projects( query_params: _ProjectCreateParams, request_context: RequestContext, predefined_project: Optional[ProjectDict], -): + product_name: str, +) -> None: """ :raises web.HTTPBadRequest @@ -313,7 +315,7 @@ async def _create_projects( # This is a new project and every new graph needs to be reflected in the pipeline tables await director_v2_api.create_or_update_pipeline( - app, request_context.user_id, new_project["uuid"] + app, request_context.user_id, new_project["uuid"], product_name ) # Appends state @@ -636,7 +638,10 @@ async def replace_project(request: web.Request): request.app, path_params.project_id ) await director_v2_api.create_or_update_pipeline( - request.app, req_ctx.user_id, path_params.project_id + request.app, + req_ctx.user_id, + path_params.project_id, + product_name=req_ctx.product_name, ) # Appends state new_project = await projects_api.add_project_states_for_user( diff --git a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_projects.py b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_projects.py index 21d2468c0735..d37e4b7b74c9 100644 --- a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_projects.py +++ b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_projects.py @@ -179,4 +179,4 @@ async def add_new_project( # # TODO: Ensure this user has access to these services! # - await create_or_update_pipeline(app, user.id, project.uuid) + await create_or_update_pipeline(app, user.id, project.uuid, product_name) diff --git a/services/web/server/tests/unit/with_dbs/01/test_director_v2.py b/services/web/server/tests/unit/with_dbs/01/test_director_v2.py index b9d600352f46..5f271c34a2dd 100644 --- a/services/web/server/tests/unit/with_dbs/01/test_director_v2.py +++ b/services/web/server/tests/unit/with_dbs/01/test_director_v2.py @@ -46,10 +46,14 @@ def cluster_id(faker: Faker) -> ClusterID: async def test_create_pipeline( - mocked_director_v2, client, user_id: UserID, project_id: ProjectID + mocked_director_v2, + client, + user_id: UserID, + project_id: ProjectID, + osparc_product_name: str, ): task_out = await director_v2_api.create_or_update_pipeline( - client.app, user_id, project_id + client.app, user_id, project_id, osparc_product_name ) assert task_out assert isinstance(task_out, dict)