Skip to content
Open
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
18 changes: 12 additions & 6 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.logging.log4j.ThreadContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
Expand Down Expand Up @@ -2713,22 +2714,29 @@ private void updateVmStateForFailedVmCreation(Long vmId, Long hostId) {
if (vm != null) {
if (vm.getState().equals(State.Stopped)) {
HostVO host = _hostDao.findById(hostId);
logger.debug("Destroying vm {} as it failed to create on Host: {} with id {}", vm, host, hostId);
logger.debug("Destroying VM [{}] as it was unable to be deployed on Host: {}.", vm, host);
try {
_itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationFailedToError, null);
} catch (NoTransitionException e1) {
logger.warn(e1.getMessage());
logger.error("Error when transitioning state of [{}].", vm, e1);
}
// destroy associated volumes for vm in error state
// get all volumes in non destroyed state
logger.debug("Destroying associated volumes of [{}] as it was unable to be deployed.", vm);
List<VolumeVO> volumesForThisVm = _volsDao.findUsableVolumesForInstance(vm.getId());
for (VolumeVO volume : volumesForThisVm) {
if (volume.getState() != Volume.State.Destroy) {
logger.trace("Destroying volume [{}] as its VM was unable to be deployed.", volume);
volumeMgr.destroyVolume(volume);
}
}
String msg = String.format("Failed to deploy Vm %s, on Host %s with Id: %d", vm, host, hostId);
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
String subject = String.format("Failed to deploy Instance [ID: %s]", vm.getId());
String body = String.format("Failed to deploy [%s]%s. To troubleshoot, please check the logs with [logid:%s].",
vm,
hostId != null ? String.format(" on host [%s]", hostId) : "",
ThreadContext.get("logcontextid"));

_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), subject, body);

// Get serviceOffering and template for Virtual Machine
ServiceOfferingVO offering = serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
Expand All @@ -2740,8 +2748,6 @@ private void updateVmStateForFailedVmCreation(Long vmId, Long hostId) {
}
}



private class VmIpFetchTask extends ManagedContextRunnable {

@Override
Expand Down
Loading