Skip to content

Commit 1dffca2

Browse files
Merge branch 'add-project-grouping-for-task-manager' into add-filter-on-active-jobs
2 parents db2efc4 + ca93f7a commit 1dffca2

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

services/director-v2/src/simcore_service_director_v2/api/routes/computations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ async def _try_start_pipeline(
224224
wallet_id = computation.wallet_info.wallet_id
225225
wallet_name = computation.wallet_info.wallet_name
226226

227+
if computation.collection_run_id is None:
228+
raise HTTPException(
229+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
230+
detail=f"Project {computation.project_id} has no collection run ID",
231+
)
227232
await run_new_pipeline(
228233
app,
229234
user_id=computation.user_id,

services/director-v2/tests/integration/01/test_computation_api.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def fake_workbench_computational_pipeline_details_not_started(
170170
"project_id": "16e60a5d-834e-4267-b44d-3af49171bf21",
171171
"product_name": "not a product",
172172
"product_api_base_url": "http://invalid",
173-
"collection_run_id": "16e60a5d-834e-4267-b44d-3af49171bf21",
174173
},
175174
status.HTTP_404_NOT_FOUND,
176175
),
@@ -997,7 +996,6 @@ async def test_pipeline_with_control_loop_made_of_dynamic_services_is_allowed(
997996
"start_pipeline": False,
998997
"product_name": osparc_product_name,
999998
"product_api_base_url": osparc_product_api_base_url,
1000-
"collection_run_id": str(uuid.uuid4()),
1001999
},
10021000
)
10031001
assert (
@@ -1084,7 +1082,6 @@ async def test_pipeline_with_cycle_containing_a_computational_service_is_forbidd
10841082
"start_pipeline": False,
10851083
"product_name": osparc_product_name,
10861084
"product_api_base_url": osparc_product_api_base_url,
1087-
"collection_run_id": str(uuid.uuid4()),
10881085
},
10891086
)
10901087
assert (

services/director-v2/tests/integration/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ async def _creator(
100100
"start_pipeline": start_pipeline,
101101
"product_name": product_name,
102102
"product_api_base_url": product_api_base_url,
103-
"collection_run_id": str(uuid.uuid4()),
103+
"collection_run_id": (
104+
str(uuid.uuid4()) if start_pipeline is True else None
105+
),
104106
**kwargs,
105107
},
106108
)

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_api_route_computations.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,13 @@ async def test_computation_create_validators(
387387
product_name=product_name,
388388
product_api_base_url=product_api_base_url,
389389
use_on_demand_clusters=True,
390-
collection_run_id=fake_collection_run_id,
391390
)
392391
ComputationCreate(
393392
user_id=user["id"],
394393
project_id=proj.uuid,
395394
product_name=product_name,
396395
product_api_base_url=product_api_base_url,
397396
use_on_demand_clusters=False,
398-
collection_run_id=fake_collection_run_id,
399397
)
400398

401399

@@ -422,7 +420,6 @@ async def test_create_computation(
422420
project_id=proj.uuid,
423421
product_name=product_name,
424422
product_api_base_url=product_api_base_url,
425-
collection_run_id=fake_collection_run_id,
426423
)
427424
),
428425
)
@@ -540,7 +537,6 @@ async def test_create_computation_with_wallet(
540537
product_name=product_name,
541538
product_api_base_url=product_api_base_url,
542539
wallet_info=wallet_info,
543-
collection_run_id=fake_collection_run_id,
544540
)
545541
),
546542
)
@@ -644,7 +640,6 @@ async def test_create_computation_with_wallet_with_invalid_pricing_unit_name_rai
644640
product_name=product_name,
645641
product_api_base_url=product_api_base_url,
646642
wallet_info=wallet_info,
647-
collection_run_id=fake_collection_run_id,
648643
)
649644
),
650645
)
@@ -686,7 +681,6 @@ async def test_create_computation_with_wallet_with_no_clusters_keeper_raises_503
686681
product_name=product_name,
687682
product_api_base_url=product_api_base_url,
688683
wallet_info=wallet_info,
689-
collection_run_id=fake_collection_run_id,
690684
)
691685
),
692686
)
@@ -702,13 +696,40 @@ async def test_start_computation_without_product_fails(
702696
create_registered_user: Callable[..., dict[str, Any]],
703697
create_project: Callable[..., Awaitable[ProjectAtDB]],
704698
async_client: httpx.AsyncClient,
699+
fake_collection_run_id: CollectionRunID,
700+
):
701+
user = create_registered_user()
702+
proj = await create_project(user, workbench=fake_workbench_without_outputs)
703+
create_computation_url = httpx.URL("/v2/computations")
704+
response = await async_client.post(
705+
create_computation_url,
706+
json={
707+
"user_id": f"{user['id']}",
708+
"project_id": f"{proj.uuid}",
709+
"start_pipeline": f"{True}",
710+
"collection_run_id": f"{fake_collection_run_id}",
711+
},
712+
)
713+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY, response.text
714+
715+
716+
async def test_start_computation_without_collection_run_id_fails(
717+
minimal_configuration: None,
718+
mocked_director_service_fcts: respx.MockRouter,
719+
mocked_catalog_service_fcts: respx.MockRouter,
720+
product_name: str,
721+
fake_workbench_without_outputs: dict[str, Any],
722+
create_registered_user: Callable[..., dict[str, Any]],
723+
create_project: Callable[..., Awaitable[ProjectAtDB]],
724+
async_client: httpx.AsyncClient,
705725
):
706726
user = create_registered_user()
707727
proj = await create_project(user, workbench=fake_workbench_without_outputs)
708728
create_computation_url = httpx.URL("/v2/computations")
709729
response = await async_client.post(
710730
create_computation_url,
711731
json={
732+
"product_name": product_name,
712733
"user_id": f"{user['id']}",
713734
"project_id": f"{proj.uuid}",
714735
"start_pipeline": f"{True}",

services/storage/src/simcore_service_storage/modules/s3.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,42 @@
77
from common_library.json_serialization import json_dumps
88
from fastapi import FastAPI
99
from pydantic import TypeAdapter
10-
from servicelib.logging_utils import log_context
10+
from tenacity import retry, wait_random_exponential
1111
from tenacity.asyncio import AsyncRetrying
1212
from tenacity.before_sleep import before_sleep_log
1313
from tenacity.wait import wait_fixed
1414
from types_aiobotocore_s3.literals import BucketLocationConstraintType
1515

1616
from ..constants import RETRY_WAIT_SECS
17-
from ..core.settings import get_application_settings
17+
from ..core.settings import ApplicationSettings, get_application_settings
1818
from ..exceptions.errors import ConfigurationError
1919

2020
_logger = logging.getLogger(__name__)
2121

2222

23+
@retry(
24+
wait=wait_random_exponential(),
25+
before_sleep=before_sleep_log(_logger, logging.WARNING),
26+
reraise=True,
27+
)
28+
async def _ensure_s3_bucket(
29+
client: SimcoreS3API, settings: ApplicationSettings
30+
) -> None:
31+
assert settings.STORAGE_S3 # nosec
32+
if await client.bucket_exists(bucket=settings.STORAGE_S3.S3_BUCKET_NAME):
33+
_logger.info(
34+
"S3 bucket %s exists already, skipping creation",
35+
settings.STORAGE_S3.S3_BUCKET_NAME,
36+
)
37+
return
38+
await client.create_bucket(
39+
bucket=settings.STORAGE_S3.S3_BUCKET_NAME,
40+
region=TypeAdapter(
41+
BucketLocationConstraintType | Literal["us-east-1"]
42+
).validate_python(settings.STORAGE_S3.S3_REGION),
43+
)
44+
45+
2346
def setup_s3(app: FastAPI) -> None:
2447
async def _on_startup() -> None:
2548
app.state.s3_client = None
@@ -44,14 +67,7 @@ async def _on_startup() -> None:
4467
assert client # nosec
4568
app.state.s3_client = client
4669

47-
with log_context(_logger, logging.DEBUG, msg="setup.s3_bucket.cleanup_ctx"):
48-
assert settings.STORAGE_S3 # nosec
49-
await client.create_bucket(
50-
bucket=settings.STORAGE_S3.S3_BUCKET_NAME,
51-
region=TypeAdapter(
52-
BucketLocationConstraintType | Literal["us-east-1"]
53-
).validate_python(settings.STORAGE_S3.S3_REGION),
54-
)
70+
await _ensure_s3_bucket(client, settings)
5571

5672
async def _on_shutdown() -> None:
5773
if app.state.s3_client:

0 commit comments

Comments
 (0)