mirror of https://github.com/apache/cloudstack.git
Merge remote-tracking branch 'origin/4.15' into main
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
commit
c34a0c5f92
|
|
@ -138,6 +138,10 @@ public class HostMetricsResponse extends HostResponse {
|
|||
}
|
||||
}
|
||||
|
||||
public String getCpuAllocatedGhz() {
|
||||
return cpuAllocated;
|
||||
}
|
||||
|
||||
public void setMemTotal(final Long memTotal) {
|
||||
if (memTotal != null) {
|
||||
this.memTotal = String.format("%.2f GB", memTotal / (1024.0 * 1024.0 * 1024.0));
|
||||
|
|
@ -182,13 +186,13 @@ public class HostMetricsResponse extends HostResponse {
|
|||
|
||||
public void setCpuAllocatedThreshold(final String cpuAllocated, final Double threshold) {
|
||||
if (cpuAllocated != null && threshold != null) {
|
||||
this.cpuAllocatedThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold );
|
||||
this.cpuAllocatedThresholdExceeded = parseCPU(cpuAllocated) > (100.0 * threshold );
|
||||
}
|
||||
}
|
||||
|
||||
public void setCpuAllocatedDisableThreshold(final String cpuAllocated, final Float threshold) {
|
||||
if (cpuAllocated != null && threshold != null) {
|
||||
this.cpuAllocatedDisableThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold);
|
||||
this.cpuAllocatedDisableThresholdExceeded = parseCPU(cpuAllocated) > (100.0 * threshold);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.cloudstack.response;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class HostMetricsResponseTest {
|
||||
|
||||
@Test
|
||||
public void testSetCpuAllocatedWithZeroCpu() {
|
||||
final HostMetricsResponse hostResponse = new HostMetricsResponse();
|
||||
hostResponse.setCpuAllocated("50.25%", 0, 1000L);
|
||||
Assert.assertEquals("0.00 Ghz", hostResponse.getCpuAllocatedGhz());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCpuAllocatedWithInfiniteCpuAllocated() {
|
||||
final HostMetricsResponse hostResponse = new HostMetricsResponse();
|
||||
hostResponse.setCpuAllocated("∞%", 10, 1000L);
|
||||
Assert.assertEquals("Infinity Ghz", hostResponse.getCpuAllocatedGhz());
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
public void testSetCpuAllocatedWithInvalidCpu() {
|
||||
final HostMetricsResponse hostResponse = new HostMetricsResponse();
|
||||
hostResponse.setCpuAllocated("abc", 10, 1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCpuAllocatedWithValidCpu() {
|
||||
final HostMetricsResponse hostResponse = new HostMetricsResponse();
|
||||
hostResponse.setCpuAllocated("50.25%", 10, 1000L);
|
||||
Assert.assertEquals("5.03 Ghz", hostResponse.getCpuAllocatedGhz());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue