From e205c0af443b406f62d3f2d539e0c2160040257c Mon Sep 17 00:00:00 2001 From: davidjumani Date: Tue, 24 Nov 2020 10:25:21 +0530 Subject: [PATCH 1/2] Adding cpuallocatedwithoverprovisoning to hostresponse and hostsformigrationresponse --- .../api/response/HostForMigrationResponse.java | 8 ++++++++ .../apache/cloudstack/api/response/HostResponse.java | 10 +++++++++- .../java/com/cloud/api/query/dao/HostJoinDaoImpl.java | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) 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 e4a84a3166c9..92535f3d1074 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 @@ -99,6 +99,10 @@ public class HostForMigrationResponse extends BaseResponse { @Param(description = "the amount of the host's CPU currently allocated") private String cpuAllocated; + @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 +307,10 @@ public void setCpuAllocated(String cpuAllocated) { this.cpuAllocated = cpuAllocated; } + 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 7b80f22b7b67..77194316f52e 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 @@ -107,12 +107,16 @@ public class HostResponse extends BaseResponse { @Param(description = "the amount of the host's CPU currently allocated") private String cpuAllocated; + @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 +346,10 @@ public void setCpuAllocated(String cpuAllocated) { this.cpuAllocated = cpuAllocated; } + 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 9f5bfee0dd4c..d67cbdc2d8c8 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,10 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet detail hostResponse.setHypervisorVersion(host.getHypervisorVersion()); + String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%"; + hostResponse.setCpuAllocated(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 +347,10 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu hostResponse.setHypervisorVersion(host.getHypervisorVersion()); + String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%"; + hostResponse.setCpuAllocated(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)); } From f2f44df84633ff63c396848a9d880d3150d18fbe Mon Sep 17 00:00:00 2001 From: davidjumani Date: Wed, 25 Nov 2020 10:56:03 +0530 Subject: [PATCH 2/2] Adding cpuallocatedpercentage and cpuallocatedvalue --- .../api/response/HostForMigrationResponse.java | 17 +++++++++++++++++ .../cloudstack/api/response/HostResponse.java | 17 +++++++++++++++++ .../cloud/api/query/dao/HostJoinDaoImpl.java | 4 ++++ 3 files changed, 38 insertions(+) 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 92535f3d1074..8501f71eda15 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,19 @@ 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; @@ -307,6 +316,14 @@ public void setCpuAllocated(String 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; } 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 77194316f52e..8d7d8b312e8e 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,10 +103,19 @@ 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; @@ -346,6 +355,14 @@ public void setCpuAllocated(String 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; } 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 d67cbdc2d8c8..f7373a7687ac 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,10 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet detail 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.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning)); @@ -347,8 +349,10 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu 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.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));