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

fix: restore removed graphene fields and set them deprecated #1677

Merged
merged 11 commits into from
Nov 1, 2023
1 change: 1 addition & 0 deletions changes/1677.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore removed graphene fields of resource policies and set them deprecated.
68 changes: 53 additions & 15 deletions src/ai/backend/manager/models/resource_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from .keypair import keypairs
from .user import UserRole
from .utils import deprecation_reason_msg, description_msg

if TYPE_CHECKING:
from .gql import GraphQueryContext
Expand Down Expand Up @@ -57,6 +58,34 @@
)


def user_max_vfolder_count(required: bool = False):
return graphene.Int(
required=required,
description=description_msg("24.03.1", "Limitation of the number of user vfolders."),
)


def user_max_quota_scope_size(required: bool = False):
return BigInt(
required=required,
description=description_msg("24.03.1", "Limitation of the quota size of user vfolders."),
)


def project_max_vfolder_count(required: bool = False):
return graphene.Int(
required=required,
description=description_msg("24.03.1", "Limitation of the number of project vfolders."),
)


def project_max_quota_scope_size(required: bool = False):
return BigInt(
required=required,
description=description_msg("24.03.1", "Limitation of the quota size of project vfolders."),
)


keypair_resource_policies = sa.Table(
"keypair_resource_policies",
mapper_registry.metadata,
Expand Down Expand Up @@ -143,6 +172,10 @@ class KeyPairResourcePolicy(graphene.ObjectType):
idle_timeout = BigInt()
allowed_vfolder_hosts = graphene.JSONString()

max_vfolder_count = graphene.Int(deprecation_reason=deprecation_reason_msg("23.09.4"))
max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4"))
max_quota_scope_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4"))

@classmethod
def from_row(
cls,
Expand Down Expand Up @@ -290,6 +323,9 @@ class CreateKeyPairResourcePolicyInput(graphene.InputObjectType):
max_containers_per_session = graphene.Int(required=True)
idle_timeout = BigInt(required=True)
allowed_vfolder_hosts = graphene.JSONString(required=False)
max_vfolder_count = graphene.Int(deprecation_reason=deprecation_reason_msg("23.09.4"))
max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4"))
max_quota_scope_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4"))


class ModifyKeyPairResourcePolicyInput(graphene.InputObjectType):
Expand All @@ -300,6 +336,9 @@ class ModifyKeyPairResourcePolicyInput(graphene.InputObjectType):
max_containers_per_session = graphene.Int(required=False)
idle_timeout = BigInt(required=False)
allowed_vfolder_hosts = graphene.JSONString(required=False)
max_vfolder_count = graphene.Int(deprecation_reason=deprecation_reason_msg("23.09.4"))
max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4"))
max_quota_scope_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4"))


class CreateKeyPairResourcePolicy(graphene.Mutation):
Expand Down Expand Up @@ -407,9 +446,9 @@ class UserResourcePolicy(graphene.ObjectType):
id = graphene.ID(required=True)
name = graphene.String(required=True)
created_at = GQLDateTime(required=True)
max_vfolder_count = graphene.Int()
max_vfolder_size = BigInt(deprecation_reason="Deprecated since 23.09.1")
max_quota_scope_size = BigInt()
max_vfolder_count = user_max_vfolder_count()
max_quota_scope_size = user_max_quota_scope_size()
max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.1"))

@classmethod
def from_row(
Expand All @@ -424,7 +463,6 @@ def from_row(
name=row.name,
created_at=row.created_at,
max_vfolder_count=row.max_vfolder_count,
max_vfolder_size=row.max_quota_scope_size, # aliased field
max_quota_scope_size=row.max_quota_scope_size,
)

Expand Down Expand Up @@ -482,13 +520,13 @@ async def batch_load_by_user(


class CreateUserResourcePolicyInput(graphene.InputObjectType):
max_vfolder_count = graphene.Int()
max_quota_scope_size = BigInt()
max_vfolder_count = user_max_vfolder_count()
max_quota_scope_size = user_max_quota_scope_size()


class ModifyUserResourcePolicyInput(graphene.InputObjectType):
max_vfolder_count = graphene.Int()
max_quota_scope_size = BigInt()
max_vfolder_count = user_max_vfolder_count()
max_quota_scope_size = user_max_quota_scope_size()


class CreateUserResourcePolicy(graphene.Mutation):
Expand Down Expand Up @@ -585,9 +623,9 @@ class ProjectResourcePolicy(graphene.ObjectType):
id = graphene.ID(required=True)
name = graphene.String(required=True)
created_at = GQLDateTime(required=True)
max_vfolder_count = graphene.Int()
max_vfolder_size = BigInt(deprecation_reason="Deprecated since 23.09.1")
max_quota_scope_size = BigInt()
max_vfolder_count = project_max_vfolder_count()
max_quota_scope_size = project_max_quota_scope_size()
max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.1"))

@classmethod
def from_row(
Expand Down Expand Up @@ -660,13 +698,13 @@ async def batch_load_by_project(


class CreateProjectResourcePolicyInput(graphene.InputObjectType):
max_vfolder_count = graphene.Int()
max_quota_scope_size = BigInt()
max_vfolder_count = project_max_vfolder_count()
max_quota_scope_size = project_max_quota_scope_size()


class ModifyProjectResourcePolicyInput(graphene.InputObjectType):
max_vfolder_count = graphene.Int()
max_quota_scope_size = BigInt()
max_vfolder_count = project_max_vfolder_count()
max_quota_scope_size = project_max_quota_scope_size()


class CreateProjectResourcePolicy(graphene.Mutation):
Expand Down
11 changes: 11 additions & 0 deletions src/ai/backend/manager/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,14 @@ def agg_to_array(column: sa.Column) -> sa.sql.functions.Function:

def is_db_retry_error(e: Exception) -> bool:
return isinstance(e, DBAPIError) and getattr(e.orig, "pgcode", None) == "40001"


def description_msg(version: str, detail: str | None = None):
val = f"Added since {version}."
if detail:
val = f"{val} {detail}"
return val


def deprecation_reason_msg(version: str):
Copy link
Member

Choose a reason for hiding this comment

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

Let's add the detail: strto here alos.

Copy link
Member

Choose a reason for hiding this comment

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

Except for this, everything looks good to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated it, thank you!

return f"Deprecated since {version}."
Loading