Search in sources :

Example 1 with PrimaryDataStoreLifeCycle

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle in project cloudstack by apache.

the class StorageManagerImpl method updateStoragePool.

@Override
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
    // Input validation
    Long id = cmd.getId();
    StoragePoolVO pool = _storagePoolDao.findById(id);
    if (pool == null) {
        throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
    }
    String name = cmd.getName();
    if (StringUtils.isNotBlank(name)) {
        s_logger.debug("Updating Storage Pool name to: " + name);
        pool.setName(name);
        _storagePoolDao.update(pool.getId(), pool);
    }
    final List<String> storagePoolTags = cmd.getTags();
    if (storagePoolTags != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Updating Storage Pool Tags to :" + storagePoolTags);
        }
        if (pool.getPoolType() == StoragePoolType.DatastoreCluster) {
            List<StoragePoolVO> childStoragePools = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(pool.getId());
            for (StoragePoolVO childPool : childStoragePools) {
                _storagePoolTagsDao.persist(childPool.getId(), storagePoolTags);
            }
        }
        _storagePoolTagsDao.persist(pool.getId(), storagePoolTags);
    }
    Long updatedCapacityBytes = null;
    Long capacityBytes = cmd.getCapacityBytes();
    if (capacityBytes != null) {
        if (capacityBytes != pool.getCapacityBytes()) {
            updatedCapacityBytes = capacityBytes;
        }
    }
    Long updatedCapacityIops = null;
    Long capacityIops = cmd.getCapacityIops();
    if (capacityIops != null) {
        if (!capacityIops.equals(pool.getCapacityIops())) {
            updatedCapacityIops = capacityIops;
        }
    }
    if (updatedCapacityBytes != null || updatedCapacityIops != null) {
        StoragePoolVO storagePool = _storagePoolDao.findById(id);
        DataStoreProvider dataStoreProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
        DataStoreLifeCycle dataStoreLifeCycle = dataStoreProvider.getDataStoreLifeCycle();
        if (dataStoreLifeCycle instanceof PrimaryDataStoreLifeCycle) {
            Map<String, String> details = new HashMap<String, String>();
            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);
        }
    }
    Boolean enabled = cmd.getEnabled();
    if (enabled != null) {
        if (enabled) {
            enablePrimaryStoragePool(pool);
        } else {
            disablePrimaryStoragePool(pool);
        }
    }
    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(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 2 with PrimaryDataStoreLifeCycle

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle in project cloudstack by apache.

the class StorageManagerImpl method disablePrimaryStoragePool.

@ActionEvent(eventType = EventTypes.EVENT_DISABLE_PRIMARY_STORAGE, eventDescription = "disable storage pool")
private void disablePrimaryStoragePool(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());
    }
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    ((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).disableStoragePool(store);
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ActionEvent(com.cloud.event.ActionEvent)

Example 3 with PrimaryDataStoreLifeCycle

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle in project cloudstack by apache.

the class StorageManagerImpl method enablePrimaryStoragePool.

@ActionEvent(eventType = EventTypes.EVENT_ENABLE_PRIMARY_STORAGE, eventDescription = "enable storage pool")
private void enablePrimaryStoragePool(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());
    }
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    ((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).enableStoragePool(store);
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

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