aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@oath.com>2019-10-23 13:56:56 +0200
committerGitHub <noreply@github.com>2019-10-23 13:56:56 +0200
commitb0a3f19fa2d8e6ffafdee93ca4c56ea572ef466a (patch)
tree3d1a40f610f4d0f9bd22d6001545ab2cf59d318b /controller-server/src/test/java/com/yahoo
parent2c2a533067954a7312f99211f6afa4c920506b75 (diff)
Revert "Revert "Added TenantCost""
Diffstat (limited to 'controller-server/src/test/java/com/yahoo')
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java6
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java46
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/cost-report.json20
3 files changed, 71 insertions, 1 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java
index 965e1db0e2e..416f2ee89ad 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java
@@ -28,6 +28,8 @@ import com.yahoo.vespa.hosted.controller.api.integration.organization.MockIssueH
import com.yahoo.vespa.hosted.controller.api.integration.organization.OwnershipIssues;
import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer;
import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient;
+import com.yahoo.vespa.hosted.controller.api.integration.resource.MockTenantCost;
+import com.yahoo.vespa.hosted.controller.api.integration.resource.TenantCost;
import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService;
import com.yahoo.vespa.hosted.controller.api.integration.routing.MemoryGlobalRoutingService;
import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator;
@@ -69,6 +71,7 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg
private final ApplicationStoreMock applicationStoreMock = new ApplicationStoreMock();
private final MockRunDataStore mockRunDataStore = new MockRunDataStore();
private final MockBuildService mockBuildService = new MockBuildService();
+ private final MockTenantCost mockTenantCost = new MockTenantCost();
@Override
public ConfigServer configServer() {
@@ -170,6 +173,9 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg
return memoryNameService;
}
+ @Override
+ public TenantCost tenantCost() { return mockTenantCost;}
+
public ZoneRegistryMock zoneRegistryMock() {
return zoneRegistryMock;
}
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 09fd804ea0c..36366a34fa5 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
@@ -40,7 +40,9 @@ import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
import com.yahoo.vespa.hosted.controller.api.integration.organization.Contact;
import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId;
import com.yahoo.vespa.hosted.controller.api.integration.organization.User;
+import com.yahoo.vespa.hosted.controller.api.integration.resource.CostInfo;
import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringInfo;
+import com.yahoo.vespa.hosted.controller.api.integration.resource.MockTenantCost;
import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation;
import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot;
import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMeteringClient;
@@ -75,10 +77,13 @@ 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;
import java.time.Instant;
+import java.time.LocalDate;
+import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
@@ -87,6 +92,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.TreeSet;
import java.util.function.Supplier;
import static com.yahoo.application.container.handler.Request.Method.DELETE;
@@ -200,7 +206,7 @@ public class ApplicationApiTest extends ControllerContainerTest {
// GET cost for a month for a tenant
tester.assertResponse(request("/application/v4/tenant/tenant1/cost/2018-01", GET).userIdentity(USER_ID).oktaAccessToken(OKTA_AT),
- "{}");
+ "{\"month\":\"2018-01\",\"items\":[]}");
// Add another Athens domain, so we can try to create more tenants
createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN_2, USER_ID); // New domain to test tenant w/property ID
@@ -1072,6 +1078,44 @@ public class ApplicationApiTest extends ControllerContainerTest {
}
@Test
+ public void testTenantCostResponse() {
+ ApplicationId applicationId = createTenantAndApplication();
+ MockTenantCost mockTenantCost = (MockTenantCost) controllerTester.containerTester().serviceRegistry().tenantCost();
+
+ mockTenantCost.setMonthsWithMetering(
+ new TreeSet<>(Set.of(
+ YearMonth.of(2019, 10),
+ YearMonth.of(2019, 9)
+ ))
+ );
+
+ tester.assertResponse(request("/application/v4/tenant/" + applicationId.tenant().value() + "/cost", GET)
+ .userIdentity(USER_ID)
+ .oktaAccessToken(OKTA_AT),
+ "{\"months\":[\"2019-09\",\"2019-10\"]}");
+
+ 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)
+ );
+
+ tester.assertResponse(request("/application/v4/tenant/" + applicationId.tenant().value() + "/cost/2019-09", GET)
+ .userIdentity(USER_ID)
+ .oktaAccessToken(OKTA_AT),
+ new File("cost-report.json"));
+ }
+
+ @Test
public void testErrorResponses() throws Exception {
tester.computeVersionStatus();
createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID);
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/cost-report.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/cost-report.json
new file mode 100644
index 00000000000..8f6dbf17d51
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/cost-report.json
@@ -0,0 +1,20 @@
+{
+ "month": "2019-09",
+ "items": [
+ {
+ "applicationId":"tenant1:application1:instance1",
+ "zoneId":"prod.us-south-1",
+ "cpu": {"usage":7.0,"charge":35},
+ "memory": {"usage":600.0,"charge":23},
+ "disk": {"usage":1000.0,"charge":10}
+ },
+ {
+ "applicationId":"tenant1:application1:instance1",
+ "zoneId":"prod.us-north-1",
+ "cpu": {"usage":2.0,"charge":10},
+ "memory": {"usage":3.0,"charge":20},
+ "disk": {"usage":4.0,"charge":30}
+ }
+ ]
+
+} \ No newline at end of file