GabrielBrascher commented on a change in pull request #3681: Validate disk 
offering IOPS normal and maximum read/write values
URL: https://github.com/apache/cloudstack/pull/3681#discussion_r385933875
 
 

 ##########
 File path: 
server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
 ##########
 @@ -2999,6 +3020,57 @@ public DiskOffering createDiskOffering(final 
CreateDiskOfferingCmd cmd) {
                 hypervisorSnapshotReserve);
     }
 
+    /**
+     * Validates rate offerings, being flexible about which rate is being 
validated (e.g. read/write Bytes, read/write IOPS).</br>
+     * It throws InvalidParameterValueException if normal rate is greater than 
maximum rate
+     */
+    protected void validateMaxRateEqualsOrGreater(Long normalRate, Long 
maxRate, String rateType) {
+        if (normalRate != null && maxRate != null && maxRate < normalRate) {
+            throw new InvalidParameterValueException(
+                    String.format("%s rate (%d) cannot be greater than %s 
maximum rate (%d)", rateType, normalRate, rateType, maxRate));
+        }
+    }
+
+    /**
+     *  Throws InvalidParameterValueException if At least one of the VM disk 
Bytes/IOPS Read/Write length are smaller than the respective disk offering max 
length.</br>
+     *  It will ignore verification in case of default values (zero):
+     * <ul>
+     *  <li>vm.disk.bytes.maximum.read.length = 0</li>
+     *  <li>vm.disk.bytes.maximum.write.length = 0</li>
+     *  <li>vm.disk.iops.maximum.read.length = 0</li>
+     *  <li>vm.disk.iops.maximum.write.length = 0</li>
+     * </ul>
+     */
+    protected void validateMaximumIopsAndBytesLength(final Long 
iopsReadRateMaxLength, final Long iopsWriteRateMaxLength, Long 
bytesReadRateMaxLength, Long bytesWriteRateMaxLength) {
+        if (IOPS_MAX_READ_LENGTH.value() != null && 
IOPS_MAX_READ_LENGTH.value() != 0l) {
+            if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 
IOPS_MAX_READ_LENGTH.value()) {
+                throw new InvalidParameterValueException(String.format("IOPS 
read max length (%d seconds) cannot be greater than 
vm.disk.iops.maximum.read.length (%d seconds)",
+                        iopsReadRateMaxLength, IOPS_MAX_READ_LENGTH.value()));
+            }
+        }
+
+        if (IOPS_MAX_WRITE_LENGTH.value() != null && 
IOPS_MAX_WRITE_LENGTH.value() != 0l) {
+            if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 
IOPS_MAX_WRITE_LENGTH.value()) {
+                throw new InvalidParameterValueException(String.format("IOPS 
write max length (%d seconds) cannot be greater than 
vm.disk.iops.maximum.write.length (%d seconds)",
+                        iopsWriteRateMaxLength, 
IOPS_MAX_WRITE_LENGTH.value()));
+            }
+        }
+
+        if (BYTES_MAX_READ_LENGTH.value() != null && 
BYTES_MAX_READ_LENGTH.value() != 0l) {
+            if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 
BYTES_MAX_READ_LENGTH.value()) {
+                throw new InvalidParameterValueException(String.format("Bytes 
read max length (%d seconds) cannot be greater than 
vm.disk.bytes.maximum.read.length (%d seconds)",
+                        bytesReadRateMaxLength, 
BYTES_MAX_READ_LENGTH.value()));
+            }
+        }
+
+        if (BYTES_MAX_WRITE_LENGTH.value() != null && 
BYTES_MAX_WRITE_LENGTH.value() != 0l) {
+            if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 
BYTES_MAX_WRITE_LENGTH.value()) {
 
 Review comment:
   Well noted, thanks for the review and tests, @RodrigoDLopez. I just fixed it!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to