Skip to content

Commit eb43f78

Browse files
author
prachi
committed
Bug 13824 - VM deployment fails due to volume not being recreatable
Reviewed-By: Alex Changes: - Reuse the same storagepool where the Volume is ready on each retry of VM deployment until the cluster where the volume is has capacity - After the cluster is out of capacity, we look in other clusters and find a new storagepool. - At this point if the volume is recreatable on the new storagepool, depoyment will succeed provided everytyhing else goes through - But if the volume is not recreatable and its cluster is out of capacity, we will still fail to deploy the VM
1 parent cdf10cc commit eb43f78

2 files changed

Lines changed: 59 additions & 54 deletions

File tree

‎server/src/com/cloud/deploy/FirstFitPlanner.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm
187187
HostVO host = _hostDao.findById(vm.getLastHostId());
188188
if(host == null){
189189
s_logger.debug("The last host of this VM cannot be found");
190+
}else if(avoid.shouldAvoid(host)){
191+
s_logger.debug("The last host of this VM is in avoid set");
190192
}else{
191193
if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) {
192194
if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor, true)){

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -645,63 +645,63 @@ public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.P
645645
s_logger.debug("Deploy avoids pods: " + avoids.getPodsToAvoid() + ", clusters: " + avoids.getClustersToAvoid() + ", hosts: " + avoids.getHostsToAvoid());
646646
}
647647

648-
// edit plan if this vm's ROOT volume is in READY state already
649-
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
648+
650649
boolean planChangedByVolume = false;
651-
boolean rootVolumeisRecreatable = false;
650+
boolean reuseVolume = true;
652651
DataCenterDeployment originalPlan = plan;
653-
for (VolumeVO vol : vols) {
654-
// make sure if the templateId is unchanged. If it is changed,
655-
// let planner
656-
// reassign pool for the volume even if it ready.
657-
Long volTemplateId = vol.getTemplateId();
658-
if (volTemplateId != null && volTemplateId.longValue() != template.getId()) {
659-
if (s_logger.isDebugEnabled()) {
660-
s_logger.debug(vol + " of " + vm + " is READY, but template ids don't match, let the planner reassign a new pool");
661-
}
662-
continue;
663-
}
664652

665-
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
666-
if (!pool.isInMaintenance()) {
667-
if (s_logger.isDebugEnabled()) {
668-
s_logger.debug("Root volume is ready, need to place VM in volume's cluster");
669-
}
670-
long rootVolDcId = pool.getDataCenterId();
671-
Long rootVolPodId = pool.getPodId();
672-
Long rootVolClusterId = pool.getClusterId();
673-
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
674-
Long clusterIdSpecified = planToDeploy.getClusterId();
675-
if (clusterIdSpecified != null && rootVolClusterId != null) {
676-
if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
677-
// cannot satisfy the plan passed in to the
678-
// planner
653+
int retry = _retry;
654+
while (retry-- != 0) { // It's != so that it can match -1.
655+
656+
if(reuseVolume){
657+
// edit plan if this vm's ROOT volume is in READY state already
658+
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
659+
for (VolumeVO vol : vols) {
660+
// make sure if the templateId is unchanged. If it is changed,
661+
// let planner
662+
// reassign pool for the volume even if it ready.
663+
Long volTemplateId = vol.getTemplateId();
664+
if (volTemplateId != null && volTemplateId.longValue() != template.getId()) {
665+
if (s_logger.isDebugEnabled()) {
666+
s_logger.debug(vol + " of " + vm + " is READY, but template ids don't match, let the planner reassign a new pool");
667+
}
668+
continue;
669+
}
670+
671+
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
672+
if (!pool.isInMaintenance()) {
673+
if (s_logger.isDebugEnabled()) {
674+
s_logger.debug("Root volume is ready, need to place VM in volume's cluster");
675+
}
676+
long rootVolDcId = pool.getDataCenterId();
677+
Long rootVolPodId = pool.getPodId();
678+
Long rootVolClusterId = pool.getClusterId();
679+
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
680+
Long clusterIdSpecified = planToDeploy.getClusterId();
681+
if (clusterIdSpecified != null && rootVolClusterId != null) {
682+
if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
683+
// cannot satisfy the plan passed in to the
684+
// planner
685+
if (s_logger.isDebugEnabled()) {
686+
s_logger.debug("Cannot satisfy the deployment plan passed in since the ready Root volume is in different cluster. volume's cluster: " + rootVolClusterId
687+
+ ", cluster specified: " + clusterIdSpecified);
688+
}
689+
throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
690+
+ vm, Cluster.class, clusterIdSpecified);
691+
}
692+
}
693+
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null);
694+
}else{
695+
plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null);
679696
if (s_logger.isDebugEnabled()) {
680-
s_logger.debug("Cannot satisfy the deployment plan passed in since the ready Root volume is in different cluster. volume's cluster: " + rootVolClusterId
681-
+ ", cluster specified: " + clusterIdSpecified);
697+
s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + " , and clusterId: " + rootVolClusterId);
682698
}
683-
throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
684-
+ vm, Cluster.class, clusterIdSpecified);
699+
planChangedByVolume = true;
685700
}
686701
}
687-
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null);
688-
}else{
689-
plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null);
690-
if (s_logger.isDebugEnabled()) {
691-
s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + " , and clusterId: " + rootVolClusterId);
692-
}
693-
planChangedByVolume = true;
694-
if (vol.isRecreatable()) {
695-
rootVolumeisRecreatable = true;
696-
}
697-
698702
}
699703
}
700-
}
701-
702-
int retry = _retry;
703-
while (retry-- != 0) { // It's != so that it can match -1.
704-
704+
705705
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, account, params);
706706
DeployDestination dest = null;
707707
for (DeploymentPlanner planner : _planners) {
@@ -719,11 +719,11 @@ public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.P
719719

720720
if (dest == null) {
721721
if (planChangedByVolume) {
722-
if (rootVolumeisRecreatable) {
723-
plan = originalPlan;
724-
planChangedByVolume = false;
725-
continue;
726-
}
722+
plan = originalPlan;
723+
planChangedByVolume = false;
724+
//do not enter volume reuse for next retry, since we want to look for resorces outside the volume's cluster
725+
reuseVolume = false;
726+
continue;
727727
}
728728
throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
729729
}
@@ -747,7 +747,10 @@ public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.P
747747
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
748748
_storageMgr.prepare(vmProfile, dest);
749749
}
750-
750+
//since StorageMgr succeeded in volume creation, resue Volume for further tries until current cluster has capacity
751+
if(!reuseVolume){
752+
reuseVolume = true;
753+
}
751754
vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx);
752755

753756
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);

0 commit comments

Comments
 (0)