diff options
3 files changed, 24 insertions, 12 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java index ed63b1608ca..50c257acd23 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java @@ -4,6 +4,8 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.zone.ZoneId; +import java.math.BigDecimal; + /** * @author olaa */ @@ -11,16 +13,16 @@ public class CostInfo { private final ApplicationId applicationId; private final ZoneId zoneId; - private final double cpuHours; - private final double memoryHours; - private final double diskHours; + private final BigDecimal cpuHours; + private final BigDecimal memoryHours; + private final BigDecimal diskHours; private final int cpuCost; private final int memoryCost; private final int diskCost; public CostInfo(ApplicationId applicationId, ZoneId zoneId, - double cpuHours, double memoryHours, double diskHours, + BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, int cpuCost, int memoryCost, int diskCost) { this.applicationId = applicationId; this.zoneId = zoneId; @@ -40,15 +42,15 @@ public class CostInfo { return zoneId; } - public double getCpuHours() { + public BigDecimal getCpuHours() { return cpuHours; } - public double getMemoryHours() { + public BigDecimal getMemoryHours() { return memoryHours; } - public double getDiskHours() { + public BigDecimal getDiskHours() { return diskHours; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 26d0520164e..e13374352c6 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -94,6 +94,7 @@ import javax.ws.rs.NotAuthorizedException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.math.RoundingMode; import java.net.URI; import java.net.URISyntaxException; import java.security.DigestInputStream; @@ -404,13 +405,13 @@ public class ApplicationApiHandler extends LoggingRequestHandler { costObject.setString("applicationId", costInfo.getApplicationId().serializedForm()); costObject.setString("zoneId", costInfo.getZoneId().value()); Cursor cpu = costObject.setObject("cpu"); - cpu.setDouble("usage", costInfo.getCpuHours()); + cpu.setDouble("usage", costInfo.getCpuHours().setScale(1, RoundingMode.HALF_UP).doubleValue()); cpu.setLong("charge", costInfo.getCpuCost()); Cursor memory = costObject.setObject("memory"); - memory.setDouble("usage", costInfo.getMemoryHours()); + memory.setDouble("usage", costInfo.getMemoryHours().setScale(1, RoundingMode.HALF_UP).doubleValue()); memory.setLong("charge", costInfo.getMemoryCost()); Cursor disk = costObject.setObject("disk"); - disk.setDouble("usage", costInfo.getDiskHours()); + disk.setDouble("usage", costInfo.getDiskHours().setScale(1, RoundingMode.HALF_UP).doubleValue()); disk.setLong("charge", costInfo.getDiskCost()); }); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java index 4592d1515e0..4f7427bb75f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java @@ -75,6 +75,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; +import java.math.BigDecimal; import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Duration; @@ -1037,8 +1038,16 @@ public class ApplicationApiTest extends ControllerContainerTest { .oktaAccessToken(OKTA_AT), "{\"months\":[\"2019-09\",\"2019-10\"]}"); - CostInfo costInfo1 = new CostInfo(applicationId, ZoneId.from("prod", "us-south-1"), 7.0, 600.0, 1000.0, 35, 23, 10); - CostInfo costInfo2 = new CostInfo(applicationId, ZoneId.from("prod", "us-north-1"), 2.0, 3.0, 4.0, 10, 20, 30); + CostInfo costInfo1 = new CostInfo(applicationId, ZoneId.from("prod", "us-south-1"), + new BigDecimal("7.0"), + new BigDecimal("600.0"), + new BigDecimal("1000.0"), + 35, 23, 10); + CostInfo costInfo2 = new CostInfo(applicationId, ZoneId.from("prod", "us-north-1"), + new BigDecimal("2.0"), + new BigDecimal("3.0"), + new BigDecimal("4.0"), + 10, 20, 30); mockTenantCost.setCostInfoList( List.of(costInfo1, costInfo2) |