@@ -997,31 +997,41 @@ protected boolean doDeleteHost(final long hostId, final boolean isForced, final
997997 // Verify that host exists
998998 final HostVO host = _hostDao .findById (hostId );
999999 if (host == null ) {
1000- throw new InvalidParameterValueException ("Host with id " + hostId + " doesn't exist" );
1000+ String errorMessage = String .format ("Host with ID [%s] was not found" , hostId );
1001+ logger .warn (errorMessage );
1002+ throw new InvalidParameterValueException (errorMessage );
10011003 }
1004+ logger .info ("Attempting to delete host with UUID [{}]." , host .getUuid ());
1005+
10021006 _accountMgr .checkAccessAndSpecifyAuthority (CallContext .current ().getCallingAccount (), host .getDataCenterId ());
10031007
10041008 if (!canDeleteHost (host ) && !isForced ) {
1005- throw new CloudRuntimeException ("Host " + host .getUuid () +
1006- " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion." );
1009+ String errorMessage = String .format ("Host with UUID [%s] is not in maintenance mode and no forced deletion was requested." , host .getUuid ());
1010+ logger .warn (errorMessage );
1011+ throw new CloudRuntimeException (errorMessage );
10071012 }
10081013 // Get storage pool host mappings here because they can be removed as a
10091014 // part of handleDisconnect later
10101015 final List <StoragePoolHostVO > pools = _storagePoolHostDao .listByHostIdIncludingRemoved (hostId );
10111016
1017+ logger .debug ("Getting storage pools including those removed by host with UUID [{}]: [{}]." , host .getUuid (), pools );
1018+
10121019 final ResourceStateAdapter .DeleteHostAnswer answer =
10131020 (ResourceStateAdapter .DeleteHostAnswer )dispatchToStateAdapters (ResourceStateAdapter .Event .DELETE_HOST , false , host , isForced ,
10141021 isForceDeleteStorage );
10151022
10161023 if (answer == null ) {
1017- throw new CloudRuntimeException (String .format ("No resource adapter respond to DELETE_HOST event for %s, hypervisorType is %s, host type is %s" ,
1018- host , host .getHypervisorType (), host .getType ()));
1024+ String errorMessage = String .format ("No resource adapter answer was returned to DELETE_HOST event for host [%s] with ID [%s], hypervisor type [%s] and host type [%s]." ,
1025+ host .getUuid (), hostId , host .getHypervisorType (), host .getType ());
1026+ logger .warn (errorMessage );
1027+ throw new CloudRuntimeException (errorMessage );
10191028 }
10201029
10211030 if (answer .getIsException ()) {
10221031 return false ;
10231032 }
10241033
1034+ logger .info ("Host with UUID [{}] has been successfully deleted." , host .getUuid ());
10251035 if (!answer .getIsContinue ()) {
10261036 return true ;
10271037 }
@@ -1033,16 +1043,20 @@ protected boolean doDeleteHost(final long hostId, final boolean isForced, final
10331043 Transaction .execute (new TransactionCallbackNoReturn () {
10341044 @ Override
10351045 public void doInTransactionWithoutResult (final TransactionStatus status ) {
1046+ logger .debug ("Releasing private IP address of host with UUID [{}]." , host .getUuid ());
10361047 _dcDao .releasePrivateIpAddress (host .getPrivateIpAddress (), host .getDataCenterId (), null );
10371048 _agentMgr .disconnectWithoutInvestigation (hostId , Status .Event .Remove );
10381049
10391050 // delete host details
1051+ logger .debug ("Deleting details from database for host with UUID [{}]." , host .getUuid ());
10401052 _hostDetailsDao .deleteDetails (hostId );
10411053
10421054 // if host is GPU enabled, delete GPU entries
1055+ logger .debug ("Deleting GPU entries from database for host with UUID [{}]." , host .getUuid ());
10431056 _hostGpuGroupsDao .deleteGpuEntries (hostId );
10441057
10451058 // delete host tags
1059+ logger .debug ("Deleting tags from database for host with UUID [{}]." , host .getUuid ());
10461060 _hostTagsDao .deleteTags (hostId );
10471061
10481062 host .setGuid (null );
@@ -1051,6 +1065,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10511065 _hostDao .update (host .getId (), host );
10521066
10531067 Host hostRemoved = _hostDao .findById (hostId );
1068+ logger .debug ("Removing host with UUID [{}] from database." , host .getUuid ());
10541069 _hostDao .remove (hostId );
10551070 if (clusterId != null ) {
10561071 final List <Long > hostIds = _hostDao .listIdsByClusterId (clusterId );
@@ -1064,16 +1079,18 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10641079 try {
10651080 resourceStateTransitTo (host , ResourceState .Event .DeleteHost , _nodeId );
10661081 } catch (final NoTransitionException e ) {
1067- logger .debug (String . format ( "Cannot transit %s to Enabled state" , host ) , e );
1082+ logger .debug ("Cannot transit host [{}] to Enabled state" , host , e );
10681083 }
10691084
10701085 // Delete the associated entries in host ref table
1086+ logger .debug ("Deleting storage pool entries from database for host with UUID [{}]." , host .getUuid ());
10711087 _storagePoolHostDao .deletePrimaryRecordsForHost (hostId );
10721088
10731089 // Make sure any VMs that were marked as being on this host are cleaned up
10741090 final List <VMInstanceVO > vms = _vmDao .listByHostId (hostId );
10751091 for (final VMInstanceVO vm : vms ) {
10761092 // this is how VirtualMachineManagerImpl does it when it syncs VM states
1093+ logger .debug ("Setting VM with UUID [{}] as stopped, as it was in host with UUID [{}], which has been removed." , vm .getUuid (), host .getUuid ());
10771094 vm .setState (State .Stopped );
10781095 vm .setHostId (null );
10791096 _vmDao .persist (vm );
@@ -1090,7 +1107,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10901107 storagePool .setClusterId (null );
10911108 _storagePoolDao .update (poolId , storagePool );
10921109 _storagePoolDao .remove (poolId );
1093- logger .debug ("Local storage [id : {}] is removed as a part of {} removal" , storagePool , hostRemoved );
1110+ logger .debug ("Local storage [ID : {}] is removed as a part of host [{}] removal" , poolId , hostRemoved . toString () );
10941111 }
10951112 }
10961113
@@ -1099,6 +1116,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10991116 final SearchCriteria <CapacityVO > hostCapacitySC = _capacityDao .createSearchCriteria ();
11001117 hostCapacitySC .addAnd ("hostOrPoolId" , SearchCriteria .Op .EQ , hostId );
11011118 hostCapacitySC .addAnd ("capacityType" , SearchCriteria .Op .IN , capacityTypes );
1119+ logger .debug ("Deleting capacity entries from database for host with UUID [{}]." , host .getUuid ());
11021120 _capacityDao .remove (hostCapacitySC );
11031121 // remove from dedicated resources
11041122 final DedicatedResourceVO dr = _dedicatedDao .findByHostId (hostId );
@@ -1107,6 +1125,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
11071125 }
11081126
11091127 // Remove comments (if any)
1128+ logger .debug ("Deleting comments from database for host with UUID [{}]." , host .getUuid ());
11101129 annotationDao .removeByEntityType (AnnotationService .EntityType .HOST .name (), host .getUuid ());
11111130 }
11121131 });
0 commit comments