Skip to content

Commit 0e689db

Browse files
author
Prachi Damle
committed
CLOUDSTACK-2096 Deployment Planner - Deployment planner is not looking for hosts in other clusters when vm is being started.
Changes: - Cloud-engine 2 step reserver and deploy flow was not retrying out of clusters, if there are no resources in the volume's cluster. - Fixed this by letting the reservationm step not error out and continue to let deploy step find out resources outside cluster
1 parent b888450 commit 0e689db

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface VMEntityManager {
3737

3838
String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan plan, ExcludeList exclude) throws InsufficientCapacityException, ResourceUnavailableException;
3939

40-
void deployVirtualMachine(String reservationId, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException;
40+
void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException;
4141

4242
boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException;
4343

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.UUID;
2324

2425
import javax.inject.Inject;
2526

@@ -136,6 +137,7 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
136137
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
137138
}
138139

140+
boolean planChangedByReadyVolume = false;
139141
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
140142
if(!vols.isEmpty()){
141143
VolumeVO vol = vols.get(0);
@@ -158,7 +160,7 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
158160
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
159161
}else{
160162
plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
161-
163+
planChangedByReadyVolume = true;
162164
}
163165
}
164166

@@ -187,38 +189,47 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
187189
_vmEntityDao.persist(vmEntityVO);
188190

189191
return vmReservation.getUuid();
192+
} else if (planChangedByReadyVolume) {
193+
// we could not reserve in the Volume's cluster - let the deploy
194+
// call retry it.
195+
return UUID.randomUUID().toString();
190196
}else{
191197
throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
192198
}
193199

194200
}
195201

196202
@Override
197-
public void deployVirtualMachine(String reservationId, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException{
203+
public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException{
198204
//grab the VM Id and destination using the reservationId.
199205

206+
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
207+
200208
VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
201-
long vmId = vmReservation.getVmId();
202-
203-
VMInstanceVO vm = _vmDao.findById(vmId);
204-
//Pass it down
205-
Long poolId = null;
206-
Map<Long,Long> storage = vmReservation.getVolumeReservation();
207-
if(storage != null){
208-
List<Long> volIdList = new ArrayList<Long>(storage.keySet());
209-
if(volIdList !=null && !volIdList.isEmpty()){
210-
poolId = storage.get(volIdList.get(0));
209+
if(vmReservation != null){
210+
// Pass it down
211+
Long poolId = null;
212+
Map<Long, Long> storage = vmReservation.getVolumeReservation();
213+
if (storage != null) {
214+
List<Long> volIdList = new ArrayList<Long>(storage.keySet());
215+
if (volIdList != null && !volIdList.isEmpty()) {
216+
poolId = storage.get(volIdList.get(0));
217+
}
211218
}
212-
}
213219

214-
DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
215-
vmReservation.getHostId(), null , null);
216-
try{
217-
VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), reservedPlan);
218-
}catch(Exception ex){
219-
//Retry the deployment without using the reservation plan
220-
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), null, null,null, null , null);
221-
_itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);
220+
DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(),
221+
vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
222+
try {
223+
VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)),
224+
_accountDao.findById(vm.getAccountId()), reservedPlan);
225+
} catch (Exception ex) {
226+
// Retry the deployment without using the reservation plan
227+
_itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()),
228+
null);
229+
}
230+
} else {
231+
// no reservation found. Let VirtualMachineManager retry
232+
_itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), null);
222233
}
223234

224235
}

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void migrateTo(String reservationId, String caller) {
206206

207207
@Override
208208
public void deploy(String reservationId, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException{
209-
manager.deployVirtualMachine(reservationId, caller, params);
209+
manager.deployVirtualMachine(reservationId, this.vmEntityVO, caller, params);
210210
}
211211

212212
@Override

0 commit comments

Comments
 (0)