Maor Lipchuk has uploaded a new change for review. Change subject: core: Extract method of snapshot id. ......................................................................
core: Extract method of snapshot id. Extracting a new method to get the snapshot id instead of working directly with the parameters command. Signed-off-by: Maor Lipchuk <[email protected]> Related to Bug-Url: https://bugzilla.redhat.com/867339 Change-Id: I4754e381d70f08a9650596a4eeb3de296b3cb44f --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java 1 file changed, 14 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/25688/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 7a7341b..85e4d25 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 @@ -91,11 +91,11 @@ } // The snapshot being restored to - Snapshot targetSnapshot = getSnapshotDao().get(getParameters().getDstSnapshotId()); + Snapshot targetSnapshot = getSnapshotDao().get(getSnapshotId()); if (targetSnapshot == null) { throw new VdcBLLException(VdcBllErrors.ENGINE, "Can't find target snapshot by id: " - + getParameters().getDstSnapshotId()); + + getSnapshotId()); } restoreSnapshotAndRemoveObsoleteSnapshots(targetSnapshot); @@ -121,11 +121,15 @@ deleteOrphanedImages(); } else { getVmStaticDAO().incrementDbGeneration(getVm().getId()); - getSnapshotDao().updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.OK); + getSnapshotDao().updateStatus(getSnapshotId(), SnapshotStatus.OK); unlockVm(); } setSucceeded(succeeded); + } + + private Guid getSnapshotId() { + return getParameters().getDstSnapshotId(); } protected void removeSnapshotsFromDB() { @@ -341,9 +345,8 @@ } private List<DiskImage> getImagesList() { - if (getParameters().getImages() == null && !getParameters().getDstSnapshotId().equals(Guid.Empty)) { - getParameters().setImages( - getDiskImageDao().getAllSnapshotsForVmSnapshot(getParameters().getDstSnapshotId())); + if (getParameters().getImages() == null && !getSnapshotId().equals(Guid.Empty)) { + getParameters().setImages(getDiskImageDao().getAllSnapshotsForVmSnapshot(getSnapshotId())); } return getParameters().getImages(); } @@ -363,7 +366,7 @@ public Map<String, String> getJobMessageProperties() { if (jobProperties == null) { jobProperties = super.getJobMessageProperties(); - Snapshot snapshot = getSnapshotDao().get(getParameters().getDstSnapshotId()); + Snapshot snapshot = getSnapshotDao().get(getSnapshotId()); if (snapshot != null) { jobProperties.put(VdcObjectType.Snapshot.name().toLowerCase(), snapshot.getDescription()); } @@ -381,13 +384,13 @@ return false; } - if (Guid.Empty.equals(getParameters().getDstSnapshotId())) { + if (Guid.Empty.equals(getSnapshotId())) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID); } SnapshotsValidator snapshotValidator = createSnapshotValidator(); VmValidator vmValidator = createVmValidator(getVm()); - if (!validate(snapshotValidator.snapshotExists(getVmId(), getParameters().getDstSnapshotId())) || + if (!validate(snapshotValidator.snapshotExists(getVmId(), getSnapshotId())) || !validate(new StoragePoolValidator(getStoragePool()).isUp())) { return false; } @@ -404,7 +407,7 @@ return false; } - Snapshot snapshot = getSnapshotDao().get(getParameters().getDstSnapshotId()); + Snapshot snapshot = getSnapshotDao().get(getSnapshotId()); if (snapshot.getType() == SnapshotType.REGULAR && snapshot.getStatus() != SnapshotStatus.IN_PREVIEW) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW); @@ -476,7 +479,7 @@ @Override protected void endVmCommand() { // if we got here, the target snapshot exists for sure - getSnapshotDao().updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.OK); + getSnapshotDao().updateStatus(getSnapshotId(), SnapshotStatus.OK); super.endVmCommand(); } -- To view, visit http://gerrit.ovirt.org/25688 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4754e381d70f08a9650596a4eeb3de296b3cb44f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
