use of com.cloud.engine.cloud.entity.api.db.VMReservationVO in project cosmic by MissionCriticalCloud.
the class VMEntityManagerImpl method deployVirtualMachine.
@Override
public void deployVirtualMachine(final String reservationId, final VMEntityVO vmEntityVO, final String caller, final Map<VirtualMachineProfile.Param, Object> params, final boolean deployOnGivenHost) throws InsufficientCapacityException, ResourceUnavailableException {
// grab the VM Id and destination using the reservationId.
final VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
final VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
if (vmReservation != null) {
final DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
try {
_itMgr.start(vm.getUuid(), params, reservedPlan, _planningMgr.getDeploymentPlannerByName(vmReservation.getDeploymentPlanner()));
} catch (final Exception ex) {
// the instance may be started on another host instead of the intended one.
if (!deployOnGivenHost) {
final DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
if (reservedPlan.getAvoids() != null) {
plan.setAvoids(reservedPlan.getAvoids());
}
_itMgr.start(vm.getUuid(), params, plan, null);
}
}
} else {
// no reservation found. Let VirtualMachineManager retry
_itMgr.start(vm.getUuid(), params, null, null);
}
}
use of com.cloud.engine.cloud.entity.api.db.VMReservationVO in project cosmic by MissionCriticalCloud.
the class VMReservationDaoImpl method findByVmId.
@Override
public VMReservationVO findByVmId(final long vmId) {
final SearchCriteria<VMReservationVO> sc = VmIdSearch.create("vmId", vmId);
final VMReservationVO vmRes = findOneBy(sc);
loadVolumeReservation(vmRes);
return vmRes;
}
use of com.cloud.engine.cloud.entity.api.db.VMReservationVO in project cosmic by MissionCriticalCloud.
the class VMReservationDaoImpl method findByReservationId.
@Override
public VMReservationVO findByReservationId(final String reservationId) {
final VMReservationVO vmRes = super.findByUuid(reservationId);
loadVolumeReservation(vmRes);
return vmRes;
}
use of com.cloud.engine.cloud.entity.api.db.VMReservationVO in project cosmic by MissionCriticalCloud.
the class DeploymentPlanningManagerImpl method finalizeReservation.
@DB
@Override
public String finalizeReservation(final DeployDestination plannedDestination, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoids, final DeploymentPlanner planner) throws InsufficientServerCapacityException, AffinityConflictException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
return Transaction.execute(new TransactionCallback<String>() {
@Override
public String doInTransaction(final TransactionStatus status) {
boolean saveReservation = true;
if (vmGroupCount > 0) {
final List<Long> groupIds = _affinityGroupVMMapDao.listAffinityGroupIdsByVmId(vm.getId());
final SearchCriteria<AffinityGroupVO> criteria = _affinityGroupDao.createSearchCriteria();
criteria.addAnd("id", SearchCriteria.Op.IN, groupIds.toArray(new Object[groupIds.size()]));
_affinityGroupDao.lockRows(criteria, null, true);
for (final AffinityGroupProcessor processor : _affinityProcessors) {
if (!processor.check(vmProfile, plannedDestination)) {
saveReservation = false;
break;
}
}
}
if (saveReservation) {
final VMReservationVO vmReservation = new VMReservationVO(vm.getId(), plannedDestination.getZone().getId(), plannedDestination.getPod().getId(), plannedDestination.getCluster().getId(), plannedDestination.getHost().getId());
if (planner != null) {
vmReservation.setDeploymentPlanner(planner.getName());
}
final Map<Long, Long> volumeReservationMap = new HashMap<>();
for (final Volume vo : plannedDestination.getStorageForDisks().keySet()) {
volumeReservationMap.put(vo.getId(), plannedDestination.getStorageForDisks().get(vo).getId());
}
vmReservation.setVolumeReservation(volumeReservationMap);
_reservationDao.persist(vmReservation);
return vmReservation.getUuid();
}
return null;
}
});
}
use of com.cloud.engine.cloud.entity.api.db.VMReservationVO in project cosmic by MissionCriticalCloud.
the class VMEntityDaoImpl method loadVmReservation.
@Override
public void loadVmReservation(final VMEntityVO vm) {
final VMReservationVO vmReservation = _vmReservationDao.findByVmId(vm.getId());
vm.setVmReservation(vmReservation);
}
Aggregations