mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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 <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
08749d8354
commit
f023fc53c0
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user