mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Add logs for host removal (#10423)
Co-authored-by: Julien Hervot de Mattos Vaz <julien.vaz@scclouds.com.br> Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
This commit is contained in:
parent
c9ce6e305c
commit
a574f7ac99
@ -28,6 +28,7 @@ import javax.persistence.Temporal;
|
|||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join table for storage pools and hosts
|
* Join table for storage pools and hosts
|
||||||
@ -100,4 +101,9 @@ public class StoragePoolHostVO implements StoragePoolHostAssoc {
|
|||||||
this.localPath = localPath;
|
this.localPath = localPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "hostId", "poolId");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -997,31 +997,41 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
// Verify that host exists
|
// Verify that host exists
|
||||||
final HostVO host = _hostDao.findById(hostId);
|
final HostVO host = _hostDao.findById(hostId);
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
|
String errorMessage = String.format("Host with ID [%s] was not found", hostId);
|
||||||
|
logger.warn(errorMessage);
|
||||||
|
throw new InvalidParameterValueException(errorMessage);
|
||||||
}
|
}
|
||||||
|
logger.info("Attempting to delete host with UUID [{}].", host.getUuid());
|
||||||
|
|
||||||
_accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
|
_accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
|
||||||
|
|
||||||
if (!canDeleteHost(host) && !isForced) {
|
if (!canDeleteHost(host) && !isForced) {
|
||||||
throw new CloudRuntimeException("Host " + host.getUuid() +
|
String errorMessage = String.format("Host with UUID [%s] is not in maintenance mode and no forced deletion was requested.", host.getUuid());
|
||||||
" cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
|
logger.warn(errorMessage);
|
||||||
|
throw new CloudRuntimeException(errorMessage);
|
||||||
}
|
}
|
||||||
// Get storage pool host mappings here because they can be removed as a
|
// Get storage pool host mappings here because they can be removed as a
|
||||||
// part of handleDisconnect later
|
// part of handleDisconnect later
|
||||||
final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
|
final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
|
||||||
|
|
||||||
|
logger.debug("Getting storage pools including those removed by host with UUID [{}]: [{}].", host.getUuid(), pools);
|
||||||
|
|
||||||
final ResourceStateAdapter.DeleteHostAnswer answer =
|
final ResourceStateAdapter.DeleteHostAnswer answer =
|
||||||
(ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced,
|
(ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced,
|
||||||
isForceDeleteStorage);
|
isForceDeleteStorage);
|
||||||
|
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
throw new CloudRuntimeException(String.format("No resource adapter respond to DELETE_HOST event for %s, hypervisorType is %s, host type is %s",
|
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].",
|
||||||
host, host.getHypervisorType(), host.getType()));
|
host.getUuid(), hostId, host.getHypervisorType(), host.getType());
|
||||||
|
logger.warn(errorMessage);
|
||||||
|
throw new CloudRuntimeException(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answer.getIsException()) {
|
if (answer.getIsException()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("Host with UUID [{}] has been successfully deleted.", host.getUuid());
|
||||||
if (!answer.getIsContinue()) {
|
if (!answer.getIsContinue()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1033,16 +1043,20 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||||
@Override
|
@Override
|
||||||
public void doInTransactionWithoutResult(final TransactionStatus status) {
|
public void doInTransactionWithoutResult(final TransactionStatus status) {
|
||||||
|
logger.debug("Releasing private IP address of host with UUID [{}].", host.getUuid());
|
||||||
_dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
|
_dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
|
||||||
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
|
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
|
||||||
|
|
||||||
// delete host details
|
// delete host details
|
||||||
|
logger.debug("Deleting details from database for host with UUID [{}].", host.getUuid());
|
||||||
_hostDetailsDao.deleteDetails(hostId);
|
_hostDetailsDao.deleteDetails(hostId);
|
||||||
|
|
||||||
// if host is GPU enabled, delete GPU entries
|
// if host is GPU enabled, delete GPU entries
|
||||||
|
logger.debug("Deleting GPU entries from database for host with UUID [{}].", host.getUuid());
|
||||||
_hostGpuGroupsDao.deleteGpuEntries(hostId);
|
_hostGpuGroupsDao.deleteGpuEntries(hostId);
|
||||||
|
|
||||||
// delete host tags
|
// delete host tags
|
||||||
|
logger.debug("Deleting tags from database for host with UUID [{}].", host.getUuid());
|
||||||
_hostTagsDao.deleteTags(hostId);
|
_hostTagsDao.deleteTags(hostId);
|
||||||
|
|
||||||
host.setGuid(null);
|
host.setGuid(null);
|
||||||
@ -1051,6 +1065,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
_hostDao.update(host.getId(), host);
|
_hostDao.update(host.getId(), host);
|
||||||
|
|
||||||
Host hostRemoved = _hostDao.findById(hostId);
|
Host hostRemoved = _hostDao.findById(hostId);
|
||||||
|
logger.debug("Removing host with UUID [{}] from database.", host.getUuid());
|
||||||
_hostDao.remove(hostId);
|
_hostDao.remove(hostId);
|
||||||
if (clusterId != null) {
|
if (clusterId != null) {
|
||||||
final List<Long> hostIds = _hostDao.listIdsByClusterId(clusterId);
|
final List<Long> hostIds = _hostDao.listIdsByClusterId(clusterId);
|
||||||
@ -1064,16 +1079,18 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
try {
|
try {
|
||||||
resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
|
resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
|
||||||
} catch (final NoTransitionException e) {
|
} catch (final NoTransitionException e) {
|
||||||
logger.debug(String.format("Cannot transit %s to Enabled state", host), e);
|
logger.debug("Cannot transit host [{}] to Enabled state", host, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the associated entries in host ref table
|
// Delete the associated entries in host ref table
|
||||||
|
logger.debug("Deleting storage pool entries from database for host with UUID [{}].", host.getUuid());
|
||||||
_storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
|
_storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
|
||||||
|
|
||||||
// Make sure any VMs that were marked as being on this host are cleaned up
|
// Make sure any VMs that were marked as being on this host are cleaned up
|
||||||
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
||||||
for (final VMInstanceVO vm : vms) {
|
for (final VMInstanceVO vm : vms) {
|
||||||
// this is how VirtualMachineManagerImpl does it when it syncs VM states
|
// this is how VirtualMachineManagerImpl does it when it syncs VM states
|
||||||
|
logger.debug("Setting VM with UUID [{}] as stopped, as it was in host with UUID [{}], which has been removed.", vm.getUuid(), host.getUuid());
|
||||||
vm.setState(State.Stopped);
|
vm.setState(State.Stopped);
|
||||||
vm.setHostId(null);
|
vm.setHostId(null);
|
||||||
_vmDao.persist(vm);
|
_vmDao.persist(vm);
|
||||||
@ -1090,7 +1107,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
storagePool.setClusterId(null);
|
storagePool.setClusterId(null);
|
||||||
_storagePoolDao.update(poolId, storagePool);
|
_storagePoolDao.update(poolId, storagePool);
|
||||||
_storagePoolDao.remove(poolId);
|
_storagePoolDao.remove(poolId);
|
||||||
logger.debug("Local storage [id: {}] is removed as a part of {} removal", storagePool, hostRemoved);
|
logger.debug("Local storage [ID: {}] is removed as a part of host [{}] removal", poolId, hostRemoved.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1099,6 +1116,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
final SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
|
final SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
|
||||||
hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
|
hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
|
||||||
hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
|
hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
|
||||||
|
logger.debug("Deleting capacity entries from database for host with UUID [{}].", host.getUuid());
|
||||||
_capacityDao.remove(hostCapacitySC);
|
_capacityDao.remove(hostCapacitySC);
|
||||||
// remove from dedicated resources
|
// remove from dedicated resources
|
||||||
final DedicatedResourceVO dr = _dedicatedDao.findByHostId(hostId);
|
final DedicatedResourceVO dr = _dedicatedDao.findByHostId(hostId);
|
||||||
@ -1107,6 +1125,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove comments (if any)
|
// Remove comments (if any)
|
||||||
|
logger.debug("Deleting comments from database for host with UUID [{}].", host.getUuid());
|
||||||
annotationDao.removeByEntityType(AnnotationService.EntityType.HOST.name(), host.getUuid());
|
annotationDao.removeByEntityType(AnnotationService.EntityType.HOST.name(), host.getUuid());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user