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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations