Skip to content

Commit b7216bf

Browse files
author
Ortiga
committed
Improve details when VM fails to deploy
1 parent 5d61ba3 commit b7216bf

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
import org.apache.commons.lang3.StringUtils;
161161
import org.apache.commons.lang3.builder.ToStringBuilder;
162162
import org.apache.commons.lang3.builder.ToStringStyle;
163+
import org.apache.logging.log4j.ThreadContext;
163164
import org.jetbrains.annotations.NotNull;
164165
import org.jetbrains.annotations.Nullable;
165166
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -2713,22 +2714,29 @@ private void updateVmStateForFailedVmCreation(Long vmId, Long hostId) {
27132714
if (vm != null) {
27142715
if (vm.getState().equals(State.Stopped)) {
27152716
HostVO host = _hostDao.findById(hostId);
2716-
logger.debug("Destroying vm {} as it failed to create on Host: {} with id {}", vm, host, hostId);
2717+
logger.debug("Destroying vm [{}] as it was unable to be deployed on Host: {} with id {}", vm, host, hostId);
27172718
try {
27182719
_itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationFailedToError, null);
27192720
} catch (NoTransitionException e1) {
2720-
logger.warn(e1.getMessage());
2721+
logger.error("Error when transitioning state of [{}] due to [{}].", vm, e1.getMessage());
27212722
}
27222723
// destroy associated volumes for vm in error state
27232724
// get all volumes in non destroyed state
2725+
logger.debug("Destroying associated volumes of [{}] as it was unable to be deployed.", vm);
27242726
List<VolumeVO> volumesForThisVm = _volsDao.findUsableVolumesForInstance(vm.getId());
27252727
for (VolumeVO volume : volumesForThisVm) {
27262728
if (volume.getState() != Volume.State.Destroy) {
2729+
logger.trace("Destroying volume [{}] as its VM was unable to be deployed.", volume);
27272730
volumeMgr.destroyVolume(volume);
27282731
}
27292732
}
2730-
String msg = String.format("Failed to deploy Vm %s, on Host %s with Id: %d", vm, host, hostId);
2731-
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
2733+
String subject = String.format("Failed to deploy Instance [ID: %s]", vm.getId());
2734+
String body = String.format("Failed to deploy [%s]%s. To troubleshoot, please check the logs with [logid:%s].",
2735+
vm,
2736+
hostId != null ? String.format(" on host [%s]", hostId) : "",
2737+
ThreadContext.get("logcontextid"));
2738+
2739+
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), subject, body);
27322740

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

2743-
2744-
27452751
private class VmIpFetchTask extends ManagedContextRunnable {
27462752

27472753
@Override

0 commit comments

Comments
 (0)