Skip to content

Commit 7d64993

Browse files
jopemachineclaude
andcommitted
refactor(BA-5982): drop list_active_deployments action; reuse search_deployments
Adding a dedicated read-side action for the bulk-refresh pre-fetch was unnecessary — ``SearchDeploymentsAction`` already returns ``ModelDeploymentData`` with ``revision`` populated to the current revision (via ``_convert_deployment_info_to_data``). Reuse it directly: - Delete ``actions/list_active_deployments_with_current_revision.py`` and the matching service method, processor, and spec entry. - ``DeploymentRevisionAdapter.admin_refresh_deployment_revisions`` now builds a ``BatchQuerier`` with ``DeploymentConditions.by_lifecycle_stages(EndpointLifecycle.active_states())``, calls ``processor.search_deployments``, and iterates the resulting ``ModelDeploymentData`` list — skipping entries whose ``revision`` is ``None`` (deployments that only have a deploying revision and no current one to project from). Conversion still happens entirely in the adapter; ``creators_by_id`` is then handed to the existing batch ``RefreshDeploymentRevisionsAction``. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f8e7cf4 commit 7d64993

4 files changed

Lines changed: 27 additions & 109 deletions

File tree

src/ai/backend/manager/api/adapters/deployment_revision/adapter.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from __future__ import annotations
1111

12+
from ai.backend.common.data.endpoint.types import EndpointLifecycle
1213
from ai.backend.common.dto.manager.v2.deployment.response import (
1314
AdminRefreshDeploymentRevisionsPayload,
1415
RevisionRefreshResultInfo,
@@ -25,12 +26,14 @@
2526
ResourceSpec,
2627
)
2728
from ai.backend.manager.errors.api import InvalidAPIParameters
28-
from ai.backend.manager.services.deployment.actions.list_active_deployments_with_current_revision import (
29-
ListActiveDeploymentsWithCurrentRevisionAction,
30-
)
29+
from ai.backend.manager.models.endpoint.conditions import DeploymentConditions
30+
from ai.backend.manager.repositories.base import BatchQuerier, NoPagination
3131
from ai.backend.manager.services.deployment.actions.refresh_deployment_revisions import (
3232
RefreshDeploymentRevisionsAction,
3333
)
34+
from ai.backend.manager.services.deployment.actions.search_deployments import (
35+
SearchDeploymentsAction,
36+
)
3437

3538

3639
class DeploymentRevisionAdapter(BaseAdapter):
@@ -45,21 +48,31 @@ async def admin_refresh_deployment_revisions(
4548
) -> AdminRefreshDeploymentRevisionsPayload:
4649
"""Create and activate a fresh revision for every active deployment.
4750
48-
Two-phase orchestration: a read-side action returns the current
49-
``ModelRevisionData`` for every active deployment, this adapter
50-
projects each onto a ``ModelRevisionCreator`` (failures here
51-
surface per-item without aborting the whole sweep), and the batch
52-
refresh action processes the resulting ``creators_by_id`` map in a
53-
single service call.
51+
Two-phase orchestration: ``search_deployments`` returns the active
52+
deployments along with each one's current ``ModelRevisionData``;
53+
this adapter projects each onto a ``ModelRevisionCreator``
54+
(per-item conversion failures surface in the response without
55+
aborting the sweep), and the batch refresh action processes the
56+
resulting ``creators_by_id`` map in a single service call.
5457
"""
55-
list_result = await self._processors.deployment.list_active_deployments_with_current_revision.wait_for_complete(
56-
ListActiveDeploymentsWithCurrentRevisionAction()
58+
active_querier = BatchQuerier(
59+
pagination=NoPagination(),
60+
conditions=[
61+
DeploymentConditions.by_lifecycle_stages(EndpointLifecycle.active_states()),
62+
],
63+
)
64+
search_result = await self._processors.deployment.search_deployments.wait_for_complete(
65+
SearchDeploymentsAction(querier=active_querier)
5766
)
5867
creators_by_id: dict[DeploymentID, ModelRevisionCreator] = {}
5968
conversion_failures: list[RevisionRefreshResultInfo] = []
60-
for revision in list_result.revisions:
69+
for deployment in search_result.data:
70+
if deployment.revision is None:
71+
# No current revision (e.g., still PENDING with only a
72+
# deploying revision) — nothing to refresh from.
73+
continue
6174
try:
62-
creators_by_id[revision.deployment_id] = self._creator_from_data(revision)
75+
creators_by_id[deployment.id] = self._creator_from_data(deployment.revision)
6376
except InvalidAPIParameters as exc:
6477
# Conversion failed (e.g., revision missing the model
6578
# vfolder after a SET-NULL FK cleanup). Surface it as a
@@ -68,7 +81,7 @@ async def admin_refresh_deployment_revisions(
6881
# to provide via try/except.
6982
conversion_failures.append(
7083
RevisionRefreshResultInfo(
71-
deployment_id=revision.deployment_id,
84+
deployment_id=deployment.id,
7285
new_revision_id=None,
7386
success=False,
7487
failure_reason=f"{type(exc).__name__}: {exc}",

src/ai/backend/manager/services/deployment/actions/list_active_deployments_with_current_revision.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@
8282
GetReplicaByIdAction,
8383
GetReplicaByIdActionResult,
8484
)
85-
from ai.backend.manager.services.deployment.actions.list_active_deployments_with_current_revision import (
86-
ListActiveDeploymentsWithCurrentRevisionAction,
87-
ListActiveDeploymentsWithCurrentRevisionActionResult,
88-
)
8985
from ai.backend.manager.services.deployment.actions.model_revision.add_model_revision import (
9086
AddModelRevisionAction,
9187
AddModelRevisionActionResult,
@@ -187,10 +183,6 @@ class DeploymentProcessors(AbstractProcessorPackage):
187183
SearchRevisionResourceSlotsAction, SearchRevisionResourceSlotsActionResult
188184
]
189185
activate_revision: ActionProcessor[ActivateRevisionAction, ActivateRevisionActionResult]
190-
list_active_deployments_with_current_revision: ActionProcessor[
191-
ListActiveDeploymentsWithCurrentRevisionAction,
192-
ListActiveDeploymentsWithCurrentRevisionActionResult,
193-
]
194186
refresh_deployment_revisions: ActionProcessor[
195187
RefreshDeploymentRevisionsAction, RefreshDeploymentRevisionsActionResult
196188
]
@@ -281,9 +273,6 @@ def __init__(
281273
service.search_revision_resource_slots, action_monitors
282274
)
283275
self.activate_revision = ActionProcessor(service.activate_revision, action_monitors)
284-
self.list_active_deployments_with_current_revision = ActionProcessor(
285-
service.list_active_deployments_with_current_revision, action_monitors
286-
)
287276
self.refresh_deployment_revisions = ActionProcessor(
288277
service.refresh_deployment_revisions, action_monitors
289278
)
@@ -347,7 +336,6 @@ def supported_actions(self) -> list[ActionSpec]:
347336
SearchRevisionsAction.spec(),
348337
SearchRevisionResourceSlotsAction.spec(),
349338
ActivateRevisionAction.spec(),
350-
ListActiveDeploymentsWithCurrentRevisionAction.spec(),
351339
RefreshDeploymentRevisionsAction.spec(),
352340
# Route operations
353341
SyncReplicaAction.spec(),

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
DeploymentPolicyRow,
4242
)
4343
from ai.backend.manager.models.endpoint import EndpointTokenRow
44-
from ai.backend.manager.models.endpoint.conditions import DeploymentConditions
45-
from ai.backend.manager.repositories.base import BatchQuerier, NoPagination
4644
from ai.backend.manager.repositories.base.rbac.entity_creator import RBACEntityCreator
4745
from ai.backend.manager.repositories.base.upserter import Upserter
4846
from ai.backend.manager.repositories.deployment import DeploymentRepository
@@ -129,10 +127,6 @@
129127
GetReplicaByIdAction,
130128
GetReplicaByIdActionResult,
131129
)
132-
from ai.backend.manager.services.deployment.actions.list_active_deployments_with_current_revision import (
133-
ListActiveDeploymentsWithCurrentRevisionAction,
134-
ListActiveDeploymentsWithCurrentRevisionActionResult,
135-
)
136130
from ai.backend.manager.services.deployment.actions.model_revision.add_model_revision import (
137131
AddModelRevisionAction,
138132
AddModelRevisionActionResult,
@@ -612,46 +606,6 @@ async def activate_revision(
612606
deployment_policy=result.deployment_policy,
613607
)
614608

615-
async def list_active_deployments_with_current_revision(
616-
self,
617-
action: ListActiveDeploymentsWithCurrentRevisionAction,
618-
) -> ListActiveDeploymentsWithCurrentRevisionActionResult:
619-
"""List active deployments paired with their current revision data.
620-
621-
Backs the admin bulk revision refresh: the adapter consumes this
622-
list, projects each ``ModelRevisionData`` onto a
623-
``ModelRevisionCreator``, then invokes
624-
``refresh_deployment_revisions`` once with the prepared map. All
625-
type conversions stay in the adapter; the service only orchestrates
626-
the read pass.
627-
"""
628-
# Bulk scan + per-id read: two-phase fetch is required to preserve
629-
# partial-success semantics in the adapter (a single missing
630-
# revision must not abort the entire refresh).
631-
active_querier = BatchQuerier(
632-
pagination=NoPagination(),
633-
conditions=[
634-
DeploymentConditions.by_lifecycle_stages(EndpointLifecycle.active_states()),
635-
],
636-
)
637-
deployment_ids = await self._deployment_repository.search_deployment_ids(
638-
querier=active_querier,
639-
)
640-
revisions: list[ModelRevisionData] = []
641-
for deployment_id in deployment_ids:
642-
try:
643-
revision = await self._deployment_repository.get_current_revision(deployment_id)
644-
except Exception as exc:
645-
log.warning(
646-
"list_active_deployments_with_current_revision: skipping {}: {}: {}",
647-
deployment_id,
648-
type(exc).__name__,
649-
exc,
650-
)
651-
continue
652-
revisions.append(revision)
653-
return ListActiveDeploymentsWithCurrentRevisionActionResult(revisions=revisions)
654-
655609
async def refresh_deployment_revisions(
656610
self,
657611
action: RefreshDeploymentRevisionsAction,

0 commit comments

Comments
 (0)