You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/11/28 13:06:47 UTC

[GitHub] [cloudstack] GutoVeronezi commented on a diff in pull request #6704: server: fix volume migration on user vm scale

GutoVeronezi commented on code in PR #6704:
URL: https://github.com/apache/cloudstack/pull/6704#discussion_r1033519440


##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -1823,6 +1823,26 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
         return volume;
     }
 
+    /**
+     * This method is to compare long values, in miniops and maxiops a or b can be null or 0.
+     * Use this method to treat 0 and null as same
+     *
+     * @param a
+     * @param b
+     * @return true if a and b are equal excluding 0 and null values.
+     */
+    private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
+        if ((a != null && a == 0 && b == null) || (a == null && b != null && b == 0)) {
+            return true;
+        }
+
+        if (a == b) {
+            return true;
+        }
+
+        return false;
+    }

Review Comment:
   We could moved this method to `NumbersUtils` and add unit tests.
   
   As zero and null will be considered the same, we can simplify the code:
   
   `org.apache.commons.lang3.ObjectUtils`
   
   ```suggestion
       private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
           a = ObjectUtils.defaultIfNull(a, 0L);
           b = ObjectUtils.defaultIfNull(b, 0L);
   
           return a.equals(b);
       }
   ```



##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -1823,6 +1823,26 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
         return volume;
     }
 
+    /**
+     * This method is to compare long values, in miniops and maxiops a or b can be null or 0.
+     * Use this method to treat 0 and null as same
+     *
+     * @param a
+     * @param b
+     * @return true if a and b are equal excluding 0 and null values.
+     */
+    private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
+        if ((a != null && a == 0 && b == null) || (a == null && b != null && b == 0)) {
+            return true;
+        }
+
+        if (a == b) {
+            return true;
+        }
+
+        return false;
+    }

Review Comment:
   We could move this method to `NumbersUtils` and add unit tests.
   
   As zero and null will be considered the same, we can simplify the code:
   
   `org.apache.commons.lang3.ObjectUtils`
   
   ```suggestion
       private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
           a = ObjectUtils.defaultIfNull(a, 0L);
           b = ObjectUtils.defaultIfNull(b, 0L);
   
           return a.equals(b);
       }
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org