Search in sources :

Example 71 with ExcludeList

use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.

the class ManagementServerImpl method listStoragePoolsForMigrationOfVolumeInternal.

public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool) {
    final Account caller = getCaller();
    if (!_accountMgr.isRootAdmin(caller.getId())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Caller is not a root admin, permission denied to migrate the volume");
        }
        throw new PermissionDeniedException("No permission to migrate volume, only root admin can migrate a volume");
    }
    final VolumeVO volume = _volumeDao.findById(volumeId);
    if (volume == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find volume with" + " specified id.");
        ex.addProxyObject(volumeId.toString(), "volumeId");
        throw ex;
    }
    Long diskOfferingId = volume.getDiskOfferingId();
    if (newDiskOfferingId != null) {
        diskOfferingId = newDiskOfferingId;
    }
    // Volume must be attached to an instance for live migration.
    List<? extends StoragePool> allPools = new ArrayList<StoragePool>();
    List<? extends StoragePool> suitablePools = new ArrayList<StoragePool>();
    // Volume must be in Ready state to be migrated.
    if (!Volume.State.Ready.equals(volume.getState())) {
        s_logger.info("Volume " + volume + " must be in ready state for migration.");
        return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
    }
    final Long instanceId = volume.getInstanceId();
    VMInstanceVO vm = null;
    if (instanceId != null) {
        vm = _vmInstanceDao.findById(instanceId);
    }
    if (vm == null) {
        s_logger.info("Volume " + volume + " isn't attached to any vm. Looking for storage pools in the " + "zone to which this volumes can be migrated.");
    } else if (vm.getState() != State.Running) {
        s_logger.info("Volume " + volume + " isn't attached to any running vm. Looking for storage pools in the " + "cluster to which this volumes can be migrated.");
    } else {
        s_logger.info("Volume " + volume + " is attached to any running vm. Looking for storage pools in the " + "cluster to which this volumes can be migrated.");
        boolean storageMotionSupported = false;
        // Check if the underlying hypervisor supports storage motion.
        final Long hostId = vm.getHostId();
        if (hostId != null) {
            final HostVO host = _hostDao.findById(hostId);
            HypervisorCapabilitiesVO capabilities = null;
            if (host != null) {
                capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(host.getHypervisorType(), host.getHypervisorVersion());
            } else {
                s_logger.error("Details of the host on which the vm " + vm + ", to which volume " + volume + " is " + "attached, couldn't be retrieved.");
            }
            if (capabilities != null) {
                storageMotionSupported = capabilities.isStorageMotionSupported();
            } else {
                s_logger.error("Capabilities for host " + host + " couldn't be retrieved.");
            }
        }
        if (!storageMotionSupported) {
            s_logger.info("Volume " + volume + " is attached to a running vm and the hypervisor doesn't support" + " storage motion.");
            return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
        }
    }
    StoragePool srcVolumePool = _poolDao.findById(volume.getPoolId());
    HypervisorType hypervisorType = getHypervisorType(vm, srcVolumePool);
    Pair<Host, List<Cluster>> hostClusterPair = getVolumeVmHostClusters(srcVolumePool, vm, hypervisorType);
    Host vmHost = hostClusterPair.first();
    List<Cluster> clusters = hostClusterPair.second();
    allPools = getAllStoragePoolCompatibleWithVolumeSourceStoragePool(srcVolumePool, hypervisorType, clusters);
    ExcludeList avoid = new ExcludeList();
    if (!keepSourceStoragePool) {
        allPools.remove(srcVolumePool);
        avoid.addPool(srcVolumePool.getId());
    }
    if (vm != null) {
        suitablePools = findAllSuitableStoragePoolsForVm(volume, diskOfferingId, newSize, newMinIops, newMaxIops, vm, vmHost, avoid, CollectionUtils.isNotEmpty(clusters) ? clusters.get(0) : null, hypervisorType);
    } else {
        suitablePools = findAllSuitableStoragePoolsForDetachedVolume(volume, diskOfferingId, allPools);
    }
    removeDataStoreClusterParents((List<StoragePool>) allPools);
    removeDataStoreClusterParents((List<StoragePool>) suitablePools);
    return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
}
Also used : HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) Account(com.cloud.user.Account) StoragePool(com.cloud.storage.StoragePool) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) Cluster(com.cloud.org.Cluster) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair)

Example 72 with ExcludeList

use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.

the class StorageAllocatorTest method testCLOUDSTACK3481.

@Test
public void testCLOUDSTACK3481() {
    try {
        createDb();
        StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
        pool.setHypervisor(HypervisorType.KVM);
        pool.setScope(ScopeType.ZONE);
        pool.setClusterId(null);
        pool.setPodId(null);
        storagePoolDao.update(pool.getId(), pool);
        DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.KVM);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Account account = Mockito.mock(Account.class);
        Mockito.when(account.getAccountId()).thenReturn(1L);
        Mockito.when(vmProfile.getHypervisorType()).thenReturn(HypervisorType.KVM);
        Mockito.when(vmProfile.getOwner()).thenReturn(account);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        Mockito.when(storageMgr.storagePoolHasEnoughIops(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) Account(com.cloud.user.Account) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 73 with ExcludeList

use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.

the class StorageAllocatorTest method testClusterAllocatorWithWrongTag.

@Test
public void testClusterAllocatorWithWrongTag() {
    try {
        createDb();
        StoragePoolDetailVO detailVO = new StoragePoolDetailVO(this.storagePoolId, "high", "true", true);
        poolDetailsDao.persist(detailVO);
        DiskOfferingVO diskOff = this.diskOfferingDao.findById(diskOffering.getId());
        List<String> tags = new ArrayList<String>();
        tags.add("low");
        diskOff.setTagsArray(tags);
        diskOfferingDao.update(diskOff.getId(), diskOff);
        DiskProfile profile = new DiskProfile(volume, diskOff, HypervisorType.XenServer);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                foundAcct++;
            }
        }
        if (foundAcct != 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) ArrayList(java.util.ArrayList) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 74 with ExcludeList

use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.

the class StorageAllocatorTest method testPoolStateIsNotUp.

@Test
public void testPoolStateIsNotUp() {
    try {
        createDb();
        StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
        pool.setScope(ScopeType.ZONE);
        pool.setStatus(StoragePoolStatus.Maintenance);
        storagePoolDao.update(pool.getId(), pool);
        DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct == 1) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Volume(com.cloud.storage.Volume) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 75 with ExcludeList

use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cloudstack by apache.

the class ImplicitPlannerTest method checkStrictModeWithCurrentAccountVmsPresent.

@Test
public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientServerCapacityException {
    VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    ExcludeList avoids = new ExcludeList();
    initializeForTest(vmProfile, plan);
    initializeForImplicitPlannerTest(false);
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    // Validations.
    // Check cluster 2 and 3 are not in the cluster list.
    // Host 6 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 != 1) {
            fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
        } else {
            foundNeededCluster = true;
        }
    }
    assertTrue("Didn't find cluster 1 in the list. It should have been present", foundNeededCluster);
    Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
    assertFalse("Host 5 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(5L));
    Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
    hostsThatShouldBeInAvoidList.add(6L);
    hostsThatShouldBeInAvoidList.add(7L);
    assertTrue("Hosts 6 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)

Aggregations

ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)78 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)45 ArrayList (java.util.ArrayList)32 StoragePool (com.cloud.storage.StoragePool)30 Test (org.junit.Test)30 HashMap (java.util.HashMap)23 Volume (com.cloud.storage.Volume)21 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)18 List (java.util.List)18 Host (com.cloud.host.Host)16 HostVO (com.cloud.host.HostVO)16 Pair (com.cloud.utils.Pair)16 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)16 DiskProfile (com.cloud.vm.DiskProfile)15 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)15 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)14 VolumeVO (com.cloud.storage.VolumeVO)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 Account (com.cloud.user.Account)12 Map (java.util.Map)11