9494import com .cloud .utils .fsm .StateMachine2 ;
9595import com .cloud .vm .ItWorkVO .Type ;
9696import com .cloud .vm .VirtualMachine .Event ;
97+ import com .cloud .vm .dao .ConsoleProxyDao ;
98+ import com .cloud .vm .dao .DomainRouterDao ;
99+ import com .cloud .vm .dao .SecondaryStorageVmDao ;
100+ import com .cloud .vm .dao .UserVmDao ;
97101import com .cloud .vm .dao .VMInstanceDao ;
98102
99103@ Local (value =VmManager .class )
@@ -113,6 +117,10 @@ public class MauriceMoss implements VmManager, ClusterManagerListener {
113117 @ Inject private ClusterManager _clusterMgr ;
114118 @ Inject private ItWorkDao _workDao ;
115119 @ Inject private CapacityDao _capacityDao ;
120+ @ Inject private UserVmDao _userVmDao ;
121+ @ Inject private DomainRouterDao _routerDao ;
122+ @ Inject private ConsoleProxyDao _consoleDao ;
123+ @ Inject private SecondaryStorageVmDao _secondaryDao ;
116124
117125 @ Inject (adapter =DeploymentPlanner .class )
118126 private Adapters <DeploymentPlanner > _planners ;
@@ -340,13 +348,15 @@ public <T extends VMInstanceVO> T start(T vm, Map<String, Object> params, User c
340348
341349 ExcludeList avoids = new ExcludeList ();
342350 int retry = _retry ;
343- while (retry -- != 0 ) { // It's != so that it can match -1.
351+ DeployDestination dest = null ;
352+ while (retry -- != 0 ) { // It's != so that it can match -1.
353+ /*this will release resource allocated on dest host*/
344354 if (retry < (_retry -1 )) {
345- stateTransitTo (vm , Event .OperationRetry , null );
355+ stateTransitTo (vm , Event .OperationRetry , dest . getHost (). getId () );
346356 }
347357
348358 VirtualMachineProfileImpl <T > vmProfile = new VirtualMachineProfileImpl <T >(vm , template , offering , null , params );
349- DeployDestination dest = null ;
359+
350360 for (DeploymentPlanner planner : _planners ) {
351361 dest = planner .plan (vmProfile , plan , avoids );
352362 if (dest != null ) {
@@ -366,7 +376,7 @@ public <T extends VMInstanceVO> T start(T vm, Map<String, Object> params, User c
366376 try {
367377 _storageMgr .prepare (vmProfile , dest );
368378 } catch (ConcurrentOperationException e ) {
369- stateTransitTo (vm , Event .OperationFailed , null );
379+ stateTransitTo (vm , Event .OperationFailed , dest . getHost (). getId () );
370380 throw e ;
371381 } catch (StorageUnavailableException e ) {
372382 s_logger .warn ("Unable to contact storage." , e );
@@ -401,7 +411,7 @@ public <T extends VMInstanceVO> T start(T vm, Map<String, Object> params, User c
401411 }
402412 }
403413
404- stateTransitTo (vm , Event .OperationFailed , null );
414+ stateTransitTo (vm , Event .OperationFailed , dest . getHost (). getId () );
405415
406416 if (s_logger .isDebugEnabled ()) {
407417 s_logger .debug ("Creation complete for VM " + vm );
@@ -463,7 +473,7 @@ public <T extends VMInstanceVO> boolean stop(T vm, User user, Account account) t
463473 }
464474
465475 boolean cleanup = false ;
466-
476+
467477 VirtualMachineProfile <T > profile = new VirtualMachineProfileImpl <T >(vm );
468478 try {
469479 _networkMgr .release (profile );
@@ -510,7 +520,7 @@ public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long sel
510520 }
511521
512522 private void setStateMachine () {
513- _stateMachine = new StateMachine2 <State , VirtualMachine .Event , VMInstanceVO >( _vmDao );
523+ _stateMachine = new StateMachine2 <State , VirtualMachine .Event , VMInstanceVO >( );
514524
515525 _stateMachine .addTransition (null , VirtualMachine .Event .CreateRequested , State .Creating );
516526 _stateMachine .addTransition (State .Creating , VirtualMachine .Event .OperationSucceeded , State .Stopped );
@@ -534,6 +544,8 @@ private void setStateMachine() {
534544 _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .MigrationRequested , State .Migrating );
535545 _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .OperationSucceeded , State .Running );
536546 _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .OperationFailed , State .Running );
547+ _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .MigrationFailedOnSource , State .Running );
548+ _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .MigrationFailedOnDest , State .Running );
537549 _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .AgentReportRunning , State .Running );
538550 _stateMachine .addTransition (State .Migrating , VirtualMachine .Event .AgentReportStopped , State .Stopped );
539551 _stateMachine .addTransition (State .Stopping , VirtualMachine .Event .OperationSucceeded , State .Stopped );
@@ -544,11 +556,20 @@ private void setStateMachine() {
544556 _stateMachine .addTransition (State .Expunging , VirtualMachine .Event .OperationFailed , State .Expunging );
545557 _stateMachine .addTransition (State .Expunging , VirtualMachine .Event .ExpungeOperation , State .Expunging );
546558
547- _stateMachine .registerListener (new VMStateListener (_capacityDao , _offeringDao , _vmDao ));
559+ _stateMachine .registerListener (new VMStateListener (_capacityDao , _offeringDao ));
548560 }
549561
550562 @ Override
551563 public boolean stateTransitTo (VMInstanceVO vm , VirtualMachine .Event e , Long id ) {
552- return _stateMachine .transitTO (vm , e , id );
564+ if (vm instanceof UserVmVO ) {
565+ return _stateMachine .transitTO (vm , e , id , _userVmDao );
566+ } else if (vm instanceof ConsoleProxyVO ) {
567+ return _stateMachine .transitTO (vm , e , id , _consoleDao );
568+ } else if (vm instanceof SecondaryStorageVmVO ) {
569+ return _stateMachine .transitTO (vm , e , id , _secondaryDao );
570+ } else if (vm instanceof DomainRouterVO ) {
571+ return _stateMachine .transitTO (vm , e , id , _routerDao );
572+ }
573+ return false ;
553574 }
554575}
0 commit comments