Skip to content
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

refactor(BA-501): Add draft vFolder handler Interface of manager #3493

Open
wants to merge 2 commits into
base: feat/add-pydantic-handling-decorator-for-req-res
Choose a base branch
from

Conversation

seedspirit
Copy link

@seedspirit seedspirit commented Jan 17, 2025

resolves #3433 (BA-501)

This PR adds a skeleton interface for vFolder CRUD operations in manager, laying groundwork for reduced code duplication and improved maintainability in VFolder API handlers.

Codes added under src/ai/backend/manager/api/vfolders and test code in tests/manager/api/vfolders

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

📚 Documentation preview 📚: https://sorna--3493.org.readthedocs.build/en/3493/


📚 Documentation preview 📚: https://sorna-ko--3493.org.readthedocs.build/ko/3493/

@seedspirit seedspirit self-assigned this Jan 17, 2025
@github-actions github-actions bot added comp:manager Related to Manager component size:XL 500~ LoC area:docs Documentations labels Jan 17, 2025
Comment on lines 217 to 218
class BaseResponseModel(BaseModel):
status: Annotated[int, Field(strict=True, exclude=True, ge=100, lt=600)] = 200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed here?

Copy link
Author

@seedspirit seedspirit Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the values returned by the VFolder API (ex. VFolder Create), there was an issue where the field called 'status' was duplicated in the returned values, causing conflicts in pants check etc. To prevent this, we changed the part that means status code but is expressed as status

class VFolderCreateResponseModel(BaseResponseModel):
    id: str
   ...
    cloneable: bool
    status: VFolderOperationStatus = Field(default=VFolderOperationStatus.READY)

https://github.com/lablup/backend.ai/pull/3493/files#diff-e35d6520e5e553d13a0a6bbd4e1ff47002cfd11ebd5ecc5fcd380495ee1cfac0R135

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to specify the status_code, it might be better to create a wrapper class instead of including it as a field in the Pydantic model.
(However, it must be ensured that the wrapper class is always unwrapped to apply the Pydantic model to the HTTP response, which can be enforced through middleware or similar mechanisms.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please do not modify the existing model to avoid affecting the current behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can solve this issue by using new @api_handler included in #3511

Comment on lines 217 to 218
class BaseResponseModel(BaseModel):
status: Annotated[int, Field(strict=True, exclude=True, ge=100, lt=600)] = 200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to specify the status_code, it might be better to create a wrapper class instead of including it as a field in the Pydantic model.
(However, it must be ensured that the wrapper class is always unwrapped to apply the Pydantic model to the HTTP response, which can be enforced through middleware or similar mechanisms.)

Comment on lines 217 to 218
class BaseResponseModel(BaseModel):
status: Annotated[int, Field(strict=True, exclude=True, ge=100, lt=600)] = 200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please do not modify the existing model to avoid affecting the current behavior.

Comment on lines 26 to 41
class VFolderHandlerProtocol(Protocol):
async def create_vfolder(
self, request: web.Request, params: VFolderCreateRequestModel
) -> VFolderCreateResponseModel: ...

async def list_vfolders(
self, request: web.Request, params: VFolderListRequestModel
) -> VFolderListResponseModel: ...

async def rename_vfodler(
self, request: web.Request, params: VFolderRenameRequestModel
) -> CreatedResponseModel: ...

async def delete_vfolder(
self, request: web.Request, params: VFolderDeleteRequestModel
) -> NoContentResponseModel: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the definition of VFolderHandlerProtocol is not necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will delete it



class VFolderListRequestModel(BaseModel):
all: bool = Field(default=False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all an existing flag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all flag exists, but it seems deprecated option. Can I delete this flag in refactored APIs?

@check_api_params(
    t.Dict({
        t.Key("all", default=False): t.ToBool,
    }),
)
async def list_folders(request: web.Request, params: Any) -> web.Response:
	...
        if params["all"]:
            raise InvalidAPIParameters("Deprecated use of 'all' option")

Comment on lines 157 to 177
class VFolderListItem:
id: str
name: str
quota_scope_id: str
host: str
usage_mode: VFolderUsageMode
created_at: str
permission: VFolderPermission
max_size: int
creator: str
ownership_type: VFolderOwnershipType
user: str | None
group: str | None
cloneable: bool
status: VFolderOperationStatus
is_owner: bool
user_email: str
group_name: str
type: str # legacy
max_files: int
cur_size: int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to group the values among the fields?
If it’s difficult right now, we can proceed with it after implementing the service layer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can proceed it when implementing service layer(we could do now, but it will change in high possibility when implementing service layer)

Comment on lines 185 to 191
class VFolderListResponseModel(BaseResponseModel):
root: list[VFolderListItem] = Field(default_factory=list)

@classmethod
def from_dataclass(cls, vfolder_list: VFolderList) -> "VFolderListResponseModel":
return cls(root=vfolder_list.entries)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, files or packages dealing with request and response should be separated from those dealing with internal models.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated api_schemas.py for req/res and dtos.py for the dataclasses

@seedspirit seedspirit marked this pull request as ready for review February 4, 2025 14:15
@seedspirit seedspirit force-pushed the refactor/implemet-crud-handlers-for-manager branch from b910b73 to 471a16d Compare February 5, 2025 04:21
@github-actions github-actions bot added the comp:common Related to Common component label Feb 5, 2025
@HyeockJinKim HyeockJinKim changed the base branch from main to feat/add-pydantic-handling-decorator-for-req-res February 5, 2025 08:17
@HyeockJinKim HyeockJinKim changed the base branch from feat/add-pydantic-handling-decorator-for-req-res to main February 5, 2025 08:18
@seedspirit seedspirit changed the base branch from main to feat/add-pydantic-handling-decorator-for-req-res February 5, 2025 08:36
@seedspirit seedspirit changed the base branch from feat/add-pydantic-handling-decorator-for-req-res to main February 5, 2025 09:35
@seedspirit seedspirit force-pushed the refactor/implemet-crud-handlers-for-manager branch from 30740cb to b000898 Compare February 5, 2025 09:47
@github-actions github-actions bot added comp:agent Related to Agent component comp:client Related to Client component comp:cli Related to CLI component comp:webserver Related to Web Server component require:db-migration Automatically set when alembic migrations are added or updated labels Feb 5, 2025
@seedspirit seedspirit changed the base branch from main to feat/add-pydantic-handling-decorator-for-req-res February 5, 2025 09:48
@seedspirit seedspirit force-pushed the feat/add-pydantic-handling-decorator-for-req-res branch from 43510a5 to b1dce6c Compare February 5, 2025 09:50
@seedspirit seedspirit force-pushed the refactor/implemet-crud-handlers-for-manager branch from b000898 to 1eece08 Compare February 5, 2025 09:53
@seedspirit seedspirit removed comp:agent Related to Agent component area:docs Documentations require:db-migration Automatically set when alembic migrations are added or updated labels Feb 5, 2025
@seedspirit seedspirit removed comp:webserver Related to Web Server component comp:common Related to Common component comp:client Related to Client component comp:cli Related to CLI component labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:manager Related to Manager component size:XL 500~ LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the skeleton interface of VFolder CRUD APIs using the new layered architecture in Manager
2 participants