Maor Lipchuk has uploaded a new change for review. Change subject: core: Extract method of snapshot id. ......................................................................
core: Extract method of snapshot id. Extracting the snapshot id to a new method, and add a private parameter instead working with the parameters. Signed-off-by: Maor Lipchuk <[email protected]> Related to Bug-Url: https://bugzilla.redhat.com/1018554 Change-Id: I4754e381d70f08a9650596a4eeb3de296b3cb44f --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java 1 file changed, 16 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/19/20419/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java index 2a8ad53..a9c9b76 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java @@ -56,6 +56,7 @@ public class RestoreAllSnapshotsCommand<T extends RestoreAllSnapshotsParameters> extends VmCommand<T> implements QuotaStorageDependent { private final Set<Guid> snapshotsToRemove = new HashSet<Guid>(); + private Guid snapshotId; /** * The snapshot id which will be removed (the stateless/preview/active image). @@ -87,11 +88,11 @@ } // The snapshot being restored to - Snapshot targetSnapshot = getSnapshotDao().get(getParameters().getDstSnapshotId()); + Snapshot targetSnapshot = getSnapshotDao().get(snapshotId); if (targetSnapshot == null) { throw new VdcBLLException(VdcBllErrors.ENGINE, "Can't find target snapshot by id: " - + getParameters().getDstSnapshotId()); + + snapshotId); } restoreSnapshotAndRemoveObsoleteSnapshots(targetSnapshot); @@ -117,11 +118,15 @@ deleteOrphanedImages(); } else { getVmStaticDAO().incrementDbGeneration(getVm().getId()); - getSnapshotDao().updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.OK); + getSnapshotDao().updateStatus(snapshotId, SnapshotStatus.OK); unlockVm(); } setSucceeded(succeeded); + } + + private Guid getSnapshotId() { + return getParameters().getDstSnapshotId(); } protected void removeSnapshotsFromDB() { @@ -311,9 +316,9 @@ } private List<DiskImage> getImagesList() { - if (getParameters().getImagesList() == null && !getParameters().getDstSnapshotId().equals(Guid.Empty)) { + if (getParameters().getImagesList() == null && !snapshotId.equals(Guid.Empty)) { getParameters().setImagesList( - getDiskImageDao().getAllSnapshotsForVmSnapshot(getParameters().getDstSnapshotId())); + getDiskImageDao().getAllSnapshotsForVmSnapshot(snapshotId)); } return getParameters().getImagesList(); } @@ -333,7 +338,7 @@ public Map<String, String> getJobMessageProperties() { if (jobProperties == null) { jobProperties = super.getJobMessageProperties(); - Snapshot snapshot = getSnapshotDao().get(getParameters().getDstSnapshotId()); + Snapshot snapshot = getSnapshotDao().get(snapshotId); if (snapshot != null) { jobProperties.put(VdcObjectType.Snapshot.name().toLowerCase(), snapshot.getDescription()); } @@ -351,13 +356,14 @@ return false; } - if (Guid.Empty.equals(getParameters().getDstSnapshotId())) { + snapshotId = getSnapshotId(); + if (Guid.Empty.equals(snapshotId)) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID); } SnapshotsValidator snapshotValidator = createSnapshotValidator(); VmValidator vmValidator = new VmValidator(getVm()); - if (!validate(snapshotValidator.snapshotExists(getVmId(), getParameters().getDstSnapshotId())) || + if (!validate(snapshotValidator.snapshotExists(getVmId(), snapshotId)) || !validate(new StoragePoolValidator(getStoragePool()).isUp())) { return false; } @@ -370,7 +376,7 @@ return false; } - Snapshot snapshot = getSnapshotDao().get(getParameters().getDstSnapshotId()); + Snapshot snapshot = getSnapshotDao().get(snapshotId); if (snapshot.getType() == SnapshotType.REGULAR && snapshot.getStatus() != SnapshotStatus.IN_PREVIEW) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW); @@ -438,7 +444,7 @@ @Override protected void endVmCommand() { // if we got here, the target snapshot exists for sure - getSnapshotDao().updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.OK); + getSnapshotDao().updateStatus(snapshotId, SnapshotStatus.OK); super.endVmCommand(); } -- To view, visit http://gerrit.ovirt.org/20419 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4754e381d70f08a9650596a4eeb3de296b3cb44f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
