//call planner and get the deployDestination.
//load vm instance and offerings and call virtualMachineManagerImpl
//FIXME: profile should work on VirtualMachineEntity
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
}
boolean planChangedByReadyVolume = false;
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
if(!vols.isEmpty()){
VolumeVO vol = vols.get(0);
StoragePool pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
if (!pool.isInMaintenance()) {
long rootVolDcId = pool.getDataCenterId();
Long rootVolPodId = pool.getPodId();
Long rootVolClusterId = pool.getClusterId();
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
Long clusterIdSpecified = planToDeploy.getClusterId();
if (clusterIdSpecified != null && rootVolClusterId != null) {
if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
// cannot satisfy the plan passed in to the
// planner
throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
+ vm, Cluster.class, clusterIdSpecified);
}
}
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
}else{
plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
planChangedByReadyVolume = true;
}
}
}
while (true) {
DeployDestination dest = null;
try {
dest = _dpMgr.planDeployment(vmProfile, plan, exclude);
} catch (AffinityConflictException e) {
throw new CloudRuntimeException(
"Unable to create deployment, affinity rules associted to the VM conflict");
}
if (dest != null) {
String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude);
if(reservationId != null){
return reservationId;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot finalize the VM reservation for this destination found, retrying");
}
exclude.addHost(dest.getHost().getId());
continue;
}
} else if (planChangedByReadyVolume) {
// we could not reserve in the Volume's cluster - let the deploy
// call retry it.
return UUID.randomUUID().toString();
} else {
throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile,
DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile));
}
}
}