Gustavo Frederico Temple Pedrosa has uploaded a new change for review.

Change subject: engine: Disk interface validation
......................................................................

engine: Disk interface validation

This change displays an error if the disk interface is not compatible
with the selected operating system.

Change-Id: Ibe095557089aa5670c50eaa120eac9f60e13aea0
Signed-off-by: Gustavo Pedrosa <gustavo.pedr...@eldorado.org.br>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllAttachableDisksQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/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
8 files changed, 86 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/18648/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
index 32db917..2177f45 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
@@ -111,6 +111,11 @@
             return false;
         }
 
+        if (!validate(diskValidator.isDiskInterfaceSupported(getVm().getOs(),
+                getVm().getVdsGroupCompatibilityVersion()))) {
+            return false;
+        }
+
         if (!isVmNotInPreviewSnapshot()) {
             return false;
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllAttachableDisksQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllAttachableDisksQuery.java
index fdccc30..5e29db51 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllAttachableDisksQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllAttachableDisksQuery.java
@@ -1,6 +1,14 @@
 package org.ovirt.engine.core.bll;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.DiskInterface;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.queries.GetAllAttachableDisks;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 
 public class GetAllAttachableDisksQuery<P extends GetAllAttachableDisks> 
extends QueriesCommandBase<P> {
@@ -11,11 +19,41 @@
 
     @Override
     protected void executeQueryCommand() {
-        setReturnValue(DbFacade.getInstance()
+        List<Disk> diskList = DbFacade.getInstance()
                 .getDiskDao()
                 
.getAllAttachableDisksByPoolId(getParameters().getStoragePoolId(),
                         getParameters().getVmId(),
                         getUserID(),
-                        getParameters().isFiltered()));
+                        getParameters().isFiltered());
+
+        ArrayList<Disk> filteredDiskList = new ArrayList<Disk>();
+
+        VM vm = 
DbFacade.getInstance().getVmDao().get(getParameters().getVmId());
+
+        List<String> supportedDiskInterfaceNames =
+                getOsRepository().getDiskInterfaces(vm.getOs(), 
vm.getVdsGroupCompatibilityVersion());
+
+        List<DiskInterface> supportedDiskInterfaces = new 
ArrayList<DiskInterface>();
+
+        for (String interfaceName : supportedDiskInterfaceNames) {
+            try {
+                
supportedDiskInterfaces.add(DiskInterface.valueOf(interfaceName));
+            } catch (IllegalArgumentException e) {
+                // ignore if we can't find the enum value.
+            }
+        }
+
+        for (Disk disk : diskList) {
+            if (supportedDiskInterfaces.contains(disk.getDiskInterface())) {
+                filteredDiskList.add(disk);
+            }
+        }
+
+        setReturnValue(filteredDiskList);
     }
+
+    public OsRepository getOsRepository() {
+        return SimpleDependecyInjector.getInstance().get(OsRepository.class);
+    }
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
index 98b59ca..a8811b7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.bll.validator;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.ovirt.engine.core.bll.ValidationResult;
@@ -13,6 +14,7 @@
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
+import org.ovirt.engine.core.compat.Version;
 
 /**
  * A validator for the {@link Disk} class.
@@ -65,4 +67,36 @@
         }
         return ValidationResult.VALID;
     }
+
+    /**
+     * Check if the disk interface is supported.
+     *
+     * @param osId
+     *            Type of the OS.
+     * @param version
+     *            The cluster version.
+     * @return An error if the disk interface is not compatible with the 
selected operating system.
+     */
+    public ValidationResult isDiskInterfaceSupported(int osId, Version 
version) {
+        List<String> supportedDiskInterfaceNames = 
getOsRepository().getDiskInterfaces(osId, version);
+        List<DiskInterface> supportedDiskInterfaces = new 
ArrayList<DiskInterface>();
+
+        for (String interfaceName : supportedDiskInterfaceNames) {
+            try {
+                
supportedDiskInterfaces.add(DiskInterface.valueOf(interfaceName));
+            } catch (IllegalArgumentException e) {
+                // ignore if we can't find the enum value.
+            }
+        }
+
+        return (!supportedDiskInterfaces.contains(disk.getDiskInterface()))
+                ? new 
ValidationResult(VdcBllMessages.ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED)
+                : ValidationResult.VALID;
+
+    }
+
+    public OsRepository getOsRepository() {
+        return SimpleDependecyInjector.getInstance().get(OsRepository.class);
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 276e24f..20501ed 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -103,6 +103,7 @@
     ACTION_TYPE_FAILED_NAME_ALREADY_USED(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_VM_IN_PREVIEW(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_DISKS_LOCKED(ErrorType.CONFLICT),
+    ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_DISKS_ILLEGAL(ErrorType.INTERNAL_ERROR),
     ACTION_TYPE_FAILED_IMPORT_DISKS_ALREADY_EXIST(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_VM_IS_LOCKED(ErrorType.CONFLICT),
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 47cb478..1a4fe1d 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -135,6 +135,7 @@
 ACTION_TYPE_FAILED_STOARGE_DOMAIN_IS_WRONG=Cannot ${action} ${type}. Provided 
wrong storage domain, which is not related to disk.
 ACTION_TYPE_FAILED_VM_IN_PREVIEW=Cannot ${action} ${type}. VM is previewing a 
Snapshot.
 ACTION_TYPE_FAILED_DISKS_LOCKED=Cannot ${action} ${type}: The following disks 
are locked: ${diskAliases}. Please try again in a few minutes.
+ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED=Cannot ${action} ${type}: The disk 
interface is not supported by the VM.
 ACTION_TYPE_FAILED_DISKS_ILLEGAL=Cannot ${action} ${type}. The following 
attached disks are in ILLEGAL status: ${diskAliases} - please remove them and 
try again.
 ACTION_TYPE_FAILED_IMPORT_DISKS_ALREADY_EXIST=Cannot ${action} ${type}. The 
following disks already exist: ${diskAliases}. Please import as a clone.
 ACTION_TYPE_FAILED_VM_IS_LOCKED=Cannot ${action} ${type}: VM is locked. Please 
try again in a few minutes.
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 6f30ea8..b631c2c 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
@@ -340,6 +340,9 @@
     @DefaultStringValue("Cannot ${action} ${type}: The following disks are 
locked: ${diskAliases}. Please try again in a few minutes.")
     String ACTION_TYPE_FAILED_DISKS_LOCKED();
 
+    @DefaultStringValue("Cannot ${action} ${type}: The disk interface is not 
supported by the VM.")
+    String ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED();
+
     @DefaultStringValue("Cannot ${action} ${type}. The following attached 
disks are in ILLEGAL status: ${diskAliases} - please remove them and try 
again.")
     String ACTION_TYPE_FAILED_DISKS_ILLEGAL();
 
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 8adafcf..9188019 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
@@ -128,6 +128,7 @@
 VM_NOT_FOUND=VM not found
 ACTION_TYPE_FAILED_VM_IN_PREVIEW=Cannot ${action} ${type}. VM is previewing a 
Snapshot.
 ACTION_TYPE_FAILED_DISKS_LOCKED=Cannot ${action} ${type}: The following disks 
are locked: ${diskAliases}. Please try again in a few minutes.
+ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED=Cannot ${action} ${type}: The disk 
interface is not supported by the VM.
 ACTION_TYPE_FAILED_DISKS_ILLEGAL=Cannot ${action} ${type}. The following 
attached disks are in ILLEGAL status: ${diskAliases} - please remove them and 
try again.
 ACTION_TYPE_FAILED_IMPORT_DISKS_ALREADY_EXIST=Cannot ${action} ${type}. The 
following disks already exist: ${diskAliases}. Please import as a clone.
 ACTION_TYPE_FAILED_VM_IS_LOCKED=Cannot ${action} ${type}: VM is locked. Please 
try again in a few minutes.
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 c60e334..efb7d25 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
@@ -132,6 +132,7 @@
 VM_NOT_FOUND=VM not found
 ACTION_TYPE_FAILED_VM_IN_PREVIEW=Cannot ${action} ${type}. VM is previewing a 
Snapshot.
 ACTION_TYPE_FAILED_DISKS_LOCKED=Cannot ${action} ${type}: The following disks 
are locked: ${diskAliases}. Please try again in a few minutes.
+ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED=Cannot ${action} ${type}: The disk 
interface is not supported by the VM.
 ACTION_TYPE_FAILED_DISKS_ILLEGAL=Cannot ${action} ${type}. The following 
attached disks are in ILLEGAL status: ${diskAliases} - please remove them and 
try again.
 ACTION_TYPE_FAILED_IMPORT_DISKS_ALREADY_EXIST=Cannot ${action} ${type}. The 
following disks already exist: ${diskAliases}. Please import as a clone.
 ACTION_TYPE_FAILED_VM_IS_LOCKED=Cannot ${action} ${type}: VM is locked. Please 
try again in a few minutes.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe095557089aa5670c50eaa120eac9f60e13aea0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Gustavo Frederico Temple Pedrosa <gustavo.pedr...@eldorado.org.br>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to