rafaelweingartner commented on a change in pull request #2629: Fix primary 
storage count when deleting volumes
URL: https://github.com/apache/cloudstack/pull/2629#discussion_r187592366
 
 

 ##########
 File path: server/src/com/cloud/storage/VolumeApiServiceImpl.java
 ##########
 @@ -1259,92 +1261,139 @@ private VolumeVO orchestrateResizeVolume(long 
volumeId, long currentSize, long n
         }
     }
 
-    @Override
     @DB
+    @Override
     @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription 
= "deleting volume")
-    public boolean deleteVolume(long volumeId, Account caller) throws 
ConcurrentOperationException {
+    /**
+     * Executes the removal of the volume. If the volume is only allocated we 
do not try to remove it from primary and secondary storage.
+     * Otherwise, after the removal in the database, we will try to remove the 
volume from both primary and secondary storage.
+     */
+    public boolean deleteVolume(long volumeId, Account caller){
+        VolumeVO volume = retrieveAndValidateVolume(volumeId, caller);
+        try {
+            destroyVolumeIfPossible(volume);
+            // Mark volume as removed if volume has not been created on 
primary or secondary
+            if (volume.getState() == Volume.State.Allocated) {
+                _volsDao.remove(volumeId);
+                stateTransitTo(volume, Volume.Event.DestroyRequested);
+                return true;
+            }
+            expungeVolumesInPrimaryStorageIfNeeded(volume);
+            expungeVolumesInSecondaryStorageIfNeeded(volume);
+            cleanVolumesCache(volume);
+            return true;
+        } catch (InterruptedException | ExecutionException | 
NoTransitionException e) {
+            s_logger.warn("Failed to expunge volume: " + volume.getUuid(), e);
+            return false;
+        }
+    }
+
+    /**
 
 Review comment:
   I am using `protected` modifier here because I have unit tests for this 
method.
   
   I used Java doc notation style because that is what I am used to do. I am 
change though. It is probably an influence of Apache commons and Spring suite 
code style.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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