-
Notifications
You must be signed in to change notification settings - Fork 168
feat(BA-3209): Add artifact_storages common table
#7057
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
Open
jopemachine
wants to merge
10
commits into
main
Choose a base branch
from
feat/BA-3209
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7217e21
feat: Add `artifact_storages` table
jopemachine de9bec3
fix: Reflect feedback
jopemachine 984ec0f
fix: alembic conflcit
jopemachine ecdb3b2
fix: Apply SQLAlchemy Joined Table Inheritance to artifact_storages (…
jopemachine 9c1d73b
chore: update api schema dump
jopemachine 1e0a7ad
fix: Migration script
jopemachine 032aab3
wip
jopemachine 5371c73
wip
jopemachine 8be3451
test: Fix Broken tests
jopemachine 18253bc
test: Add
jopemachine 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add `artifact_storages` common table for storage metadata management across object storage and VFS storage backends, and add `adminUpdateArtifactStorage` GraphQL mutation for updating artifact storage metadata (e.g., name) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from aiohttp import web | ||
|
|
||
| from ai.backend.common.exception import ( | ||
| BackendAIError, | ||
| ErrorCode, | ||
| ErrorDetail, | ||
| ErrorDomain, | ||
| ErrorOperation, | ||
| ) | ||
|
|
||
|
|
||
| class ArtifactStorageNotFoundError(BackendAIError, web.HTTPNotFound): | ||
| error_type = "https://api.backend.ai/probs/artifact-storage-not-found" | ||
| error_title = "Artifact Storage Not Found" | ||
|
|
||
| def error_code(self) -> ErrorCode: | ||
| return ErrorCode( | ||
| domain=ErrorDomain.ARTIFACT_STORAGE, | ||
| operation=ErrorOperation.READ, | ||
| error_detail=ErrorDetail.NOT_FOUND, | ||
| ) | ||
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
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
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,124 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import uuid | ||
| from enum import StrEnum | ||
| from typing import Self | ||
|
|
||
| import strawberry | ||
| from strawberry import ID, UNSET, Info | ||
|
|
||
| from ai.backend.common.data.storage.types import ArtifactStorageData, ArtifactStorageType | ||
| from ai.backend.common.types import ArtifactStorageId | ||
| from ai.backend.manager.api.gql.utils import check_admin_only | ||
| from ai.backend.manager.data.artifact_storages.types import ArtifactStorageUpdaterSpec | ||
| from ai.backend.manager.models.artifact_storages import ArtifactStorageRow | ||
| from ai.backend.manager.repositories.base.updater import Updater | ||
| from ai.backend.manager.services.artifact_storage.actions.update import ( | ||
| UpdateArtifactStorageAction, | ||
| ) | ||
| from ai.backend.manager.types import OptionalState | ||
|
|
||
| from .types import StrawberryGQLContext | ||
|
|
||
|
|
||
| @strawberry.enum( | ||
| name="ArtifactStorageType", | ||
| description=( | ||
| "Added in 26.3.0. The type of artifact storage backend. " | ||
| "OBJECT_STORAGE: Object storage (e.g., S3-compatible). " | ||
| "VFS_STORAGE: Virtual folder storage. " | ||
| "GIT_LFS: Git LFS storage." | ||
| ), | ||
| ) | ||
| class ArtifactStorageTypeGQL(StrEnum): | ||
| """Artifact storage type enum.""" | ||
|
|
||
| OBJECT_STORAGE = "object_storage" | ||
| VFS_STORAGE = "vfs_storage" | ||
| GIT_LFS = "git_lfs" | ||
|
|
||
| @classmethod | ||
| def from_internal(cls, internal_type: ArtifactStorageType) -> ArtifactStorageTypeGQL: | ||
| """Convert internal ArtifactStorageType to GraphQL enum.""" | ||
| match internal_type: | ||
| case ArtifactStorageType.OBJECT_STORAGE: | ||
| return cls.OBJECT_STORAGE | ||
| case ArtifactStorageType.VFS_STORAGE: | ||
| return cls.VFS_STORAGE | ||
| case ArtifactStorageType.GIT_LFS: | ||
| return cls.GIT_LFS | ||
|
|
||
| def to_internal(self) -> ArtifactStorageType: | ||
| """Convert GraphQL enum to internal ArtifactStorageType.""" | ||
| match self: | ||
| case ArtifactStorageTypeGQL.OBJECT_STORAGE: | ||
| return ArtifactStorageType.OBJECT_STORAGE | ||
| case ArtifactStorageTypeGQL.VFS_STORAGE: | ||
| return ArtifactStorageType.VFS_STORAGE | ||
| case ArtifactStorageTypeGQL.GIT_LFS: | ||
| return ArtifactStorageType.GIT_LFS | ||
|
|
||
|
|
||
| @strawberry.type(name="ArtifactStorage", description="Added in 26.3.0. Artifact storage metadata") | ||
| class ArtifactStorageGQL: | ||
| id: ID = strawberry.field(description="The ID of the artifact storage") | ||
| name: str = strawberry.field(description="The name of the artifact storage") | ||
| type: ArtifactStorageTypeGQL = strawberry.field(description="The type of the artifact storage") | ||
|
|
||
| @classmethod | ||
| def from_dataclass(cls, data: ArtifactStorageData) -> Self: | ||
| return cls( | ||
| id=ID(str(data.id)), | ||
| name=data.name, | ||
| type=ArtifactStorageTypeGQL.from_internal(data.type), | ||
| ) | ||
|
|
||
|
|
||
| @strawberry.input( | ||
| name="UpdateArtifactStorageInput", | ||
| description="Added in 26.3.0. Input for updating artifact storage metadata", | ||
| ) | ||
| class UpdateArtifactStorageInputGQL: | ||
| """Input for updating artifact storage metadata (common fields like name).""" | ||
|
|
||
| id: ID = strawberry.field(description="The ID of the artifact storage") | ||
| name: str | None = strawberry.field( | ||
| default=UNSET, description="The new name for the artifact storage" | ||
| ) | ||
|
|
||
| def to_updater(self) -> Updater[ArtifactStorageRow]: | ||
| spec = ArtifactStorageUpdaterSpec( | ||
| name=OptionalState[str].from_graphql(self.name), | ||
| ) | ||
| return Updater(spec=spec, pk_value=ArtifactStorageId(uuid.UUID(self.id))) | ||
|
|
||
|
|
||
| @strawberry.type( | ||
| name="UpdateArtifactStoragePayload", | ||
| description="Added in 26.3.0. Payload for updating artifact storage metadata", | ||
| ) | ||
| class UpdateArtifactStoragePayloadGQL: | ||
| artifact_storage: ArtifactStorageGQL = strawberry.field( | ||
| description="The updated artifact storage" | ||
| ) | ||
|
|
||
|
|
||
| @strawberry.mutation( # type: ignore[misc] | ||
| name="adminUpdateArtifactStorage", | ||
| description="Added in 26.3.0. Update artifact storage metadata (common fields like name)", | ||
| ) | ||
| async def update_artifact_storage( | ||
| input: UpdateArtifactStorageInputGQL, info: Info[StrawberryGQLContext] | ||
| ) -> UpdateArtifactStoragePayloadGQL: | ||
| check_admin_only() | ||
| processors = info.context.processors | ||
|
|
||
| action_result = await processors.artifact_storage.update.wait_for_complete( | ||
| UpdateArtifactStorageAction( | ||
| updater=input.to_updater(), | ||
| ) | ||
| ) | ||
|
|
||
| return UpdateArtifactStoragePayloadGQL( | ||
| artifact_storage=ArtifactStorageGQL.from_dataclass(action_result.result), | ||
| ) |
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.