Adding cpuallocated percentage and value to host and hostsformigrationresponse (#4499)

* Adding cpuallocatedwithoverprovisoning to hostresponse and hostsformigrationresponse

* Adding cpuallocatedpercentage and cpuallocatedvalue
This commit is contained in:
davidjumani 2020-12-01 13:56:19 +05:30 committed by GitHub
parent e82813b509
commit afebfd5bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 3 deletions

View File

@ -95,10 +95,23 @@ public class HostForMigrationResponse extends BaseResponse {
@Param(description = "the CPU speed of the host") @Param(description = "the CPU speed of the host")
private Long cpuSpeed; private Long cpuSpeed;
@Deprecated
@SerializedName("cpuallocated") @SerializedName("cpuallocated")
@Param(description = "the amount of the host's CPU currently allocated") @Param(description = "the amount of the host's CPU currently allocated")
private String cpuAllocated; private String cpuAllocated;
@SerializedName("cpuallocatedvalue")
@Param(description = "the amount of the host's CPU currently allocated in MHz")
private Long cpuAllocatedValue;
@SerializedName("cpuallocatedpercentage")
@Param(description = "the amount of the host's CPU currently allocated in percentage")
private String cpuAllocatedPercentage;
@SerializedName("cpuallocatedwithoverprovisioning")
@Param(description = "the amount of the host's CPU currently allocated after applying the cpu.overprovisioning.factor")
private String cpuAllocatedWithOverprovisioning;
@SerializedName("cpuused") @SerializedName("cpuused")
@Param(description = "the amount of the host's CPU currently used") @Param(description = "the amount of the host's CPU currently used")
private String cpuUsed; private String cpuUsed;
@ -303,6 +316,18 @@ public class HostForMigrationResponse extends BaseResponse {
this.cpuAllocated = cpuAllocated; this.cpuAllocated = cpuAllocated;
} }
public void setCpuAllocatedValue(Long cpuAllocatedValue) {
this.cpuAllocatedValue = cpuAllocatedValue;
}
public void setCpuAllocatedPercentage(String cpuAllocatedPercentage) {
this.cpuAllocatedPercentage = cpuAllocatedPercentage;
}
public void setCpuAllocatedWithOverprovisioning(String cpuAllocatedWithOverprovisioning) {
this.cpuAllocatedWithOverprovisioning = cpuAllocatedWithOverprovisioning;
}
public void setCpuUsed(String cpuUsed) { public void setCpuUsed(String cpuUsed) {
this.cpuUsed = cpuUsed; this.cpuUsed = cpuUsed;
} }

View File

@ -103,10 +103,23 @@ public class HostResponse extends BaseResponse {
@Param(description = "the CPU speed of the host") @Param(description = "the CPU speed of the host")
private Long cpuSpeed; private Long cpuSpeed;
@Deprecated
@SerializedName("cpuallocated") @SerializedName("cpuallocated")
@Param(description = "the amount of the host's CPU currently allocated") @Param(description = "the amount of the host's CPU currently allocated")
private String cpuAllocated; private String cpuAllocated;
@SerializedName("cpuallocatedvalue")
@Param(description = "the amount of the host's CPU currently allocated in MHz")
private Long cpuAllocatedValue;
@SerializedName("cpuallocatedpercentage")
@Param(description = "the amount of the host's CPU currently allocated in percentage")
private String cpuAllocatedPercentage;
@SerializedName("cpuallocatedwithoverprovisioning")
@Param(description = "the amount of the host's CPU currently allocated after applying the cpu.overprovisioning.factor")
private String cpuAllocatedWithOverprovisioning;
@SerializedName("cpuused") @SerializedName("cpuused")
@Param(description = "the amount of the host's CPU currently used") @Param(description = "the amount of the host's CPU currently used")
private String cpuUsed; private String cpuUsed;
@ -342,6 +355,18 @@ public class HostResponse extends BaseResponse {
this.cpuAllocated = cpuAllocated; this.cpuAllocated = cpuAllocated;
} }
public void setCpuAllocatedValue(Long cpuAllocatedValue) {
this.cpuAllocatedValue = cpuAllocatedValue;
}
public void setCpuAllocatedPercentage(String cpuAllocatedPercentage) {
this.cpuAllocatedPercentage = cpuAllocatedPercentage;
}
public void setCpuAllocatedWithOverprovisioning(String cpuAllocatedWithOverprovisioning) {
this.cpuAllocatedWithOverprovisioning = cpuAllocatedWithOverprovisioning;
}
public void setCpuUsed(String cpuUsed) { public void setCpuUsed(String cpuUsed) {
this.cpuUsed = cpuUsed; this.cpuUsed = cpuUsed;
} }

View File

@ -193,8 +193,12 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
hostResponse.setHypervisorVersion(host.getHypervisorVersion()); hostResponse.setHypervisorVersion(host.getHypervisorVersion());
hostResponse.setCpuAllocatedValue(cpu);
String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%";
hostResponse.setCpuAllocated(cpuAlloc);
hostResponse.setCpuAllocatedPercentage(cpuAlloc);
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()); float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning)); hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
} }
@ -345,8 +349,12 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
hostResponse.setHypervisorVersion(host.getHypervisorVersion()); hostResponse.setHypervisorVersion(host.getHypervisorVersion());
hostResponse.setCpuAllocatedValue(cpu);
String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%";
hostResponse.setCpuAllocated(cpuAlloc);
hostResponse.setCpuAllocatedPercentage(cpuAlloc);
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()); float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning)); hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
} }