You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2018/04/20 13:10:46 UTC

[cloudstack] branch 4.11 updated: Prevent NPE if guest OS mapping is missing while prioritizing hosts (#2577)

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

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


The following commit(s) were added to refs/heads/4.11 by this push:
     new 995775d  Prevent NPE if guest OS mapping is missing while prioritizing hosts (#2577)
995775d is described below

commit 995775d58855250a2072b22275cf032065efd7b7
Author: Khosrow Moossavi <kh...@gmail.com>
AuthorDate: Fri Apr 20 09:10:38 2018 -0400

    Prevent NPE if guest OS mapping is missing while prioritizing hosts (#2577)
---
 .../cloud/agent/manager/allocator/impl/FirstFitAllocator.java | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
index 33cee36..f4ad478 100644
--- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
+++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
@@ -29,6 +29,8 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import com.google.common.base.Strings;
+
 import com.cloud.agent.manager.allocator.HostAllocator;
 import com.cloud.capacity.CapacityManager;
 import com.cloud.capacity.CapacityVO;
@@ -417,6 +419,10 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
         // Determine the guest OS category of the template
         String templateGuestOSCategory = getTemplateGuestOSCategory(template);
 
+        if (Strings.isNullOrEmpty(templateGuestOSCategory)) {
+            return hosts;
+        }
+
         List<Host> prioritizedHosts = 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) {
         long guestOSId = template.getGuestOSId();
         GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
+
+        if (guestOS == null) {
+            return null;
+        }
+
         long guestOSCategoryId = guestOS.getCategoryId();
         GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
         return guestOSCategory.getName();

-- 
To stop receiving notification emails like this one, please contact
dahn@apache.org.