use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo 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.PrimaryDataStoreInfo in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method preparePrimaryStorageForMaintenance.
@Override
@DB
public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(final Long primaryStorageId) throws ResourceUnavailableException, InsufficientCapacityException {
final StoragePoolVO primaryStorage;
primaryStorage = _storagePoolDao.findById(primaryStorageId);
if (primaryStorage == null) {
final String msg = "Unable to obtain lock on the storage pool record in preparePrimaryStorageForMaintenance()";
s_logger.error(msg);
throw new InvalidParameterValueException(msg);
}
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up) && !primaryStorage.getStatus().equals(StoragePoolStatus.ErrorInMaintenance)) {
throw new InvalidParameterValueException("Primary storage with id " + primaryStorageId + " is not ready for migration, as the status is:" + primaryStorage.getStatus().toString());
}
final DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
final DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
lifeCycle.maintain(store);
return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Aggregations