Search in sources :

Example 6 with VMReservationVO

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;
        }
    });
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) SearchCriteria(com.cloud.utils.db.SearchCriteria) VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) Volume(com.cloud.storage.Volume) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) AffinityGroupProcessor(org.apache.cloudstack.affinity.AffinityGroupProcessor) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine) DB(com.cloud.utils.db.DB)

Example 7 with VMReservationVO

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;
}
Also used : VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) ResourceState(com.cloud.resource.ResourceState) State(com.cloud.vm.VirtualMachine.State)

Example 8 with VMReservationVO

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);
}
Also used : VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO)

Aggregations

VMReservationVO (org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO)8 DB (com.cloud.utils.db.DB)2 VirtualMachine (com.cloud.vm.VirtualMachine)2 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)1 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 AffinityConflictException (com.cloud.exception.AffinityConflictException)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 ResourceState (com.cloud.resource.ResourceState)1 Volume (com.cloud.storage.Volume)1 SearchCriteria (com.cloud.utils.db.SearchCriteria)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 State (com.cloud.vm.VirtualMachine.State)1