99from orb .application .provider .commands import ExecuteProviderOperationCommand
1010from orb .application .services .orchestration .base import OrchestratorBase
1111from orb .application .services .orchestration .dtos import StartMachinesInput , StartMachinesOutput
12+ from orb .application .services .provider_registry_service import ProviderRegistryService
1213from orb .domain .base .operations import (
1314 Operation as ProviderOperation ,
1415 OperationType as ProviderOperationType ,
@@ -20,11 +21,16 @@ class StartMachinesOrchestrator(OrchestratorBase[StartMachinesInput, StartMachin
2021 """Orchestrator for starting machines via the provider layer."""
2122
2223 def __init__ (
23- self , command_bus : CommandBusPort , query_bus : QueryBusPort , logger : LoggingPort
24+ self ,
25+ command_bus : CommandBusPort ,
26+ query_bus : QueryBusPort ,
27+ logger : LoggingPort ,
28+ provider_registry_service : ProviderRegistryService ,
2429 ) -> None :
2530 self ._command_bus = command_bus
2631 self ._query_bus = query_bus
2732 self ._logger = logger
33+ self ._provider_registry_service = provider_registry_service
2834
2935 async def execute (self , input : StartMachinesInput ) -> StartMachinesOutput : # type: ignore[return]
3036 self ._logger .info (
@@ -57,11 +63,35 @@ async def execute(self, input: StartMachinesInput) -> StartMachinesOutput: # ty
5763 message = "No machines to start" ,
5864 )
5965
66+ # Resolve the effective provider identifier so the command handler can
67+ # route the operation to the correct provider strategy. Preference
68+ # order: explicit name > explicit type > active provider from registry.
69+ if input .provider_name :
70+ strategy_override = input .provider_name
71+ elif input .provider_type :
72+ strategy_override = input .provider_type
73+ else :
74+ try :
75+ selection = self ._provider_registry_service .select_active_provider ()
76+ strategy_override = selection .provider_name
77+ except Exception as exc :
78+ self ._logger .error (
79+ "StartMachinesOrchestrator: cannot resolve active provider: %s" , exc
80+ )
81+ return StartMachinesOutput (
82+ started_machines = [],
83+ failed_machines = list (machine_ids ),
84+ success = False ,
85+ message = f"Cannot resolve active provider: { exc } " ,
86+ )
87+
6088 provider_op = ProviderOperation (
6189 operation_type = ProviderOperationType .START_INSTANCES ,
6290 parameters = {"instance_ids" : machine_ids },
6391 )
64- command = ExecuteProviderOperationCommand (operation = provider_op )
92+ command = ExecuteProviderOperationCommand (
93+ operation = provider_op , strategy_override = strategy_override
94+ )
6595 await self ._command_bus .execute (command )
6696
6797 if command .result and command .result .get ("success" ):
0 commit comments