Source:
<code>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); <START> if (createdSnapshot == null) { <END> 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()); } }</code><technical_language>1. Ravi, IMO this of transaction, need open a new transaction if do anything.. 2. return this point</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 = true; } 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()); } }