Arik Hadas has uploaded a new change for review.

Change subject: core: Refactor InternalMigrateVmCommand#canMigrateVm
......................................................................

core: Refactor InternalMigrateVmCommand#canMigrateVm

Change InternalMigrateVmCommand#canMigrateVm method such that:

1. The check whether the vm is migratable is being done before
calling super.canMigrateVm. That way, the checks in
MigrateVmCommand#canMigrateVm won't be made if the vm is not
migratable, as they are irrelevant in that case.

2. Add a proper error in case InternalMigrateVmCommand fails
because the VM is not migratable.

Change-Id: Ida10d53ccd5321d3ccc510bd2111fa013dcdcdbe
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
6 files changed, 19 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/10107/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java
index a6b0772..f517e5f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java
@@ -2,8 +2,8 @@
 
 import org.ovirt.engine.core.common.action.MigrateVmParameters;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
-import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.VdcBllMessages;
 
 @InternalCommandAttribute
 public class InternalMigrateVmCommand<T extends MigrateVmParameters> extends 
MigrateVmCommand<T> {
@@ -23,16 +23,18 @@
         }
     }
 
+    /**
+     * Internal migrate command is initiated by server.
+     * if the VM's migration support is not set to {@link 
MigrationSupport.MIGRATABLE},
+     * the internal migration command should fail
+     */
     @Override
     protected boolean canMigrateVm(Guid vmGuid, java.util.ArrayList<String> 
reasons) {
-        boolean canMigrateVM = super.canMigrateVm(vmGuid, reasons);
-        VM vm = getVm();
-        // Internal migrate command is initiated by server, if migration 
support
-        // is not set to "migratable" the internal migration
-        // should fail
-
-        canMigrateVM = vm.getMigrationSupport() == MigrationSupport.MIGRATABLE 
&& canMigrateVM;
-        return canMigrateVM;
-
+        if (getVm().getMigrationSupport() == MigrationSupport.MIGRATABLE) {
+            return super.canMigrateVm(vmGuid, reasons);
+        }
+        else {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE);
+        }
     }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index 08cb356..5cdfab3 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -517,6 +517,7 @@
     NETWORK_ADDR_IN_SUBNET_BAD_FORMAT,
     USER_FAILED_TO_AUTHENTICATION_WRONG_AUTHENTICATION_METHOD,
     ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST,
+    ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE,
     
ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE,
     VDS_CANNOT_MAINTENANCE_IT_INCLUDES_NON_MIGRATABLE_VM,
     ACTION_TYPE_FAILED_VM_CANNOT_BE_HIGHLY_AVAILABLE_AND_PINNED_TO_HOST,
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index f3d94458..86de294 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -144,6 +144,7 @@
 ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER=Cannot ${action} 
${type}. The VM was running as Stateless and didn't clean up successfully. 
Please try to run the VM which should clean up the VM, and then try again when 
VM is not running.
 ACTION_TYPE_FAILED_VM_IN_USE_BY_OTHER_USER=Cannot ${action} ${type}. The VM is 
in use by other user.
 ACTION_TYPE_FAILED_VM_NOT_FOUND=Cannot ${action} ${type}. VM is not found.
+ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE=Cannot ${action} ${type}. VM is non 
migratable.
 
ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE=Cannot
 ${action} ${type}. VM is non migratable and user did not specify the 
force-migration flag
 ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST=Cannot ${action} ${type}. VM is pinned 
to Host.
 VM_PINNED_TO_HOST_CANNOT_RUN_ON_THE_DEFAULT_VDS=Cannot ${action} ${type}. VM 
is pinned to a specific Host but cannot run on it due to:\n\
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 44fa62b..da262ac 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -362,6 +362,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. VM is not found.")
     String ACTION_TYPE_FAILED_VM_NOT_FOUND();
 
+    @DefaultStringValue("Cannot ${action} ${type}. VM is non migratable.")
+    String ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE();
+
     @DefaultStringValue("Cannot ${action} ${type}. VM is non migratable and 
user did not specify the force-migration flag")
     String 
ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE();
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 8a616d3..676630f 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -142,6 +142,7 @@
 ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER=Cannot ${action} 
${type}. The VM was running as Stateless and didn't clean up successfully. 
Please try to run the VM which should clean up the VM, and then try again when 
VM is not running.
 ACTION_TYPE_FAILED_VM_IN_USE_BY_OTHER_USER=Cannot ${action} ${type}. The VM is 
in use by other user.
 ACTION_TYPE_FAILED_VM_NOT_FOUND=Cannot ${action} ${type}. VM is not found.
+ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE=Cannot ${action} ${type}. VM is non 
migratable.
 
ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE=Cannot
 ${action} ${type}. VM is non migratable and user did not specify the 
force-migration flag
 ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST=Cannot ${action} ${type}. VM is pinned 
to Host.
 VM_PINNED_TO_HOST_CANNOT_RUN_ON_THE_DEFAULT_VDS=Cannot ${action} ${type}. VM 
is pinned to a specific Host but cannot run on it due to:\n\
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index c52ffdd..898753d 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -141,6 +141,7 @@
 ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER=Cannot ${action} 
${type}. The VM was running as Stateless and didn't clean up successfully. 
Please try to run the VM which should clean up the VM, and then try again when 
VM is not running.
 ACTION_TYPE_FAILED_VM_IN_USE_BY_OTHER_USER=Cannot ${action} ${type}. The VM is 
in use by other user.
 ACTION_TYPE_FAILED_VM_NOT_FOUND=Cannot ${action} ${type}. VM is not found.
+ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE=Cannot ${action} ${type}. VM is non 
migratable.
 
ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE=Cannot
 ${action} ${type}. VM is non migratable and user did not specify the 
force-migration flag
 ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST=Cannot ${action} ${type}. VM is pinned 
to Host.
 VM_PINNED_TO_HOST_CANNOT_RUN_ON_THE_DEFAULT_VDS=Cannot ${action} ${type}. VM 
is pinned to a specific Host but cannot run on it due to:\n\


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

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

Reply via email to