Search in sources :

Example 1 with PrimaryDataStoreLifeCycle

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

the class StorageManagerImpl method disablePrimaryStoragePool.

@ActionEvent(eventType = EventTypes.EVENT_DISABLE_PRIMARY_STORAGE, eventDescription = "disable storage pool")
private void disablePrimaryStoragePool(final StoragePoolVO primaryStorage) {
    if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up)) {
        throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be disabled. 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).disableStoragePool(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 2 with PrimaryDataStoreLifeCycle

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle 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 3 with PrimaryDataStoreLifeCycle

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle 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)

Aggregations

DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)3 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)3 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)2 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 PrimaryDataStoreInfo (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo)1 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 HashMap (java.util.HashMap)1