Search in sources :

Example 1 with CheckDataStoreStoragePolicyComplainceCommand

use of org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand in project cloudstack by apache.

the class VmwareManagerImpl method listVsphereStoragePolicyCompatibleStoragePools.

@Override
public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd) {
    Long policyId = cmd.getPolicyId();
    VsphereStoragePolicyVO storagePolicy = vsphereStoragePolicyDao.findById(policyId);
    if (storagePolicy == null) {
        throw new CloudRuntimeException("Storage policy with ID = " + policyId + " was not found");
    }
    long zoneId = storagePolicy.getZoneId();
    List<StoragePoolVO> poolsInZone = primaryStorageDao.listByStatusInZone(zoneId, StoragePoolStatus.Up);
    List<StoragePool> compatiblePools = new ArrayList<>();
    for (StoragePoolVO pool : poolsInZone) {
        StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
        List<Long> hostIds = storageManager.getUpHostsInPool(pool.getId());
        if (CollectionUtils.isNullOrEmpty(hostIds)) {
            s_logger.debug("Did not find a suitable host to verify compatibility of the pool " + pool.getName());
            continue;
        }
        Collections.shuffle(hostIds);
        CheckDataStoreStoragePolicyComplainceCommand command = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicy.getPolicyId(), storageFilerTO);
        long targetHostId = hypervisorGuruManager.getGuruProcessedCommandTargetHost(hostIds.get(0), command);
        try {
            Answer answer = _agentMgr.send(targetHostId, command);
            boolean result = answer != null && answer.getResult();
            if (result) {
                compatiblePools.add(pool);
            }
        } catch (AgentUnavailableException | OperationTimedoutException e) {
            s_logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName());
        }
    }
    return compatiblePools;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) StoragePool(com.cloud.storage.StoragePool) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) ArrayList(java.util.ArrayList) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 2 with CheckDataStoreStoragePolicyComplainceCommand

use of org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand in project cloudstack by apache.

the class StorageManagerImpl method isStoragePoolCompliantWithStoragePolicy.

@Override
public boolean isStoragePoolCompliantWithStoragePolicy(List<Pair<Volume, DiskProfile>> volumes, StoragePool pool) throws StorageUnavailableException {
    if (CollectionUtils.isEmpty(volumes)) {
        return false;
    }
    List<Pair<Volume, Answer>> answers = new ArrayList<Pair<Volume, Answer>>();
    for (Pair<Volume, DiskProfile> volumeDiskProfilePair : volumes) {
        String storagePolicyId = null;
        Volume volume = volumeDiskProfilePair.first();
        DiskProfile diskProfile = volumeDiskProfilePair.second();
        if (volume.getVolumeType() == Type.ROOT) {
            Long vmId = volume.getInstanceId();
            if (vmId != null) {
                VMInstanceVO vm = _vmInstanceDao.findByIdIncludingRemoved(vmId);
                storagePolicyId = _serviceOfferingDetailsDao.getDetail(vm.getServiceOfferingId(), ApiConstants.STORAGE_POLICY);
            }
        } else {
            storagePolicyId = _diskOfferingDetailsDao.getDetail(diskProfile.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
        }
        if (StringUtils.isNotEmpty(storagePolicyId)) {
            VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
            List<Long> hostIds = getUpHostsInPool(pool.getId());
            Collections.shuffle(hostIds);
            if (hostIds == null || hostIds.isEmpty()) {
                throw new StorageUnavailableException("Unable to send command to the pool " + pool.getName() + " due to there is no enabled hosts up in this cluster", pool.getId());
            }
            try {
                StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
                CheckDataStoreStoragePolicyComplainceCommand cmd = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicyVO.getPolicyId(), storageFilerTO);
                long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostIds.get(0), cmd);
                Answer answer = _agentMgr.send(targetHostId, cmd);
                answers.add(new Pair<>(volume, answer));
            } catch (AgentUnavailableException e) {
                s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostIds.get(0), e);
                throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
            } catch (OperationTimedoutException e) {
                s_logger.debug("Failed to process storage pool command to " + pool + " via " + hostIds.get(0), e);
                throw new StorageUnavailableException("Failed to process storage command to the pool ", pool.getId());
            }
        }
    }
    // check cummilative result for all volumes
    for (Pair<Volume, Answer> answer : answers) {
        if (!answer.second().getResult()) {
            s_logger.debug(String.format("Storage pool %s is not compliance with storage policy for volume %s", pool.getUuid(), answer.first().getName()));
            return false;
        }
    }
    return true;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) DiskProfile(com.cloud.vm.DiskProfile) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) Answer(com.cloud.agent.api.Answer) SyncVolumePathAnswer(org.apache.cloudstack.storage.command.SyncVolumePathAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO) Pair(com.cloud.utils.Pair)

Aggregations

Answer (com.cloud.agent.api.Answer)2 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)2 VsphereStoragePolicyVO (com.cloud.dc.VsphereStoragePolicyVO)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 ArrayList (java.util.ArrayList)2 CheckDataStoreStoragePolicyComplainceCommand (org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)1 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)1 GetVolumeStatsAnswer (com.cloud.agent.api.GetVolumeStatsAnswer)1 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 StoragePool (com.cloud.storage.StoragePool)1 Pair (com.cloud.utils.Pair)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DiskProfile (com.cloud.vm.DiskProfile)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 SyncVolumePathAnswer (org.apache.cloudstack.storage.command.SyncVolumePathAnswer)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1