@@ -84,6 +84,29 @@ public GuestOSHypervisorDaoImpl() {
8484 hypervisorTypeAndVersionSearch .done ();
8585 }
8686
87+ private GuestOSHypervisorVO getMappingForHypervisorVersionOrParentVersionIfNeeded (GuestOSHypervisorVO mapping ,
88+ String hypervisorType , String hypervisorVersion , Long guestOsId , String guestOsName ) {
89+ if (mapping != null || !Hypervisor .HypervisorType .VMware .toString ().equals (hypervisorType )) {
90+ return mapping ;
91+ }
92+ String guestOs = guestOsId != null ? String .format ("guest OS ID: %d" , guestOsId ) : String .format ("guest OS ID: %s" , guestOsName );
93+ String parentVersion = CloudStackVersion .getVMwareParentVersion (hypervisorVersion );
94+ if (parentVersion == null ) {
95+ if (s_logger .isDebugEnabled ()) {
96+ s_logger .info (String .format ("Mapping for %s for hypervisor: %s with version: %s can not be found. Parent version is also null" ,
97+ guestOs , hypervisorType , hypervisorVersion ));
98+ }
99+ return null ;
100+ }
101+ if (s_logger .isDebugEnabled ()) {
102+ s_logger .debug (String .format ("Mapping for %s for hypervisor: %s with version: %s can not be found. " +
103+ "Trying to find one for the parent version: %s" , guestOs , hypervisorType , hypervisorVersion , parentVersion ));
104+ }
105+ return guestOsId != null ?
106+ findByOsIdAndHypervisorInternal (guestOsId , hypervisorType , parentVersion ):
107+ findByOsNameAndHypervisorInternal (guestOsName , hypervisorType , parentVersion );
108+ }
109+
87110 @ Override
88111 public List <GuestOSHypervisorVO > listByGuestOsId (long guestOsId ) {
89112 SearchCriteria <GuestOSHypervisorVO > sc = guestOsSearch .create ();
@@ -106,16 +129,7 @@ private GuestOSHypervisorVO findByOsIdAndHypervisorInternal(long guestOsId, Stri
106129 @ Override
107130 public GuestOSHypervisorVO findByOsIdAndHypervisor (long guestOsId , String hypervisorType , String hypervisorVersion ) {
108131 GuestOSHypervisorVO mapping = findByOsIdAndHypervisorInternal (guestOsId , hypervisorType , hypervisorVersion );
109- if (mapping != null || !Hypervisor .HypervisorType .VMware .toString ().equals (hypervisorType )) {
110- return mapping ;
111- }
112- String parentVersion = CloudStackVersion .getVMwareParentVersion (hypervisorVersion );
113- if (parentVersion == null ) {
114- return null ;
115- }
116- s_logger .info (String .format ("Mapping for guest OS ID: %d for hypervisor: %s with version: %s can not be found. " +
117- "Trying to find one for the parent version: %s" , guestOsId , hypervisorType , hypervisorVersion , parentVersion ));
118- return findByOsIdAndHypervisorInternal (guestOsId , hypervisorType , parentVersion );
132+ return getMappingForHypervisorVersionOrParentVersionIfNeeded (mapping , hypervisorType , hypervisorVersion , guestOsId , null );
119133 }
120134
121135 @ Override
@@ -158,16 +172,7 @@ private GuestOSHypervisorVO findByOsNameAndHypervisorInternal(String guestOsName
158172 @ Override
159173 public GuestOSHypervisorVO findByOsNameAndHypervisor (String guestOsName , String hypervisorType , String hypervisorVersion ) {
160174 GuestOSHypervisorVO mapping = findByOsNameAndHypervisorInternal (guestOsName , hypervisorType , hypervisorVersion );
161- if (mapping != null || !Hypervisor .HypervisorType .VMware .toString ().equals (hypervisorType )) {
162- return mapping ;
163- }
164- String parentVersion = CloudStackVersion .getVMwareParentVersion (hypervisorVersion );
165- if (parentVersion == null ) {
166- return null ;
167- }
168- s_logger .info (String .format ("Mapping for guest OS: %s for hypervisor: %s with version: %s can not be found. " +
169- "Trying to find one for the parent version: %s" , guestOsName , hypervisorType , hypervisorVersion , parentVersion ));
170- return findByOsNameAndHypervisorInternal (guestOsName , hypervisorType , parentVersion );
175+ return getMappingForHypervisorVersionOrParentVersionIfNeeded (mapping , hypervisorType , hypervisorVersion , null , guestOsName );
171176 }
172177
173178 @ Override
0 commit comments