DaanHoogland commented on a change in pull request #3688: New feature: Add
support to destroy/recover volumes
URL: https://github.com/apache/cloudstack/pull/3688#discussion_r364832740
##########
File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
##########
@@ -1389,6 +1385,89 @@ protected boolean stateTransitTo(Volume vol,
Volume.Event event) throws NoTransi
return _volStateMachine.transitTo(vol, event, null, _volsDao);
}
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DESTROY, eventDescription
= "destroying a volume")
+ public Volume destroyVolume(long volumeId, Account caller, boolean
expunge, boolean forceExpunge) {
+ VolumeVO volume = retrieveAndValidateVolume(volumeId, caller);
+
+ if (expunge) {
+ // When trying to expunge, permission is denied when the caller is
not an admin and the AllowUserExpungeRecoverVolume is false for the caller.
+ final Long userId = caller.getAccountId();
+ if (!forceExpunge && !_accountMgr.isAdmin(userId) &&
!AllowUserExpungeRecoverVolume.valueIn(userId)) {
+ throw new PermissionDeniedException("Expunging a volume can
only be done by an Admin. Or when the allow.user.expunge.recover.volume key is
set.");
+ }
+ } else if (volume.getState() == Volume.State.Allocated ||
volume.getState() == Volume.State.Uploaded) {
+ throw new InvalidParameterValueException("The volume in
Allocated/Uploaded state can only be expunged not destroyed/recovered");
+ }
+
+ destroyVolumeIfPossible(volume);
+
+ if (expunge) {
+ // Mark volume as removed if volume has not been created on
primary or secondary
+ if (volume.getState() == Volume.State.Allocated) {
+ _volsDao.remove(volume.getId());
+ try {
+ stateTransitTo(volume, Volume.Event.DestroyRequested);
+ } catch (NoTransitionException e) {
+ s_logger.debug("Failed to destroy volume" +
volume.getId(), e);
+ return null;
+ }
+
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(),
ResourceType.volume, volume.isDisplay());
+
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(),
ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize()));
+ return volume;
+ }
+ if (!deleteVolumeFromStorage(volume, caller)) {
+ s_logger.warn("Failed to expunge volume: " + volumeId);
+ return null;
+ }
+ }
+
+ return volume;
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VOLUME_RECOVER, eventDescription
= "recovering a Destroy volume")
Review comment:
typo "destroy" instead of "destroyed"
----------------------------------------------------------------
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