Search in sources :

Example 16 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException 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 17 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.

the class KVMHostActivityChecker method verifyActivityOfStorageOnHost.

protected boolean verifyActivityOfStorageOnHost(HashMap<StoragePool, List<Volume>> poolVolMap, StoragePool pool, Host agent, DateTime suspectTime, boolean activityStatus) throws HACheckerException, IllegalStateException {
    List<Volume> volume_list = poolVolMap.get(pool);
    final CheckVMActivityOnStoragePoolCommand cmd = new CheckVMActivityOnStoragePoolCommand(agent, pool, volume_list, suspectTime);
    LOG.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId()));
    try {
        Answer answer = storageManager.sendToPool(pool, getNeighbors(agent), cmd);
        if (answer != null) {
            activityStatus = !answer.getResult();
            LOG.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId()));
        } else {
            String message = String.format("Did not get a valid response for VM activity check for %s on storage pool [%s].", agent.toString(), pool.getId());
            LOG.debug(message);
            throw new IllegalStateException(message);
        }
    } catch (StorageUnavailableException e) {
        String message = String.format("Storage [%s] is unavailable to do the check, probably the %s is not reachable.", pool.getId(), agent.toString());
        LOG.warn(message, e);
        throw new HACheckerException(message, e);
    }
    return activityStatus;
}
Also used : Answer(com.cloud.agent.api.Answer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) Volume(com.cloud.storage.Volume) HACheckerException(org.apache.cloudstack.ha.provider.HACheckerException) CheckVMActivityOnStoragePoolCommand(com.cloud.agent.api.CheckVMActivityOnStoragePoolCommand)

Example 18 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.

the class TemplateManagerImpl method evictTemplateFromStoragePool.

@Override
@DB
public void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO) {
    // Need to hold the lock; otherwise, another thread may create a volume from the template at the same time.
    // Assumption here is that we will hold the same lock during create volume from template.
    VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolVO.getId());
    if (templatePoolRef == null) {
        s_logger.debug("Can't aquire the lock for template pool ref: " + templatePoolVO.getId());
        return;
    }
    PrimaryDataStore pool = (PrimaryDataStore) _dataStoreMgr.getPrimaryDataStore(templatePoolVO.getPoolId());
    TemplateInfo template = _tmplFactory.getTemplateOnPrimaryStorage(templatePoolRef.getTemplateId(), pool, templatePoolRef.getDeploymentOption());
    try {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Evicting " + templatePoolVO);
        }
        if (pool.isManaged()) {
            // For managed store, just delete the template volume.
            AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.deleteTemplateOnPrimary(template, pool);
            TemplateApiResult result = future.get();
            if (result.isFailed()) {
                s_logger.debug("Failed to delete template " + template.getId() + " from storage pool " + pool.getId());
            } else {
                // Remove the templatePoolVO.
                if (_tmpltPoolDao.remove(templatePoolVO.getId())) {
                    s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName());
                }
            }
        } else {
            DestroyCommand cmd = new DestroyCommand(pool, templatePoolVO);
            Answer answer = _storageMgr.sendToPool(pool, cmd);
            if (answer != null && answer.getResult()) {
                // Remove the templatePoolVO.
                if (_tmpltPoolDao.remove(templatePoolVO.getId())) {
                    s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName());
                }
            } else {
                s_logger.info("Will retry evict template " + template.getName() + " from storage pool " + pool.getName());
            }
        }
    } catch (StorageUnavailableException | InterruptedException | ExecutionException e) {
        s_logger.info("Storage is unavailable currently. Will retry evicte template " + template.getName() + " from storage pool " + pool.getName());
    } finally {
        _tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) ExecutionException(java.util.concurrent.ExecutionException) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DB(com.cloud.utils.db.DB)

Example 19 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.

the class StorageManagerImpl method cancelPrimaryStorageForMaintenance.

@Override
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
    Long primaryStorageId = cmd.getId();
    StoragePoolVO primaryStorage = null;
    primaryStorage = _storagePoolDao.findById(primaryStorageId);
    if (primaryStorage == null) {
        String msg = "Unable to obtain lock on the storage pool in cancelPrimaryStorageForMaintenance()";
        s_logger.error(msg);
        throw new InvalidParameterValueException(msg);
    }
    if (primaryStorage.getStatus().equals(StoragePoolStatus.Up) || primaryStorage.getStatus().equals(StoragePoolStatus.PrepareForMaintenance)) {
        throw new StorageUnavailableException("Primary storage with id " + primaryStorageId + " is not ready to complete migration, as the status is:" + primaryStorage.getStatus().toString(), primaryStorageId);
    }
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    if (primaryStorage.getPoolType() == StoragePoolType.DatastoreCluster) {
        primaryStorage.setStatus(StoragePoolStatus.Up);
        _storagePoolDao.update(primaryStorage.getId(), primaryStorage);
        // FR41 need to handle when one of the primary stores is unable to cancel the maintenance mode
        List<StoragePoolVO> childDatastores = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(primaryStorageId);
        for (StoragePoolVO childDatastore : childDatastores) {
            DataStore childStore = _dataStoreMgr.getDataStore(childDatastore.getId(), DataStoreRole.Primary);
            lifeCycle.cancelMaintain(childStore);
        }
    }
    lifeCycle.cancelMaintain(store);
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DB(com.cloud.utils.db.DB)

Example 20 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.

the class UserVmManagerImpl method getVolumePoolMappingForMigrateVmWithStorage.

private Map<Long, Long> getVolumePoolMappingForMigrateVmWithStorage(VMInstanceVO vm, Map<String, String> volumeToPool) {
    Map<Long, Long> volToPoolObjectMap = new HashMap<Long, Long>();
    List<VolumeVO> vmVolumes = getVmVolumesForMigrateVmWithStorage(vm);
    if (MapUtils.isNotEmpty(volumeToPool)) {
        // Check if all the volumes and pools passed as parameters are valid.
        for (Map.Entry<String, String> entry : volumeToPool.entrySet()) {
            VolumeVO volume = _volsDao.findByUuid(entry.getKey());
            StoragePoolVO pool = _storagePoolDao.findByUuid(entry.getValue());
            if (volume == null) {
                throw new InvalidParameterValueException("There is no volume present with the given id " + entry.getKey());
            } else if (pool == null) {
                throw new InvalidParameterValueException("There is no storage pool present with the given id " + entry.getValue());
            } else if (pool.isInMaintenance()) {
                throw new InvalidParameterValueException("Cannot migrate volume " + volume + "to the destination storage pool " + pool.getName() + " as the storage pool is in maintenance mode.");
            } else {
                // Verify the volume given belongs to the vm.
                if (!vmVolumes.contains(volume)) {
                    throw new InvalidParameterValueException(String.format("Volume " + volume + " doesn't belong to the VM %s (ID: %s) that has to be migrated", vm.getInstanceName(), vm.getUuid()));
                }
                volToPoolObjectMap.put(volume.getId(), pool.getId());
            }
            HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId());
            if (hypervisorType.equals(HypervisorType.VMware)) {
                try {
                    DiskOffering diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
                    DiskProfile diskProfile = new DiskProfile(volume, diskOffering, _volsDao.getHypervisorType(volume.getId()));
                    Pair<Volume, DiskProfile> volumeDiskProfilePair = new Pair<>(volume, diskProfile);
                    boolean isStoragePoolStoragepolicyCompliance = storageManager.isStoragePoolCompliantWithStoragePolicy(Arrays.asList(volumeDiskProfilePair), pool);
                    if (!isStoragePoolStoragepolicyCompliance) {
                        throw new CloudRuntimeException(String.format("Storage pool %s is not storage policy compliance with the volume %s", pool.getUuid(), volume.getUuid()));
                    }
                } catch (StorageUnavailableException e) {
                    throw new CloudRuntimeException(String.format("Could not verify storage policy compliance against storage pool %s due to exception %s", pool.getUuid(), e.getMessage()));
                }
            }
        }
    }
    return volToPoolObjectMap;
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair)

Aggregations

StorageUnavailableException (com.cloud.exception.StorageUnavailableException)52 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)21 DB (com.cloud.utils.db.DB)16 ExecutionException (java.util.concurrent.ExecutionException)15 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)14 ArrayList (java.util.ArrayList)13 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 StoragePool (com.cloud.storage.StoragePool)12 Pair (com.cloud.utils.Pair)11 Answer (com.cloud.agent.api.Answer)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)10 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)9 ConfigurationException (javax.naming.ConfigurationException)9 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 DiskOffering (com.cloud.offering.DiskOffering)8 VolumeVO (com.cloud.storage.VolumeVO)8 ExecutionException (com.cloud.utils.exception.ExecutionException)8 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)7