diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java index e4a84a3166c..8501f71eda1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java @@ -95,10 +95,23 @@ public class HostForMigrationResponse extends BaseResponse { @Param(description = "the CPU speed of the host") private Long cpuSpeed; + @Deprecated @SerializedName("cpuallocated") @Param(description = "the amount of the host's CPU currently allocated") 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") @Param(description = "the amount of the host's CPU currently used") private String cpuUsed; @@ -303,6 +316,18 @@ public class HostForMigrationResponse extends BaseResponse { 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) { this.cpuUsed = cpuUsed; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java index 7b80f22b7b6..8d7d8b312e8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java @@ -103,16 +103,29 @@ public class HostResponse extends BaseResponse { @Param(description = "the CPU speed of the host") private Long cpuSpeed; + @Deprecated @SerializedName("cpuallocated") @Param(description = "the amount of the host's CPU currently allocated") 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") @Param(description = "the amount of the host's CPU currently used") private String cpuUsed; @SerializedName("cpuwithoverprovisioning") - @Param(description = "the amount of the host's CPU after applying the cpu.overprovisioning.factor ") + @Param(description = "the amount of the host's CPU after applying the cpu.overprovisioning.factor") private String cpuWithOverprovisioning; @SerializedName(ApiConstants.CPU_LOAD_AVERAGE) @@ -342,6 +355,18 @@ public class HostResponse extends BaseResponse { 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) { this.cpuUsed = cpuUsed; } diff --git a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java index 9f5bfee0dd4..f7373a7687a 100644 --- a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java +++ b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java @@ -193,8 +193,12 @@ public class HostJoinDaoImpl extends GenericDaoBase implements 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()); - hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); + hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning)); } @@ -345,8 +349,12 @@ public class HostJoinDaoImpl extends GenericDaoBase implements 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()); - hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); + hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning)); }