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 2021/06/18 21:05:20 UTC

[GitHub] [cloudstack] GabrielBrascher commented on a change in pull request #5125: volume: Fix deletion of Uploaded volumes

GabrielBrascher commented on a change in pull request #5125:
URL: https://github.com/apache/cloudstack/pull/5125#discussion_r653853018



##########
File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
##########
@@ -1457,7 +1457,7 @@ protected VolumeVO retrieveAndValidateVolume(long volumeId, Account caller) {
      * The volume is destroyed via {@link VolumeService#destroyVolume(long)} method.
      */
     protected void destroyVolumeIfPossible(VolumeVO volume) {
-        if (volume.getState() != Volume.State.Destroy && volume.getState() != Volume.State.Expunging && volume.getState() != Volume.State.Expunged && volume.getState() != Volume.State.Allocated && volume.getState() != Volume.State.Uploaded) {
+        if (volume.getState() != Volume.State.Destroy && volume.getState() != Volume.State.Expunging && volume.getState() != Volume.State.Expunged && volume.getState() != Volume.State.Allocated) {

Review comment:
       1. replace big "IFs" to a Set of the ENUM items that should (or not) match with the compared value.
   ```
           private static final Set<Volume.State> STATES_VOLUME_CANNOT_BE_DESTROYED = new HashSet<>(Arrays.asList(Volume.State.Destroy, Volume.State.Expunging, Volume.State.Expunged, Volume.State.Allocated));
   ...
           if (!STATES_VOLUME_CANNOT_BE_DESTROYED.contains(volume.getState())) {
   ```
   
   
   2. the other suggestion would be to update the Javadoc by adding the Volume.State.Allocated
   
   ```
        * <ul>
        *  <li> {@value Volume.State#Destroy};
        *  <li> {@value Volume.State#Expunging};
        *  <li> {@value Volume.State#Expunged}.
        * </ul>
   ```
   




-- 
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:
users@infra.apache.org