Skip to content

Commit 18dd883

Browse files
committed
honour and show object store total size
1 parent 75859b6 commit 18dd883

File tree

7 files changed

+17
-4
lines changed

7 files changed

+17
-4
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class UpdateObjectStoragePoolCmd extends BaseCmd {
4444
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "the url for the object store")
4545
private String url;
4646

47-
@Parameter(name = ApiConstants.SIZE, type = CommandType.LONG, description = "the total size of the object store in GiB. Used for tracking capacity and sending alerts", since = "4.21")
47+
@Parameter(name = ApiConstants.SIZE, type = CommandType.LONG, description = "the total size of the object store in GiB. Used for tracking capacity and sending alerts. Set to 0 to stop tracking.", since = "4.21")
4848
private Long size;
4949

5050
/////////////////////////////////////////////////////

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ObjectStoreDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public ObjectStoreResponse newObjectStoreResponse(ObjectStoreVO store) {
146146
ObjectStoreResponse osResponse = new ObjectStoreResponse();
147147
osResponse.setId(store.getUuid());
148148
osResponse.setName(store.getName());
149-
if (store.getTotalSize() != null) {
149+
if (store.getTotalSize() != null && store.getTotalSize() != 0L) {
150150
osResponse.setStorageTotal(store.getTotalSize());
151151
}
152152
if (store.getUsedSize() == null) {

server/src/main/java/org/apache/cloudstack/storage/object/BucketApiServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ public Bucket createBucket(CreateBucketCmd cmd) {
173173
if (cmd.getQuota() != null) {
174174
objectStore.setQuota(bucketTO, cmd.getQuota());
175175
resourceLimitManager.incrementResourceCount(bucket.getAccountId(), Resource.ResourceType.object_storage, (cmd.getQuota() * Resource.ResourceType.bytesToGiB));
176+
if (objectStoreVO.getTotalSize() != null && objectStoreVO.getTotalSize() != 0 && objectStoreVO.getAllocatedSize() != null) {
177+
Long allocatedSize = objectStoreVO.getAllocatedSize() / Resource.ResourceType.bytesToGiB;
178+
Long totalSize = objectStoreVO.getTotalSize() / Resource.ResourceType.bytesToGiB;
179+
if (cmd.getQuota() + objectStoreVO.getAllocatedSize() > objectStoreVO.getTotalSize()) {
180+
logger.error("Object store {}'s allocated size has reached the total size limit of {}GiB.", objectStoreVO.getName(), (objectStoreVO.getTotalSize() / Resource.ResourceType.bytesToGiB));
181+
throw new CloudRuntimeException("Not enough space in object store to create the bucket");
182+
}
183+
}
176184
}
177185

178186
if (cmd.getPolicy() != null) {

server/src/test/java/org/apache/cloudstack/storage/object/BucketApiServiceImplTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void testCreateBucket() {
110110

111111
ObjectStoreVO objectStoreVO = Mockito.mock(ObjectStoreVO.class);
112112
Mockito.when(objectStoreVO.getId()).thenReturn(objectStoreId);
113+
Mockito.when(objectStoreVO.getTotalSize()).thenReturn(20000000L);
113114
Mockito.when(objectStoreDao.findById(poolId)).thenReturn(objectStoreVO);
114115
ObjectStoreEntity objectStore = Mockito.mock(ObjectStoreEntity.class);
115116
Mockito.when(dataStoreMgr.getDataStore(objectStoreId, DataStoreRole.Object)).thenReturn(objectStore);

ui/public/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,9 @@
21852185
"label.srx.firewall": "Juniper SRX firewall",
21862186
"label.ssh.key.pairs": "SSH key pairs",
21872187
"label.storageaccessgroups": "Storage Access Groups",
2188+
"label.storageallocated": "Allocated size",
2189+
"label.storagetotal": "Total size",
2190+
"label.storageused": "Used size",
21882191
"label.clusterstorageaccessgroups": "Cluster Storage Access Groups",
21892192
"label.podstorageaccessgroups": "Pod Storage Access Groups",
21902193
"label.zonestorageaccessgroups": "Zone Storage Access Groups",

ui/src/config/section/infra/objectStorages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
return fields
3030
},
3131
details: () => {
32-
var fields = ['name', 'id', 'url', 'providername']
32+
var fields = ['name', 'id', 'url', 'providername', 'storagetotal', 'storageallocated', 'storageused']
3333
return fields
3434
},
3535
resourceType: 'ObjectStorage',

ui/src/views/infra/AddObjectStorage.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ export default {
166166
const values = this.handleRemoveFields(formRaw)
167167
168168
var data = {
169-
name: values.name
169+
name: values.name,
170+
size: values.size
170171
}
171172
var provider = values.provider
172173

0 commit comments

Comments
 (0)