mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: Fix cpuallocated value in findHostsForMIgration api (#4220)
The findHostsForMigration api displays 0% always for cpuallocated field which is wrong. Fixes #4221
This commit is contained in:
parent
2fce8b733e
commit
a529470b16
@ -190,10 +190,9 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
||||
|
||||
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)) {
|
||||
@ -317,7 +316,7 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
||||
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());
|
||||
@ -340,10 +339,9 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
||||
|
||||
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)) {
|
||||
@ -471,4 +469,9 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user