GabrielBrascher commented on a change in pull request #4220:
URL: https://github.com/apache/cloudstack/pull/4220#discussion_r458826571
##########
File path: server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java
##########
@@ -330,10 +330,10 @@ 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() + "%";
+ float cpuWithOverprovisioning = new Float(host.getCpus() *
host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()));
+ String cpuAlloc = decimalFormat.format(((float)cpu /
cpuWithOverprovisioning * 100f)) + "%";
Review comment:
I see `100f` a couple of times on the code, there is also `100.0f`.
What do you think of extracting these _magic_ `100f`/`100.0f` into a
constant?
Another approach that would be even nicer would be to have these pieces
extracted to a method like `calculateResourceAllocatedPercentage`, and add a
few unit test case methods.
```
public String calculateResourceAllocatedPercentage(float resource, float
resourceWithOverprovisioning) {
return decimalFormat.format(((float)resource /
resourceWithOverprovisioning * 100f)) + **"%"**
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]