Search in sources :

Example 6 with PrimaryDataStoreInfo

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);
}
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 7 with PrimaryDataStoreInfo

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);
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DB(com.cloud.utils.db.DB)

Aggregations

PrimaryDataStoreInfo (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)5 DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)4 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)4 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)4 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 StorageConflictException (com.cloud.exception.StorageConflictException)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 DB (com.cloud.utils.db.DB)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)1 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)1 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1