Search in sources :

Example 1 with VMReservationVO

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);
    }
}
Also used : VMReservationVO(com.cloud.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)

Example 2 with VMReservationVO

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

Example 3 with VMReservationVO

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

Example 4 with VMReservationVO

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;
        }
    });
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) SearchCriteria(com.cloud.utils.db.SearchCriteria) VMReservationVO(com.cloud.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(com.cloud.affinity.AffinityGroupProcessor) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine) DB(com.cloud.utils.db.DB)

Example 5 with VMReservationVO

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

Aggregations

VMReservationVO (com.cloud.engine.cloud.entity.api.db.VMReservationVO)8 DB (com.cloud.utils.db.DB)2 VirtualMachine (com.cloud.vm.VirtualMachine)2 AffinityGroupProcessor (com.cloud.affinity.AffinityGroupProcessor)1 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 AllocationState (com.cloud.model.enumeration.AllocationState)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