Search in sources :

Example 11 with DataStoreProvider

use of com.cloud.engine.subsystem.api.storage.DataStoreProvider in project cosmic by MissionCriticalCloud.

the class DataStoreProviderManagerImpl method getCacheDataStoreProviders.

public List<StorageProviderResponse> getCacheDataStoreProviders() {
    final List<StorageProviderResponse> providers = new ArrayList<>();
    for (final DataStoreProvider provider : providerMap.values()) {
        if (provider.getTypes().contains(DataStoreProviderType.ImageCache)) {
            final StorageProviderResponse response = new StorageProviderResponse();
            response.setName(provider.getName());
            response.setType(DataStoreProviderType.ImageCache.toString());
            providers.add(response);
        }
    }
    return providers;
}
Also used : StorageProviderResponse(com.cloud.api.response.StorageProviderResponse) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 12 with DataStoreProvider

use of com.cloud.engine.subsystem.api.storage.DataStoreProvider in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method deletePool.

@Override
@DB
public boolean deletePool(final DeletePoolCmd cmd) {
    final Long id = cmd.getId();
    final boolean forced = cmd.isForced();
    final StoragePoolVO sPool = _storagePoolDao.findById(id);
    if (sPool == null) {
        s_logger.warn("Unable to find pool:" + id);
        throw new InvalidParameterValueException("Unable to find pool by id " + id);
    }
    if (sPool.getStatus() != StoragePoolStatus.Maintenance) {
        s_logger.warn("Unable to delete storage id: " + id + " due to it is not in Maintenance state");
        throw new InvalidParameterValueException("Unable to delete storage due to it is not in Maintenance state, id: " + id);
    }
    if (sPool.isLocal()) {
        s_logger.warn("Unable to delete local storage id:" + id);
        throw new InvalidParameterValueException("Unable to delete local storage id: " + id);
    }
    final Pair<Long, Long> vlms = _volsDao.getCountAndTotalByPool(id);
    if (forced) {
        if (vlms.first() > 0) {
            final Pair<Long, Long> nonDstrdVlms = _volsDao.getNonDestroyedCountAndTotalByPool(id);
            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
            final List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed();
            for (final VolumeVO vol : vols) {
                final AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volFactory.getVolume(vol.getId()));
                try {
                    future.get();
                } catch (final InterruptedException e) {
                    s_logger.debug("expunge volume failed:" + vol.getId(), e);
                } catch (final 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
    final 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 " + id);
    final DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(sPool.getStorageProviderName());
    final DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    final DataStore store = _dataStoreMgr.getDataStore(sPool.getId(), DataStoreRole.Primary);
    return lifeCycle.deleteDataStore(store);
}
Also used : DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) DB(com.cloud.utils.db.DB)

Example 13 with DataStoreProvider

use of com.cloud.engine.subsystem.api.storage.DataStoreProvider in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method enablePrimaryStoragePool.

@ActionEvent(eventType = EventTypes.EVENT_ENABLE_PRIMARY_STORAGE, eventDescription = "enable storage pool")
private void enablePrimaryStoragePool(final StoragePoolVO primaryStorage) {
    if (!primaryStorage.getStatus().equals(StoragePoolStatus.Disabled)) {
        throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be enabled. Storage pool state : " + primaryStorage.getStatus().toString());
    }
    final DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    final DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
    final DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    ((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).enableStoragePool(store);
}
Also used : DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ActionEvent(com.cloud.event.ActionEvent)

Example 14 with DataStoreProvider

use of com.cloud.engine.subsystem.api.storage.DataStoreProvider in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method updateStoragePool.

@Override
public PrimaryDataStoreInfo updateStoragePool(final UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
    // Input validation
    final Long id = cmd.getId();
    final List<String> tags = cmd.getTags();
    final StoragePoolVO pool = _storagePoolDao.findById(id);
    if (pool == null) {
        throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
    }
    final Map<String, String> updatedDetails = new HashMap<>();
    if (tags != null) {
        final Map<String, String> existingDetails = _storagePoolDetailsDao.listDetailsKeyPairs(id);
        final Set<String> existingKeys = existingDetails.keySet();
        final Map<String, String> existingDetailsToKeep = new HashMap<>();
        for (final String existingKey : existingKeys) {
            final String existingValue = existingDetails.get(existingKey);
            if (!Boolean.TRUE.toString().equalsIgnoreCase(existingValue)) {
                existingDetailsToKeep.put(existingKey, existingValue);
            }
        }
        final Map<String, String> details = new HashMap<>();
        for (String tag : tags) {
            tag = tag.trim();
            if (tag.length() > 0 && !details.containsKey(tag)) {
                details.put(tag, "true");
            }
        }
        final Set<String> existingKeysToKeep = existingDetailsToKeep.keySet();
        for (final String existingKeyToKeep : existingKeysToKeep) {
            final String existingValueToKeep = existingDetailsToKeep.get(existingKeyToKeep);
            if (details.containsKey(existingKeyToKeep)) {
                throw new CloudRuntimeException("Storage tag '" + existingKeyToKeep + "' conflicts with a stored property of this primary storage. No changes were made.");
            }
            details.put(existingKeyToKeep, existingValueToKeep);
        }
        updatedDetails.putAll(details);
    }
    Long updatedCapacityBytes = null;
    final Long capacityBytes = cmd.getCapacityBytes();
    if (capacityBytes != null) {
        if (capacityBytes != pool.getCapacityBytes()) {
            updatedCapacityBytes = capacityBytes;
        }
    }
    Long updatedCapacityIops = null;
    final Long capacityIops = cmd.getCapacityIops();
    if (capacityIops != null) {
        if (!capacityIops.equals(pool.getCapacityIops())) {
            updatedCapacityIops = capacityIops;
        }
    }
    if (updatedCapacityBytes != null || updatedCapacityIops != null) {
        final StoragePoolVO storagePool = _storagePoolDao.findById(id);
        final DataStoreProvider dataStoreProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
        final DataStoreLifeCycle dataStoreLifeCycle = dataStoreProvider.getDataStoreLifeCycle();
        if (dataStoreLifeCycle instanceof PrimaryDataStoreLifeCycle) {
            final Map<String, String> details = new HashMap<>();
            details.put(PrimaryDataStoreLifeCycle.CAPACITY_BYTES, updatedCapacityBytes != null ? String.valueOf(updatedCapacityBytes) : null);
            details.put(PrimaryDataStoreLifeCycle.CAPACITY_IOPS, updatedCapacityIops != null ? String.valueOf(updatedCapacityIops) : null);
            ((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).updateStoragePool(storagePool, details);
        }
    }
    final Boolean enabled = cmd.getEnabled();
    if (enabled != null) {
        if (enabled) {
            enablePrimaryStoragePool(pool);
        } else {
            disablePrimaryStoragePool(pool);
        }
    } else if (updatedDetails.size() >= 0) {
        _storagePoolDao.updateDetails(id, updatedDetails);
    }
    if (updatedCapacityBytes != null) {
        _storagePoolDao.updateCapacityBytes(id, capacityBytes);
    }
    if (updatedCapacityIops != null) {
        _storagePoolDao.updateCapacityIops(id, capacityIops);
    }
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 15 with DataStoreProvider

use of com.cloud.engine.subsystem.api.storage.DataStoreProvider in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method createLocalStorage.

@DB
@Override
public DataStore createLocalStorage(final Host host, final StoragePoolInfo pInfo) throws ConnectionException {
    final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    if (dc == null) {
        return null;
    }
    boolean useLocalStorageForSystemVM = false;
    final Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
    if (isLocal != null) {
        useLocalStorageForSystemVM = isLocal.booleanValue();
    }
    if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
        return null;
    }
    final DataStore store;
    try {
        final String hostAddress = pInfo.getHost();
        StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid());
        if (pool == null) {
            // the path can be different, but if they have the same uuid, assume they are the same storage
            pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, null, pInfo.getUuid());
            if (pool != null) {
                s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different hostpath " + pInfo.getHostPath() + ", still treat it as the same pool");
            }
        }
        final DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
        if (pool == null) {
            final Map<String, Object> params = new HashMap<>();
            final String name = host.getName() + " Local Storage";
            params.put("zoneId", host.getDataCenterId());
            params.put("clusterId", host.getClusterId());
            params.put("podId", host.getPodId());
            params.put("url", pInfo.getPoolType().toString() + "://" + pInfo.getHost() + "/" + pInfo.getHostPath());
            params.put("name", name);
            params.put("localStorage", true);
            params.put("details", pInfo.getDetails());
            params.put("uuid", pInfo.getUuid());
            params.put("providerName", provider.getName());
            store = lifeCycle.initialize(params);
        } else {
            store = _dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
        }
        pool = _storagePoolDao.findById(store.getId());
        if (pool.getStatus() != StoragePoolStatus.Maintenance && pool.getStatus() != StoragePoolStatus.Removed) {
            final HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
            lifeCycle.attachHost(store, scope, pInfo);
        }
    } catch (final Exception e) {
        s_logger.warn("Unable to setup the local storage pool for " + host, e);
        throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
    }
    return _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ConnectionException(com.cloud.exception.ConnectionException) DB(com.cloud.utils.db.DB)

Aggregations

DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)18 DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)10 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)10 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)9 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 HashMap (java.util.HashMap)5 ExecutionException (java.util.concurrent.ExecutionException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 PrimaryDataStoreInfo (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo)4 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 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 ResourceInUseException (com.cloud.exception.ResourceInUseException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4