Search in sources :

Example 76 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ImplicitPlannerTest method checkStrictModeNoHostsAvailable.

@Test
public void checkStrictModeNoHostsAvailable() throws InsufficientServerCapacityException {
    @SuppressWarnings("unchecked") VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    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);
    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)

Example 77 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ImplicitPlannerTest method checkWhenDcInAvoidList.

@Test
public void checkWhenDcInAvoidList() throws InsufficientServerCapacityException {
    DataCenterVO mockDc = mock(DataCenterVO.class);
    ExcludeList avoids = mock(ExcludeList.class);
    VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    VMInstanceVO vm = mock(VMInstanceVO.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    when(avoids.shouldAvoid(mockDc)).thenReturn(true);
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    when(vm.getDataCenterId()).thenReturn(1L);
    when(dcDao.findById(1L)).thenReturn(mockDc);
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    assertTrue("Cluster list should be null/empty if the dc is in avoid list", (clusterList == null || clusterList.isEmpty()));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) VMInstanceVO(com.cloud.vm.VMInstanceVO) Test(org.junit.Test)

Example 78 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ImplicitPlannerTest method checkStrictModeHostWithCurrentAccountVmsFull.

@Test
public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientServerCapacityException {
    @SuppressWarnings("unchecked") VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    ExcludeList avoids = new ExcludeList();
    initializeForTest(vmProfile, plan);
    initializeForImplicitPlannerTest(false);
    // Mark the host 5 with current account vms to be in avoid list.
    avoids.addHost(5L);
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    // Validations.
    // Check cluster 1 and 3 are not in the cluster list.
    // Host 5 and 7 should also be in avoid list.
    assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
    boolean foundNeededCluster = false;
    for (Long cluster : clusterList) {
        if (cluster != 2) {
            fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
        } else {
            foundNeededCluster = true;
        }
    }
    assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
    Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
    assertFalse("Host 6 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(6L));
    Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
    hostsThatShouldBeInAvoidList.add(5L);
    hostsThatShouldBeInAvoidList.add(7L);
    assertTrue("Hosts 5 and 7 that should have been present were not found in avoid list", hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with DataCenterDeployment

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

the class VirtualMachineManagerImpl method orchestrateMigrateAway.

private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        s_logger.debug("Unable to find a VM for " + vmUuid);
        throw new CloudRuntimeException("Unable to find " + vmUuid);
    }
    final ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    final Long hostId = vm.getHostId();
    if (hostId == null) {
        s_logger.debug("Unable to migrate because the VM doesn't have a host id: " + vm);
        throw new CloudRuntimeException("Unable to migrate " + vmUuid);
    }
    final Host host = _hostDao.findById(hostId);
    Long poolId = null;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    for (final VolumeVO rootVolumeOfVm : vols) {
        final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
        if (rootDiskPool != null) {
            poolId = rootDiskPool.getId();
        }
    }
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, poolId, null);
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(hostId);
    DeployDestination dest = null;
    while (true) {
        dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
        if (dest != null) {
            s_logger.debug("Found destination " + dest + " for migrating to.");
        } else {
            s_logger.debug("Unable to find destination for migrating the vm " + profile);
            throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", host.getClusterId());
        }
        excludes.addHost(dest.getHost().getId());
        try {
            migrate(vm, srcHostId, dest);
            return;
        } catch (final ResourceUnavailableException e) {
            s_logger.debug("Unable to migrate to unavailable " + dest);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
        }
        try {
            advanceStop(vmUuid, true);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ResourceUnavailableException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final OperationTimedoutException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        }
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.legacymodel.exceptions.InsufficientServerCapacityException) Host(com.cloud.legacymodel.dc.Host) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException)

Example 80 with DataCenterDeployment

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

the class VmWorkStart method getPlan.

public DeploymentPlan getPlan() {
    if (podId != null || clusterId != null || hostId != null || poolId != null || physicalNetworkId != null || avoids != null) {
        // this is ugly, to work with legacy code, we need to re-construct the DeploymentPlan hard-codely
        // this has to be refactored together with migrating legacy code into the new way
        ReservationContext context = null;
        if (reservationId != null) {
            final Journal journal = new Journal.LogJournal("VmWorkStart", s_logger);
            context = new ReservationContextImpl(reservationId, journal, CallContext.current().getCallingUser(), CallContext.current().getCallingAccount());
        }
        final DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, hostId, poolId, physicalNetworkId, context);
        plan.setAvoids(avoids);
        return plan;
    }
    return null;
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Journal(com.cloud.utils.Journal) DeploymentPlan(com.cloud.deploy.DeploymentPlan)

Aggregations

DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)89 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)45 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)24 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 StoragePool (com.cloud.storage.StoragePool)19 HashMap (java.util.HashMap)19 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)18 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)17 DeployDestination (com.cloud.deploy.DeployDestination)16 VolumeVO (com.cloud.storage.VolumeVO)16 LinkedHashMap (java.util.LinkedHashMap)16 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)14 DeploymentPlan (com.cloud.deploy.DeploymentPlan)13 NetworkVO (com.cloud.network.dao.NetworkVO)13 List (java.util.List)13 DiskProfile (com.cloud.vm.DiskProfile)12 VMInstanceVO (com.cloud.vm.VMInstanceVO)12 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)11