This is an automated email from the ASF dual-hosted git repository.

shwstppr pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.18 by this push:
     new f023fc53c0a engine-schema: fix finding guestos mapping with parent 
version (#8426)
f023fc53c0a is described below

commit f023fc53c0acc68716a46cbce66ffc67dde2461d
Author: Abhishek Kumar <[email protected]>
AuthorDate: Mon Jan 8 17:51:04 2024 +0530

    engine-schema: fix finding guestos mapping with parent version (#8426)
    
    GuestOS mappings are retrieved from the parent hypervisor version when a 
minor, patch hypervisor version doesn't exist.
    
    Fixes #8412
    
    Signed-off-by: Abhishek Kumar <[email protected]>
---
 .../storage/dao/GuestOSHypervisorDaoImpl.java      | 45 ++++++++++++++++++++--
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git 
a/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
 
b/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
index e03e3f7ce64..69f4d4a3ceb 100644
--- 
a/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
+++ 
b/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
@@ -20,9 +20,12 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.cloudstack.utils.CloudStackVersion;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import com.cloud.hypervisor.Hypervisor;
 import com.cloud.storage.GuestOSHypervisorVO;
 import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.QueryBuilder;
@@ -32,6 +35,7 @@ import com.cloud.utils.db.SearchCriteria;
 
 @Component
 public class GuestOSHypervisorDaoImpl extends 
GenericDaoBase<GuestOSHypervisorVO, Long> implements GuestOSHypervisorDao {
+    private static final Logger s_logger = 
Logger.getLogger(GuestOSHypervisorDaoImpl.class);
 
     protected final SearchBuilder<GuestOSHypervisorVO> guestOsSearch;
     protected final SearchBuilder<GuestOSHypervisorVO> mappingSearch;
@@ -80,6 +84,29 @@ public class GuestOSHypervisorDaoImpl extends 
GenericDaoBase<GuestOSHypervisorVO
         hypervisorTypeAndVersionSearch.done();
     }
 
+    private GuestOSHypervisorVO 
getMappingForHypervisorVersionOrParentVersionIfNeeded(GuestOSHypervisorVO 
mapping,
+       String hypervisorType, String hypervisorVersion, Long guestOsId, String 
guestOsName) {
+        if (mapping != null || 
!Hypervisor.HypervisorType.VMware.toString().equals(hypervisorType)) {
+            return mapping;
+        }
+        String guestOs = guestOsId != null ? String.format("guest OS ID: %d", 
guestOsId) : String.format("guest OS ID: %s", guestOsName);
+        String parentVersion = 
CloudStackVersion.getVMwareParentVersion(hypervisorVersion);
+        if (parentVersion == null) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.info(String.format("Mapping for %s for hypervisor: %s 
with version: %s can not be found. Parent version is also null",
+                        guestOs, hypervisorType, hypervisorVersion));
+            }
+            return null;
+        }
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug(String.format("Mapping for %s for hypervisor: %s 
with version: %s can not be found. " +
+                    "Trying to find one for the parent version: %s", guestOs, 
hypervisorType, hypervisorVersion, parentVersion));
+        }
+        return guestOsId != null ?
+                findByOsIdAndHypervisorInternal(guestOsId, hypervisorType, 
parentVersion):
+                findByOsNameAndHypervisorInternal(guestOsName, hypervisorType, 
parentVersion);
+    }
+
     @Override
     public List<GuestOSHypervisorVO> listByGuestOsId(long guestOsId) {
         SearchCriteria<GuestOSHypervisorVO> sc = guestOsSearch.create();
@@ -87,8 +114,7 @@ public class GuestOSHypervisorDaoImpl extends 
GenericDaoBase<GuestOSHypervisorVO
         return listBy(sc);
     }
 
-    @Override
-    public GuestOSHypervisorVO findByOsIdAndHypervisor(long guestOsId, String 
hypervisorType, String hypervisorVersion) {
+    private GuestOSHypervisorVO findByOsIdAndHypervisorInternal(long 
guestOsId, String hypervisorType, String hypervisorVersion) {
         SearchCriteria<GuestOSHypervisorVO> sc = mappingSearch.create();
         String version = "default";
         if (!(hypervisorVersion == null || hypervisorVersion.isEmpty())) {
@@ -100,6 +126,12 @@ public class GuestOSHypervisorDaoImpl extends 
GenericDaoBase<GuestOSHypervisorVO
         return findOneBy(sc);
     }
 
+    @Override
+    public GuestOSHypervisorVO findByOsIdAndHypervisor(long guestOsId, String 
hypervisorType, String hypervisorVersion) {
+        GuestOSHypervisorVO mapping = 
findByOsIdAndHypervisorInternal(guestOsId, hypervisorType, hypervisorVersion);
+        return getMappingForHypervisorVersionOrParentVersionIfNeeded(mapping, 
hypervisorType, hypervisorVersion, guestOsId, null);
+    }
+
     @Override
     public GuestOSHypervisorVO findByOsIdAndHypervisorAndUserDefined(long 
guestOsId, String hypervisorType, String hypervisorVersion, boolean 
isUserDefined) {
         SearchCriteria<GuestOSHypervisorVO> sc = 
userDefinedMappingSearch.create();
@@ -123,8 +155,7 @@ public class GuestOSHypervisorDaoImpl extends 
GenericDaoBase<GuestOSHypervisorVO
         return super.remove(id);
     }
 
-    @Override
-    public GuestOSHypervisorVO findByOsNameAndHypervisor(String guestOsName, 
String hypervisorType, String hypervisorVersion) {
+    private GuestOSHypervisorVO findByOsNameAndHypervisorInternal(String 
guestOsName, String hypervisorType, String hypervisorVersion) {
         SearchCriteria<GuestOSHypervisorVO> sc = guestOsNameSearch.create();
         String version = "default";
         if (!(hypervisorVersion == null || hypervisorVersion.isEmpty())) {
@@ -138,6 +169,12 @@ public class GuestOSHypervisorDaoImpl extends 
GenericDaoBase<GuestOSHypervisorVO
         return CollectionUtils.isNotEmpty(results) ? results.get(0) : null;
     }
 
+    @Override
+    public GuestOSHypervisorVO findByOsNameAndHypervisor(String guestOsName, 
String hypervisorType, String hypervisorVersion) {
+        GuestOSHypervisorVO mapping = 
findByOsNameAndHypervisorInternal(guestOsName, hypervisorType, 
hypervisorVersion);
+        return getMappingForHypervisorVersionOrParentVersionIfNeeded(mapping, 
hypervisorType, hypervisorVersion, null, guestOsName);
+    }
+
     @Override
     public GuestOSHypervisorVO 
findByOsNameAndHypervisorOrderByCreatedDesc(String guestOsName, String 
hypervisorType, String hypervisorVersion) {
         SearchCriteria<GuestOSHypervisorVO> sc = guestOsNameSearch.create();

Reply via email to