Skip to content

Commit a093f00

Browse files
lucas-a-martinsLucas MartinsDaanHoogland
authored
Add IOPS and bytes preset variables to VOLUME usage type (#10326)
* Add bytes and iops preset variables to volume usage type * Add new line at the end of file Co-authored-by: dahn <daan.hoogland@gmail.com> * Change disk offering preset variable class name --------- Co-authored-by: Lucas Martins <lucas.martins@scclouds.com.br> Co-authored-by: dahn <daan.hoogland@gmail.com>
1 parent 2a4a1f7 commit a093f00

File tree

4 files changed

+216
-10
lines changed

4 files changed

+216
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.quota.activationrule.presetvariables;
19+
20+
public class DiskOfferingPresetVariables extends GenericPresetVariable {
21+
22+
@PresetVariableDefinition(description = "A long informing the bytes read rate of the disk offering.")
23+
private Long bytesReadRate;
24+
25+
@PresetVariableDefinition(description = "A long informing the burst bytes read rate of the disk offering.")
26+
private Long bytesReadBurst;
27+
28+
@PresetVariableDefinition(description = "The length (in seconds) of the bytes read burst.")
29+
private Long bytesReadBurstLength;
30+
31+
@PresetVariableDefinition(description = "A long informing the bytes write rate of the disk offering.")
32+
private Long bytesWriteRate;
33+
34+
@PresetVariableDefinition(description = "A long informing the burst bytes write rate of the disk offering.")
35+
private Long bytesWriteBurst;
36+
37+
@PresetVariableDefinition(description = "The length (in seconds) of the bytes write burst.")
38+
private Long bytesWriteBurstLength;
39+
40+
@PresetVariableDefinition(description = "A long informing the I/O requests read rate of the disk offering.")
41+
private Long iopsReadRate;
42+
43+
@PresetVariableDefinition(description = "A long informing the burst I/O requests read rate of the disk offering.")
44+
private Long iopsReadBurst;
45+
46+
@PresetVariableDefinition(description = "The length (in seconds) of the IOPS read burst.")
47+
private Long iopsReadBurstLength;
48+
49+
@PresetVariableDefinition(description = "A long informing the I/O requests write rate of the disk offering.")
50+
private Long iopsWriteRate;
51+
52+
@PresetVariableDefinition(description = "A long informing the burst I/O requests write rate of the disk offering.")
53+
private Long iopsWriteBurst;
54+
55+
@PresetVariableDefinition(description = "The length (in seconds) of the IOPS write burst.")
56+
private Long iopsWriteBurstLength;
57+
58+
public Long getBytesReadRate() {
59+
return bytesReadRate;
60+
}
61+
62+
public void setBytesReadRate(Long bytesReadRate) {
63+
this.bytesReadRate = bytesReadRate;
64+
fieldNamesToIncludeInToString.add("bytesReadRate");
65+
}
66+
67+
public Long getBytesReadBurst() {
68+
return bytesReadBurst;
69+
}
70+
71+
public void setBytesReadBurst(Long bytesReadBurst) {
72+
this.bytesReadBurst = bytesReadBurst;
73+
fieldNamesToIncludeInToString.add("bytesReadBurst");
74+
}
75+
76+
public Long getBytesReadBurstLength() {
77+
return bytesReadBurstLength;
78+
}
79+
80+
public void setBytesReadBurstLength(Long bytesReadBurstLength) {
81+
this.bytesReadBurstLength = bytesReadBurstLength;
82+
fieldNamesToIncludeInToString.add("bytesReadBurstLength");
83+
}
84+
85+
public Long getBytesWriteRate() {
86+
return bytesWriteRate;
87+
}
88+
89+
public void setBytesWriteRate(Long bytesWriteRate) {
90+
this.bytesWriteRate = bytesWriteRate;
91+
fieldNamesToIncludeInToString.add("bytesWriteRate");
92+
}
93+
94+
public Long getBytesWriteBurst() {
95+
return bytesWriteBurst;
96+
}
97+
98+
public void setBytesWriteBurst(Long bytesWriteBurst) {
99+
this.bytesWriteBurst = bytesWriteBurst;
100+
fieldNamesToIncludeInToString.add("bytesWriteBurst");
101+
}
102+
103+
public Long getBytesWriteBurstLength() {
104+
return bytesWriteBurstLength;
105+
}
106+
107+
public void setBytesWriteBurstLength(Long bytesWriteBurstLength) {
108+
this.bytesWriteBurstLength = bytesWriteBurstLength;
109+
fieldNamesToIncludeInToString.add("bytesWriteBurstLength");
110+
}
111+
112+
public Long getIopsReadRate() {
113+
return iopsReadRate;
114+
}
115+
116+
public void setIopsReadRate(Long iopsReadRate) {
117+
this.iopsReadRate = iopsReadRate;
118+
fieldNamesToIncludeInToString.add("iopsReadRate");
119+
}
120+
121+
public Long getIopsReadBurst() {
122+
return iopsReadBurst;
123+
}
124+
125+
public void setIopsReadBurst(Long iopsReadBurst) {
126+
this.iopsReadBurst = iopsReadBurst;
127+
fieldNamesToIncludeInToString.add("iopsReadBurst");
128+
}
129+
130+
public Long getIopsReadBurstLength() {
131+
return iopsReadBurstLength;
132+
}
133+
134+
public void setIopsReadBurstLength(Long iopsReadBurstLength) {
135+
this.iopsReadBurstLength = iopsReadBurstLength;
136+
fieldNamesToIncludeInToString.add("iopsReadBurstLength");
137+
}
138+
139+
public Long getIopsWriteRate() {
140+
return iopsWriteRate;
141+
}
142+
143+
public void setIopsWriteRate(Long iopsWriteRate) {
144+
this.iopsWriteRate = iopsWriteRate;
145+
fieldNamesToIncludeInToString.add("iopsWriteRate");
146+
}
147+
148+
public Long getIopsWriteBurst() {
149+
return iopsWriteBurst;
150+
}
151+
152+
public void setIopsWriteBurst(Long iopsWriteBurst) {
153+
this.iopsWriteBurst = iopsWriteBurst;
154+
fieldNamesToIncludeInToString.add("iopsWriteBurst");
155+
}
156+
157+
public Long getIopsWriteBurstLength() {
158+
return iopsWriteBurstLength;
159+
}
160+
161+
public void setIopsWriteBurstLength(Long iopsWriteBurstLength) {
162+
this.iopsWriteBurstLength = iopsWriteBurstLength;
163+
fieldNamesToIncludeInToString.add("iopsWriteBurstLength");
164+
}
165+
}

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ protected void loadPresetVariableValueForVolume(UsageVO usageRecord, Value value
492492
value.setId(volumeVo.getUuid());
493493
value.setName(volumeVo.getName());
494494
value.setProvisioningType(volumeVo.getProvisioningType());
495+
value.setVolumeType(volumeVo.getVolumeType());
495496

496497
Long poolId = volumeVo.getPoolId();
497498
if (poolId == null) {
@@ -510,13 +511,25 @@ protected void loadPresetVariableValueForVolume(UsageVO usageRecord, Value value
510511
}
511512
}
512513

513-
protected GenericPresetVariable getPresetVariableValueDiskOffering(Long diskOfferingId) {
514+
protected DiskOfferingPresetVariables getPresetVariableValueDiskOffering(Long diskOfferingId) {
514515
DiskOfferingVO diskOfferingVo = diskOfferingDao.findByIdIncludingRemoved(diskOfferingId);
515516
validateIfObjectIsNull(diskOfferingVo, diskOfferingId, "disk offering");
516517

517-
GenericPresetVariable diskOffering = new GenericPresetVariable();
518+
DiskOfferingPresetVariables diskOffering = new DiskOfferingPresetVariables();
518519
diskOffering.setId(diskOfferingVo.getUuid());
519520
diskOffering.setName(diskOfferingVo.getName());
521+
diskOffering.setBytesReadRate(diskOfferingVo.getBytesReadRate());
522+
diskOffering.setBytesReadBurst(diskOfferingVo.getBytesReadRateMax());
523+
diskOffering.setBytesReadBurstLength(diskOfferingVo.getBytesReadRateMaxLength());
524+
diskOffering.setBytesWriteRate(diskOfferingVo.getBytesWriteRate());
525+
diskOffering.setBytesWriteBurst(diskOfferingVo.getBytesWriteRateMax());
526+
diskOffering.setBytesWriteBurstLength(diskOfferingVo.getBytesWriteRateMaxLength());
527+
diskOffering.setIopsReadRate(diskOfferingVo.getIopsReadRate());
528+
diskOffering.setIopsReadBurst(diskOfferingVo.getIopsReadRateMax());
529+
diskOffering.setIopsReadBurstLength(diskOfferingVo.getIopsReadRateMaxLength());
530+
diskOffering.setIopsWriteRate(diskOfferingVo.getIopsWriteRate());
531+
diskOffering.setIopsWriteBurst(diskOfferingVo.getIopsWriteRateMax());
532+
diskOffering.setIopsWriteBurstLength(diskOfferingVo.getIopsWriteRateMaxLength());
520533

521534
return diskOffering;
522535
}

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.cloud.storage.Snapshot;
2424
import com.cloud.storage.Storage.ProvisioningType;
25+
import com.cloud.storage.Volume;
2526
import com.cloud.vm.snapshot.VMSnapshot;
2627
import org.apache.cloudstack.quota.constant.QuotaTypes;
2728

@@ -75,7 +76,7 @@ public class Value extends GenericPresetVariable {
7576
private GenericPresetVariable template;
7677

7778
@PresetVariableDefinition(description = "Disk offering of the volume.", supportedTypes = {QuotaTypes.VOLUME})
78-
private GenericPresetVariable diskOffering;
79+
private DiskOfferingPresetVariables diskOffering;
7980

8081
@PresetVariableDefinition(description = "Storage where the volume or snapshot is. While handling with snapshots, this value can be from the primary storage if the global " +
8182
"setting 'snapshot.backup.to.secondary' is false, otherwise it will be from secondary storage.", supportedTypes = {QuotaTypes.VOLUME, QuotaTypes.SNAPSHOT})
@@ -93,6 +94,10 @@ public class Value extends GenericPresetVariable {
9394

9495
@PresetVariableDefinition(description = "The volume format. Values can be: RAW, VHD, VHDX, OVA and QCOW2.", supportedTypes = {QuotaTypes.VOLUME, QuotaTypes.VOLUME_SECONDARY})
9596
private String volumeFormat;
97+
98+
@PresetVariableDefinition(description = "The volume type. Values can be: UNKNOWN, ROOT, SWAP, DATADISK and ISO.", supportedTypes = {QuotaTypes.VOLUME})
99+
private Volume.Type volumeType;
100+
96101
private String state;
97102

98103
public Host getHost() {
@@ -194,11 +199,11 @@ public void setTemplate(GenericPresetVariable template) {
194199
fieldNamesToIncludeInToString.add("template");
195200
}
196201

197-
public GenericPresetVariable getDiskOffering() {
202+
public DiskOfferingPresetVariables getDiskOffering() {
198203
return diskOffering;
199204
}
200205

201-
public void setDiskOffering(GenericPresetVariable diskOffering) {
206+
public void setDiskOffering(DiskOfferingPresetVariables diskOffering) {
202207
this.diskOffering = diskOffering;
203208
fieldNamesToIncludeInToString.add("diskOffering");
204209
}
@@ -257,6 +262,15 @@ public String getVolumeFormat() {
257262
return volumeFormat;
258263
}
259264

265+
public Volume.Type getVolumeType() {
266+
return volumeType;
267+
}
268+
269+
public void setVolumeType(Volume.Type volumeType) {
270+
this.volumeType = volumeType;
271+
fieldNamesToIncludeInToString.add("volumeType");
272+
}
273+
260274
public String getState() {
261275
return state;
262276
}

framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.cloud.storage.Storage.ImageFormat;
7777
import com.cloud.storage.Storage.ProvisioningType;
7878
import com.cloud.storage.VMTemplateVO;
79+
import com.cloud.storage.Volume;
7980
import com.cloud.storage.VolumeVO;
8081
import com.cloud.storage.dao.DiskOfferingDao;
8182
import com.cloud.storage.dao.GuestOSDao;
@@ -208,14 +209,15 @@ private Value getValueForTests() {
208209
value.setComputeOffering(getComputeOfferingForTests());
209210
value.setTags(Collections.singletonMap("tag1", "value1"));
210211
value.setTemplate(getGenericPresetVariableForTests());
211-
value.setDiskOffering(getGenericPresetVariableForTests());
212+
value.setDiskOffering(getDiskOfferingForTests());
212213
value.setProvisioningType(ProvisioningType.THIN);
213214
value.setStorage(getStorageForTests());
214215
value.setSize(ByteScaleUtils.GiB);
215216
value.setSnapshotType(Snapshot.Type.HOURLY);
216217
value.setTag("tag_test");
217218
value.setVmSnapshotType(VMSnapshot.Type.Disk);
218219
value.setComputingResources(getComputingResourcesForTests());
220+
value.setVolumeType(Volume.Type.DATADISK);
219221
return value;
220222
}
221223

@@ -308,6 +310,13 @@ private BackupOffering getBackupOfferingForTests() {
308310
return backupOffering;
309311
}
310312

313+
private DiskOfferingPresetVariables getDiskOfferingForTests() {
314+
DiskOfferingPresetVariables diskOffering = new DiskOfferingPresetVariables();
315+
diskOffering.setId("disk_offering_id");
316+
diskOffering.setName("disk_offering_name");
317+
return diskOffering;
318+
}
319+
311320
private void mockMethodValidateIfObjectIsNull() {
312321
Mockito.doNothing().when(presetVariableHelperSpy).validateIfObjectIsNull(Mockito.any(), Mockito.anyLong(), Mockito.anyString());
313322
}
@@ -698,6 +707,7 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndHasStorageSetFi
698707
Mockito.doReturn(expected.getName()).when(volumeVoMock).getName();
699708
Mockito.doReturn(expected.getDiskOffering()).when(presetVariableHelperSpy).getPresetVariableValueDiskOffering(Mockito.anyLong());
700709
Mockito.doReturn(expected.getProvisioningType()).when(volumeVoMock).getProvisioningType();
710+
Mockito.doReturn(expected.getVolumeType()).when(volumeVoMock).getVolumeType();
701711
Mockito.doReturn(expected.getStorage()).when(presetVariableHelperSpy).getPresetVariableValueStorage(Mockito.anyLong(), Mockito.anyInt());
702712
Mockito.doReturn(expected.getTags()).when(presetVariableHelperSpy).getPresetVariableValueResourceTags(Mockito.anyLong(), Mockito.any(ResourceObjectType.class));
703713
Mockito.doReturn(expected.getSize()).when(volumeVoMock).getSize();
@@ -713,12 +723,13 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndHasStorageSetFi
713723
assertPresetVariableIdAndName(expected, result);
714724
Assert.assertEquals(expected.getDiskOffering(), result.getDiskOffering());
715725
Assert.assertEquals(expected.getProvisioningType(), result.getProvisioningType());
726+
Assert.assertEquals(expected.getVolumeType(), result.getVolumeType());
716727
Assert.assertEquals(expected.getStorage(), result.getStorage());
717728
Assert.assertEquals(expected.getTags(), result.getTags());
718729
Assert.assertEquals(expectedSize, result.getSize());
719730
Assert.assertEquals(imageFormat.name(), result.getVolumeFormat());
720731

721-
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "storage", "tags", "size", "volumeFormat"), result);
732+
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "volumeType", "storage", "tags", "size", "volumeFormat"), result);
722733
}
723734

724735
Mockito.verify(presetVariableHelperSpy, Mockito.times(ImageFormat.values().length)).getPresetVariableValueResourceTags(Mockito.anyLong(),
@@ -740,6 +751,7 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndDoesNotHaveStor
740751
Mockito.doReturn(expected.getName()).when(volumeVoMock).getName();
741752
Mockito.doReturn(expected.getDiskOffering()).when(presetVariableHelperSpy).getPresetVariableValueDiskOffering(Mockito.anyLong());
742753
Mockito.doReturn(expected.getProvisioningType()).when(volumeVoMock).getProvisioningType();
754+
Mockito.doReturn(expected.getVolumeType()).when(volumeVoMock).getVolumeType();
743755
Mockito.doReturn(expected.getTags()).when(presetVariableHelperSpy).getPresetVariableValueResourceTags(Mockito.anyLong(), Mockito.any(ResourceObjectType.class));
744756
Mockito.doReturn(expected.getSize()).when(volumeVoMock).getSize();
745757
Mockito.doReturn(imageFormat).when(volumeVoMock).getFormat();
@@ -754,12 +766,13 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndDoesNotHaveStor
754766
assertPresetVariableIdAndName(expected, result);
755767
Assert.assertEquals(expected.getDiskOffering(), result.getDiskOffering());
756768
Assert.assertEquals(expected.getProvisioningType(), result.getProvisioningType());
769+
Assert.assertEquals(expected.getVolumeType(), result.getVolumeType());
757770
Assert.assertNull(result.getStorage());
758771
Assert.assertEquals(expected.getTags(), result.getTags());
759772
Assert.assertEquals(expectedSize, result.getSize());
760773
Assert.assertEquals(imageFormat.name(), result.getVolumeFormat());
761774

762-
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "tags", "size", "volumeFormat"), result);
775+
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "volumeType", "tags", "size", "volumeFormat"), result);
763776
}
764777

765778
Mockito.verify(presetVariableHelperSpy, Mockito.times(ImageFormat.values().length)).getPresetVariableValueResourceTags(Mockito.anyLong(),
@@ -772,14 +785,15 @@ public void getPresetVariableValueDiskOfferingTestSetValuesAndReturnObject() {
772785
Mockito.doReturn(diskOfferingVoMock).when(diskOfferingDaoMock).findByIdIncludingRemoved(Mockito.anyLong());
773786
mockMethodValidateIfObjectIsNull();
774787

775-
GenericPresetVariable expected = getGenericPresetVariableForTests();
788+
DiskOfferingPresetVariables expected = getDiskOfferingForTests();
776789
Mockito.doReturn(expected.getId()).when(diskOfferingVoMock).getUuid();
777790
Mockito.doReturn(expected.getName()).when(diskOfferingVoMock).getName();
778791

779792
GenericPresetVariable result = presetVariableHelperSpy.getPresetVariableValueDiskOffering(1l);
780793

781794
assertPresetVariableIdAndName(expected, result);
782-
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name"), result);
795+
validateFieldNamesToIncludeInToString(Arrays.asList("bytesReadBurst", "bytesReadBurstLength", "bytesReadRate", "bytesWriteBurst", "bytesWriteBurstLength", "bytesWriteRate",
796+
"id", "iopsReadBurst", "iopsReadBurstLength", "iopsReadRate", "iopsWriteBurst", "iopsWriteBurstLength", "iopsWriteRate", "name"), result);
783797
}
784798

785799
@Test

0 commit comments

Comments
 (0)