Skip to content

Commit 39b7b90

Browse files
committed
feat: Implment sync replica mutation in api layer
1 parent 5ac9282 commit 39b7b90

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/ai/backend/manager/api/gql/model_deployment/model_deployment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from ai.backend.manager.api.gql.types import StrawberryGQLContext
3939
from ai.backend.manager.api.gql.user import User
40+
from ai.backend.manager.services.deployment.actions.sync_replicas import SyncReplicaAction
4041

4142
from .model_revision import (
4243
CreateModelRevisionInput,
@@ -595,4 +596,9 @@ class SyncReplicaPayload:
595596
async def sync_replicas(
596597
input: SyncReplicaInput, info: Info[StrawberryGQLContext]
597598
) -> SyncReplicaPayload:
599+
deployment_processor = info.context.processors.deployment
600+
assert deployment_processor is not None
601+
await deployment_processor.sync_replicas.wait_for_complete(
602+
SyncReplicaAction(deployment_id=UUID(input.model_deployment_id))
603+
)
598604
return SyncReplicaPayload(success=True)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from dataclasses import dataclass
2+
from typing import Optional, override
3+
from uuid import UUID
4+
5+
from ai.backend.manager.actions.action import BaseActionResult
6+
from ai.backend.manager.services.deployment.actions.base import DeploymentBaseAction
7+
8+
9+
@dataclass
10+
class SyncReplicaAction(DeploymentBaseAction):
11+
"""Action to sync replicas for an existing deployment."""
12+
13+
deployment_id: UUID
14+
15+
@override
16+
def entity_id(self) -> Optional[str]:
17+
return str(self.deployment_id)
18+
19+
@override
20+
@classmethod
21+
def operation_type(cls) -> str:
22+
return "sync_replicas"
23+
24+
25+
@dataclass
26+
class SyncReplicaActionResult(BaseActionResult):
27+
success: bool
28+
29+
@override
30+
def entity_id(self) -> Optional[str]:
31+
return None

src/ai/backend/manager/services/deployment/processors.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
DestroyDeploymentAction,
2626
DestroyDeploymentActionResult,
2727
)
28+
from ai.backend.manager.services.deployment.actions.sync_replicas import (
29+
SyncReplicaAction,
30+
SyncReplicaActionResult,
31+
)
2832
from ai.backend.manager.services.deployment.actions.update_auto_scaling_rule import (
2933
UpdateAutoScalingRuleAction,
3034
UpdateAutoScalingRuleActionResult,
@@ -52,6 +56,8 @@ async def create_access_token(
5256
self, action: CreateAccessTokenAction
5357
) -> CreateAccessTokenActionResult: ...
5458

59+
async def sync_replicas(self, action: SyncReplicaAction) -> SyncReplicaActionResult: ...
60+
5561

5662
class DeploymentProcessors(AbstractProcessorPackage):
5763
"""Processors for deployment operations."""
@@ -68,6 +74,7 @@ class DeploymentProcessors(AbstractProcessorPackage):
6874
DeleteAutoScalingRuleAction, DeleteAutoScalingRuleActionResult
6975
]
7076
create_access_token: ActionProcessor[CreateAccessTokenAction, CreateAccessTokenActionResult]
77+
sync_replicas: ActionProcessor[SyncReplicaAction, SyncReplicaActionResult]
7178

7279
def __init__(
7380
self, service: DeploymentServiceProtocol, action_monitors: list[ActionMonitor]
@@ -84,6 +91,7 @@ def __init__(
8491
self.create_deployment = ActionProcessor(service.create, action_monitors)
8592
self.destroy_deployment = ActionProcessor(service.destroy, action_monitors)
8693
self.create_access_token = ActionProcessor(service.create_access_token, action_monitors)
94+
self.sync_replicas = ActionProcessor(service.sync_replicas, action_monitors)
8795

8896
@override
8997
def supported_actions(self) -> list[ActionSpec]:
@@ -94,4 +102,5 @@ def supported_actions(self) -> list[ActionSpec]:
94102
UpdateAutoScalingRuleAction.spec(),
95103
DeleteAutoScalingRuleAction.spec(),
96104
CreateAccessTokenAction.spec(),
105+
SyncReplicaAction.spec(),
97106
]

src/ai/backend/manager/services/deployment/service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
DestroyDeploymentAction,
3232
DestroyDeploymentActionResult,
3333
)
34+
from ai.backend.manager.services.deployment.actions.sync_replicas import (
35+
SyncReplicaAction,
36+
SyncReplicaActionResult,
37+
)
3438
from ai.backend.manager.services.deployment.actions.update_auto_scaling_rule import (
3539
UpdateAutoScalingRuleAction,
3640
UpdateAutoScalingRuleActionResult,
@@ -136,3 +140,6 @@ async def create_access_token(
136140
created_at=datetime.now(),
137141
)
138142
)
143+
144+
async def sync_replicas(self, action: SyncReplicaAction) -> SyncReplicaActionResult:
145+
return SyncReplicaActionResult(success=True)

0 commit comments

Comments
 (0)