-
Notifications
You must be signed in to change notification settings - Fork 30
♻️ Refactoring of APIs for computations in web-server, api-server and directorv2 #7520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pcrespov
merged 31 commits into
ITISFoundation:master
from
pcrespov:is7516/web-api-tasks
Apr 15, 2025
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d77f28e
🐛Fix: update import paths from comp_tasks to computations and changed…
pcrespov 5d02342
fixes examples
pcrespov eed997c
updates OAS
pcrespov 36cf680
✨Update: refine copilot instructions for documentation and coding pra…
pcrespov 805cf8b
cleanup
pcrespov 4e10a56
models
pcrespov 7b2d3b7
refactor: remove unused computation methods from DirectorV2Api
pcrespov 84f32b7
models
pcrespov 1018992
feat: add custom exception handling for DirectorService errors
pcrespov 0042c12
cleanup tests
pcrespov 86705d2
refactor: reorganize imports and replace ComputationsApi references w…
pcrespov 33f8d9d
cleanup
pcrespov 14e79b7
feat: add utility functions and health check for DirectorV2 service
pcrespov 17bf7fe
feat: refactor group properties retrieval and update service dependen…
pcrespov c1c6baf
refactor: use Annotated for field definitions in Computation models
pcrespov 23cb515
feat: implement REST exception handling and computation routes in Dir…
pcrespov 47914a8
refactor: remove unused ServiceWaitingForManualIntervention exception…
pcrespov d4ffc45
feat: introduce project run policy abstraction and default implementa…
pcrespov bd9ec99
cleanup
pcrespov 845e7cc
fixes tests
pcrespov 728f831
feat: enhance ComputationsApi to return typed responses and improve p…
pcrespov 54bbbfd
refactor: replace exception mapper with client status code mapper in …
pcrespov e8eedd9
refactor: rename ComputationsApi to DirectorV2RestClient and update m…
pcrespov 54563e1
reusing
pcrespov abb5547
refactor: update import statements to include CommitID in the REST co…
pcrespov 036d938
refactor: replace get_directorv2_client with DirectorV2RestClient in …
pcrespov a0c188c
docs: add additional resources section in copilot instructions
pcrespov 5452a7f
fixes mypy
pcrespov 77d19d8
Update services/director-v2/src/simcore_service_director_v2/api/route…
pcrespov fb377c3
Merge branch 'master' into is7516/web-api-tasks
pcrespov ae4df2a
Merge branch 'master' into is7516/web-api-tasks
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
packages/models-library/src/models_library/api_schemas_directorv2/comp_tasks.py
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
packages/models-library/src/models_library/api_schemas_directorv2/computations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from typing import Annotated, Any, TypeAlias | ||
|
||
from pydantic import ( | ||
AnyHttpUrl, | ||
AnyUrl, | ||
BaseModel, | ||
ConfigDict, | ||
Field, | ||
ValidationInfo, | ||
field_validator, | ||
) | ||
|
||
from ..basic_types import IDStr | ||
from ..projects import ProjectID | ||
from ..projects_nodes_io import NodeID | ||
from ..projects_pipeline import ComputationTask | ||
from ..users import UserID | ||
from ..wallets import WalletInfo | ||
|
||
|
||
class ComputationGet(ComputationTask): | ||
url: Annotated[ | ||
AnyHttpUrl, Field(description="the link where to get the status of the task") | ||
] | ||
stop_url: Annotated[ | ||
AnyHttpUrl | None, Field(description="the link where to stop the task") | ||
] = None | ||
|
||
model_config = ConfigDict( | ||
json_schema_extra={ | ||
"examples": [ | ||
x | {"url": "https://url.local"} | ||
for x in ComputationTask.model_json_schema()["examples"] | ||
] | ||
} | ||
) | ||
|
||
|
||
class ComputationCreate(BaseModel): | ||
user_id: UserID | ||
project_id: ProjectID | ||
start_pipeline: Annotated[ | ||
bool | None, | ||
Field(description="if True the computation pipeline will start right away"), | ||
] = False | ||
product_name: Annotated[str, Field()] | ||
subgraph: Annotated[ | ||
list[NodeID] | None, | ||
Field( | ||
description="An optional set of nodes that must be executed, if empty the whole pipeline is executed" | ||
), | ||
] = None | ||
force_restart: Annotated[ | ||
bool | None, | ||
Field(description="if True will force re-running all dependent nodes"), | ||
] = False | ||
simcore_user_agent: str = "" | ||
use_on_demand_clusters: Annotated[ | ||
bool, | ||
Field( | ||
description="if True, a cluster will be created as necessary (wallet_id cannot be None)", | ||
validate_default=True, | ||
), | ||
] = False | ||
wallet_info: Annotated[ | ||
WalletInfo | None, | ||
Field( | ||
description="contains information about the wallet used to bill the running service" | ||
), | ||
] = None | ||
|
||
@field_validator("product_name") | ||
@classmethod | ||
def _ensure_product_name_defined_if_computation_starts( | ||
cls, v, info: ValidationInfo | ||
): | ||
if info.data.get("start_pipeline") and v is None: | ||
msg = "product_name must be set if computation shall start!" | ||
raise ValueError(msg) | ||
return v | ||
|
||
|
||
class ComputationStop(BaseModel): | ||
user_id: UserID | ||
|
||
|
||
class ComputationDelete(ComputationStop): | ||
force: Annotated[ | ||
bool | None, | ||
Field( | ||
description="if True then the pipeline will be removed even if it is running" | ||
), | ||
] = False | ||
|
||
|
||
class TaskLogFileGet(BaseModel): | ||
task_id: NodeID | ||
download_link: Annotated[ | ||
AnyUrl | None, | ||
Field(description="Presigned link for log file or None if still not available"), | ||
] = None | ||
|
||
|
||
class TasksSelection(BaseModel): | ||
nodes_ids: list[NodeID] | ||
|
||
|
||
OutputName: TypeAlias = IDStr | ||
|
||
|
||
class TasksOutputs(BaseModel): | ||
nodes_outputs: dict[NodeID, dict[OutputName, Any]] |
42 changes: 38 additions & 4 deletions
42
packages/models-library/src/models_library/api_schemas_webserver/computations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,43 @@ | ||
from pydantic import BaseModel | ||
from typing import Annotated | ||
|
||
from common_library.basic_types import DEFAULT_FACTORY | ||
from pydantic import BaseModel, Field | ||
|
||
class ComputationStart(BaseModel): | ||
from ..api_schemas_directorv2.computations import ( | ||
ComputationGet as _DirectorV2ComputationGet, | ||
) | ||
from ..projects import CommitID, ProjectID | ||
from ._base import InputSchemaWithoutCamelCase, OutputSchemaWithoutCamelCase | ||
|
||
|
||
class ComputationPathParams(BaseModel): | ||
project_id: ProjectID | ||
|
||
|
||
class ComputationGet(_DirectorV2ComputationGet, OutputSchemaWithoutCamelCase): | ||
# NOTE: this is a copy of the same class in models_library.api_schemas_directorv2 | ||
# but it is used in a different context (webserver) | ||
# and we need to add the `OutputSchema` mixin | ||
# so that it can be used as a response model in FastAPI | ||
pass | ||
|
||
|
||
class ComputationStart(InputSchemaWithoutCamelCase): | ||
force_restart: bool = False | ||
subgraph: set[str] = set() | ||
subgraph: Annotated[ | ||
set[str], Field(default_factory=set, json_schema_extra={"default": []}) | ||
] = DEFAULT_FACTORY | ||
|
||
|
||
__all__: tuple[str, ...] = ("ComputationStart",) | ||
class ComputationStarted(OutputSchemaWithoutCamelCase): | ||
pipeline_id: Annotated[ | ||
ProjectID, Field(description="ID for created pipeline (=project identifier)") | ||
] | ||
ref_ids: Annotated[ | ||
list[CommitID], | ||
Field( | ||
default_factory=list, | ||
description="Checkpoints IDs for created pipeline", | ||
json_schema_extra={"default": []}, | ||
), | ||
] = DEFAULT_FACTORY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.