Skip to content

Commit 98a2cbe

Browse files
julien-vazJulien Hervot de Mattos Vazbernardodemarco
authored andcommitted
Add logs for host removal (apache#10423)
Co-authored-by: Julien Hervot de Mattos Vaz <[email protected]> Co-authored-by: Bernardo De Marco Gonçalves <[email protected]>
1 parent fb62b25 commit 98a2cbe

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

engine/schema/src/main/java/com/cloud/storage/StoragePoolHostVO.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.persistence.TemporalType;
2929

3030
import com.cloud.utils.db.GenericDaoBase;
31+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3132

3233
/**
3334
* Join table for storage pools and hosts
@@ -100,4 +101,9 @@ public void setLocalPath(String localPath) {
100101
this.localPath = localPath;
101102
}
102103

104+
@Override
105+
public String toString() {
106+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "hostId", "poolId");
107+
}
108+
103109
}

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,31 +998,41 @@ protected boolean doDeleteHost(final long hostId, final boolean isForced, final
998998
// Verify that host exists
999999
final HostVO host = _hostDao.findById(hostId);
10001000
if (host == null) {
1001-
throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
1001+
String errorMessage = String.format("Host with ID [%s] was not found", hostId);
1002+
logger.warn(errorMessage);
1003+
throw new InvalidParameterValueException(errorMessage);
10021004
}
1005+
logger.info("Attempting to delete host with UUID [{}].", host.getUuid());
1006+
10031007
_accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
10041008

10051009
if (!canDeleteHost(host) && !isForced) {
1006-
throw new CloudRuntimeException("Host " + host.getUuid() +
1007-
" cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
1010+
String errorMessage = String.format("Host with UUID [%s] is not in maintenance mode and no forced deletion was requested.", host.getUuid());
1011+
logger.warn(errorMessage);
1012+
throw new CloudRuntimeException(errorMessage);
10081013
}
10091014
// Get storage pool host mappings here because they can be removed as a
10101015
// part of handleDisconnect later
10111016
final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
10121017

1018+
logger.debug("Getting storage pools including those removed by host with UUID [{}]: [{}].", host.getUuid(), pools);
1019+
10131020
final ResourceStateAdapter.DeleteHostAnswer answer =
10141021
(ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced,
10151022
isForceDeleteStorage);
10161023

10171024
if (answer == null) {
1018-
throw new CloudRuntimeException(String.format("No resource adapter respond to DELETE_HOST event for %s, hypervisorType is %s, host type is %s",
1019-
host, host.getHypervisorType(), host.getType()));
1025+
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].",
1026+
host.getUuid(), hostId, host.getHypervisorType(), host.getType());
1027+
logger.warn(errorMessage);
1028+
throw new CloudRuntimeException(errorMessage);
10201029
}
10211030

10221031
if (answer.getIsException()) {
10231032
return false;
10241033
}
10251034

1035+
logger.info("Host with UUID [{}] has been successfully deleted.", host.getUuid());
10261036
if (!answer.getIsContinue()) {
10271037
return true;
10281038
}
@@ -1034,16 +1044,20 @@ protected boolean doDeleteHost(final long hostId, final boolean isForced, final
10341044
Transaction.execute(new TransactionCallbackNoReturn() {
10351045
@Override
10361046
public void doInTransactionWithoutResult(final TransactionStatus status) {
1047+
logger.debug("Releasing private IP address of host with UUID [{}].", host.getUuid());
10371048
_dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
10381049
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
10391050

10401051
// delete host details
1052+
logger.debug("Deleting details from database for host with UUID [{}].", host.getUuid());
10411053
_hostDetailsDao.deleteDetails(hostId);
10421054

10431055
// if host is GPU enabled, delete GPU entries
1056+
logger.debug("Deleting GPU entries from database for host with UUID [{}].", host.getUuid());
10441057
_hostGpuGroupsDao.deleteGpuEntries(hostId);
10451058

10461059
// delete host tags
1060+
logger.debug("Deleting tags from database for host with UUID [{}].", host.getUuid());
10471061
_hostTagsDao.deleteTags(hostId);
10481062

10491063
host.setGuid(null);
@@ -1052,6 +1066,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10521066
_hostDao.update(host.getId(), host);
10531067

10541068
Host hostRemoved = _hostDao.findById(hostId);
1069+
logger.debug("Removing host with UUID [{}] from database.", host.getUuid());
10551070
_hostDao.remove(hostId);
10561071
if (clusterId != null) {
10571072
final List<Long> hostIds = _hostDao.listIdsByClusterId(clusterId);
@@ -1065,16 +1080,18 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10651080
try {
10661081
resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
10671082
} catch (final NoTransitionException e) {
1068-
logger.debug(String.format("Cannot transit %s to Enabled state", host), e);
1083+
logger.debug("Cannot transit host [{}] to Enabled state", host, e);
10691084
}
10701085

10711086
// Delete the associated entries in host ref table
1087+
logger.debug("Deleting storage pool entries from database for host with UUID [{}].", host.getUuid());
10721088
_storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
10731089

10741090
// Make sure any VMs that were marked as being on this host are cleaned up
10751091
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
10761092
for (final VMInstanceVO vm : vms) {
10771093
// this is how VirtualMachineManagerImpl does it when it syncs VM states
1094+
logger.debug("Setting VM with UUID [{}] as stopped, as it was in host with UUID [{}], which has been removed.", vm.getUuid(), host.getUuid());
10781095
vm.setState(State.Stopped);
10791096
vm.setHostId(null);
10801097
_vmDao.persist(vm);
@@ -1091,7 +1108,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10911108
storagePool.setClusterId(null);
10921109
_storagePoolDao.update(poolId, storagePool);
10931110
_storagePoolDao.remove(poolId);
1094-
logger.debug("Local storage [id: {}] is removed as a part of {} removal", storagePool, hostRemoved);
1111+
logger.debug("Local storage [ID: {}] is removed as a part of host [{}] removal", poolId, hostRemoved.toString());
10951112
}
10961113
}
10971114

@@ -1100,6 +1117,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
11001117
final SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
11011118
hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
11021119
hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
1120+
logger.debug("Deleting capacity entries from database for host with UUID [{}].", host.getUuid());
11031121
_capacityDao.remove(hostCapacitySC);
11041122
// remove from dedicated resources
11051123
final DedicatedResourceVO dr = _dedicatedDao.findByHostId(hostId);
@@ -1108,6 +1126,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
11081126
}
11091127

11101128
// Remove comments (if any)
1129+
logger.debug("Deleting comments from database for host with UUID [{}].", host.getUuid());
11111130
annotationDao.removeByEntityType(AnnotationService.EntityType.HOST.name(), host.getUuid());
11121131
}
11131132
});

0 commit comments

Comments
 (0)