Search in sources :

Example 1 with VMReservationVO

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

Example 2 with VMReservationVO

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

Example 3 with VMReservationVO

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

Example 4 with VMReservationVO

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

Example 5 with VMReservationVO

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);
    }
}
Also used : VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VMInstanceVO(com.cloud.vm.VMInstanceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AffinityConflictException(com.cloud.exception.AffinityConflictException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

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