Source:
protected void endVmCommand() { TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override public Void runInTransaction() { final boolean taskGroupSucceeded = getParameters().getTaskGroupSuccess(); Snapshot createdSnapshot = getSnapshotDao().get(getVmId(), getParameters().getSnapshotType(), SnapshotStatus.LOCKED); if (taskGroupSucceeded) { getSnapshotDao().updateStatus(createdSnapshot.getId(), SnapshotStatus.OK); if (isLiveSnapshotApplicable()) { performLiveSnapshot(createdSnapshot); } else { String memoryVolume = createdSnapshot.getMemoryVolume(); if (!memoryVolume.isEmpty() && getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolume) == 1) { boolean succeed = removeMemoryVolumes(memoryVolume, getActionType(), false); if (!succeed) { log.errorFormat("Failed to remove unused memory {0} of snapshot {1}", memoryVolume, createdSnapshot.getId()); } } } } else { if (createdSnapshot != null) { revertToActiveSnapshot(createdSnapshot.getId()); String memoryVolume = createdSnapshot.getMemoryVolume(); if (!memoryVolume.isEmpty() && getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolume) == 1) { boolean succeed = removeMemoryVolumes(memoryVolume, getActionType(), false); if (!succeed) { log.warnFormat("Failed to remove memory {0} of snapshot {1}", memoryVolume, createdSnapshot.getId()); } } } else { log.infoFormat("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()); } }

Target:
protected void endVmCommand() { TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override public Void runInTransaction() { final boolean taskGroupSucceeded = getParameters().getTaskGroupSuccess(); Snapshot createdSnapshot = getSnapshotDao().get(getVmId(), getParameters().getSnapshotType(), SnapshotStatus.LOCKED); if (taskGroupSucceeded) { getSnapshotDao().updateStatus(createdSnapshot.getId(), SnapshotStatus.OK); if (isLiveSnapshotApplicable()) { performLiveSnapshot(createdSnapshot); } else { String memoryVolume = createdSnapshot.getMemoryVolume(); if (!memoryVolume.isEmpty() && getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolume) == 1) { boolean succeed = removeMemoryVolumes(memoryVolume, getActionType(), false); if (!succeed) { log.errorFormat("Failed to remove unused memory {0} of snapshot {1}", memoryVolume, createdSnapshot.getId()); } } } } else { if (createdSnapshot != null) { revertToActiveSnapshot(createdSnapshot.getId()); String memoryVolume = createdSnapshot.getMemoryVolume(); if (!memoryVolume.isEmpty() && getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolume) == 1) { boolean succeed = removeMemoryVolumes(memoryVolume, getActionType(), false); if (!succeed) { log.warnFormat("Failed to remove memory {0} of snapshot {1}", memoryVolume, 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()); } }