Skip to content

Commit d730b55

Browse files
committed
Block backup deletion while create-VM-from-backup or restore jobs are in progress
1 parent 7aa0558 commit d730b55

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,8 @@ public boolean deleteBackup(final Long backupId, final Boolean forced) {
15291529
}
15301530
logger.debug("Deleting backup {} belonging to instance {}", backup.toString(), vmId);
15311531

1532+
checkForPendingBackupJobs(backup);
1533+
15321534
validateBackupForZone(backup.getZoneId());
15331535
accountManager.checkAccess(CallContext.current().getCallingAccount(), null, true, vm == null ? backup : vm);
15341536
final BackupOffering offering = backupOfferingDao.findByIdIncludingRemoved(backup.getBackupOfferingId());
@@ -1551,6 +1553,17 @@ public boolean deleteBackup(final Long backupId, final Boolean forced) {
15511553
throw new CloudRuntimeException("Failed to delete the backup");
15521554
}
15531555

1556+
private void checkForPendingBackupJobs(final BackupVO backup) {
1557+
String backupUuid = backup.getUuid();
1558+
long pendingJobs = asyncJobManager.countPendingJobs(backupUuid,
1559+
CreateVMFromBackupCmd.class.getName(),
1560+
CreateVMFromBackupCmdByAdmin.class.getName(),
1561+
RestoreBackupCmd.class.getName());
1562+
if (pendingJobs > 0) {
1563+
throw new CloudRuntimeException("Cannot delete backup while a create instance from backup or restore operation is in progress, please try again later.");
1564+
}
1565+
}
1566+
15541567
/**
15551568
* Get the pair: hostIp, datastoreUuid in which to restore the volume, based on the VM to be attached information
15561569
*/

0 commit comments

Comments
 (0)