Skip to content

Commit f4f35a8

Browse files
Enhance UpdateDiskOfferingCmd (#4409)
1 parent ee5094b commit f4f35a8

File tree

3 files changed

+219
-83
lines changed

3 files changed

+219
-83
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,44 @@ public class UpdateDiskOfferingCmd extends BaseCmd {
8585
since = "4.15")
8686
private String tags;
8787

88+
@Parameter(name = ApiConstants.BYTES_READ_RATE, type = CommandType.LONG, description = "bytes read rate of the disk offering", since = "4.15")
89+
private Long bytesReadRate;
90+
91+
@Parameter(name = ApiConstants.BYTES_READ_RATE_MAX, type = CommandType.LONG, description = "burst bytes read rate of the disk offering", since = "4.15")
92+
private Long bytesReadRateMax;
93+
94+
@Parameter(name = ApiConstants.BYTES_READ_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
95+
private Long bytesReadRateMaxLength;
96+
97+
@Parameter(name = ApiConstants.BYTES_WRITE_RATE, type = CommandType.LONG, description = "bytes write rate of the disk offering", since = "4.15")
98+
private Long bytesWriteRate;
99+
100+
@Parameter(name = ApiConstants.BYTES_WRITE_RATE_MAX, type = CommandType.LONG, description = "burst bytes write rate of the disk offering", since = "4.15")
101+
private Long bytesWriteRateMax;
102+
103+
@Parameter(name = ApiConstants.BYTES_WRITE_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
104+
private Long bytesWriteRateMaxLength;
105+
106+
@Parameter(name = ApiConstants.IOPS_READ_RATE, type = CommandType.LONG, description = "io requests read rate of the disk offering", since = "4.15")
107+
private Long iopsReadRate;
108+
109+
@Parameter(name = ApiConstants.IOPS_READ_RATE_MAX, type = CommandType.LONG, description = "burst requests read rate of the disk offering", since = "4.15")
110+
private Long iopsReadRateMax;
111+
112+
@Parameter(name = ApiConstants.IOPS_READ_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
113+
private Long iopsReadRateMaxLength;
114+
115+
@Parameter(name = ApiConstants.IOPS_WRITE_RATE, type = CommandType.LONG, description = "io requests write rate of the disk offering", since = "4.15")
116+
private Long iopsWriteRate;
117+
118+
@Parameter(name = ApiConstants.IOPS_WRITE_RATE_MAX, type = CommandType.LONG, description = "burst io requests write rate of the disk offering", since = "4.15")
119+
private Long iopsWriteRateMax;
120+
121+
@Parameter(name = ApiConstants.IOPS_WRITE_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
122+
private Long iopsWriteRateMaxLength;
123+
124+
@Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, description = "the cache mode to use for this disk offering", since = "4.15")
125+
private String cacheMode;
88126

89127
/////////////////////////////////////////////////////
90128
/////////////////// Accessors ///////////////////////
@@ -174,7 +212,59 @@ public String getTags() {
174212
return tags;
175213
}
176214

177-
/////////////////////////////////////////////////////
215+
public String getCacheMode() {
216+
return cacheMode;
217+
}
218+
219+
public Long getBytesReadRate() {
220+
return bytesReadRate;
221+
}
222+
223+
public Long getBytesReadRateMax() {
224+
return bytesReadRateMax;
225+
}
226+
227+
public Long getBytesReadRateMaxLength() {
228+
return bytesReadRateMaxLength;
229+
}
230+
231+
public Long getBytesWriteRate() {
232+
return bytesWriteRate;
233+
}
234+
235+
public Long getBytesWriteRateMax() {
236+
return bytesWriteRateMax;
237+
}
238+
239+
public Long getBytesWriteRateMaxLength() {
240+
return bytesWriteRateMaxLength;
241+
}
242+
243+
public Long getIopsReadRate() {
244+
return iopsReadRate;
245+
}
246+
247+
public Long getIopsReadRateMax() {
248+
return iopsReadRateMax;
249+
}
250+
251+
public Long getIopsReadRateMaxLength() {
252+
return iopsReadRateMaxLength;
253+
}
254+
255+
public Long getIopsWriteRate() {
256+
return iopsWriteRate;
257+
}
258+
259+
public Long getIopsWriteRateMax() {
260+
return iopsWriteRateMax;
261+
}
262+
263+
public Long getIopsWriteRateMaxLength() {
264+
return iopsWriteRateMaxLength;
265+
}
266+
267+
/////////////////////////////////////////////////////
178268
/////////////// API Implementation///////////////////
179269
/////////////////////////////////////////////////////
180270

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 91 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,42 +2530,9 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole
25302530
offering.setMinIops(minIops);
25312531
offering.setMaxIops(maxIops);
25322532

2533-
if (bytesReadRate != null && bytesReadRate > 0) {
2534-
offering.setBytesReadRate(bytesReadRate);
2535-
}
2536-
if (bytesReadRateMax != null && bytesReadRateMax > 0) {
2537-
offering.setBytesReadRateMax(bytesReadRateMax);
2538-
}
2539-
if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
2540-
offering.setBytesReadRateMaxLength(bytesReadRateMaxLength);
2541-
}
2542-
if (bytesWriteRate != null && bytesWriteRate > 0) {
2543-
offering.setBytesWriteRate(bytesWriteRate);
2544-
}
2545-
if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
2546-
offering.setBytesWriteRateMax(bytesWriteRateMax);
2547-
}
2548-
if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
2549-
offering.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
2550-
}
2551-
if (iopsReadRate != null && iopsReadRate > 0) {
2552-
offering.setIopsReadRate(iopsReadRate);
2553-
}
2554-
if (iopsReadRateMax != null && iopsReadRateMax > 0) {
2555-
offering.setIopsReadRateMax(iopsReadRateMax);
2556-
}
2557-
if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
2558-
offering.setIopsReadRateMaxLength(iopsReadRateMaxLength);
2559-
}
2560-
if (iopsWriteRate != null && iopsWriteRate > 0) {
2561-
offering.setIopsWriteRate(iopsWriteRate);
2562-
}
2563-
if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
2564-
offering.setIopsWriteRateMax(iopsWriteRateMax);
2565-
}
2566-
if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 0) {
2567-
offering.setIopsWriteRateMaxLength(iopsWriteRateMaxLength);
2568-
}
2533+
setBytesRate(offering, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
2534+
setIopsRate(offering, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength);
2535+
25692536
if(cacheMode != null) {
25702537
offering.setCacheMode(DiskOffering.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
25712538
}
@@ -2631,6 +2598,48 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole
26312598
}
26322599
}
26332600

2601+
private void setIopsRate(DiskOffering offering, Long iopsReadRate, Long iopsReadRateMax, Long iopsReadRateMaxLength, Long iopsWriteRate, Long iopsWriteRateMax, Long iopsWriteRateMaxLength) {
2602+
if (iopsReadRate != null && iopsReadRate > 0) {
2603+
offering.setIopsReadRate(iopsReadRate);
2604+
}
2605+
if (iopsReadRateMax != null && iopsReadRateMax > 0) {
2606+
offering.setIopsReadRateMax(iopsReadRateMax);
2607+
}
2608+
if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
2609+
offering.setIopsReadRateMaxLength(iopsReadRateMaxLength);
2610+
}
2611+
if (iopsWriteRate != null && iopsWriteRate > 0) {
2612+
offering.setIopsWriteRate(iopsWriteRate);
2613+
}
2614+
if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
2615+
offering.setIopsWriteRateMax(iopsWriteRateMax);
2616+
}
2617+
if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 0) {
2618+
offering.setIopsWriteRateMaxLength(iopsWriteRateMaxLength);
2619+
}
2620+
}
2621+
2622+
private void setBytesRate(DiskOffering offering, Long bytesReadRate, Long bytesReadRateMax, Long bytesReadRateMaxLength, Long bytesWriteRate, Long bytesWriteRateMax, Long bytesWriteRateMaxLength) {
2623+
if (bytesReadRate != null && bytesReadRate > 0) {
2624+
offering.setBytesReadRate(bytesReadRate);
2625+
}
2626+
if (bytesReadRateMax != null && bytesReadRateMax > 0) {
2627+
offering.setBytesReadRateMax(bytesReadRateMax);
2628+
}
2629+
if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
2630+
offering.setBytesReadRateMaxLength(bytesReadRateMaxLength);
2631+
}
2632+
if (bytesWriteRate != null && bytesWriteRate > 0) {
2633+
offering.setBytesWriteRate(bytesWriteRate);
2634+
}
2635+
if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
2636+
offering.setBytesWriteRateMax(bytesWriteRateMax);
2637+
}
2638+
if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
2639+
offering.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
2640+
}
2641+
}
2642+
26342643
@Override
26352644
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_EDIT, eventDescription = "updating service offering")
26362645
public ServiceOffering updateServiceOffering(final UpdateServiceOfferingCmd cmd) {
@@ -2897,42 +2906,9 @@ protected DiskOfferingVO createDiskOffering(final Long userId, final List<Long>
28972906
newDiskOffering.setUseLocalStorage(localStorageRequired);
28982907
newDiskOffering.setDisplayOffering(isDisplayOfferingEnabled);
28992908

2900-
if (bytesReadRate != null && bytesReadRate > 0) {
2901-
newDiskOffering.setBytesReadRate(bytesReadRate);
2902-
}
2903-
if (bytesReadRateMax != null && bytesReadRateMax > 0) {
2904-
newDiskOffering.setBytesReadRateMax(bytesReadRateMax);
2905-
}
2906-
if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
2907-
newDiskOffering.setBytesReadRateMaxLength(bytesReadRateMaxLength);
2908-
}
2909-
if (bytesWriteRate != null && bytesWriteRate > 0) {
2910-
newDiskOffering.setBytesWriteRate(bytesWriteRate);
2911-
}
2912-
if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
2913-
newDiskOffering.setBytesWriteRateMax(bytesWriteRateMax);
2914-
}
2915-
if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
2916-
newDiskOffering.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
2917-
}
2918-
if (iopsReadRate != null && iopsReadRate > 0) {
2919-
newDiskOffering.setIopsReadRate(iopsReadRate);
2920-
}
2921-
if (iopsReadRateMax != null && iopsReadRateMax > 0) {
2922-
newDiskOffering.setIopsReadRateMax(iopsReadRateMax);
2923-
}
2924-
if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
2925-
newDiskOffering.setIopsReadRateMaxLength(iopsReadRateMaxLength);
2926-
}
2927-
if (iopsWriteRate != null && iopsWriteRate > 0) {
2928-
newDiskOffering.setIopsWriteRate(iopsWriteRate);
2929-
}
2930-
if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
2931-
newDiskOffering.setIopsWriteRateMax(iopsWriteRateMax);
2932-
}
2933-
if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 0) {
2934-
newDiskOffering.setIopsWriteRateMaxLength(iopsWriteRateMaxLength);
2935-
}
2909+
setBytesRate(newDiskOffering, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
2910+
setIopsRate(newDiskOffering, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength);
2911+
29362912
if (cacheMode != null) {
29372913
newDiskOffering.setCacheMode(DiskOffering.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
29382914
}
@@ -3111,6 +3087,20 @@ public DiskOffering updateDiskOffering(final UpdateDiskOfferingCmd cmd) {
31113087
final List<Long> zoneIds = cmd.getZoneIds();
31123088
final String tags = cmd.getTags();
31133089

3090+
Long bytesReadRate = cmd.getBytesReadRate();
3091+
Long bytesReadRateMax = cmd.getBytesReadRateMax();
3092+
Long bytesReadRateMaxLength = cmd.getBytesReadRateMaxLength();
3093+
Long bytesWriteRate = cmd.getBytesWriteRate();
3094+
Long bytesWriteRateMax = cmd.getBytesWriteRateMax();
3095+
Long bytesWriteRateMaxLength = cmd.getBytesWriteRateMaxLength();
3096+
Long iopsReadRate = cmd.getIopsReadRate();
3097+
Long iopsReadRateMax = cmd.getIopsReadRateMax();
3098+
Long iopsReadRateMaxLength = cmd.getIopsReadRateMaxLength();
3099+
Long iopsWriteRate = cmd.getIopsWriteRate();
3100+
Long iopsWriteRateMax = cmd.getIopsWriteRateMax();
3101+
Long iopsWriteRateMaxLength = cmd.getIopsWriteRateMaxLength();
3102+
String cacheMode = cmd.getCacheMode();
3103+
31143104
// Check if diskOffering exists
31153105
final DiskOffering diskOfferingHandle = _entityMgr.findById(DiskOffering.class, diskOfferingId);
31163106
if (diskOfferingHandle == null) {
@@ -3191,7 +3181,10 @@ public DiskOffering updateDiskOffering(final UpdateDiskOfferingCmd cmd) {
31913181
throw new InvalidParameterValueException(String.format("Unable to update disk offering: %s by id user: %s because it is not root-admin or domain-admin", diskOfferingHandle.getUuid(), user.getUuid()));
31923182
}
31933183

3194-
final boolean updateNeeded = shouldUpdateDiskOffering(name, displayText, sortKey, displayDiskOffering, tags);
3184+
boolean updateNeeded = shouldUpdateDiskOffering(name, displayText, sortKey, displayDiskOffering, tags, cacheMode) ||
3185+
shouldUpdateIopsRateParameters(iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength) ||
3186+
shouldUpdateBytesRateParameters(bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
3187+
31953188
final boolean detailsUpdateNeeded = !filteredDomainIds.equals(existingDomainIds) || !filteredZoneIds.equals(existingZoneIds);
31963189
if (!updateNeeded && !detailsUpdateNeeded) {
31973190
return _diskOfferingDao.findById(diskOfferingId);
@@ -3217,6 +3210,20 @@ public DiskOffering updateDiskOffering(final UpdateDiskOfferingCmd cmd) {
32173210

32183211
updateDiskOfferingTagsIfIsNotNull(tags, diskOffering);
32193212

3213+
validateMaxRateEqualsOrGreater(iopsReadRate, iopsReadRateMax, IOPS_READ_RATE);
3214+
validateMaxRateEqualsOrGreater(iopsWriteRate, iopsWriteRateMax, IOPS_WRITE_RATE);
3215+
validateMaxRateEqualsOrGreater(bytesReadRate, bytesReadRateMax, BYTES_READ_RATE);
3216+
validateMaxRateEqualsOrGreater(bytesWriteRate, bytesWriteRateMax, BYTES_WRITE_RATE);
3217+
validateMaximumIopsAndBytesLength(iopsReadRateMaxLength, iopsWriteRateMaxLength, bytesReadRateMaxLength, bytesWriteRateMaxLength);
3218+
3219+
setBytesRate(diskOffering, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
3220+
setIopsRate(diskOffering, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength);
3221+
3222+
if (cacheMode != null) {
3223+
validateCacheMode(cacheMode);
3224+
diskOffering.setCacheMode(DiskOffering.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
3225+
}
3226+
32203227
if (updateNeeded && !_diskOfferingDao.update(diskOfferingId, diskOffering)) {
32213228
return null;
32223229
}
@@ -3273,8 +3280,17 @@ protected void updateDiskOfferingTagsIfIsNotNull(String tags, DiskOfferingVO dis
32733280
* Check if it needs to update any parameter when updateDiskoffering is called
32743281
* Verify if name or displayText are not blank, tags is not null, sortkey and displayDiskOffering is not null
32753282
*/
3276-
protected boolean shouldUpdateDiskOffering(String name, String displayText, Integer sortKey, Boolean displayDiskOffering, String tags) {
3277-
return StringUtils.isNotBlank(name) || StringUtils.isNotBlank(displayText) || tags != null || sortKey != null || displayDiskOffering != null;
3283+
protected boolean shouldUpdateDiskOffering(String name, String displayText, Integer sortKey, Boolean displayDiskOffering, String tags, String cacheMode) {
3284+
return StringUtils.isNotBlank(name) || StringUtils.isNotBlank(displayText) || tags != null || sortKey != null || displayDiskOffering != null || StringUtils.isNotBlank(cacheMode);
3285+
}
3286+
3287+
protected boolean shouldUpdateBytesRateParameters(Long bytesReadRate, Long bytesReadRateMax, Long bytesReadRateMaxLength, Long bytesWriteRate, Long bytesWriteRateMax, Long bytesWriteRateMaxLength) {
3288+
return bytesReadRate != null || bytesReadRateMax != null || bytesReadRateMaxLength != null || bytesWriteRate != null ||
3289+
bytesWriteRateMax != null || bytesWriteRateMaxLength != null;
3290+
}
3291+
3292+
protected boolean shouldUpdateIopsRateParameters(Long iopsReadRate, Long iopsReadRateMax, Long iopsReadRateMaxLength, Long iopsWriteRate, Long iopsWriteRateMax, Long iopsWriteRateMaxLength) {
3293+
return iopsReadRate != null || iopsReadRateMax != null || iopsReadRateMaxLength != null || iopsWriteRate != null || iopsWriteRateMax != null || iopsWriteRateMaxLength != null;
32783294
}
32793295

32803296
@Override

0 commit comments

Comments
 (0)