Skip to content

Commit 4197912

Browse files
committed
Add object storage capacity and alerts.
1 parent a60b717 commit 4197912

File tree

29 files changed

+260
-35
lines changed

29 files changed

+260
-35
lines changed

api/src/main/java/com/cloud/capacity/Capacity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ public interface Capacity extends InternalIdentity, Identity {
3434
public static final short CAPACITY_TYPE_LOCAL_STORAGE = 9;
3535
public static final short CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = 10;
3636
public static final short CAPACITY_TYPE_GPU = 19;
37+
public static final short CAPACITY_TYPE_OBJECT_STORAGE = 20;
38+
public static final short CAPACITY_TYPE_BACKUP_STORAGE = 21;
3739

3840
public static final short CAPACITY_TYPE_CPU_CORE = 90;
3941

4042
public static final List<Short> STORAGE_CAPACITY_TYPES = List.of(CAPACITY_TYPE_STORAGE,
4143
CAPACITY_TYPE_STORAGE_ALLOCATED,
4244
CAPACITY_TYPE_SECONDARY_STORAGE,
43-
CAPACITY_TYPE_LOCAL_STORAGE);
45+
CAPACITY_TYPE_LOCAL_STORAGE,
46+
CAPACITY_TYPE_BACKUP_STORAGE,
47+
CAPACITY_TYPE_OBJECT_STORAGE);
4448

4549
public Long getHostOrPoolId();
4650

api/src/main/java/com/cloud/storage/StorageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public interface StorageService {
131131

132132
void removeSecondaryStorageHeuristic(RemoveSecondaryStorageSelectorCmd cmd);
133133

134-
ObjectStore discoverObjectStore(String name, String url, String providerName, Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
134+
ObjectStore discoverObjectStore(String name, String url, Long size, String providerName, Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
135135

136136
boolean deleteObjectStore(DeleteObjectStoragePoolCmd cmd);
137137

api/src/main/java/org/apache/cloudstack/alert/AlertService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ private AlertType(short type, String name, boolean isDefault) {
7373
public static final AlertType ALERT_TYPE_VM_SNAPSHOT = new AlertType((short)32, "ALERT.VM.SNAPSHOT", true);
7474
public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PUBLIC.IFACE.MTU", true);
7575
public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PRIVATE.IFACE.MTU", true);
76+
public static final AlertType ALERT_TYPE_BACKUP_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_BACKUP_STORAGE, "ALERT.STORAGE.BACKUP", true);
77+
public static final AlertType ALERT_TYPE_OBJECT_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_OBJECT_STORAGE, "ALERT.STORAGE.OBJECT", true);
7678

7779
public short getType() {
7880
return type;

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ApiConstants {
2929
public static final String ADDRESS = "address";
3030
public static final String ALGORITHM = "algorithm";
3131
public static final String ALIAS = "alias";
32+
public static final String ALLOCATED = "allocated";
3233
public static final String ALLOCATED_DATE = "allocateddate";
3334
public static final String ALLOCATED_ONLY = "allocatedonly";
3435
public static final String ALLOCATED_TIME = "allocated";
@@ -521,6 +522,7 @@ public class ApiConstants {
521522
public static final String TRUST_STORE_PASSWORD = "truststorepass";
522523
public static final String URL = "url";
523524
public static final String USAGE_INTERFACE = "usageinterface";
525+
public static final String USED = "used";
524526
public static final String USED_SUBNETS = "usedsubnets";
525527
public static final String USED_IOPS = "usediops";
526528
public static final String USER_DATA = "userdata";

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public class AddObjectStoragePoolCmd extends BaseCmd {
5656
@Parameter(name = ApiConstants.TAGS, type = CommandType.STRING, description = "the tags for the storage pool")
5757
private String tags;
5858

59+
@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")
60+
private Long size;
61+
5962
/////////////////////////////////////////////////////
6063
/////////////////// Accessors ///////////////////////
6164
/////////////////////////////////////////////////////
@@ -68,6 +71,10 @@ public String getName() {
6871
return name;
6972
}
7073

74+
public Long getTotalSize() {
75+
return size;
76+
}
77+
7178
public Map<String, String> getDetails() {
7279
Map<String, String> detailsMap = null;
7380
if (details != null && !details.isEmpty()) {
@@ -112,7 +119,7 @@ public long getEntityOwnerId() {
112119
@Override
113120
public void execute(){
114121
try{
115-
ObjectStore result = _storageService.discoverObjectStore(getName(), getUrl(), getProviderName(), getDetails());
122+
ObjectStore result = _storageService.discoverObjectStore(getName(), getUrl(), getTotalSize(), getProviderName(), getDetails());
116123
ObjectStoreResponse storeResponse = null;
117124
if (result != null) {
118125
storeResponse = _responseGenerator.createObjectStoreResponse(result);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ 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")
48+
private Long size;
4749

4850
/////////////////////////////////////////////////////
4951
/////////////////// Accessors ///////////////////////
@@ -61,6 +63,10 @@ public String getUrl() {
6163
return url;
6264
}
6365

66+
public Long getSize() {
67+
return size;
68+
}
69+
6470
/////////////////////////////////////////////////////
6571
/////////////// API Implementation///////////////////
6672
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/ObjectStoreResponse.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,40 @@
1717
package org.apache.cloudstack.api.response;
1818

1919
import com.cloud.serializer.Param;
20+
21+
import org.apache.cloudstack.api.ApiConstants;
2022
import org.apache.cloudstack.storage.object.ObjectStore;
2123
import com.google.gson.annotations.SerializedName;
2224
import org.apache.cloudstack.api.BaseResponseWithAnnotations;
2325
import org.apache.cloudstack.api.EntityReference;
2426

2527
@EntityReference(value = ObjectStore.class)
2628
public class ObjectStoreResponse extends BaseResponseWithAnnotations {
27-
@SerializedName("id")
29+
@SerializedName(ApiConstants.ID)
2830
@Param(description = "the ID of the object store")
2931
private String id;
3032

31-
@SerializedName("name")
33+
@SerializedName(ApiConstants.NAME)
3234
@Param(description = "the name of the object store")
3335
private String name;
3436

35-
@SerializedName("url")
37+
@SerializedName(ApiConstants.URL)
3638
@Param(description = "the url of the object store")
3739
private String url;
3840

39-
@SerializedName("providername")
40-
@Param(description = "the provider name of the object store")
41+
@SerializedName(ApiConstants.PROVIDER)
42+
@Param(description = "the name of the object store provider")
4143
private String providerName;
4244

43-
@SerializedName("storagetotal")
45+
@SerializedName(ApiConstants.SIZE)
4446
@Param(description = "the total size of the object store")
4547
private Long storageTotal;
4648

47-
@SerializedName("storageused")
49+
@SerializedName(ApiConstants.ALLOCATED)
50+
@Param(description = "the object store currently allocated size")
51+
private Long storageAllocated;
52+
53+
@SerializedName(ApiConstants.USED)
4854
@Param(description = "the object store currently used size")
4955
private Long storageUsed;
5056

@@ -96,6 +102,14 @@ public void setStorageTotal(Long storageTotal) {
96102
this.storageTotal = storageTotal;
97103
}
98104

105+
public Long getStorageAllocated() {
106+
return storageAllocated;
107+
}
108+
109+
public void setStorageAllocated(Long storageAllocated) {
110+
this.storageAllocated = storageAllocated;
111+
}
112+
99113
public Long getStorageUsed() {
100114
return storageUsed;
101115
}

api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class AddObjectStoragePoolCmdTest {
6161

6262
String provider = "Simulator";
6363

64+
Long size = 10L;
65+
6466
Map<String, String> details;
6567

6668
private AutoCloseable closeable;
@@ -74,6 +76,7 @@ public void setUp() throws Exception {
7476
ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "url", url);
7577
ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "providerName", provider);
7678
ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "details", details);
79+
ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "size", size);
7780
addObjectStoragePoolCmdSpy._storageService = storageService;
7881
addObjectStoragePoolCmdSpy._responseGenerator = responseGenerator;
7982
}
@@ -87,12 +90,12 @@ public void tearDown() throws Exception {
8790
@Test
8891
public void testAddObjectStore() throws DiscoveryException {
8992
Mockito.doReturn(objectStore).when(storageService).discoverObjectStore(Mockito.anyString(),
90-
Mockito.anyString(), Mockito.anyString(), any());
93+
Mockito.anyString(), Mockito.anyLong(), Mockito.anyString(), any());
9194
ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse();
9295
Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any());
9396
addObjectStoragePoolCmdSpy.execute();
9497

9598
Mockito.verify(storageService, Mockito.times(1))
96-
.discoverObjectStore(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
99+
.discoverObjectStore(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
97100
}
98101
}

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,5 @@ void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope scope,
408408

409409
void validateChildDatastoresToBeAddedInUpState(StoragePoolVO datastoreClusterPool, List<ModifyStoragePoolAnswer> childDatastoreAnswerList);
410410

411+
CapacityVO getObjectStorageUsedStats(Long zoneId);
411412
}

engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ public String getUuid() {
254254
capacityNames.put(CAPACITY_TYPE_GPU, "GPU");
255255
capacityNames.put(CAPACITY_TYPE_CPU_CORE, "CPU_CORE");
256256
capacityNames.put(CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET, "VIRTUAL_NETWORK_IPV6_SUBNET");
257+
capacityNames.put(CAPACITY_TYPE_BACKUP_STORAGE, "BACKUP_STORAGE");
258+
capacityNames.put(CAPACITY_TYPE_OBJECT_STORAGE, "OBJECT_STORAGE");
257259
}
258260

259261
public static String getCapacityName (Short capacityType) {

0 commit comments

Comments
 (0)