Idan Shaby has uploaded a new change for review. Change subject: core: add a getActiveSnapshot method to VmHandler ......................................................................
core: add a getActiveSnapshot method to VmHandler The method getActiveSnapshot can be useful in other places other than ImportVmCommand. This patch adds it to VmHandler so others can also use it. Change-Id: Id4aa4df1117d0993845e18a95a4e6c0f75738990 Signed-off-by: Idan Shaby <ish...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java 2 files changed, 22 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/82/39882/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java index 8e51d12..3d9c6e2 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java @@ -986,12 +986,11 @@ @Override protected Snapshot getActiveSnapshot() { - for (Snapshot snapshot : getVm().getSnapshots()) { - if (snapshot.getType() == SnapshotType.ACTIVE) - return snapshot; + Snapshot activeSnapshot = VmHandler.getActiveSnapshot(getVm()); + if (activeSnapshot == null) { + log.warn("VM '{}' doesn't have active snapshot in export domain", getVmId()); } - log.warn("VM '{}' doesn't have active snapshot in export domain", getVmId()); - return null; + return activeSnapshot; } /** diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java index f097aca..4125113 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java @@ -38,6 +38,7 @@ import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.common.businessentities.GuestAgentStatus; import org.ovirt.engine.core.common.businessentities.NumaTuneMode; +import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.StorageDomain; import org.ovirt.engine.core.common.businessentities.StorageDomainStatus; import org.ovirt.engine.core.common.businessentities.UsbPolicy; @@ -87,6 +88,8 @@ import org.ovirt.engine.core.utils.transaction.TransactionSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import static org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType; public class VmHandler { @@ -664,6 +667,21 @@ } /** + * Returns the vm's active snapshot, or null if one doesn't exist. + * Note that this method takes into consideration that the vm snapshots are already loaded from DB. + * @param vm The vm to get the active snapshot from. + * @return the vm's active snapshot, or null if one doesn't exist. + */ + public static Snapshot getActiveSnapshot(VM vm) { + for (Snapshot snapshot : vm.getSnapshots()) { + if (snapshot.getType() == SnapshotType.ACTIVE) { + return snapshot; + } + } + return null; + } + + /** * Checks that the USB policy is legal for the VM. If it is ENABLED_NATIVE then it is legal only in case the cluster * level is >= 3.1. If it is ENABLED_LEGACY then it is not legal on Linux VMs. * -- To view, visit https://gerrit.ovirt.org/39882 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id4aa4df1117d0993845e18a95a4e6c0f75738990 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Idan Shaby <ish...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches