From 0f60b5d41cc1db8d29ff72de1a8c38f96a44915e Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Wed, 14 Aug 2013 15:02:57 -0600 Subject: [PATCH] CLOUDSTACK-4331 - Enable more capacity from a managed storage device to be given to CloudStack --- .../admin/storage/UpdateStoragePoolCmd.java | 15 +++++++ .../datastore/db/PrimaryDataStoreDao.java | 15 +++---- .../datastore/db/PrimaryDataStoreDaoImpl.java | 9 ++-- .../com/cloud/storage/StorageManagerImpl.java | 42 ++++++++++++++++++- 4 files changed, 65 insertions(+), 16 deletions(-) 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/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java index 669dd25f5d3..59c338e2803 100644 --- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java +++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java @@ -42,19 +42,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/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index 1032526f10e..b39f8444c35 100644 --- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -140,18 +140,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 23e713ef059..b5d6ff953ef 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -733,6 +733,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(); @@ -767,10 +769,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