CLOUDSTACK-6678: API:MS: listCapacity returns; errorcode":530,"cserrorcode":9999,"errortext":"Index: 0, Size: 0"}.

This commit is contained in:
Sanjay Tripathi 2014-05-15 14:07:10 +05:30 committed by Daan Hoogland
parent f20b2f47dd
commit da97f3f6e5
1 changed files with 6 additions and 2 deletions

View File

@ -1738,7 +1738,7 @@ public class ApiResponseHelper implements ResponseGenerator {
}
List<VgpuTypesInfo> gpuCapacities;
if ((gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
if (!result.isEmpty() && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
HashMap<String, Long> vgpuVMs = ApiDBUtils.getVgpuVmsCount(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId());
float capacityUsed = 0;
@ -1771,7 +1771,11 @@ public class ApiResponseHelper implements ResponseGenerator {
capacityResponse.setCapacityType(Capacity.CAPACITY_TYPE_GPU);
capacityResponse.setCapacityUsed((long)Math.ceil(capacityUsed));
capacityResponse.setCapacityTotal(capacityMax);
capacityResponse.setPercentUsed(format.format(capacityUsed / capacityMax * 100f));
if (capacityMax > 0) {
capacityResponse.setPercentUsed(format.format(capacityUsed / capacityMax * 100f));
} else {
capacityResponse.setPercentUsed(format.format(0));
}
capacityResponse.setObjectName("capacity");
capacityResponses.add(capacityResponse);
}