Skip to content

Commit 9138e20

Browse files
CSTACKEX-18_2: rollback the object creation in case of failures
1 parent e1a6465 commit 9138e20

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/vmsnapshot/OntapVMSnapshotStrategy.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
272272
"Please use snapshotmemory=false for disk-only snapshots.",
273273
userVm.getInstanceName());
274274
logger.error("takeVMSnapshot: {}", errorMsg);
275+
// Clean up the VM snapshot record that was created in Allocated state before throwing
276+
// This prevents orphaned snapshot records from showing in the UI
277+
try {
278+
vmSnapshotDao.remove(vmSnapshotVO.getId());
279+
logger.debug("takeVMSnapshot: Removed VM snapshot record [{}] after memory snapshot validation failure", vmSnapshotVO.getId());
280+
} catch (Exception cleanupEx) {
281+
logger.warn("takeVMSnapshot: Failed to remove VM snapshot record [{}] during cleanup: {}",
282+
vmSnapshotVO.getId(), cleanupEx.getMessage());
283+
}
275284
throw new CloudRuntimeException(errorMsg);
276285
}
277286

0 commit comments

Comments
 (0)