Allon Mureinik has uploaded a new change for review.

Change subject: core: Extracted VmValidator
......................................................................

core: Extracted VmValidator

Extracted several VM validation utils from
CreateAllSnapshotsFromVmCommand to a VmValidator class (similar to the
SnapshotValidator design) in order to share its code with other commands
(that will be introduced in subsequent patches).

Change-Id: I6c76d242d7722f7271ead094e0cc936588db22d1
Signed-off-by: Allon Mureinik <amure...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidator.java
2 files changed, 42 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/8101/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
index fccfaf0..426cfcc 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
@@ -8,12 +8,13 @@
 
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
+import org.ovirt.engine.core.bll.quota.Quotable;
 import org.ovirt.engine.core.bll.quota.StorageQuotaValidationParameter;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsManager;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator;
-import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
-import org.ovirt.engine.core.bll.quota.Quotable;
+import org.ovirt.engine.core.bll.validator.VmValidator;
+import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.CreateAllSnapshotsFromVmParameters;
 import org.ovirt.engine.core.common.action.ImagesActionsParametersBase;
@@ -24,7 +25,6 @@
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
 import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
@@ -233,9 +233,10 @@
         boolean result = true;
         List<DiskImage> disksList = getDisksList();
         if (disksList.size() > 0) {
+            VmValidator vmValidator = new VmValidator(getVm());
             result = validate(new 
SnapshotsValidator().vmNotDuringSnapshot(getVmId()))
-                    && validate(vmNotDuringMigration())
-                    && validate(vmNotRunningStateless())
+                    && validate(vmValidator.vmNotDuringMigration())
+                    && validate(vmValidator.vmNotRunningStateless())
                     && ImagesHandler.PerformImagesChecks(getVm(),
                             getReturnValue().getCanDoActionMessages(),
                             getVm().getstorage_pool_id(),
@@ -265,26 +266,7 @@
                 ConfigValues.LiveSnapshotEnabled, 
getStoragePool().getcompatibility_version().getValue());
     }
 
-    /**
-     * @return Validation result that indicates if the VM is during migration 
or not.
-     */
-    private ValidationResult vmNotDuringMigration() {
-        if (getVm().getstatus() == VMStatus.MigratingFrom || 
getVm().getstatus() == VMStatus.MigratingTo) {
-            return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS);
-        }
 
-        return ValidationResult.VALID;
-    }
-
-    private ValidationResult vmNotRunningStateless() {
-        if (getSnapshotDao().exists(getVm().getId(), SnapshotType.STATELESS)) {
-            VdcBllMessages message = getVm().isStatusUp() ? 
VdcBllMessages.ACTION_TYPE_FAILED_VM_RUNNING_STATELESS :
-                
VdcBllMessages.ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER;
-            return new ValidationResult(message);
-        }
-
-        return ValidationResult.VALID;
-    }
 
     @Override
     protected VdcActionType getChildActionType() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidator.java
new file mode 100644
index 0000000..28ecf54
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidator.java
@@ -0,0 +1,36 @@
+package org.ovirt.engine.core.bll.validator;
+
+import org.ovirt.engine.core.bll.ValidationResult;
+import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.dal.VdcBllMessages;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+
+/** A Validator for various VM canDoAction needs */
+public class VmValidator {
+    private VM vm;
+
+    public VmValidator(VM vm) {
+        this.vm = vm;
+    }
+
+    /** @return Validation result that indicates if the VM is during migration 
or not. */
+    public ValidationResult vmNotDuringMigration() {
+        if (vm.getstatus() == VMStatus.MigratingFrom || vm.getstatus() == 
VMStatus.MigratingTo) {
+            return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS);
+        }
+
+        return ValidationResult.VALID;
+    }
+
+    public ValidationResult vmNotRunningStateless() {
+        if (DbFacade.getInstance().getSnapshotDao().exists(vm.getId(), 
SnapshotType.STATELESS)) {
+            VdcBllMessages message = vm.isStatusUp() ? 
VdcBllMessages.ACTION_TYPE_FAILED_VM_RUNNING_STATELESS :
+                    
VdcBllMessages.ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER;
+            return new ValidationResult(message);
+        }
+
+        return ValidationResult.VALID;
+    }
+}


--
To view, visit http://gerrit.ovirt.org/8101
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c76d242d7722f7271ead094e0cc936588db22d1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <amure...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to