Roy Golan has uploaded a new change for review.

Change subject: core: Replace Remove Unassigned and map it to Other
......................................................................

core: Replace Remove Unassigned and map it to Other

This patch replaces "Unassigned" values with "Other" but keeps backward
compatibility with REST values:

* REST - VmMapper - convert Unassigned value to Other
* REST - capabilities - merge the osinfo values with OsType values
* DB   - change all os type 6 to 0
* osinfo.properties - rename unassigned to other. keep the id 0.

Change-Id: Ie508a8828caedf4cb8fdf971e14139404f7dded3
Bug-Url: https://bugzilla.redhat.com/980813
Signed-off-by: Roy Golan <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OsType.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
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 packaging/conf/osinfo-defaults.properties
A packaging/dbscripts/upgrade/03_03_0400_alter_os_type_unassigned_to_other.sql
7 files changed, 58 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/16679/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OsType.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OsType.java
index d4246ef..449cbfc 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OsType.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OsType.java
@@ -16,7 +16,14 @@
 
 package org.ovirt.engine.api.model;
 
+/**
+ * TODO following the work on osino this enum is kept for backward 
compatibility <br>
+ * and should be removed in version 4.0 <br>
+ * {@link org.ovirt.engine.core.common.osinfo.OsRepository}
+ */
+@Deprecated
 public enum OsType {
+    @Deprecated // this value is kept for backward compatibility but shouldn't 
be used. Please use "OTHER" instead.
     UNASSIGNED,
     WINDOWS_XP,
     WINDOWS_2003,
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
index 23e4892..bff8e16 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.api.restapi.resource;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -102,7 +103,9 @@
 import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 import org.ovirt.engine.core.common.businessentities.ServerCpu;
 import org.ovirt.engine.core.common.businessentities.VmPauseStatus;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.queries.ConfigurationValues;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.compat.Guid;
 
 public class BackendCapabilitiesResource extends BackendResource implements 
CapabilitiesResource {
@@ -312,9 +315,17 @@
 
     private void addOsTypes(VersionCaps version, OsType[] types) {
         version.setOsTypes(new OsTypes());
-        for (OsType type : types) {
-            version.getOsTypes().getOsTypes().add(type.value());
+        // merge the backend list of oss with the OsType enum
+        Set<String> mergedTypes = new HashSet<>();
+
+        OsRepository osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
+        for (String uniqueName : osRepository.getUniqueOsNames().values()) {
+            
mergedTypes.add(osRepository.osNameUpperCasedAndUnderscored(uniqueName).toLowerCase());
         }
+        for (OsType type : types) {
+            mergedTypes.add(type.value());
+        }
+        version.getOsTypes().getOsTypes().addAll(mergedTypes);
     }
 
     private void addNfsVersions(VersionCaps version, NfsVersion[] nfsVersions) 
{
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
index d88089f..0056324 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
@@ -812,6 +812,13 @@
 
     @Mapping(from = OsType.class, to = Integer.class)
     public static int map(OsType type, Class<Integer> incoming) {
+
+        //TODO remove this treatment when OsType enum is deleted.
+        //backward compatibility code - UNASSIGNED is mapped to OTHER
+        if (type == OsType.UNASSIGNED) {
+            type = OsType.OTHER;
+        }
+
         for (Map.Entry<Integer, String> e : 
SimpleDependecyInjector.getInstance().get(OsRepository.class).getUniqueOsNames().entrySet())
 {
             if (e.getValue().equalsIgnoreCase(type.name().replace("_",""))) {
                 return e.getKey();
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 aecb626..8260268 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
@@ -36,6 +36,13 @@
         _vmTemplate.setId(new 
Guid(section.Attributes.get("ovf:id").getValue()));
         XmlNode node = section.SelectSingleNode("Description");
         if (node != null) {
+
+            // backward compatibility code - os id of type Other is now 0 . 
"Unassigned" is removed but its Id is in
+            // use. This should be removed in 4.0
+            if (node.InnerText.equals(6)) {
+                node.InnerText = "0";
+            }
+
             
_vmTemplate.setOsId(osRepository.getOsIdByUniqueName(node.InnerText));
         }
     }
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 53c9ca4..e34c57d 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
@@ -45,6 +45,13 @@
     protected void readOsSection(XmlNode section) {
         _vm.getStaticData().setId(new 
Guid(section.Attributes.get("ovf:id").getValue()));
         XmlNode node = section.SelectSingleNode("Description");
+
+        // backward compatibility code - os id of type Other is now 0 . 
"Unassigned" is removed but its Id is in use.
+        // This should be removed in 4.0
+        if (node.InnerText.equals(6)) {
+            node.InnerText = "0";
+        }
+        
         if (node != null) {
             
_vm.getStaticData().setOsId(osRepository.getOsIdByUniqueName(node.InnerText));
         }
diff --git a/packaging/conf/osinfo-defaults.properties 
b/packaging/conf/osinfo-defaults.properties
index 73eab36..61bfbe4 100644
--- a/packaging/conf/osinfo-defaults.properties
+++ b/packaging/conf/osinfo-defaults.properties
@@ -26,32 +26,32 @@
 # note: every OS has a unique namespace for the native unique representation 
of the data.
 # i.e os.RHEL6.somekey = val belongs only to rhel6
 # Both engine and DWH rely on id value and not the os.{osid).*
-os.Unassigned.id.value = 0
+os.Other.id.value = 0
 
 # name is I18N if the one creates a 01-os_${LOCALE}.properties with the 
co-responding name property
-os.Unassigned.name.value = default OS
+os.Other.name.value = Other OS
 
 # OS family values: Linux/Windows/Other
-os.Unassigned.family.value = Other
+os.Other.family.value = Other
 
 # CPU architecture (*not* the bus width 64/32 bit). Currently only x86 is 
supported
 # but ppc7 is a work in progress and possibly arm someday as well
-os.Unassigned.cpuArchitecture.value = x86
+os.Other.cpuArchitecture.value = x86
 
-os.Unassigned.bus.value = 32
-os.Unassigned.resources.minimum.ram.value = 256
-os.Unassigned.resources.maximum.ram.value = 64000
-os.Unassigned.resources.minimum.disksize.value = 1
-os.Unassigned.resources.minimum.numberOsCpus.value = 1
-os.Unassigned.spiceSupport.value = true
+os.Other.bus.value = 32
+os.Other.resources.minimum.ram.value = 256
+os.Other.resources.maximum.ram.value = 64000
+os.Other.resources.minimum.disksize.value = 1
+os.Other.resources.minimum.numberOsCpus.value = 1
+os.Other.spiceSupport.value = true
 
-os.Unassigned.devices.audio.value = ich6
+os.Other.devices.audio.value = ich6
 # See VmInterfaceType.java
-os.Unassigned.devices.network.value =  rtl8139, e1000, pv
+os.Other.devices.network.value =  rtl8139, e1000, pv
 
 os.linux.id.value = 100
 os.linux.name.value = Linux
-os.linux.derivedFrom.value = Unassigned
+os.linux.derivedFrom.value = Other
 os.linux.description.value = General GNU/Linux
 os.linux.family.value = linux
 os.linux.devices.audio.value = ac97
@@ -59,7 +59,7 @@
 
 os.Windows.id.value = 200
 os.Windows.name.value = Windows
-os.Windows.derivedFrom.value = Unassigned
+os.Windows.derivedFrom.value = Other
 os.Windows.description.value = General Windows OS
 os.Windows.family.value = windows
 os.Windows.devices.audio.value = ac97
@@ -201,8 +201,3 @@
 os.OtherLinux.id.value = 5
 os.OtherLinux.name.value = Other Linux
 os.OtherLinux.derivedFrom.value = linux
-
-# Other(6, OsType.Other, false),
-os.Other.id.value = 6
-os.Other.name.value = Other
-os.Other.derivedFrom.value = Unassigned
diff --git 
a/packaging/dbscripts/upgrade/03_03_0400_alter_os_type_unassigned_to_other.sql 
b/packaging/dbscripts/upgrade/03_03_0400_alter_os_type_unassigned_to_other.sql
new file mode 100644
index 0000000..1293700
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_03_0400_alter_os_type_unassigned_to_other.sql
@@ -0,0 +1,3 @@
+-- os 0 is Unassigned and 6 is OTHER. 
+-- code-wise the defacto default still remains 0 and it will point to Other 
instead to Unassigned
+UPDATE vm_static set os = 0 where os = 6;


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

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

Reply via email to