Skip to content

Commit da97f3f

Browse files
sanjaytripathiDaanHoogland
authored andcommitted
CLOUDSTACK-6678: API:MS: listCapacity returns; errorcode":530,"cserrorcode":9999,"errortext":"Index: 0, Size: 0"}.
1 parent f20b2f4 commit da97f3f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> re
17381738
}
17391739

17401740
List<VgpuTypesInfo> gpuCapacities;
1741-
if ((gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
1741+
if (!result.isEmpty() && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
17421742
HashMap<String, Long> vgpuVMs = ApiDBUtils.getVgpuVmsCount(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId());
17431743

17441744
float capacityUsed = 0;
@@ -1771,7 +1771,11 @@ public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> re
17711771
capacityResponse.setCapacityType(Capacity.CAPACITY_TYPE_GPU);
17721772
capacityResponse.setCapacityUsed((long)Math.ceil(capacityUsed));
17731773
capacityResponse.setCapacityTotal(capacityMax);
1774-
capacityResponse.setPercentUsed(format.format(capacityUsed / capacityMax * 100f));
1774+
if (capacityMax > 0) {
1775+
capacityResponse.setPercentUsed(format.format(capacityUsed / capacityMax * 100f));
1776+
} else {
1777+
capacityResponse.setPercentUsed(format.format(0));
1778+
}
17751779
capacityResponse.setObjectName("capacity");
17761780
capacityResponses.add(capacityResponse);
17771781
}

0 commit comments

Comments
 (0)