Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail

hostResponse.setHypervisorVersion(host.getHypervisorVersion());

Float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
String cpuAlloc = decimalFormat.format(((float)cpu / cpuWithOverprovisioning * 100f)) + "%";
hostResponse.setCpuAllocated(cpuAlloc);
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString());
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
hostResponse.setCpuWithOverprovisioning(Float.toString(cpuWithOverprovisioning));
}

if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
Expand Down Expand Up @@ -307,7 +306,7 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
// set allocated capacities
Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
Long cpu = host.getCpuReservedCapacity() + host.getCpuReservedCapacity();
Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity();

hostResponse.setMemoryTotal(host.getTotalMemory());
Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
Expand All @@ -330,10 +329,9 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu

hostResponse.setHypervisorVersion(host.getHypervisorVersion());

Float cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()));
String cpuAlloc = decimalFormat.format(((float)cpu / cpuWithOverprovisioning * 100f)).toString() + "%";
hostResponse.setCpuAllocated(cpuAlloc);
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString());
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
hostResponse.setCpuWithOverprovisioning(Float.toString(cpuWithOverprovisioning));
}

if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
Expand Down Expand Up @@ -461,4 +459,9 @@ public List<HostJoinVO> findByClusterId(Long clusterId, Host.Type type) {
return listBy(sc);
}

private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
}

}