Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
}

// Find out if the volume is at state of download_in_progress on secondary storage
VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
if (volumeStore != null) {
if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
VolumeDataStoreVO volumeOnImageStore = _volumeStoreDao.findByVolume(volume.getId());
if (volumeOnImageStore != null) {
if (volumeOnImageStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
String msg = String.format("Volume: %s is currently being uploaded; can't delete it.", volume);
logger.debug(msg);
result.setSuccess(false);
Expand All @@ -416,10 +416,10 @@ public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {

if (!volumeExistsOnPrimary(vol)) {
// not created on primary store
if (volumeStore == null) {
if (volumeOnImageStore == null) {
// also not created on secondary store
if (logger.isDebugEnabled()) {
logger.debug("Marking volume that was never created as destroyed: " + vol);
logger.debug("Marking volume that was never created as destroyed: {}", vol);
}
VMTemplateVO template = templateDao.findById(vol.getTemplateId());
if (template != null && !template.isDeployAsIs()) {
Expand All @@ -435,11 +435,21 @@ public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
if (volume.getDataStore().getRole() == DataStoreRole.Image) {
// no need to change state in volumes table
volume.processEventOnly(Event.DestroyRequested);
if (volumeOnImageStore == null) {
logger.debug("Volume {} doesn't exist on image store, no need to delete", vol);
future.complete(result);
return future;
}
} else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
if (vol.getState() == Volume.State.Expunging) {
logger.info("Volume {} is already in Expunging, retrying", volume);
}
volume.processEvent(Event.ExpungeRequested);
if (!volumeExistsOnPrimary(vol)) {
logger.debug("Volume {} doesn't exist on primary storage, no need to delete", vol);
future.complete(result);
return future;
}
}

DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<>(null, vo, future);
Expand All @@ -460,13 +470,11 @@ public void ensureVolumeIsExpungeReady(long volumeId) {

private boolean volumeExistsOnPrimary(VolumeVO vol) {
Long poolId = vol.getPoolId();

if (poolId == null) {
return false;
}

PrimaryDataStore primaryStore = dataStoreMgr.getPrimaryDataStore(poolId);

if (primaryStore == null) {
return false;
}
Expand All @@ -476,8 +484,7 @@ private boolean volumeExistsOnPrimary(VolumeVO vol) {
}

String volumePath = vol.getPath();

if (volumePath == null || volumePath.trim().isEmpty()) {
if (StringUtils.isBlank(volumePath)) {
return false;
}

Expand Down
Loading