backend.ai icon indicating copy to clipboard operation
backend.ai copied to clipboard

Integrate PurgeScalingGroup Action with existing GraphQL implementation

Open jopemachine opened this issue 3 weeks ago • 0 comments

Objective

Complete Purge action with GraphQL integration and comprehensive tests.

Implementation Details

GraphQL mutation (~25 lines)

  • PurgeScalingGroupInput with name: str
  • PurgeScalingGroupResult with ok: bool, msg: str
  • @privileged_mutation decorator with (UserRole.SUPERADMIN,)
  • processors.scaling_group.purge_scaling_group.wait_for_complete() call

Action classes (~20 lines)

  • PurgeScalingGroupAction(ScalingGroupAction) with name: str
  • PurgeScalingGroupActionResult(BaseActionResult) with name: str

Service method (~15 lines)

  • purge_scaling_group() in ScalingGroupService
  • Call admin repository's purge_scaling_group_force()
  • Return PurgeScalingGroupActionResult

Admin Repository (~60 lines)

  • Create AdminScalingGroupRepository class
  • Pre-flight validation checks:
    • _check_scaling_group_has_active_sessions(): Fail if active sessions exist
    • _check_scaling_group_has_active_agents(): Fail if active agents exist
  • purge_scaling_group_force() method with cleanup sequence
  • Use @scaling_group_repository_resilience.apply() decorator
  • CASCADE FKs auto-delete: sgroups_for_domains, sgroups_for_groups, sgroups_for_keypairs

Processor registration (~10 lines)

  • Add purge_scaling_group: ActionProcessor to ScalingGroupProcessors
  • Register in supported_actions()

Unit tests

  • test_purge_scaling_group_service.py (~80 lines)
  • test_purge_scaling_group_repository.py (~100 lines)
  • Edge case tests (not found, active sessions/agents exist, validation) (~60 lines)

Estimated Lines

~370 lines

Dependencies

  • Story: PurgeScalingGroup Action - Action Spec
  • Reference: Group Purge implementation (services/group/actions/purge_group.py)
  • Reference: Domain Purge implementation (domain/admin_repository.py)
  • Base: Purger utility from repositories/base/purger.py

Acceptance Criteria

  • [ ] GraphQL mutation uses new processor pattern
  • [ ] PurgeScalingGroupAction properly defined with name identifier
  • [ ] Pre-flight checks validate no active sessions/agents exist
  • [ ] CASCADE delete handles many-to-many associations automatically
  • [ ] Edge cases tested (scaling group not found, active sessions exist, active agents exist)
  • [ ] All unit tests pass
  • [ ] @privileged_mutation with SUPERADMIN role applied

JIRA Issue: BA-3518

jopemachine avatar Dec 19 '25 07:12 jopemachine