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-502): Add the skeleton interface of vfolder CRUD handlers in storage-proxy (#3434) #3516

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ai/backend/storage/api/vfolder/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
Empty file.
88 changes: 88 additions & 0 deletions src/ai/backend/storage/api/vfolder/manager_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import uuid

from aiohttp import web

from ai.backend.storage.api.vfolder.manager_service import VFolderService
from ai.backend.storage.api.vfolder.types import (
QuotaConfigModel,
QuotaIDModel,
VFolderCloneModel,
VFolderIDModel,
VFolderInfoRequestModel,
VolumeIDModel,
)


class VFolderHandler:
def __init__(self, storage_service: VFolderService) -> None:
self.storage_service = storage_service

async def get_volume(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = VolumeIDModel(**data)
result = await self.storage_service.get_volume(req)
return web.json_response(result)

async def get_volumes(self, request: web.Request) -> web.Response:
result = await self.storage_service.get_volumes()
# Assume that the volume_dict is a dictionary of VolumeInfoModel objects
volumes_dict = result.volumes
volumes_dict = {k: v for k, v in volumes_dict.items()}
return web.json_response(volumes_dict)
MintCat98 marked this conversation as resolved.
Show resolved Hide resolved

async def create_quota_scope(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = QuotaConfigModel(**data)
await self.storage_service.create_quota_scope(req)
return web.Response(status=204)

async def get_quota_scope(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = QuotaIDModel(**data)
result = await self.storage_service.get_quota_scope(req)
MintCat98 marked this conversation as resolved.
Show resolved Hide resolved
return web.json_response(result)

async def update_quota_scope(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = QuotaConfigModel(**data)
await self.storage_service.update_quota_scope(req)
return web.Response(status=204)

async def delete_quota_scope(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = QuotaIDModel(**data)
await self.storage_service.delete_quota_scope(req)
return web.Response(status=204)

async def create_vfolder(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = VFolderIDModel(**data)
await self.storage_service.create_vfolder(req)
return web.Response(status=204)

async def clone_vfolder(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = VFolderCloneModel(**data)
await self.storage_service.clone_vfolder(req)
return web.Response(status=204)

async def get_vfolder_info(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = VFolderInfoRequestModel(**data)
result = await self.storage_service.get_vfolder_info(req)
return web.json_response(result)

async def delete_vfolder(self, request: web.Request) -> web.Response:
data = await request.json()
data["volume_id"] = uuid.UUID(data["volume_id"])
req = VFolderIDModel(**data)
await self.storage_service.delete_vfolder(req)
return web.Response(status=202)
90 changes: 90 additions & 0 deletions src/ai/backend/storage/api/vfolder/manager_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from pathlib import Path, PurePath
from typing import Protocol

from ai.backend.common.types import BinarySize
from ai.backend.storage.api.vfolder.types import (
QuotaConfigModel,
QuotaIDModel,
QuotaScopeInfoModel,
VFolderCloneModel,
VFolderIDModel,
VFolderInfoModel,
VFolderInfoRequestModel,
VolumeIDModel,
VolumeInfoListModel,
VolumeInfoModel,
)
from ai.backend.storage.types import CapacityUsage, TreeUsage


class VFolderServiceProtocol(Protocol):
async def get_volume(self, volume_data: VolumeIDModel) -> VolumeInfoModel:
"""by volume_id"""
...

async def get_volumes(self) -> VolumeInfoListModel: ...

async def create_quota_scope(self, quota_config_data: QuotaConfigModel) -> None: ...

async def get_quota_scope(self, quota_data: QuotaIDModel) -> QuotaScopeInfoModel: ...

async def update_quota_scope(self, quota_config_data: QuotaConfigModel) -> None: ...

async def delete_quota_scope(self, quota_data: QuotaIDModel) -> None:
"""Previous: unset_quota"""
...

async def create_vfolder(self, vfolder_data: VFolderIDModel) -> None: ...

async def clone_vfolder(self, vfolder_clone_data: VFolderCloneModel) -> None: ...

async def get_vfolder_info(self, vfolder_info: VFolderInfoRequestModel) -> VFolderInfoModel:
# Integration: vfolder_mount, metadata, vfolder_usage, vfolder_used_bytes, vfolder_fs_usage
...

async def delete_vfolder(self, vfolder_data: VFolderIDModel) -> None: ...


class VFolderService:
async def get_volume(self, volume_data: VolumeIDModel) -> VolumeInfoModel:
return VolumeInfoModel(
volume_id=volume_data.volume_id,
backend="default-backend",
path=Path("/default/path"),
fsprefix=PurePath("/fsprefix"),
capabilities=["read", "write"],
options={"option1": "value1"},
)

async def get_volumes(self) -> VolumeInfoListModel:
return VolumeInfoListModel(volumes={})

async def create_quota_scope(self, quota_config_data: QuotaConfigModel) -> None:
return None

async def get_quota_scope(self, quota_data: QuotaIDModel) -> QuotaScopeInfoModel:
return QuotaScopeInfoModel(used_bytes=0, limit_bytes=0)

async def update_quota_scope(self, quota_config_data: QuotaConfigModel) -> None:
return None

async def delete_quota_scope(self, quota_data: QuotaIDModel) -> None:
return None

async def create_vfolder(self, vfolder_data: VFolderIDModel) -> None:
return None

async def clone_vfolder(self, vfolder_clone_data: VFolderCloneModel) -> None:
return None

async def get_vfolder_info(self, vfolder_info: VFolderInfoRequestModel) -> VFolderInfoModel:
return VFolderInfoModel(
vfolder_mount=Path("/mount/point"),
vfolder_metadata=b"",
vfolder_usage=TreeUsage(file_count=0, used_bytes=0),
vfolder_used_bytes=BinarySize(0),
vfolder_fs_usage=CapacityUsage(used_bytes=0, capacity_bytes=0),
)

async def delete_vfolder(self, vfolder_data: VFolderIDModel) -> None:
return None
Loading
Loading