diff options
6 files changed, 0 insertions, 215 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java index ca939023245..f87c764b3fd 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java @@ -18,7 +18,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.organization.Mailer; 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.TenantCost; import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService; import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; @@ -70,8 +69,6 @@ public interface ServiceRegistry { RunDataStore runDataStore(); - TenantCost tenantCost(); - ZoneRegistry zoneRegistry(); ResourceTagger resourceTagger(); diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java deleted file mode 100644 index fa3d28fe50c..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.api.integration.resource; - -import com.yahoo.config.provision.TenantName; - -import java.time.YearMonth; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * @author olaa - */ -public class MockTenantCost implements TenantCost { - - private Set<YearMonth> monthsOfMetering = Collections.emptySet(); - private List<CostInfo> costInfoList = Collections.emptyList(); - - @Override - public Set<YearMonth> monthsWithMetering(TenantName tenantName) { - return monthsOfMetering; - } - - @Override - public List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTimestamp, long endTimestamp) { - return costInfoList; - } - - public void setMonthsWithMetering(Set<YearMonth> monthsOfMetering) { - this.monthsOfMetering = monthsOfMetering; - } - - public void setCostInfoList(List<CostInfo> costInfoList) { - this.costInfoList = costInfoList; - } -} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java deleted file mode 100644 index a2a91454366..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.api.integration.resource; - -import com.yahoo.config.provision.TenantName; - -import java.time.LocalDate; -import java.time.YearMonth; -import java.time.temporal.ChronoUnit; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * @author olaa - */ -public interface TenantCost { - - Set<YearMonth> monthsWithMetering(TenantName tenantName); - - List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTimestamp, long endTimestamp); - - default List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { - return getTenantCostOfPeriod(tenantName, getMonthStartTimeStamp(month), getMonthEndTimeStamp(month)); - } - - static TenantCost empty() { - return new TenantCost() { - @Override - public Set<YearMonth> monthsWithMetering(TenantName tenantName) { - return Collections.emptySet(); - } - - @Override - public List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTime, long endTime) { - return Collections.emptyList(); - } - }; - } - - private long getMonthStartTimeStamp(YearMonth month) { - LocalDate startOfMonth = LocalDate.of(month.getYear(), month.getMonth(), 1); - return startOfMonth.atStartOfDay(java.time.ZoneId.of("UTC")) - .toInstant() - .toEpochMilli(); - } - private long getMonthEndTimeStamp(YearMonth month) { - LocalDate startOfMonth = LocalDate.of(month.getYear(), month.getMonth(), 1); - return startOfMonth.plus(1, ChronoUnit.MONTHS) - .atStartOfDay(java.time.ZoneId.of("UTC")) - .toInstant() - .toEpochMilli(); - } -} 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 5115ecaf196..13efadc027a 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 @@ -207,8 +207,6 @@ public class ApplicationApiHandler extends LoggingRequestHandler { if (path.matches("/application/v4/")) return root(request); if (path.matches("/application/v4/tenant")) return tenants(request); if (path.matches("/application/v4/tenant/{tenant}")) return tenant(path.get("tenant"), request); - if (path.matches("/application/v4/tenant/{tenant}/cost")) return tenantCost(path.get("tenant"), request); - if (path.matches("/application/v4/tenant/{tenant}/cost/{month}")) return tenantCost(path.get("tenant"), path.get("month"), request); if (path.matches("/application/v4/tenant/{tenant}/application")) return applications(path.get("tenant"), Optional.empty(), request); if (path.matches("/application/v4/tenant/{tenant}/application/{application}")) return application(path.get("tenant"), path.get("application"), request); if (path.matches("/application/v4/tenant/{tenant}/application/{application}/compile-version")) return compileVersion(path.get("tenant"), path.get("application")); @@ -348,63 +346,6 @@ public class ApplicationApiHandler extends LoggingRequestHandler { return new SlimeJsonResponse(slime); } - private HttpResponse tenantCost(String tenantName, HttpRequest request) { - return controller.tenants().get(TenantName.from(tenantName)) - .map(tenant -> tenantCost(tenant, request)) - .orElseGet(() -> ErrorResponse.notFoundError("Tenant '" + tenantName + "' does not exist")); - } - - private HttpResponse tenantCost(Tenant tenant, HttpRequest request) { - Set<YearMonth> months = controller.serviceRegistry().tenantCost().monthsWithMetering(tenant.name()); - - var slime = new Slime(); - var objectCursor = slime.setObject(); - var monthsCursor = objectCursor.setArray("months"); - - months.forEach(month -> monthsCursor.addString(month.toString())); - return new SlimeJsonResponse(slime); - } - - private HttpResponse tenantCost(String tenantName, String dateString, HttpRequest request) { - return controller.tenants().get(TenantName.from(tenantName)) - .map(tenant -> tenantCost(tenant, tenantCostParseDate(dateString), request)) - .orElseGet(() -> ErrorResponse.notFoundError("Tenant '" + tenantName + "' does not exist")); - } - - private YearMonth tenantCostParseDate(String dateString) { - try { - return YearMonth.parse(dateString); - } catch (DateTimeParseException e){ - throw new IllegalArgumentException("Could not parse year-month '" + dateString + "'"); - } - } - - private HttpResponse tenantCost(Tenant tenant, YearMonth month, HttpRequest request) { - var slime = new Slime(); - Cursor cursor = slime.setObject(); - cursor.setString("month", month.toString()); - List<CostInfo> costInfos = controller.serviceRegistry().tenantCost() - .getTenantCostOfMonth(tenant.name(), month); - Cursor array = cursor.setArray("items"); - - costInfos.forEach(costInfo -> { - Cursor costObject = array.addObject(); - costObject.setString("applicationId", costInfo.getApplicationId().serializedForm()); - costObject.setString("zoneId", costInfo.getZoneId().value()); - Cursor cpu = costObject.setObject("cpu"); - 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().setScale(1, RoundingMode.HALF_UP).doubleValue()); - memory.setLong("charge", costInfo.getMemoryCost()); - Cursor disk = costObject.setObject("disk"); - disk.setDouble("usage", costInfo.getDiskHours().setScale(1, RoundingMode.HALF_UP).doubleValue()); - disk.setLong("charge", costInfo.getDiskCost()); - }); - - return new SlimeJsonResponse(slime); - } - private HttpResponse applications(String tenantName, Optional<String> applicationName, HttpRequest request) { TenantName tenant = TenantName.from(tenantName); if (controller.tenants().get(tenantName).isEmpty()) 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 98178f2a19f..39b8dc110d4 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 @@ -18,7 +18,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.organization.MockBillin import com.yahoo.vespa.hosted.controller.api.integration.organization.MockContactRetriever; import com.yahoo.vespa.hosted.controller.api.integration.organization.MockIssueHandler; import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumerMock; -import com.yahoo.vespa.hosted.controller.api.integration.resource.MockTenantCost; 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.stubs.DummyOwnershipIssues; @@ -55,7 +54,6 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg private final MockTesterCloud mockTesterCloud; private final ApplicationStoreMock applicationStoreMock = new ApplicationStoreMock(); private final MockRunDataStore mockRunDataStore = new MockRunDataStore(); - private final MockTenantCost mockTenantCost = new MockTenantCost(); private final MockResourceTagger mockResourceTagger = new MockResourceTagger(); public ServiceRegistryMock(SystemName system) { @@ -169,9 +167,6 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg } @Override - public MockTenantCost tenantCost() { return mockTenantCost;} - - @Override public ZoneRegistryMock zoneRegistry() { 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 7c703735dbf..388ca65dc40 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,9 +40,7 @@ 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.MeteringData; -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; @@ -176,14 +174,6 @@ public class ApplicationApiTest extends ControllerContainerTest { .data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}"), new File("tenant-without-applications.json")); - // GET list of months for a tenant - tester.assertResponse(request("/application/v4/tenant/tenant1/cost", GET).userIdentity(USER_ID).oktaAccessToken(OKTA_AT).oktaIdentityToken(OKTA_IT), - "{\"months\":[]}"); - - // 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).oktaIdentityToken(OKTA_IT), - "{\"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 // Add property info for that property id, as well, in the mock organization. @@ -985,44 +975,6 @@ public class ApplicationApiTest extends ControllerContainerTest { } @Test - public void testTenantCostResponse() { - ApplicationId applicationId = createTenantAndApplication(); - MockTenantCost mockTenantCost = deploymentTester.controllerTester().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).oktaIdentityToken(OKTA_IT), - "{\"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).oktaIdentityToken(OKTA_IT), - new File("cost-report.json")); - } - - @Test public void testErrorResponses() throws Exception { createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID); @@ -1179,17 +1131,6 @@ public class ApplicationApiTest extends ControllerContainerTest { "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not delete instance 'tenant1.application1.instance1': Instance not found\"}", 404); - // GET cost of unknown tenant - tester.assertResponse(request("/application/v4/tenant/no-such-tenant/cost", GET).userIdentity(USER_ID).oktaAccessToken(OKTA_AT).oktaIdentityToken(OKTA_IT), - "{\"error-code\":\"NOT_FOUND\",\"message\":\"Tenant 'no-such-tenant' does not exist\"}", 404); - - tester.assertResponse(request("/application/v4/tenant/no-such-tenant/cost/2018-01-01", GET).userIdentity(USER_ID).oktaAccessToken(OKTA_AT).oktaIdentityToken(OKTA_IT), - "{\"error-code\":\"NOT_FOUND\",\"message\":\"Tenant 'no-such-tenant' does not exist\"}", 404); - - // GET cost with invalid date string - tester.assertResponse(request("/application/v4/tenant/tenant1/cost/not-a-valid-date", GET).userIdentity(USER_ID).oktaAccessToken(OKTA_AT).oktaIdentityToken(OKTA_IT), - "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not parse year-month 'not-a-valid-date'\"}", 400); - // DELETE tenant tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE) .userIdentity(USER_ID) |