Search in sources :

Example 51 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class SolidFireHostListener method handleKVM.

private void handleKVM(long hostId, long storagePoolId) {
    StoragePool storagePool = (StoragePool) dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool);
    sendModifyStoragePoolCommand(cmd, storagePool, hostId);
}
Also used : StoragePool(com.cloud.storage.StoragePool) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 52 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class SolidFireSharedHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long storagePoolId) {
    StoragePool storagePool = (StoragePool) dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool);
    ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, hostId);
    StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId);
    if (storagePoolHost != null) {
        storagePoolHost.setLocalPath(answer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    } else {
        storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, answer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(storagePoolHost);
    }
    StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);
    storagePoolVO.setCapacityBytes(answer.getPoolInfo().getCapacityBytes());
    storagePoolVO.setUsedBytes(answer.getPoolInfo().getCapacityBytes() - answer.getPoolInfo().getAvailableBytes());
    storagePoolDao.update(storagePoolId, storagePoolVO);
    return true;
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 53 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class DeploymentPlanningManagerImpl method checkClustersforDestination.

// /refactoring planner methods
private DeployDestination checkClustersforDestination(List<Long> clusterList, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, DataCenter dc, DeploymentPlanner.PlannerResourceUsage resourceUsageRequired, ExcludeList plannerAvoidOutput) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("ClusterId List to consider: " + clusterList);
    }
    for (Long clusterId : clusterList) {
        ClusterVO clusterVO = _clusterDao.findById(clusterId);
        if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) {
            s_logger.debug("Cluster: " + clusterId + " has HyperVisorType that does not match the VM, skipping this cluster");
            avoid.addCluster(clusterVO.getId());
            continue;
        }
        s_logger.debug("Checking resources in Cluster: " + clusterId + " under Pod: " + clusterVO.getPodId());
        // search for resources(hosts and storage) under this zone, pod,
        // cluster.
        DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId(), null, plan.getReservationContext());
        Pod pod = _podDao.findById(clusterVO.getPodId());
        if (CollectionUtils.isNotEmpty(avoid.getPodsToAvoid()) && avoid.getPodsToAvoid().contains(pod.getId())) {
            s_logger.debug("The cluster is in a disabled pod : " + pod.getId());
        } else {
            // find suitable hosts under this cluster, need as many hosts as we
            // get.
            List<Host> suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
            // pools for each volume of the VM
            if (suitableHosts != null && !suitableHosts.isEmpty()) {
                if (vmProfile.getHypervisorType() == HypervisorType.BareMetal) {
                    DeployDestination dest = new DeployDestination(dc, pod, clusterVO, suitableHosts.get(0));
                    return dest;
                }
                Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, potentialPlan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
                Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
                List<Volume> readyAndReusedVolumes = result.second();
                // choose the potential host and pool for the VM
                if (!suitableVolumeStoragePools.isEmpty()) {
                    Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools, avoid, resourceUsageRequired, readyAndReusedVolumes, plan.getPreferredHosts(), vmProfile.getVirtualMachine());
                    if (potentialResources != null) {
                        Host host = _hostDao.findById(potentialResources.first().getId());
                        Map<Volume, StoragePool> storageVolMap = potentialResources.second();
                        // we don't have to prepare this volume.
                        for (Volume vol : readyAndReusedVolumes) {
                            storageVolMap.remove(vol);
                        }
                        boolean displayStorage = getDisplayStorageFromVmProfile(vmProfile);
                        DeployDestination dest = new DeployDestination(dc, pod, clusterVO, host, storageVolMap, displayStorage);
                        s_logger.debug("Returning Deployment Destination: " + dest);
                        return dest;
                    }
                } else {
                    s_logger.debug("No suitable storagePools found under this Cluster: " + clusterId);
                }
            } else {
                s_logger.debug("No suitable hosts found under this Cluster: " + clusterId);
            }
        }
        if (canAvoidCluster(clusterVO, avoid, plannerAvoidOutput, vmProfile)) {
            avoid.addCluster(clusterVO.getId());
        }
    }
    s_logger.debug("Could not find suitable Deployment Destination for this VM under any clusters, returning. ");
    return null;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StoragePool(com.cloud.storage.StoragePool) Pod(com.cloud.dc.Pod) Host(com.cloud.host.Host) Volume(com.cloud.storage.Volume) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class DeploymentPlanningManagerImpl method findPotentialDeploymentResources.

protected Pair<Host, Map<Volume, StoragePool>> findPotentialDeploymentResources(List<Host> suitableHosts, Map<Volume, List<StoragePool>> suitableVolumeStoragePools, ExcludeList avoid, PlannerResourceUsage resourceUsageRequired, List<Volume> readyAndReusedVolumes, List<Long> preferredHosts, VirtualMachine vm) {
    s_logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM");
    boolean hostCanAccessPool = false;
    boolean haveEnoughSpace = false;
    boolean hostAffinityCheck = false;
    if (readyAndReusedVolumes == null) {
        readyAndReusedVolumes = new ArrayList<Volume>();
    }
    Map<Volume, StoragePool> storage = new HashMap<Volume, StoragePool>();
    TreeSet<Volume> volumesOrderBySizeDesc = new TreeSet<Volume>(new Comparator<Volume>() {

        @Override
        public int compare(Volume v1, Volume v2) {
            if (v1.getSize() < v2.getSize())
                return 1;
            else
                return -1;
        }
    });
    volumesOrderBySizeDesc.addAll(suitableVolumeStoragePools.keySet());
    boolean multipleVolume = volumesOrderBySizeDesc.size() > 1;
    boolean deployAsIs = isDeployAsIs(vm);
    for (Host potentialHost : suitableHosts) {
        Map<StoragePool, List<Volume>> volumeAllocationMap = new HashMap<StoragePool, List<Volume>>();
        if (deployAsIs) {
            storage = new HashMap<>();
            // Find the common suitable pools
            s_logger.debug("Trying to allocate all the VM volumes to a single storage pool");
            Set<StoragePool> suitablePools = new HashSet<>();
            List<StoragePool> notAllowedPools = new ArrayList<>();
            for (List<StoragePool> pools : suitableVolumeStoragePools.values()) {
                if (CollectionUtils.isEmpty(suitablePools)) {
                    // All the suitable pools of the first volume
                    suitablePools.addAll(pools);
                } else {
                    for (StoragePool pool : pools) {
                        if (!suitablePools.contains(pool)) {
                            s_logger.debug("Storage pool " + pool.getUuid() + " not allowed for this VM");
                            notAllowedPools.add(pool);
                        }
                    }
                }
            }
            suitablePools.removeAll(notAllowedPools);
            if (CollectionUtils.isEmpty(suitablePools)) {
                s_logger.debug("Could not find a storage pool to fit all the VM volumes on this host");
                continue;
            }
            List<Volume> allVolumes = new ArrayList<>();
            allVolumes.addAll(volumesOrderBySizeDesc);
            List<Pair<Volume, DiskProfile>> volumeDiskProfilePair = getVolumeDiskProfilePairs(allVolumes);
            for (StoragePool storagePool : suitablePools) {
                haveEnoughSpace = false;
                hostCanAccessPool = false;
                hostAffinityCheck = checkAffinity(potentialHost, preferredHosts);
                if (hostCanAccessSPool(potentialHost, storagePool)) {
                    hostCanAccessPool = true;
                    if (potentialHost.getHypervisorType() == HypervisorType.VMware) {
                        try {
                            boolean isStoragePoolStoragepolicyComplaince = _storageMgr.isStoragePoolCompliantWithStoragePolicy(volumeDiskProfilePair, storagePool);
                            if (!isStoragePoolStoragepolicyComplaince) {
                                continue;
                            }
                        } catch (StorageUnavailableException e) {
                            s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", storagePool.getUuid(), e.getMessage()));
                            continue;
                        }
                        haveEnoughSpace = true;
                    }
                }
                if (hostCanAccessPool && haveEnoughSpace && hostAffinityCheck) {
                    for (Volume vol : volumesOrderBySizeDesc) {
                        s_logger.debug("Found a suitable storage pool for all the VM volumes: " + storagePool.getUuid());
                        storage.put(vol, storagePool);
                    }
                    break;
                }
            }
        } else {
            for (Volume vol : volumesOrderBySizeDesc) {
                haveEnoughSpace = false;
                s_logger.debug("Checking if host: " + potentialHost.getId() + " can access any suitable storage pool for volume: " + vol.getVolumeType());
                List<StoragePool> volumePoolList = suitableVolumeStoragePools.get(vol);
                hostCanAccessPool = false;
                hostAffinityCheck = checkAffinity(potentialHost, preferredHosts);
                for (StoragePool potentialSPool : volumePoolList) {
                    if (hostCanAccessSPool(potentialHost, potentialSPool)) {
                        hostCanAccessPool = true;
                        if (multipleVolume && !readyAndReusedVolumes.contains(vol)) {
                            List<Volume> requestVolumes = null;
                            if (volumeAllocationMap.containsKey(potentialSPool))
                                requestVolumes = volumeAllocationMap.get(potentialSPool);
                            else
                                requestVolumes = new ArrayList<Volume>();
                            requestVolumes.add(vol);
                            List<Pair<Volume, DiskProfile>> volumeDiskProfilePair = getVolumeDiskProfilePairs(requestVolumes);
                            if (potentialHost.getHypervisorType() == HypervisorType.VMware) {
                                try {
                                    boolean isStoragePoolStoragepolicyComplaince = _storageMgr.isStoragePoolCompliantWithStoragePolicy(volumeDiskProfilePair, potentialSPool);
                                    if (!isStoragePoolStoragepolicyComplaince) {
                                        continue;
                                    }
                                } catch (StorageUnavailableException e) {
                                    s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", potentialSPool.getUuid(), e.getMessage()));
                                    continue;
                                }
                            }
                            if (!_storageMgr.storagePoolHasEnoughIops(volumeDiskProfilePair, potentialSPool) || !_storageMgr.storagePoolHasEnoughSpace(volumeDiskProfilePair, potentialSPool, potentialHost.getClusterId()))
                                continue;
                            volumeAllocationMap.put(potentialSPool, requestVolumes);
                        }
                        storage.put(vol, potentialSPool);
                        haveEnoughSpace = true;
                        break;
                    }
                }
                if (!hostCanAccessPool) {
                    break;
                }
                if (!haveEnoughSpace) {
                    s_logger.warn("insufficient capacity to allocate all volumes");
                    break;
                }
                if (!hostAffinityCheck) {
                    s_logger.debug("Host affinity check failed");
                    break;
                }
            }
        }
        if (hostCanAccessPool && haveEnoughSpace && hostAffinityCheck && checkIfHostFitsPlannerUsage(potentialHost.getId(), resourceUsageRequired)) {
            s_logger.debug("Found a potential host " + "id: " + potentialHost.getId() + " name: " + potentialHost.getName() + " and associated storage pools for this VM");
            volumeAllocationMap.clear();
            return new Pair<Host, Map<Volume, StoragePool>>(potentialHost, storage);
        } else {
            avoid.addHost(potentialHost.getId());
        }
    }
    s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM");
    return null;
}
Also used : StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) Volume(com.cloud.storage.Volume) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) HashSet(java.util.HashSet) Pair(com.cloud.utils.Pair)

Example 55 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class ClusterScopeStoragePoolAllocator method select.

@Override
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
    s_logger.debug("ClusterScopeStoragePoolAllocator looking for storage pool");
    if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) {
        return null;
    }
    List<StoragePool> suitablePools = new ArrayList<StoragePool>();
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    if (podId == null) {
        // only podId is passed into this call.
        return null;
    }
    if (dskCh.getTags() != null && dskCh.getTags().length != 0) {
        s_logger.debug("Looking for pools in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId + " having tags:" + Arrays.toString(dskCh.getTags()) + ". Disabled pools will be ignored.");
    } else {
        s_logger.debug("Looking for pools in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId + ". Disabled pools will be ignored.");
    }
    if (s_logger.isTraceEnabled()) {
        // Log the pools details that are ignored because they are in disabled state
        List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(dcId, podId, clusterId, ScopeType.CLUSTER);
        if (disabledPools != null && !disabledPools.isEmpty()) {
            for (StoragePoolVO pool : disabledPools) {
                s_logger.trace("Ignoring pool " + pool + " as it is in disabled state.");
            }
        }
    }
    List<StoragePoolVO> pools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags());
    s_logger.debug("Found pools matching tags: " + pools);
    // add remaining pools in cluster, that did not match tags, to avoid set
    List<StoragePoolVO> allPools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, null);
    allPools.removeAll(pools);
    for (StoragePoolVO pool : allPools) {
        s_logger.debug("Adding pool " + pool + " to avoid set since it did not match tags");
        avoid.addPool(pool.getId());
    }
    if (pools.size() == 0) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No storage pools available for " + ServiceOffering.StorageType.shared.toString() + " volume allocation, returning");
        }
        return suitablePools;
    }
    for (StoragePoolVO pool : pools) {
        if (suitablePools.size() == returnUpTo) {
            break;
        }
        StoragePool storagePool = (StoragePool) dataStoreMgr.getPrimaryDataStore(pool.getId());
        if (filter(avoid, storagePool, dskCh, plan)) {
            suitablePools.add(storagePool);
        } else {
            avoid.addPool(pool.getId());
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("ClusterScopeStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Aggregations

StoragePool (com.cloud.storage.StoragePool)234 Answer (com.cloud.agent.api.Answer)81 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)69 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)63 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)56 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)56 Volume (com.cloud.storage.Volume)55 HashMap (java.util.HashMap)47 VolumeVO (com.cloud.storage.VolumeVO)37 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)36 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)35 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)29 DiskProfile (com.cloud.vm.DiskProfile)29 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)28 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)28 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)28 AttachAnswer (com.cloud.storage.command.AttachAnswer)28