@Override
@DB
public boolean destroyVolume(VolumeVO volume) throws ConcurrentOperationException {
try {
if (!stateTransitTo(volume, Volume.Event.DestroyRequested)) {
throw new ConcurrentOperationException("Failed to transit to destroyed state");
}
} catch (NoTransitionException e) {
s_logger.debug("Unable to destoy the volume: " + e.toString());
return false;
}
long volumeId = volume.getId();
// Delete the recurring snapshot policies for this volume.
_snapshotMgr.deletePoliciesForVolume(volumeId);
Long instanceId = volume.getInstanceId();
VMInstanceVO vmInstance = null;
if (instanceId != null) {
vmInstance = _vmInstanceDao.findById(instanceId);
}
if (instanceId == null || (vmInstance.getType().equals(VirtualMachine.Type.User))) {
// Decrement the resource count for volumes belonging user VM's only
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume);
// Log usage event for volumes belonging user VM's only
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName());
_usageEventDao.persist(usageEvent);
}
try {
if (!stateTransitTo(volume, Volume.Event.OperationSucceeded)) {
throw new ConcurrentOperationException("Failed to transit state");
}
} catch (NoTransitionException e) {
s_logger.debug("Unable to change volume state: " + e.toString());
return false;