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
parent ee29915ef0
commit f789a03769

View File

@ -1470,7 +1470,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;
@ -1503,7 +1503,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);
}