diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java index 2ecb90f69c7..f04ecbc402a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java @@ -47,6 +47,13 @@ public class UpdateStoragePoolCmd extends BaseCmd { @Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma-separated list of tags for the storage pool") private List tags; + @Parameter(name=ApiConstants.CAPACITY_IOPS, type=CommandType.LONG, + required=false, description="IOPS CloudStack can provision from this storage pool") + private Long capacityIops; + + @Parameter(name=ApiConstants.CAPACITY_BYTES, type=CommandType.LONG, + required=false, description="bytes CloudStack can provision from this storage pool") + private Long capacityBytes; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -60,6 +67,14 @@ public class UpdateStoragePoolCmd extends BaseCmd { return tags; } + public Long getCapacityIops() { + return capacityIops; + } + + public Long getCapacityBytes() { + return capacityBytes; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java index 669dd25f5d3..38dd884eff1 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java @@ -28,7 +28,6 @@ import com.cloud.utils.db.GenericDao; * Data Access Object for storage_pool table */ public interface PrimaryDataStoreDao extends GenericDao { - /** * @param datacenterId -- the id of the datacenter (availability zone) */ @@ -42,19 +41,16 @@ public interface PrimaryDataStoreDao extends GenericDao { /** * Set capacity of storage pool in bytes * @param id pool id. - * @param capacity capacity in bytes + * @param capacityBytes capacity in bytes */ - void updateCapacity(long id, long capacity); + void updateCapacityBytes(long id, long capacityBytes); /** - * Set available bytes of storage pool in bytes - * - * @param id - * pool id. - * @param available - * available capacity in bytes + * Set iops capacity of storage pool + * @param id pool id. + * @param capacityIops iops capacity */ - void updateAvailable(long id, long available); + void updateCapacityIops(long id, long capacityIops); StoragePoolVO persist(StoragePoolVO pool, Map details); diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index 96e18fc6277..2c27b0e952d 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -145,18 +145,17 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase } @Override - public void updateAvailable(long id, long available) { + public void updateCapacityBytes(long id, long capacityBytes) { StoragePoolVO pool = createForUpdate(id); - pool.setUsedBytes(available); + pool.setCapacityBytes(capacityBytes); update(id, pool); } @Override - public void updateCapacity(long id, long capacity) { + public void updateCapacityIops(long id, long capacityIops) { StoragePoolVO pool = createForUpdate(id); - pool.setCapacityBytes(capacity); + pool.setCapacityIops(capacityIops); update(id, pool); - } @Override diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 2b94df24c19..4ce134e4c58 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -791,6 +791,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C throw new IllegalArgumentException("Unable to find storage pool with ID: " + id); } + Map updatedDetails = new HashMap(); + if (tags != null) { Map existingDetails = _storagePoolDetailsDao.getDetails(id); Set existingKeys = existingDetails.keySet(); @@ -825,10 +827,46 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C details.put(existingKeyToKeep, existingValueToKeep); } - _storagePoolDao.updateDetails(id, details); + updatedDetails.putAll(details); } - return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); + Long updatedCapacityBytes = null; + Long capacityBytes = cmd.getCapacityBytes(); + + if (capacityBytes != null) { + if (capacityBytes > pool.getCapacityBytes()) { + updatedCapacityBytes = capacityBytes; + } + else if (capacityBytes < pool.getCapacityBytes()) { + throw new CloudRuntimeException("The value of 'Capacity bytes' cannot be reduced in this version."); + } + } + + Long updatedCapacityIops = null; + Long capacityIops = cmd.getCapacityIops(); + + if (capacityIops != null) { + if (capacityIops > pool.getCapacityIops()) { + updatedCapacityIops = capacityIops; + } + else if (capacityIops < pool.getCapacityIops()) { + throw new CloudRuntimeException("The value of 'Capacity IOPS' cannot be reduced in this version."); + } + } + + 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); } @Override