Search in sources :

Example 16 with DataStoreProvider

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider in project cloudstack by apache.

the class UserVmManagerImpl method getVolumeStatistics.

@Override
public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, int timeout) {
    List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up);
    StoragePoolVO storagePool = _storagePoolDao.findPoolByUUID(poolUuid);
    HashMap<String, VolumeStatsEntry> volumeStatsByUuid = new HashMap<>();
    for (HostVO neighbor : neighbors) {
        // - zone wide storage for specific hypervisortypes
        if ((ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType())) {
            // skip this neighbour if their hypervisor type is not the same as that of the store
            continue;
        }
        List<String> volumeLocators = getVolumesByHost(neighbor, storagePool);
        if (!CollectionUtils.isEmpty(volumeLocators)) {
            GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators);
            Answer answer = null;
            DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
            DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
            if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver) storeDriver).canProvideVolumeStats()) {
                // Get volume stats from the pool directly instead of sending cmd to host
                answer = storageManager.getVolumeStats(storagePool, cmd);
            } else {
                if (timeout > 0) {
                    cmd.setWait(timeout / 1000);
                }
                answer = _agentMgr.easySend(neighbor.getId(), cmd);
            }
            if (answer != null && answer instanceof GetVolumeStatsAnswer) {
                GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer) answer;
                if (volstats.getVolumeStats() != null) {
                    volumeStatsByUuid.putAll(volstats.getVolumeStats());
                }
            }
        }
    }
    return volumeStatsByUuid.size() > 0 ? volumeStatsByUuid : null;
}
Also used : VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) HostVO(com.cloud.host.HostVO) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) Answer(com.cloud.agent.api.Answer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) GetVolumeStatsCommand(com.cloud.agent.api.GetVolumeStatsCommand) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer)

Example 17 with DataStoreProvider

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider in project cloudstack by apache.

the class CapacityManagerImpl method getUsedIops.

@Override
public long getUsedIops(StoragePoolVO pool) {
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    if (storeDriver instanceof PrimaryDataStoreDriver) {
        PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
        return primaryStoreDriver.getUsedIops(pool);
    }
    throw new CloudRuntimeException("Storage driver in CapacityManagerImpl.getUsedIops(StoragePoolVO) is not a PrimaryDataStoreDriver.");
}
Also used : PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)

Example 18 with DataStoreProvider

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider in project cloudstack by apache.

the class StorageManagerImpl method deleteDataStoreInternal.

private boolean deleteDataStoreInternal(StoragePoolVO sPool, boolean forced) {
    Pair<Long, Long> vlms = _volsDao.getCountAndTotalByPool(sPool.getId());
    if (forced) {
        if (vlms.first() > 0) {
            Pair<Long, Long> nonDstrdVlms = _volsDao.getNonDestroyedCountAndTotalByPool(sPool.getId());
            if (nonDstrdVlms.first() > 0) {
                throw new CloudRuntimeException("Cannot delete pool " + sPool.getName() + " as there are associated " + "non-destroyed vols for this pool");
            }
            // force expunge non-destroyed volumes
            List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed();
            for (VolumeVO vol : vols) {
                AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volFactory.getVolume(vol.getId()));
                try {
                    future.get();
                } catch (InterruptedException e) {
                    s_logger.debug("expunge volume failed:" + vol.getId(), e);
                } catch (ExecutionException e) {
                    s_logger.debug("expunge volume failed:" + vol.getId(), e);
                }
            }
        }
    } else {
        // If it does , then you cannot delete the pool
        if (vlms.first() > 0) {
            throw new CloudRuntimeException("Cannot delete pool " + sPool.getName() + " as there are associated volumes for this pool");
        }
    }
    // First get the host_id from storage_pool_host_ref for given pool id
    StoragePoolVO lock = _storagePoolDao.acquireInLockTable(sPool.getId());
    if (lock == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Failed to acquire lock when deleting PrimaryDataStoreVO with ID: " + sPool.getId());
        }
        return false;
    }
    _storagePoolDao.releaseFromLockTable(lock.getId());
    s_logger.trace("Released lock for storage pool " + sPool.getId());
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(sPool.getStorageProviderName());
    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store = _dataStoreMgr.getDataStore(sPool.getId(), DataStoreRole.Primary);
    return lifeCycle.deleteDataStore(store);
}
Also used : DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with DataStoreProvider

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider in project cloudstack by apache.

the class StorageManagerImpl method migrateToObjectStore.

@Override
public ImageStore migrateToObjectStore(String name, String url, String providerName, Map<String, String> details) throws DiscoveryException, InvalidParameterValueException {
    // check if current cloud is ready to migrate, we only support cloud with only NFS secondary storages
    List<ImageStoreVO> imgStores = _imageStoreDao.listImageStores();
    List<ImageStoreVO> nfsStores = new ArrayList<ImageStoreVO>();
    if (imgStores != null && imgStores.size() > 0) {
        for (ImageStoreVO store : imgStores) {
            if (!store.getProviderName().equals(DataStoreProvider.NFS_IMAGE)) {
                throw new InvalidParameterValueException("We only support migrate NFS secondary storage to use object store!");
            } else {
                nfsStores.add(store);
            }
        }
    }
    // convert all NFS secondary storage to staging store
    if (nfsStores != null && nfsStores.size() > 0) {
        for (ImageStoreVO store : nfsStores) {
            long storeId = store.getId();
            _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
            DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(store.getProviderName());
            DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
            DataStore secStore = _dataStoreMgr.getDataStore(storeId, DataStoreRole.Image);
            lifeCycle.migrateToObjectStore(secStore);
            // update store_role in template_store_ref and snapshot_store_ref to ImageCache
            _templateStoreDao.updateStoreRoleToCachce(storeId);
            _snapshotStoreDao.updateStoreRoleToCache(storeId);
        }
    }
    // add object store
    return discoverImageStore(name, url, providerName, null, details);
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 20 with DataStoreProvider

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider in project cloudstack by apache.

the class StorageManagerImpl method discoverImageStore.

@Override
public ImageStore discoverImageStore(String name, String url, String providerName, Long zoneId, Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultImageDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find image store provider: " + providerName);
        }
        // ignored passed provider name and use default image store provider name
        providerName = storeProvider.getName();
    }
    ScopeType scopeType = ScopeType.ZONE;
    if (zoneId == null) {
        scopeType = ScopeType.REGION;
    }
    if (name == null) {
        name = url;
    }
    ImageStoreVO imageStore = _imageStoreDao.findByName(name);
    if (imageStore != null) {
        throw new InvalidParameterValueException("The image store with name " + name + " already exists, try creating with another name");
    }
    // check if scope is supported by store provider
    if (!((ImageStoreProvider) storeProvider).isScopeSupported(scopeType)) {
        throw new InvalidParameterValueException("Image store provider " + providerName + " does not support scope " + scopeType);
    }
    // check if we have already image stores from other different providers,
    // we currently are not supporting image stores from different
    // providers co-existing
    List<ImageStoreVO> imageStores = _imageStoreDao.listImageStores();
    for (ImageStoreVO store : imageStores) {
        if (!store.getProviderName().equalsIgnoreCase(providerName)) {
            throw new InvalidParameterValueException("You can only add new image stores from the same provider " + store.getProviderName() + " already added");
        }
    }
    if (zoneId != null) {
        // Check if the zone exists in the system
        DataCenterVO zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Can't find zone by id " + zoneId);
        }
        Account account = CallContext.current().getCallingAccount();
        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
            PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
            ex.addProxyObject(zone.getUuid(), "dcId");
            throw ex;
        }
    }
    Map<String, Object> params = new HashMap<>();
    params.put("zoneId", zoneId);
    params.put("url", url);
    params.put("name", name);
    params.put("details", details);
    params.put("scope", scopeType);
    params.put("providerName", storeProvider.getName());
    params.put("role", DataStoreRole.Image);
    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store;
    try {
        store = lifeCycle.initialize(params);
    } catch (Exception e) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        }
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    if (((ImageStoreProvider) storeProvider).needDownloadSysTemplate()) {
        // trigger system vm template download
        _imageSrv.downloadBootstrapSysTemplate(store);
    } else {
        // populate template_store_ref table
        _imageSrv.addSystemVMTemplatesToSecondary(store);
        _imageSrv.handleTemplateSync(store);
        registerSystemVmTemplateOnFirstNfsStore(zoneId, providerName, url, store);
    }
    // associate builtin template with zones associated with this image store
    associateCrosszoneTemplatesToZone(zoneId);
    // duplicate cache store records to region wide storage
    if (scopeType == ScopeType.REGION) {
        duplicateCacheStoreRecordsToRegionStore(store.getId());
    }
    return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ImageStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Aggregations

DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)33 DataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)13 PrimaryDataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 HashMap (java.util.HashMap)10 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)10 PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ArrayList (java.util.ArrayList)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 ConnectionException (com.cloud.exception.ConnectionException)4 DiscoveryException (com.cloud.exception.DiscoveryException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4