diff --git a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 43270e6a0292..826b408b3871 100644 --- a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -135,6 +135,8 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme public static final String VM_WORK_JOB_HANDLER = VMSnapshotManagerImpl.class.getSimpleName(); + private static final String ERROR_STRATEGY_NOT_FOUND = "Can't find Instance Snapshot strategy for instance snapshot"; + @Inject VMInstanceDao _vmInstanceDao; @Inject ServiceOfferingDetailsDao _serviceOfferingDetailsDao; @@ -501,7 +503,7 @@ private VMSnapshotStrategy findVMSnapshotStrategy(VMSnapshot vmSnapshot) { VMSnapshotStrategy snapshotStrategy = storageStrategyFactory.getVmSnapshotStrategy(vmSnapshot); if (snapshotStrategy == null) { - throw new CloudRuntimeException(String.format("Can't find Instance Snapshot strategy for vmsnapshot: %s", vmSnapshot)); + throw new CloudRuntimeException(String.format("%s: %s", ERROR_STRATEGY_NOT_FOUND, vmSnapshot)); } return snapshotStrategy; @@ -596,6 +598,13 @@ private VMSnapshot orchestrateCreateVMSnapshot(Long vmId, Long vmSnapshotId, Boo } catch (Exception e) { String errMsg = String.format("Failed to create Instance Snapshot: [%s] due to: %s", vmSnapshot, e.getMessage()); logger.debug(errMsg, e); + if (e instanceof CloudRuntimeException) { + CloudRuntimeException cre = (CloudRuntimeException)e; + if (cre.getMessage().startsWith(ERROR_STRATEGY_NOT_FOUND) && VMSnapshot.State.Error.equals(vmSnapshot.getState())) { + logger.debug("No instance snapshot strategy found for {}, remove it from DB", vmSnapshot); + _vmSnapshotDao.remove(vmSnapshot.getId()); + } + } throw new CloudRuntimeException(errMsg, e); } }