Search in sources :

Example 31 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (destPool == null) {
        throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
    }
    try {
        stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
    } catch (final NoTransitionException e) {
        s_logger.debug("Unable to migrate vm: " + e.toString());
        throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    boolean migrationResult = false;
    try {
        migrationResult = volumeMgr.storageMigration(profile, destPool);
        if (migrationResult) {
            if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
                final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
                final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
                _networkMgr.reallocate(vmProfile, plan);
            }
            // when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
            vm.setLastHostId(null);
            vm.setPodIdToDeployIn(destPool.getPodId());
        } else {
            s_logger.debug("Storage migration failed");
        }
    } catch (final ConcurrentOperationException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientVirtualNetworkCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final StorageUnavailableException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } finally {
        try {
            stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to change vm state: " + e.toString());
            throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
        }
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 32 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method findHostAndMigrate.

@Override
public void findHostAndMigrate(final String vmUuid, final Long newSvcOfferingId, final ExcludeList excludes) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        throw new CloudRuntimeException("Unable to find " + vmUuid);
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    final Long srcHostId = vm.getHostId();
    final Long oldSvcOfferingId = vm.getServiceOfferingId();
    if (srcHostId == null) {
        throw new CloudRuntimeException("Unable to scale the vm because it doesn't have a host id");
    }
    final Host host = _hostDao.findById(srcHostId);
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, null, null);
    excludes.addHost(vm.getHostId());
    // Need to find the destination host based on new svc offering
    vm.setServiceOfferingId(newSvcOfferingId);
    DeployDestination dest = null;
    try {
        dest = _dpMgr.planDeployment(profile, plan, excludes, null);
    } catch (final AffinityConflictException e2) {
        s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
        throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
    }
    if (dest != null) {
        s_logger.debug(" Found " + dest + " for scaling the vm to.");
    }
    if (dest == null) {
        throw new InsufficientServerCapacityException("Unable to find a server to scale the vm to.", host.getClusterId());
    }
    excludes.addHost(dest.getHost().getId());
    try {
        migrateForScale(vm.getUuid(), srcHostId, dest, oldSvcOfferingId);
    } catch (final ResourceUnavailableException e) {
        s_logger.debug("Unable to migrate to unavailable " + dest);
        throw e;
    } catch (final ConcurrentOperationException e) {
        s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
        throw e;
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 33 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment 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 34 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cosmic by MissionCriticalCloud.

the class VMEntityManagerImpl method reserveVirtualMachine.

@Override
public String reserveVirtualMachine(final VMEntityVO vmEntityVO, final DeploymentPlanner plannerToUse, final DeploymentPlan planToDeploy, final ExcludeList exclude) throws InsufficientCapacityException, ResourceUnavailableException {
    // call planner and get the deployDestination.
    // load vm instance and offerings and call virtualMachineManagerImpl
    // FIXME: profile should work on VirtualMachineEntity
    final VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
    vmProfile.setServiceOffering(_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()));
    DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
    if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
        plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
    }
    boolean planChangedByReadyVolume = false;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    if (!vols.isEmpty()) {
        final VolumeVO vol = vols.get(0);
        final StoragePool pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
        if (!pool.isInMaintenance()) {
            final long rootVolDcId = pool.getDataCenterId();
            final Long rootVolPodId = pool.getPodId();
            final Long rootVolClusterId = pool.getClusterId();
            if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
                final Long clusterIdSpecified = planToDeploy.getClusterId();
                if (clusterIdSpecified != null && rootVolClusterId != null) {
                    checkIfPlanIsDeployable(vm, rootVolClusterId, clusterIdSpecified);
                }
                plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
            } else {
                plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
                planChangedByReadyVolume = true;
            }
        }
    }
    while (true) {
        DeployDestination dest = null;
        try {
            dest = _dpMgr.planDeployment(vmProfile, plan, exclude, plannerToUse);
        } catch (final AffinityConflictException e) {
            throw new CloudRuntimeException("Unable to create deployment, affinity rules associated to the VM conflict");
        }
        if (dest != null) {
            final String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude, plannerToUse);
            if (reservationId != null) {
                return reservationId;
            } else {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Cannot finalize the VM reservation for this destination found, retrying");
                }
                exclude.addHost(dest.getHost().getId());
                continue;
            }
        } else if (planChangedByReadyVolume) {
            // call retry it.
            return UUID.randomUUID().toString();
        } else {
            throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile));
        }
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StoragePool(com.cloud.storage.StoragePool) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) VMInstanceVO(com.cloud.vm.VMInstanceVO) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) AffinityConflictException(com.cloud.exception.AffinityConflictException) DataCenter(com.cloud.dc.DataCenter) VolumeVO(com.cloud.storage.VolumeVO) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 35 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cosmic by MissionCriticalCloud.

the class ImplicitPlannerTest method checkStrictModeNoHostsAvailable.

@Test
public void checkStrictModeNoHostsAvailable() throws InsufficientServerCapacityException {
    final VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    final DataCenterDeployment plan = mock(DataCenterDeployment.class);
    final ExcludeList avoids = new ExcludeList();
    initializeForTest(vmProfile, plan);
    initializeForImplicitPlannerTest(false);
    // Mark the host 5 and 6 to be in avoid list.
    avoids.addHost(5L);
    avoids.addHost(6L);
    final List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    // Validations.
    // Check cluster list is empty.
    assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) Test(org.junit.Test)

Aggregations

DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)87 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)45 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)34 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)26 StoragePool (com.cloud.storage.StoragePool)25 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)24 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)18 HashMap (java.util.HashMap)18 DeployDestination (com.cloud.deploy.DeployDestination)16 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)16 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)15 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)15 Host (com.cloud.host.Host)15 VolumeVO (com.cloud.storage.VolumeVO)15 Account (com.cloud.user.Account)15 DiskProfile (com.cloud.vm.DiskProfile)15 LinkedHashMap (java.util.LinkedHashMap)15 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)14