Skip to content

Add logs for host removal #10423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.persistence.TemporalType;

import com.cloud.utils.db.GenericDaoBase;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;

/**
* Join table for storage pools and hosts
Expand Down Expand Up @@ -100,4 +101,9 @@
this.localPath = localPath;
}

@Override
public String toString() {
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "hostId", "poolId");
}

Check warning on line 107 in engine/schema/src/main/java/com/cloud/storage/StoragePoolHostVO.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/storage/StoragePoolHostVO.java#L105-L107

Added lines #L105 - L107 were not covered by tests

}
33 changes: 26 additions & 7 deletions server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,31 +909,41 @@
// Verify that host exists
final HostVO host = _hostDao.findById(hostId);
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);

Check warning on line 914 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java#L912-L914

Added lines #L912 - L914 were not covered by tests
}
logger.info("Attempting to delete host with UUID [{}].", host.getUuid());

Check warning on line 916 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L916 was not covered by tests

_accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());

if (!canDeleteHost(host) && !isForced) {
throw new CloudRuntimeException("Host " + host.getUuid() +
" cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
String errorMessage = String.format("Host with UUID [%s] is not in maintenance mode and no forced deletion was requested.", host.getUuid());
logger.warn(errorMessage);
throw new CloudRuntimeException(errorMessage);

Check warning on line 923 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java#L921-L923

Added lines #L921 - L923 were not covered by tests
}
// Get storage pool host mappings here because they can be removed as a
// part of handleDisconnect later
final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);

logger.debug("Getting storage pools including those removed by host with UUID [{}]: [{}].", host.getUuid(), pools);

Check warning on line 929 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L929 was not covered by tests

final ResourceStateAdapter.DeleteHostAnswer answer =
(ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced,
isForceDeleteStorage);

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",
host, host.getHypervisorType(), host.getType()));
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.getUuid(), hostId, host.getHypervisorType(), host.getType());
logger.warn(errorMessage);
throw new CloudRuntimeException(errorMessage);

Check warning on line 939 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java#L936-L939

Added lines #L936 - L939 were not covered by tests
}

if (answer.getIsException()) {
return false;
}

logger.info("Host with UUID [{}] has been successfully deleted.", host.getUuid());

Check warning on line 946 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L946 was not covered by tests
if (!answer.getIsContinue()) {
return true;
}
Expand All @@ -945,16 +955,20 @@
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
logger.debug("Releasing private IP address of host with UUID [{}].", host.getUuid());

Check warning on line 958 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L958 was not covered by tests
_dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);

// delete host details
logger.debug("Deleting details from database for host with UUID [{}].", host.getUuid());

Check warning on line 963 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L963 was not covered by tests
_hostDetailsDao.deleteDetails(hostId);

// if host is GPU enabled, delete GPU entries
logger.debug("Deleting GPU entries from database for host with UUID [{}].", host.getUuid());

Check warning on line 967 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L967 was not covered by tests
_hostGpuGroupsDao.deleteGpuEntries(hostId);

// delete host tags
logger.debug("Deleting tags from database for host with UUID [{}].", host.getUuid());

Check warning on line 971 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L971 was not covered by tests
_hostTagsDao.deleteTags(hostId);

host.setGuid(null);
Expand All @@ -963,6 +977,7 @@
_hostDao.update(host.getId(), host);

Host hostRemoved = _hostDao.findById(hostId);
logger.debug("Removing host with UUID [{}] from database.", host.getUuid());

Check warning on line 980 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L980 was not covered by tests
_hostDao.remove(hostId);
if (clusterId != null) {
final List<Long> hostIds = _hostDao.listIdsByClusterId(clusterId);
Expand All @@ -976,16 +991,18 @@
try {
resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
} 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);

Check warning on line 994 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L994 was not covered by tests
}

// Delete the associated entries in host ref table
logger.debug("Deleting storage pool entries from database for host with UUID [{}].", host.getUuid());

Check warning on line 998 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L998 was not covered by tests
_storagePoolHostDao.deletePrimaryRecordsForHost(hostId);

// Make sure any VMs that were marked as being on this host are cleaned up
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
for (final VMInstanceVO vm : vms) {
// 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());

Check warning on line 1005 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1005 was not covered by tests
vm.setState(State.Stopped);
vm.setHostId(null);
_vmDao.persist(vm);
Expand All @@ -1002,7 +1019,7 @@
storagePool.setClusterId(null);
_storagePoolDao.update(poolId, storagePool);
_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());

Check warning on line 1022 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1022 was not covered by tests
}
}

Expand All @@ -1011,6 +1028,7 @@
final SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
logger.debug("Deleting capacity entries from database for host with UUID [{}].", host.getUuid());

Check warning on line 1031 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1031 was not covered by tests
_capacityDao.remove(hostCapacitySC);
// remove from dedicated resources
final DedicatedResourceVO dr = _dedicatedDao.findByHostId(hostId);
Expand All @@ -1019,6 +1037,7 @@
}

// Remove comments (if any)
logger.debug("Deleting comments from database for host with UUID [{}].", host.getUuid());

Check warning on line 1040 in server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1040 was not covered by tests
annotationDao.removeByEntityType(AnnotationService.EntityType.HOST.name(), host.getUuid());
}
});
Expand Down
Loading