use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class HostAntiAffinityProcessor method check.
@Override
public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) throws AffinityConflictException {
if (plannedDestination.getHost() == null) {
return true;
}
long plannedHostId = plannedDestination.getHost().getId();
VirtualMachine vm = vmProfile.getVirtualMachine();
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
// if more than 1 VM's are present in the group then check for
// conflict due to parallel deployment
List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId());
groupVMIds.remove(vm.getId());
for (Long groupVMId : groupVMIds) {
VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId);
if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " + plannedHostId);
}
return false;
}
}
}
return true;
}
use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class VMReservationDaoImpl method findByReservationId.
@Override
public VMReservationVO findByReservationId(String reservationId) {
VMReservationVO vmRes = super.findByUuid(reservationId);
loadVolumeReservation(vmRes);
return vmRes;
}
use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class VMReservationDaoImpl method persist.
@Override
@DB
public VMReservationVO persist(VMReservationVO reservation) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
VMReservationVO dbVO = super.persist(reservation);
saveVolumeReservation(reservation);
loadVolumeReservation(dbVO);
txn.commit();
return dbVO;
}
use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class VMReservationDaoImpl method findByVmId.
@Override
public VMReservationVO findByVmId(long vmId) {
SearchCriteria<VMReservationVO> sc = VmIdSearch.create("vmId", vmId);
VMReservationVO vmRes = findOneBy(sc);
loadVolumeReservation(vmRes);
return vmRes;
}
use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class VMEntityManagerImpl method deployVirtualMachine.
@Override
public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException {
//grab the VM Id and destination using the reservationId.
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
if (vmReservation != null) {
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 (Exception ex) {
// Retry the deployment without using the reservation plan
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);
}
}
Aggregations