|
23 | 23 | import java.util.Collections; |
24 | 24 | import java.util.Date; |
25 | 25 | import java.util.HashMap; |
| 26 | +import java.util.HashSet; |
26 | 27 | import java.util.List; |
27 | 28 | import java.util.Map; |
28 | 29 | import java.util.Optional; |
| 30 | +import java.util.Set; |
29 | 31 | import java.util.UUID; |
30 | 32 | import java.util.concurrent.ExecutionException; |
31 | 33 |
|
@@ -306,6 +308,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic |
306 | 308 | private long _maxVolumeSizeInGb; |
307 | 309 | private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine; |
308 | 310 |
|
| 311 | + 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)); |
| 312 | + |
309 | 313 | protected VolumeApiServiceImpl() { |
310 | 314 | _volStateMachine = Volume.State.getStateMachine(); |
311 | 315 | _gson = GsonHelper.getGsonLogger(); |
@@ -1451,13 +1455,14 @@ protected VolumeVO retrieveAndValidateVolume(long volumeId, Account caller) { |
1451 | 1455 | * <ul> |
1452 | 1456 | * <li> {@value Volume.State#Destroy}; |
1453 | 1457 | * <li> {@value Volume.State#Expunging}; |
1454 | | - * <li> {@value Volume.State#Expunged}. |
| 1458 | + * <li> {@value Volume.State#Expunged}; |
| 1459 | + * <li> {@value Volume.State#Allocated}. |
1455 | 1460 | * </ul> |
1456 | 1461 | * |
1457 | 1462 | * The volume is destroyed via {@link VolumeService#destroyVolume(long)} method. |
1458 | 1463 | */ |
1459 | 1464 | protected void destroyVolumeIfPossible(VolumeVO volume) { |
1460 | | - 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) { |
| 1465 | + if (!STATES_VOLUME_CANNOT_BE_DESTROYED.contains(volume.getState())) { |
1461 | 1466 | volService.destroyVolume(volume.getId()); |
1462 | 1467 | } |
1463 | 1468 | } |
|
0 commit comments