Leonardo Bianconi has uploaded a new change for review.

Change subject: core: Fill and check arch when importing VM and Template
......................................................................

core: Fill and check arch when importing VM and Template

When importing VM and Template, its architecture must match with
cluster architecture, otherwise an error must be displayed. It's being
checked in the import command for each one.
On importing OVF files, the same validation is necessary, and filling
the architecture for VM and Template is necessary. The architecture is
filled based on the OS architecture, otherwise the architecture will
be undefined.

Change-Id: I6ac6093e253225f801e216310828a7afba73f9e6
Signed-off-by: Leonardo Bianconi <leonardo.bianc...@eldorado.org.br>
---
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/ImportVmTemplateCommand.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 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
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
8 files changed, 45 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/18702/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 3d55a8d..322625c 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
@@ -48,6 +48,7 @@
 import org.ovirt.engine.core.common.businessentities.Snapshot;
 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.ArchitectureType;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
@@ -259,6 +260,7 @@
             // At this point we should work with the VM that was read from
             // the OVF
             setVm(vm);
+
             // Iterate over all the VM images (active image and snapshots)
             for (DiskImage image : getVm().getImages()) {
                 if (Guid.Empty.equals(image.getVmSnapshotId())) {
@@ -494,13 +496,17 @@
     }
 
     /**
-     * Validates that that the required cluster exists.
+     * Validates that that the required cluster exists nad is compatible
      * @return <code>true</code> if the validation passes, <code>false</code> 
otherwise.
      */
     protected boolean validateVdsCluster() {
         List<VDSGroup> groups = 
getVdsGroupDAO().getAllForStoragePool(getParameters().getStoragePoolId());
         for (VDSGroup group : groups) {
             if (group.getId().equals(getParameters().getVdsGroupId())) {
+                if (group.getArchitectureType() != getVm().getArchitecture())
+                {
+                    return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER);
+                }
                 return true;
             }
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
index 6df80ef..b1fa975 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
@@ -30,6 +30,7 @@
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
 import org.ovirt.engine.core.common.businessentities.StorageType;
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
 import org.ovirt.engine.core.common.businessentities.VolumeFormat;
@@ -87,6 +88,10 @@
         }
         // check that the storage pool is valid
         retVal = retVal && checkStoragePool();
+
+        if (retVal) {
+            retVal = isVDSGroupCompatible();
+        }
 
         if (retVal) {
             // set the source domain and check that it is ImportExport type 
and active
@@ -203,6 +208,15 @@
         return retVal;
     }
 
+    private boolean isVDSGroupCompatible () {
+        VDSGroup vdsGroup = getVdsGroup();
+        if (vdsGroup.getArchitectureType() != 
getVmTemplate().getArchitecture()) {
+            
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_TEMPLATE_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER);
+            return false;
+        }
+        return true;
+    }
+
     protected boolean isVmTemplateWithSameNameExist() {
         return 
VmTemplateCommand.isVmTemlateWithSameNameExist(getParameters().getVmTemplate().getName());
     }
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..80279e8 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
@@ -269,6 +269,8 @@
     ACTION_TYPE_FAILED_PM_ENABLED_WITHOUT_AGENT(ErrorType.BAD_PARAMETERS),
     
ACTION_TYPE_FAILED_PM_ENABLED_WITHOUT_AGENT_CREDENTIALS(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_AGENT_NOT_SUPPORTED(ErrorType.CONFLICT),
+    
ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER(ErrorType.NOT_SUPPORTED),
+    
ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_TEMPLATE_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER(ErrorType.NOT_SUPPORTED),
     VDS_CANNOT_CHECK_VERSION_HOST_NON_RESPONSIVE(ErrorType.CONFLICT),
     // VDS_CANNOT_RUN_VM_FAILED_TO_RUN, // EINAV: not in use
     // internal const string 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 47cb478..c6050d2 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -537,6 +537,8 @@
 ACTION_TYPE_FAILED_PM_ENABLED_WITHOUT_AGENT=Cannot ${action} ${type}. Power 
Management is enabled for Host but no Agent type selected.
 ACTION_TYPE_FAILED_PM_ENABLED_WITHOUT_AGENT_CREDENTIALS=Cannot ${action} 
${type}. Power Management is enabled for Host but Agent credentials are missing.
 ACTION_TYPE_FAILED_AGENT_NOT_SUPPORTED=Cannot ${action} ${type}. Selected 
Power Management Agent is not supported.
+ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER=Cannot
 ${action} ${type}. The selected cluster doesn't support VM architecture
+ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_TEMPLATE_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER=Cannot
 ${action} ${type}. The selected cluster doesn't support Template's architecture
 ACTION_TYPE_FAILED_MOM_UPDATE_VDS_VERSION=Cannot ${action} ${type}. The 
cluster's compatibility version doesn't support MoM Policy update.
 NETWORK_BOND_NOT_ATTACCH_TO_NETWORK=Bond is not attached to Network.
 NETWORK_INTERFACE_NOT_ATTACCH_TO_NETWORK=Network Interface is not attached to 
Logical Network.
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
index edc33f0..1fff3b6 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
@@ -41,11 +41,13 @@
             if 
(node.InnerText.equals(String.valueOf(OsRepository.OLD_OTHER_ID))) {
                 node.InnerText = String.valueOf(OsRepository.DEFAULT_OS);
             }
-            
_vmTemplate.setOsId(osRepository.getOsIdByUniqueName(node.InnerText));
+            int osId = osRepository.getOsIdByUniqueName(node.InnerText);
+            _vmTemplate.setOsId(osId);
+            
_vmTemplate.setArchitecture(osRepository.getArchitectureFromOS(osId));
         }
-
-        // Workaround until the support for OVF on POWER is implemented
-        _vmTemplate.setArchitecture(ArchitectureType.x86_64);
+        else {
+            _vmTemplate.setArchitecture(ArchitectureType.undefined);
+        }
     }
 
     @Override
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
index 0f5a5cf..0f9f68f 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
@@ -51,11 +51,13 @@
             if 
(node.InnerText.equals(String.valueOf(OsRepository.OLD_OTHER_ID))) {
                 node.InnerText = String.valueOf(OsRepository.DEFAULT_OS);
             }
-            
_vm.getStaticData().setOsId(osRepository.getOsIdByUniqueName(node.InnerText));
+            int osId = osRepository.getOsIdByUniqueName(node.InnerText);
+            _vm.getStaticData().setOsId(osId);
+            _vm.setArchitecture(osRepository.getArchitectureFromOS(osId));
         }
-
-        // Workaround until the support for OVF on POWER is implemented
-        _vm.setArchitecture(ArchitectureType.x86_64);
+        else {
+            _vm.setArchitecture(ArchitectureType.undefined);
+        }
     }
 
     @Override
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..81cb028 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
@@ -1456,6 +1456,12 @@
     @DefaultStringValue("Cannot ${action} ${type}. Selected Power Management 
Agent is not supported.")
     String ACTION_TYPE_FAILED_AGENT_NOT_SUPPORTED();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The selected cluster 
doesn't support VM's architecture")
+    String 
ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER();
+
+    @DefaultStringValue("Cannot ${action} ${type}. The selected cluster 
doesn't support Template's architecture")
+    String 
ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_TEMPLATE_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER();
+
     @DefaultStringValue("Cannot ${action} ${type}. The cluster's compatibility 
version doesn't support MoM Policy update.")
     String ACTION_TYPE_FAILED_MOM_UPDATE_VDS_VERSION();
 
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..c28e227 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
@@ -526,6 +526,8 @@
 ACTION_TYPE_FAILED_AGENT_NOT_SUPPORTED=Cannot ${action} ${type}. Selected 
Power Management Agent is not supported.
 NETWORK_BOND_NOT_ATTACCH_TO_NETWORK=Bond is not attached to Network.
 NETWORK_INTERFACE_NOT_ATTACCH_TO_NETWORK=Network Interface is not attached to 
Logical Network.
+ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER=Cannot
 ${action} ${type}. The selected cluster doesn't support VM architecture
+ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_TEMPLATE_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER=Cannot
 ${action} ${type}. The selected cluster doesn't support Template's architecture
 NETWORK_INTERFACE_IN_USE_BY_VLAN=Bonding cannot be applied on an Interface 
where VLAN is defined.\n\
        -Please remove VLAN from the interface.
 NETWORK_ALREADY_ATTACHED_TO_CLUSTER=Logical Network is already attached to 
Cluster.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ac6093e253225f801e216310828a7afba73f9e6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Leonardo Bianconi <leonardo.bianc...@eldorado.org.br>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to