mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Prevent NPE if guest OS mapping is missing while prioritizing hosts (#2577)
This commit is contained in:
parent
561630e449
commit
995775d588
@ -29,6 +29,8 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import com.cloud.agent.manager.allocator.HostAllocator;
|
import com.cloud.agent.manager.allocator.HostAllocator;
|
||||||
import com.cloud.capacity.CapacityManager;
|
import com.cloud.capacity.CapacityManager;
|
||||||
import com.cloud.capacity.CapacityVO;
|
import com.cloud.capacity.CapacityVO;
|
||||||
@ -417,6 +419,10 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
|
|||||||
// Determine the guest OS category of the template
|
// Determine the guest OS category of the template
|
||||||
String templateGuestOSCategory = getTemplateGuestOSCategory(template);
|
String templateGuestOSCategory = getTemplateGuestOSCategory(template);
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(templateGuestOSCategory)) {
|
||||||
|
return hosts;
|
||||||
|
}
|
||||||
|
|
||||||
List<Host> prioritizedHosts = new ArrayList<Host>();
|
List<Host> prioritizedHosts = new ArrayList<Host>();
|
||||||
List<Host> noHvmHosts = new ArrayList<Host>();
|
List<Host> noHvmHosts = new ArrayList<Host>();
|
||||||
|
|
||||||
@ -537,6 +543,11 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
|
|||||||
protected String getTemplateGuestOSCategory(VMTemplateVO template) {
|
protected String getTemplateGuestOSCategory(VMTemplateVO template) {
|
||||||
long guestOSId = template.getGuestOSId();
|
long guestOSId = template.getGuestOSId();
|
||||||
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
|
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
|
||||||
|
|
||||||
|
if (guestOS == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
long guestOSCategoryId = guestOS.getCategoryId();
|
long guestOSCategoryId = guestOS.getCategoryId();
|
||||||
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
|
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
|
||||||
return guestOSCategory.getName();
|
return guestOSCategory.getName();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user