Source:
<code>protected void endVmCommand() { <START> TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { <END> @Override public Void runInTransaction() { final boolean taskGroupSucceeded = getParameters().getTaskGroupSuccess(); Snapshot createdSnapshot = getSnapshotDao().get(getVmId(), getParameters().getSnapshotType(), SnapshotStatus.LOCKED); if (taskGroupSucceeded) { if (createdSnapshot != null) { getSnapshotDao().updateStatus(createdSnapshot.getId(), SnapshotStatus.OK); if (isLiveSnapshotApplicable()) { performLiveSnapshot(createdSnapshot); } else { if (!createdSnapshot.getMemoryVolume().isEmpty()) { logMemorySavingFailed(); if (!removeMemoryFromSnapshot(createdSnapshot, true)) { log.errorFormat("Failed to remove unused memory {0} of snapshot {1}", createdSnapshot.getMemoryVolume(), createdSnapshot.getId()); } } } } else { log.warnFormat("No snapshot was found for VM {0} which is in LOCKED status command will be failed", getVmId()); } } else { if (createdSnapshot != null) { revertToActiveSnapshot(createdSnapshot.getId()); if (!removeMemoryFromSnapshot(createdSnapshot, false)) { log.warnFormat("Failed to remove memory {0} of snapshot {1}", createdSnapshot.getMemoryVolume(), createdSnapshot.getId()); } } else { log.warnFormat("No snapshot was created for VM {0} which is in LOCKED status", getVmId()); } } incrementVmGeneration(); endActionOnDisks(); setSucceeded(createdSnapshot == null ? false : taskGroupSucceeded); getReturnValue().setEndActionTryAgain(false); return null; } }); if (getVm() != null && getVm().isAutoStartup() && isVmDownUnintentionally() && getParameters().getInitialVmStatus() != VMStatus.Down) { Backend.getInstance().runInternalAction(VdcActionType.RunVm, new RunVmParams(getVmId()), ExecutionHandler.createInternalJobContext()); } }</code><technical_language>Allon, another question - engine restart , Ravi in commit msg, if snapshot entry compensated, want end failure somehow</technical_language>

Target:
protected void endVmCommand() { TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override public Void runInTransaction() { boolean taskGroupSucceeded = getParameters().getTaskGroupSuccess(); Snapshot createdSnapshot = getSnapshotDao().get(getVmId(), getParameters().getSnapshotType(), SnapshotStatus.LOCKED); if (createdSnapshot == null) { taskGroupSucceeded = false; } if (taskGroupSucceeded) { getSnapshotDao().updateStatus(createdSnapshot.getId(), SnapshotStatus.OK); if (isLiveSnapshotApplicable()) { performLiveSnapshot(createdSnapshot); } else { if (!createdSnapshot.getMemoryVolume().isEmpty()) { logMemorySavingFailed(); if (!removeMemoryFromSnapshot(createdSnapshot, true)) { log.errorFormat("Failed to remove unused memory {0} of snapshot {1}", createdSnapshot.getMemoryVolume(), createdSnapshot.getId()); } } } } else { if (createdSnapshot != null) { revertToActiveSnapshot(createdSnapshot.getId()); if (!removeMemoryFromSnapshot(createdSnapshot, false)) { log.warnFormat("Failed to remove memory {0} of snapshot {1}", createdSnapshot.getMemoryVolume(), createdSnapshot.getId()); } } else { log.warnFormat("No snapshot was created for VM {0} which is in LOCKED status", getVmId()); } } incrementVmGeneration(); endActionOnDisks(); setSucceeded(taskGroupSucceeded); getReturnValue().setEndActionTryAgain(false); return null; } }); if (getVm() != null && getVm().isAutoStartup() && isVmDownUnintentionally() && getParameters().getInitialVmStatus() != VMStatus.Down) { Backend.getInstance().runInternalAction(VdcActionType.RunVm, new RunVmParams(getVmId()), ExecutionHandler.createInternalJobContext()); } }