Skip to content

Commit 4ee6a6d

Browse files
author
Mike Tutkowski
committed
CLOUDSTACK-4331 - Enable more capacity from a managed storage device to be given to CloudStack
1 parent 3b9ea8e commit 4ee6a6d

4 files changed

Lines changed: 65 additions & 17 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public class UpdateStoragePoolCmd extends BaseCmd {
4747
@Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma-separated list of tags for the storage pool")
4848
private List<String> tags;
4949

50+
@Parameter(name=ApiConstants.CAPACITY_IOPS, type=CommandType.LONG,
51+
required=false, description="IOPS CloudStack can provision from this storage pool")
52+
private Long capacityIops;
53+
54+
@Parameter(name=ApiConstants.CAPACITY_BYTES, type=CommandType.LONG,
55+
required=false, description="bytes CloudStack can provision from this storage pool")
56+
private Long capacityBytes;
5057

5158
/////////////////////////////////////////////////////
5259
/////////////////// Accessors ///////////////////////
@@ -60,6 +67,14 @@ public List<String> getTags() {
6067
return tags;
6168
}
6269

70+
public Long getCapacityIops() {
71+
return capacityIops;
72+
}
73+
74+
public Long getCapacityBytes() {
75+
return capacityBytes;
76+
}
77+
6378
/////////////////////////////////////////////////////
6479
/////////////// API Implementation///////////////////
6580
/////////////////////////////////////////////////////

engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
* Data Access Object for storage_pool table
2929
*/
3030
public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
31-
3231
/**
3332
* @param datacenterId -- the id of the datacenter (availability zone)
3433
*/
@@ -42,19 +41,16 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
4241
/**
4342
* Set capacity of storage pool in bytes
4443
* @param id pool id.
45-
* @param capacity capacity in bytes
44+
* @param capacityBytes capacity in bytes
4645
*/
47-
void updateCapacity(long id, long capacity);
46+
void updateCapacityBytes(long id, long capacityBytes);
4847

4948
/**
50-
* Set available bytes of storage pool in bytes
51-
*
52-
* @param id
53-
* pool id.
54-
* @param available
55-
* available capacity in bytes
49+
* Set iops capacity of storage pool
50+
* @param id pool id.
51+
* @param capacityIops iops capacity
5652
*/
57-
void updateAvailable(long id, long available);
53+
void updateCapacityIops(long id, long capacityIops);
5854

5955
StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details);
6056

engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,17 @@ public List<StoragePoolVO> listByDataCenterId(long datacenterId) {
145145
}
146146

147147
@Override
148-
public void updateAvailable(long id, long available) {
148+
public void updateCapacityBytes(long id, long capacityBytes) {
149149
StoragePoolVO pool = createForUpdate(id);
150-
pool.setUsedBytes(available);
150+
pool.setCapacityBytes(capacityBytes);
151151
update(id, pool);
152152
}
153153

154154
@Override
155-
public void updateCapacity(long id, long capacity) {
155+
public void updateCapacityIops(long id, long capacityIops) {
156156
StoragePoolVO pool = createForUpdate(id);
157-
pool.setCapacityBytes(capacity);
157+
pool.setCapacityIops(capacityIops);
158158
update(id, pool);
159-
160159
}
161160

162161
@Override

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
791791
throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
792792
}
793793

794+
Map<String, String> updatedDetails = new HashMap<String, String>();
795+
794796
if (tags != null) {
795797
Map<String, String> existingDetails = _storagePoolDetailsDao.getDetails(id);
796798
Set<String> existingKeys = existingDetails.keySet();
@@ -825,10 +827,46 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
825827
details.put(existingKeyToKeep, existingValueToKeep);
826828
}
827829

828-
_storagePoolDao.updateDetails(id, details);
830+
updatedDetails.putAll(details);
831+
}
832+
833+
Long updatedCapacityBytes = null;
834+
Long capacityBytes = cmd.getCapacityBytes();
835+
836+
if (capacityBytes != null) {
837+
if (capacityBytes > pool.getCapacityBytes()) {
838+
updatedCapacityBytes = capacityBytes;
839+
}
840+
else if (capacityBytes < pool.getCapacityBytes()) {
841+
throw new CloudRuntimeException("The value of 'Capacity bytes' cannot be reduced in this version.");
842+
}
843+
}
844+
845+
Long updatedCapacityIops = null;
846+
Long capacityIops = cmd.getCapacityIops();
847+
848+
if (capacityIops != null) {
849+
if (capacityIops > pool.getCapacityIops()) {
850+
updatedCapacityIops = capacityIops;
851+
}
852+
else if (capacityIops < pool.getCapacityIops()) {
853+
throw new CloudRuntimeException("The value of 'Capacity IOPS' cannot be reduced in this version.");
854+
}
855+
}
856+
857+
if (updatedDetails.size() > 0) {
858+
_storagePoolDao.updateDetails(id, updatedDetails);
859+
}
860+
861+
if (updatedCapacityBytes != null) {
862+
_storagePoolDao.updateCapacityBytes(id, capacityBytes);
863+
}
864+
865+
if (updatedCapacityIops != null) {
866+
_storagePoolDao.updateCapacityIops(id, capacityIops);
829867
}
830868

831-
return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
869+
return (PrimaryDataStoreInfo)dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
832870
}
833871

834872
@Override

0 commit comments

Comments
 (0)