@@ -2370,34 +2370,32 @@ public void deleteRoutingHost(final HostVO host, final boolean isForced, final b
23702370 s_logger .debug ("Deleting Host: " + host .getId () + " Guid:" + host .getGuid ());
23712371 }
23722372
2373- if (forceDestroyStorage ) {
2373+ final StoragePoolVO storagePool = _storageMgr .findLocalStorageOnHost (host .getId ());
2374+ if (forceDestroyStorage && storagePool != null ) {
23742375 // put local storage into mainenance mode, will set all the VMs on
23752376 // this local storage into stopped state
2376- final StoragePoolVO storagePool = _storageMgr .findLocalStorageOnHost (host .getId ());
2377- if (storagePool != null ) {
2378- if (storagePool .getStatus () == StoragePoolStatus .Up || storagePool .getStatus () == StoragePoolStatus .ErrorInMaintenance ) {
2379- try {
2380- final StoragePool pool = _storageSvr .preparePrimaryStorageForMaintenance (storagePool .getId ());
2381- if (pool == null ) {
2382- s_logger .debug ("Failed to set primary storage into maintenance mode" );
2377+ if (storagePool .getStatus () == StoragePoolStatus .Up || storagePool .getStatus () == StoragePoolStatus .ErrorInMaintenance ) {
2378+ try {
2379+ final StoragePool pool = _storageSvr .preparePrimaryStorageForMaintenance (storagePool .getId ());
2380+ if (pool == null ) {
2381+ s_logger .debug ("Failed to set primary storage into maintenance mode" );
23832382
2384- throw new UnableDeleteHostException ("Failed to set primary storage into maintenance mode" );
2385- }
2386- } catch (final Exception e ) {
2387- s_logger .debug ("Failed to set primary storage into maintenance mode, due to: " + e .toString ());
2388- throw new UnableDeleteHostException ("Failed to set primary storage into maintenance mode, due to: " + e .toString ());
2383+ throw new UnableDeleteHostException ("Failed to set primary storage into maintenance mode" );
23892384 }
2385+ } catch (final Exception e ) {
2386+ s_logger .debug ("Failed to set primary storage into maintenance mode, due to: " + e .toString ());
2387+ throw new UnableDeleteHostException ("Failed to set primary storage into maintenance mode, due to: " + e .toString ());
23902388 }
2389+ }
23912390
2392- final List <VMInstanceVO > vmsOnLocalStorage = _storageMgr .listByStoragePool (storagePool .getId ());
2393- for (final VMInstanceVO vm : vmsOnLocalStorage ) {
2394- try {
2395- _vmMgr .destroy (vm .getUuid (), false );
2396- } catch (final Exception e ) {
2397- final String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host .getId ();
2398- s_logger .debug (errorMsg , e );
2399- throw new UnableDeleteHostException (errorMsg + "," + e .getMessage ());
2400- }
2391+ final List <VMInstanceVO > vmsOnLocalStorage = _storageMgr .listByStoragePool (storagePool .getId ());
2392+ for (final VMInstanceVO vm : vmsOnLocalStorage ) {
2393+ try {
2394+ _vmMgr .destroy (vm .getUuid (), false );
2395+ } catch (final Exception e ) {
2396+ final String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host .getId ();
2397+ s_logger .debug (errorMsg , e );
2398+ throw new UnableDeleteHostException (errorMsg + "," + e .getMessage ());
24012399 }
24022400 }
24032401 } else {
@@ -2407,17 +2405,22 @@ public void deleteRoutingHost(final HostVO host, final boolean isForced, final b
24072405 if (isForced ) {
24082406 // Stop HA disabled vms and HA enabled vms in Stopping state
24092407 // Restart HA enabled vms
2408+ try {
2409+ resourceStateTransitTo (host , ResourceState .Event .DeleteHost , host .getId ());
2410+ } catch (final NoTransitionException e ) {
2411+ s_logger .debug ("Cannot transmit host " + host .getId () + " to Disabled state" , e );
2412+ }
24102413 for (final VMInstanceVO vm : vms ) {
2411- if (! vm .isHaEnabled () || vm .getState () == State .Stopping ) {
2414+ if ((! HighAvailabilityManager . ForceHA . value () && ! vm .isHaEnabled () ) || vm .getState () == State .Stopping ) {
24122415 s_logger .debug ("Stopping vm: " + vm + " as a part of deleteHost id=" + host .getId ());
24132416 try {
2414- _vmMgr . advanceStop (vm . getUuid (), false );
2417+ _haMgr . scheduleStop (vm , host . getId (), WorkType . Stop );
24152418 } catch (final Exception e ) {
24162419 final String errorMsg = "There was an error stopping the vm: " + vm + " as a part of hostDelete id=" + host .getId ();
24172420 s_logger .debug (errorMsg , e );
24182421 throw new UnableDeleteHostException (errorMsg + "," + e .getMessage ());
24192422 }
2420- } else if (vm .isHaEnabled () && (vm .getState () == State .Running || vm .getState () == State .Starting )) {
2423+ } else if (( HighAvailabilityManager . ForceHA . value () || vm .isHaEnabled () ) && (vm .getState () == State .Running || vm .getState () == State .Starting )) {
24212424 s_logger .debug ("Scheduling restart for vm: " + vm + " " + vm .getState () + " on the host id=" + host .getId ());
24222425 _haMgr .scheduleRestart (vm , false );
24232426 }
0 commit comments