Allon Mureinik has uploaded a new change for review.

Change subject: core: LiveMigrateDisk extends MoveOrCopyDisk
......................................................................

core: LiveMigrateDisk extends MoveOrCopyDisk

By making LiveMigrateDisk extend MoveOrCopyDisk, we get the audit log,
MLA and Quota handling practically for free.

Change-Id: Iebc2ca95371230d60d08a4961f9c9926b2c813c7
Signed-off-by: Allon Mureinik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateDiskCommand.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, 39 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/8530/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateDiskCommand.java
index 90970c6..957d6ae 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateDiskCommand.java
@@ -3,26 +3,25 @@
 import java.util.Arrays;
 import java.util.List;
 
-import org.ovirt.engine.core.bll.BaseImagesCommand;
-import org.ovirt.engine.core.bll.ImagesHandler;
+import org.ovirt.engine.core.bll.MoveOrCopyDiskCommand;
 import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
-import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator;
 import org.ovirt.engine.core.bll.tasks.SPMAsyncTaskHandler;
-import org.ovirt.engine.core.bll.validator.VmValidator;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.LiveMigrateDiskParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSParametersBase;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.VdcBllMessages;
 
 @NonTransactiveCommandAttribute(forceCompensation = true)
-public class LiveMigrateDiskCommand<T extends LiveMigrateDiskParameters> 
extends BaseImagesCommand<T> {
+public class LiveMigrateDiskCommand<T extends LiveMigrateDiskParameters> 
extends MoveOrCopyDiskCommand<T> {
     private static final long serialVersionUID = -6216729539906812205L;
 
     /* Constructors */
@@ -32,10 +31,6 @@
         setVdsId(getVm().getrun_on_vds().getValue());
         setStoragePoolId(getVm().getstorage_pool_id());
         getParameters().setCommandType(getActionType());
-    }
-
-    protected LiveMigrateDiskCommand(Guid commandId) {
-        super(commandId);
     }
 
     /* Overridden CommandBase Methods */
@@ -50,29 +45,28 @@
                 );
     }
 
-    @Override
-    protected boolean canDoAction() {
-        // TODO: check that the disk is plugged
-        // TODO: check that the disk is attached to a VM
 
-        VmValidator vmValidator = new VmValidator(getVm());
-        SnapshotsValidator snapshotsValidator = new SnapshotsValidator();
-        return validate(snapshotsValidator.vmNotDuringSnapshot(getVmId()))
-                && validate(vmValidator.vmNotDuringMigration())
-                && validate(vmValidator.vmNotRunningStateless())
-                && ImagesHandler.PerformImagesChecks(getVm(),
-                        getReturnValue().getCanDoActionMessages(),
-                        getVm().getstorage_pool_id(),
-                        Guid.Empty,
-                        true,
-                        true,
-                        true,
-                        true,
-                        true,
-                        false,
-                        true,
-                        true,
-                        Arrays.asList(getDiskImage()));
+    @Override
+    protected boolean checkCanBeMoveInVm() {
+        List<VM> vmsForDisk = 
getVmDAO().getForDisk(getImageGroupId()).get(Boolean.TRUE);
+
+        if (vmsForDisk.size() == 0) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_FLOATING_DISK_NOT_SUPPORTED);
+        }
+
+        if (vmsForDisk.size() > 1) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_SHARED_DISK_NOT_SUPPORTED);
+        }
+
+        // Cache for future use
+        VM vm = vmsForDisk.get(0);
+        setVmId(vm.getId());
+        setVm(vm);
+
+        if (VMStatus.Up != vm.getstatus()) {
+            failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NOT_UP);
+        }
+        return true;
     }
 
     @Override
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 6097270..bb6ec7b 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
@@ -166,6 +166,8 @@
     ACTION_TYPE_FAILED_HOSNAME_CANNOT_CHANGE,
     ACTION_TYPE_FAILED_HOST_NOT_EXIST,
     ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW,
+    ACTION_TYPE_FAILED_FLOATING_DISK_NOT_SUPPORTED,
+    ACTION_TYPE_FAILED_SHARED_DISK_NOT_SUPPORTED,
 
     VDS_CANNOT_REMOVE_DEFAULT_VDS_GROUP,
     VDS_CANNOT_REMOVE_VDS_DETECTED_RUNNING_VM,
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 a329a73..4de1f35 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -724,6 +724,8 @@
 ACTION_TYPE_FAILED_NETWORK_NOT_IN_CLUSTER=Failed ${action} ${type}. The 
following networks (${networks}) are not defined in the cluster.
 ACTION_TYPE_FAILED_INTERFACE_NETWORK_NOT_CONFIGURED=Failed ${action} ${type}. 
One or more network interfaces have incomplete network configuration. Please 
configure these interfaces and try again.
 ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW=Cannot ${action} ${type} to a 
Snapshot that is not being previewed. Please select the correct Snapshot to 
restore to: Either the one being previewed, or the one before the preview.
+ACTION_TYPE_FAILED_FLOATING_DISK_NOT_SUPPORTED=${action} ${type} of a floating 
disk is not supported.
+ACTION_TYPE_FAILED_SHARD_DISK_NOT_SUPPORTED=${action} ${type} of a shared disk 
is not supported.
 ACTION_TYPE_FAILED_DISK_NOT_EXIST=Cannot ${action} ${type}. The specified disk 
does not exist.
 ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK=Cannot ${action} ${type}. The 
selected disk is not a template disk. Only template disks can be copied.
 ACTION_TYPE_FAILED_SOURCE_AND_TARGET_SAME=Cannot ${action} ${type}. The source 
and target storage domains are the same.
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 5870303..57f8471 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
@@ -1930,6 +1930,12 @@
     @DefaultStringValue("Cannot ${action} ${type} to a Snapshot that is not 
being previewed. Please select the correct Snapshot to restore to: Either the 
one being previewed, or the one before the preview.")
     String ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW();
 
+    @DefaultStringValue("${action} ${type} of a floating disk is not 
supported")
+    String ACTION_TYPE_FAILED_FLOATING_DISK_NOT_SUPPORTED();
+
+    @DefaultStringValue("${action} ${type} of a shared disk is not supported")
+    String ACTION_TYPE_FAILED_SHARED_DISK_NOT_SUPPORTED();
+
     @DefaultStringValue("Cannot ${action} ${type}. The specified disk does not 
exist.")
     String ACTION_TYPE_FAILED_DISK_NOT_EXIST();
 
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 e8fcbb8..efb3f7d 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
@@ -715,6 +715,8 @@
 DEFAULT_CLUSTER_CANNOT_BE_ON_LOCALFS=Data Center containing the default 
Cluster does not support local Storage.
 VM_CANNOT_CANCEL_MIGRATION_WHEN_VM_IS_NOT_MIGRATING=Cannot cancel migration 
for non migrating VM.
 ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW=Cannot ${action} ${type} to a 
Snapshot that is not being previewed. Please select the correct Snapshot to 
restore to: Either the one being previewed, or the one before the preview.
+ACTION_TYPE_FAILED_FLOATING_DISK_NOT_SUPPORTED=${action} ${type} of a floating 
disk is not supported.
+ACTION_TYPE_FAILED_SHARD_DISK_NOT_SUPPORTED=${action} ${type} of a shared disk 
is not supported.
 ACTION_TYPE_FAILED_DISK_NOT_EXIST=Cannot ${action} ${type}. The specified disk 
does not exist.
 ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK=Cannot ${action} ${type}. The 
selected disk is not a template disk. Only template disks can be copied.
 ACTION_TYPE_FAILED_SOURCE_AND_TARGET_SAME=Cannot ${action} ${type}. The source 
and target storage domains are the same.
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 5300979..d03efea 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
@@ -715,6 +715,8 @@
 DEFAULT_CLUSTER_CANNOT_BE_ON_LOCALFS=Data Center containing the default 
Cluster does not support local Storage.
 VM_CANNOT_CANCEL_MIGRATION_WHEN_VM_IS_NOT_MIGRATING=Cannot cancel migration 
for non migrating VM.
 ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW=Cannot ${action} ${type} to a 
Snapshot that is not being previewed. Please select the correct Snapshot to 
restore to: Either the one being previewed, or the one before the preview.
+ACTION_TYPE_FAILED_FLOATING_DISK_NOT_SUPPORTED=${action} ${type} of a floating 
disk is not supported.
+ACTION_TYPE_FAILED_SHARD_DISK_NOT_SUPPORTED=${action} ${type} of a shared disk 
is not supported.
 ACTION_TYPE_FAILED_DISK_NOT_EXIST=Cannot ${action} ${type}. The specified disk 
does not exist.
 ACTION_TYPE_FAILED_DISK_IS_NOT_TEMPLATE_DISK=Cannot ${action} ${type}. The 
selected disk is not a template disk. Only template disks can be copied.
 ACTION_TYPE_FAILED_SOURCE_AND_TARGET_SAME=Cannot ${action} ${type}. The source 
and target storage domains are the same.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebc2ca95371230d60d08a4961f9c9926b2c813c7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to