mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
server: Fixed hosts not displaying with incompatible locale (#4900)
Fixes: #4733
This commit is contained in:
parent
b28d638ade
commit
4dd7db1509
@ -18,10 +18,14 @@
|
||||
package org.apache.cloudstack.response;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
|
||||
public class HostMetricsResponse extends HostResponse {
|
||||
@SerializedName("powerstate")
|
||||
@Param(description = "out-of-band management power state")
|
||||
@ -117,7 +121,7 @@ public class HostMetricsResponse extends HostResponse {
|
||||
|
||||
public void setCpuUsed(final String cpuUsed, final Integer cpuNumber, final Long cpuSpeed) {
|
||||
if (cpuUsed != null && cpuNumber != null && cpuSpeed != null) {
|
||||
this.cpuUsed = String.format("%.2f Ghz", Double.valueOf(cpuUsed.replace("%", "")) * cpuNumber * cpuSpeed / (100.0 * 1000.0));
|
||||
this.cpuUsed = String.format("%.2f Ghz", parseCPU(cpuUsed) * cpuNumber * cpuSpeed / (100.0 * 1000.0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +133,7 @@ public class HostMetricsResponse extends HostResponse {
|
||||
|
||||
public void setCpuAllocated(final String cpuAllocated, final Integer cpuNumber, final Long cpuSpeed) {
|
||||
if (cpuAllocated != null && cpuNumber != null && cpuSpeed != null) {
|
||||
this.cpuAllocated = String.format("%.2f Ghz", Double.valueOf(cpuAllocated.replace("%", "")) * cpuNumber * cpuSpeed / (100.0 * 1000.0));
|
||||
this.cpuAllocated = String.format("%.2f Ghz", parseCPU(cpuAllocated) * cpuNumber * cpuSpeed / (100.0 * 1000.0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,25 +169,25 @@ public class HostMetricsResponse extends HostResponse {
|
||||
|
||||
public void setCpuUsageThreshold(final String cpuUsed, final Double threshold) {
|
||||
if (cpuUsed != null && threshold != null) {
|
||||
this.cpuThresholdExceeded = Double.valueOf(cpuUsed.replace("%", "")) > (100.0 * threshold);
|
||||
this.cpuThresholdExceeded = parseCPU(cpuUsed) > (100.0 * threshold);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCpuUsageDisableThreshold(final String cpuUsed, final Float threshold) {
|
||||
if (cpuUsed != null && threshold != null) {
|
||||
this.cpuDisableThresholdExceeded = Double.valueOf(cpuUsed.replace("%", "")) > (100.0 * threshold);
|
||||
this.cpuDisableThresholdExceeded = parseCPU(cpuUsed) > (100.0 * threshold);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCpuAllocatedThreshold(final String cpuAllocated, final Double overCommitRatio, final Double threshold) {
|
||||
if (cpuAllocated != null && overCommitRatio != null && threshold != null) {
|
||||
this.cpuAllocatedThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold * overCommitRatio);
|
||||
this.cpuAllocatedThresholdExceeded = parseCPU(cpuAllocated) > (100.0 * threshold * overCommitRatio);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCpuAllocatedDisableThreshold(final String cpuAllocated, final Double overCommitRatio, final Float threshold) {
|
||||
if (cpuAllocated != null && overCommitRatio != null && threshold != null) {
|
||||
this.cpuAllocatedDisableThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold * overCommitRatio);
|
||||
this.cpuAllocatedDisableThresholdExceeded = parseCPU(cpuAllocated) > (100.0 * threshold * overCommitRatio);
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,4 +215,13 @@ public class HostMetricsResponse extends HostResponse {
|
||||
}
|
||||
}
|
||||
|
||||
private Double parseCPU(String cpu) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
try {
|
||||
return decimalFormat.parse(cpu).doubleValue();
|
||||
} catch (ParseException e) {
|
||||
throw new CloudRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user