use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method finalizeReservation.
@DB
@Override
public String finalizeReservation(final DeployDestination plannedDestination, final VirtualMachineProfile vmProfile, DeploymentPlan plan, 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(TransactionStatus status) {
boolean saveReservation = true;
if (vmGroupCount > 0) {
List<Long> groupIds = _affinityGroupVMMapDao.listAffinityGroupIdsByVmId(vm.getId());
SearchCriteria<AffinityGroupVO> criteria = _affinityGroupDao.createSearchCriteria();
criteria.addAnd("id", SearchCriteria.Op.IN, groupIds.toArray(new Object[groupIds.size()]));
_affinityGroupDao.lockRows(criteria, null, true);
for (AffinityGroupProcessor processor : _affinityProcessors) {
if (!processor.check(vmProfile, plannedDestination)) {
saveReservation = false;
break;
}
}
}
if (saveReservation) {
VMReservationVO vmReservation = new VMReservationVO(vm.getId(), plannedDestination.getDataCenter().getId(), plannedDestination.getPod().getId(), plannedDestination.getCluster().getId(), plannedDestination.getHost().getId());
if (planner != null) {
vmReservation.setDeploymentPlanner(planner.getName());
}
Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>();
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
for (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 org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method postStateTransitionEvent.
@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) {
if (!status) {
return false;
}
State oldState = transition.getCurrentState();
State newState = transition.getToState();
if ((oldState == State.Starting) && (newState != State.Starting)) {
// cleanup all VM reservation entries
SearchCriteria<VMReservationVO> sc = _reservationDao.createSearchCriteria();
sc.addAnd("vmId", SearchCriteria.Op.EQ, vo.getId());
_reservationDao.expunge(sc);
}
return true;
}
use of org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO in project cloudstack by apache.
the class VMEntityDaoImpl method loadVmReservation.
@Override
public void loadVmReservation(VMEntityVO vm) {
VMReservationVO vmReservation = _vmReservationDao.findByVmId(vm.getId());
vm.setVmReservation(vmReservation);
}
Aggregations