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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8c6fb0e  CLOUDSTACK-10157: Wrong notification while migration (#2337)
8c6fb0e is described below

commit 8c6fb0e3120e80e0682b5666b13e70d640e58daf
Author: Nitin Kumar Maharana <[email protected]>
AuthorDate: Mon Dec 11 21:50:37 2017 +0530

    CLOUDSTACK-10157: Wrong notification while migration (#2337)
    
    Root Cause:
    Earlier, it was failing with ArrayIndexOutOfBoundsException, when the list 
is empty and accessing the first element.
    The error was only observed in Log, but was not showing in UI as it was not 
throwing any exception.
    Hence the API call was in turn successful.
    
    Solution:
    Added the empty check before sending device details.
    Which says either the required GPU device is not available or out of 
capacity.
---
 .../src/com/cloud/resource/ResourceManagerImpl.java   | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java 
b/server/src/com/cloud/resource/ResourceManagerImpl.java
index 9feb9b7..33c36de 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -29,6 +29,10 @@ import java.util.Map;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
 import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
@@ -44,9 +48,7 @@ import 
org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
+import org.apache.commons.collections.CollectionUtils;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -2755,8 +2757,15 @@ public class ResourceManagerImpl extends ManagerBase 
implements ResourceManager,
 
     @Override
     public GPUDeviceTO getGPUDevice(final long hostId, final String groupName, 
final String vgpuType) {
-        final HostGpuGroupsVO gpuDevice = listAvailableGPUDevice(hostId, 
groupName, vgpuType).get(0);
-        return new GPUDeviceTO(gpuDevice.getGroupName(), vgpuType, null);
+        final List<HostGpuGroupsVO> gpuDeviceList = 
listAvailableGPUDevice(hostId, groupName, vgpuType);
+
+        if (CollectionUtils.isEmpty(gpuDeviceList)) {
+            final String errorMsg = "Host " + hostId + " does not have 
required GPU device or out of capacity. GPU group: " + groupName + ", vGPU 
Type: " + vgpuType;
+            s_logger.error(errorMsg);
+            throw new CloudRuntimeException(errorMsg);
+        }
+
+        return new GPUDeviceTO(gpuDeviceList.get(0).getGroupName(), vgpuType, 
null);
     }
 
     @Override

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to