summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authortoby <smorgrav@yahoo-inc.com>2017-09-27 14:37:10 +0200
committertoby <smorgrav@yahoo-inc.com>2017-10-10 13:37:59 +0200
commit4ab41186b4e8197532a1cd13ed6ada30f5f26f59 (patch)
tree22ced06991defca126725f92a56226d5040a871e /controller-server
parentd440b79e005d7cf9ede08daac2e40ab22641bc53 (diff)
Fold cost api into the application API - take 1
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java18
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterCost.java70
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterInfo.java36
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilization.java62
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Deployment.java29
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentCost.java58
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/RootHandler.java1
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java67
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java2
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilizationTest.java29
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/cost/CostMock.java47
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java29
12 files changed, 342 insertions, 106 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java
index 4a641e6cd45..4f5c2ead4da 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java
@@ -18,8 +18,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.athens.Athens;
import com.yahoo.vespa.hosted.controller.api.integration.athens.ZmsClient;
import com.yahoo.vespa.hosted.controller.api.integration.chef.Chef;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerClient;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostApplication;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.Cost;
import com.yahoo.vespa.hosted.controller.api.integration.dns.NameService;
import com.yahoo.vespa.hosted.controller.api.integration.entity.EntityService;
import com.yahoo.vespa.hosted.controller.api.integration.github.GitHub;
@@ -28,7 +26,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingSe
import com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus;
import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator;
import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry;
-import com.yahoo.vespa.hosted.controller.common.NotFoundCheckedException;
import com.yahoo.vespa.hosted.controller.persistence.ControllerDb;
import com.yahoo.vespa.hosted.controller.persistence.CuratorDb;
import com.yahoo.vespa.hosted.controller.versions.VersionStatus;
@@ -81,7 +78,6 @@ public class Controller extends AbstractComponent {
private final EntityService entityService;
private final GlobalRoutingService globalRoutingService;
private final ZoneRegistry zoneRegistry;
- private final Cost cost;
private final ConfigServerClient configServerClient;
private final MetricsService metricsService;
private final Chef chefClient;
@@ -98,19 +94,19 @@ public class Controller extends AbstractComponent {
public Controller(ControllerDb db, CuratorDb curator, RotationRepository rotationRepository,
GitHub gitHub, Jira jiraClient, EntityService entityService,
GlobalRoutingService globalRoutingService,
- ZoneRegistry zoneRegistry, Cost cost, ConfigServerClient configServerClient,
+ ZoneRegistry zoneRegistry, ConfigServerClient configServerClient,
MetricsService metricsService, NameService nameService,
RoutingGenerator routingGenerator, Chef chefClient, Athens athens) {
this(db, curator, rotationRepository,
gitHub, jiraClient, entityService, globalRoutingService, zoneRegistry,
- cost, configServerClient, metricsService, nameService, routingGenerator, chefClient,
+ configServerClient, metricsService, nameService, routingGenerator, chefClient,
Clock.systemUTC(), athens);
}
public Controller(ControllerDb db, CuratorDb curator, RotationRepository rotationRepository,
GitHub gitHub, Jira jiraClient, EntityService entityService,
GlobalRoutingService globalRoutingService,
- ZoneRegistry zoneRegistry, Cost cost, ConfigServerClient configServerClient,
+ ZoneRegistry zoneRegistry, ConfigServerClient configServerClient,
MetricsService metricsService, NameService nameService,
RoutingGenerator routingGenerator, Chef chefClient, Clock clock, Athens athens) {
Objects.requireNonNull(db, "Controller db cannot be null");
@@ -121,7 +117,6 @@ public class Controller extends AbstractComponent {
Objects.requireNonNull(entityService, "EntityService cannot be null");
Objects.requireNonNull(globalRoutingService, "GlobalRoutingService cannot be null");
Objects.requireNonNull(zoneRegistry, "ZoneRegistry cannot be null");
- Objects.requireNonNull(cost, "Cost cannot be null");
Objects.requireNonNull(configServerClient, "ConfigServerClient cannot be null");
Objects.requireNonNull(metricsService, "MetricsService cannot be null");
Objects.requireNonNull(nameService, "NameService cannot be null");
@@ -136,7 +131,6 @@ public class Controller extends AbstractComponent {
this.entityService = entityService;
this.globalRoutingService = globalRoutingService;
this.zoneRegistry = zoneRegistry;
- this.cost = cost;
this.configServerClient = configServerClient;
this.metricsService = metricsService;
this.chefClient = chefClient;
@@ -175,12 +169,6 @@ public class Controller extends AbstractComponent {
public Clock clock() { return clock; }
- public CostApplication getApplicationCost(com.yahoo.config.provision.ApplicationId application,
- com.yahoo.config.provision.Zone zone)
- throws NotFoundCheckedException {
- return cost.getApplicationCost(zone, application);
- }
-
public URI getElkUri(Environment environment, RegionName region, DeploymentId deploymentId) {
return elkUrl(zoneRegistry.getLogServerUri(environment, region), deploymentId);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterCost.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterCost.java
new file mode 100644
index 00000000000..654c7553248
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterCost.java
@@ -0,0 +1,70 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.application;
+
+/**
+ * Calculate tco and waste for one cluster within one deployment.
+ *
+ * @author smorgrav
+ */
+public class ClusterCost {
+ private final double tco;
+ private final double waste;
+ private final ClusterInfo clusterInfo;
+ private final ClusterUtilization systemUtilization;
+ private final ClusterUtilization targetUtilization;
+ private final ClusterUtilization resultUtilization;
+
+ /**
+ * @param clusterInfo Value object with cluster info e.g. the TCO for the hardware used
+ * @param systemUtilization Utilization of system resources (as ratios)
+ */
+ public ClusterCost(ClusterInfo clusterInfo,
+ ClusterUtilization systemUtilization) {
+
+ this.clusterInfo = clusterInfo;
+ this.systemUtilization = systemUtilization;
+ this.targetUtilization = new ClusterUtilization(0.7,0.2, 0.7, 0.3);
+ this.resultUtilization = calculateResultUtilization(systemUtilization, targetUtilization);
+
+ this.tco = clusterInfo.getFlavor().cost() * Math.min(1, this.resultUtilization.getMaxUtilization());
+ this.waste = clusterInfo.getFlavor().cost() - tco;
+ }
+
+ public double getTco() {
+ return tco;
+ }
+
+ public double getWaste() {
+ return waste;
+ }
+
+ public ClusterInfo getClusterInfo() {
+ return clusterInfo;
+ }
+
+ public ClusterUtilization getSystemUtilization() {
+ return systemUtilization;
+ }
+
+ public ClusterUtilization getTargetUtilization() {
+ return targetUtilization;
+ }
+
+ public ClusterUtilization getResultUtilization() {
+ return resultUtilization;
+ }
+
+ static ClusterUtilization calculateResultUtilization(ClusterUtilization system, ClusterUtilization target) {
+ double cpu = ratio(system.getCpu(),target.getCpu());
+ double mem = ratio(system.getMemory(),target.getMemory());
+ double disk = ratio(system.getDisk(),target.getDisk());
+ double diskbusy = ratio(system.getDiskBusy(),target.getDiskBusy());
+
+ return new ClusterUtilization(mem, cpu, disk, diskbusy);
+ }
+
+ private static double ratio(double a, double b) {
+ if (b == 0) return 1;
+ return a/b;
+ }
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterInfo.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterInfo.java
new file mode 100644
index 00000000000..569e97e4f53
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterInfo.java
@@ -0,0 +1,36 @@
+package com.yahoo.vespa.hosted.controller.application;// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import com.yahoo.config.provision.ClusterSpec;
+import com.yahoo.config.provision.Flavor;
+
+import java.util.List;
+
+/**
+ * Value object of static cluster information, in particular the TCO
+ * of the hardware used for this cluster.
+ *
+ * @author smorgrav
+ */
+public class ClusterInfo {
+ private final Flavor flavor;
+ private final ClusterSpec.Type clusterType;
+ private final List<String> hostnames;
+
+ ClusterInfo(Flavor flavor, ClusterSpec.Type clusterType, List<String> hostnames) {
+ this.flavor = flavor;
+ this.clusterType = clusterType;
+ this.hostnames = hostnames;
+ }
+
+ public Flavor getFlavor() {
+ return flavor;
+ }
+
+ public ClusterSpec.Type getClusterType() {
+ return clusterType;
+ }
+
+ public List<String> getHostnames() {
+ return hostnames;
+ }
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilization.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilization.java
new file mode 100644
index 00000000000..3f6e807a581
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilization.java
@@ -0,0 +1,62 @@
+package com.yahoo.vespa.hosted.controller.application;// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+/**
+ * System resources as _ratios_ of available resources.
+ *
+ * Can be for actual readings or target numbers.
+ *
+ * @author smorgrav
+ */
+public class ClusterUtilization {
+
+ private final double memory;
+ private final double cpu;
+ private final double disk;
+ private final double diskBusy;
+ private final double maxUtilization;
+
+ /**
+ * Resource utilization as ratios. The ratio is normally between 0 and 1 where
+ * one is fully utilized but can be higher as it consumes more than it are guaranteed.
+ *
+ * @param memory Memory utilization
+ * @param cpu CPU utilization
+ * @param disk Disk utilization
+ * @param diskBusy Disk busy
+ */
+ public ClusterUtilization(double memory, double cpu, double disk, double diskBusy) {
+ this.memory = memory;
+ this.cpu = cpu;
+ this.disk = disk;
+ this.diskBusy = diskBusy;
+
+ double maxUtil = Math.max(cpu, disk);
+ maxUtil = Math.max(maxUtil, memory);
+ this.maxUtilization = Math.max(maxUtil, diskBusy);
+ }
+
+ /** @return The utilization ratio of the resource that is utilized the most. */
+ public double getMaxUtilization() {
+ return maxUtilization;
+ }
+
+ /** @return The utilization ratio for memory */
+ public double getMemory() {
+ return memory;
+ }
+
+ /** @return The utilization ratio for cpu */
+ public double getCpu() {
+ return cpu;
+ }
+
+ /** @return The utilization ratio for disk */
+ public double getDisk() {
+ return disk;
+ }
+
+ /** @return The disk busy ratio */
+ public double getDiskBusy() {
+ return diskBusy;
+ }
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Deployment.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Deployment.java
index 75e0f82cdcf..f537206d0fb 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Deployment.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Deployment.java
@@ -2,9 +2,12 @@
package com.yahoo.vespa.hosted.controller.application;
import com.yahoo.component.Version;
+import com.yahoo.config.provision.ClusterSpec.Id;
import com.yahoo.config.provision.Zone;
import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Objects;
/**
@@ -18,6 +21,8 @@ public class Deployment {
private final ApplicationRevision revision;
private final Version version;
private final Instant deployTime;
+ private final Map<Id, ClusterUtilization> clusterUtils = new HashMap<>();
+ private final Map<Id, ClusterInfo> clusterInfo = new HashMap<>();
public Deployment(Zone zone, ApplicationRevision revision, Version version, Instant deployTime) {
Objects.requireNonNull(zone, "zone cannot be null");
@@ -42,9 +47,31 @@ public class Deployment {
/** Returns the time this was deployed */
public Instant at() { return deployTime; }
+ public Map<Id, ClusterUtilization> getClusterUtilization() {
+ return clusterUtils;
+ }
+
+ public Map<Id, ClusterInfo> getClusterInfo() {
+ return clusterInfo;
+ }
+
+ /**
+ * Calculate cost for this deployment.
+ *
+ * This is based on cluster utilization and cluster info.
+ */
+ public DeploymentCost calculateCost() {
+
+ Map<String, ClusterCost> costClusters = new HashMap<>();
+ for (Id clusterId : clusterUtils.keySet()) {
+ costClusters.put(clusterId.value(), new ClusterCost(clusterInfo.get(clusterId), clusterUtils.get(clusterId)));
+ }
+
+ return new DeploymentCost(costClusters);
+ }
+
@Override
public String toString() {
return "deployment to " + zone + " of " + revision + " on version " + version + " at " + deployTime;
}
-
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentCost.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentCost.java
new file mode 100644
index 00000000000..b0bbbf7ca8c
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/DeploymentCost.java
@@ -0,0 +1,58 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.application;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Calculates cost for for an application instance.
+ *
+ * @author smorgrav
+ */
+public class DeploymentCost {
+
+ private final double utilization;
+ private final double waste;
+ private final double tco;
+
+ private final Map<String, ClusterCost> clusters;
+
+ public DeploymentCost() {
+ this(new HashMap<>());
+ }
+
+ public DeploymentCost(Map<String, ClusterCost> clusterCosts) {
+ clusters = new HashMap<>(clusterCosts);
+
+ double tco = 0;
+ double util = 0;
+ double waste = 0;
+
+ for (ClusterCost costCluster : clusterCosts.values()) {
+ tco += costCluster.getTco();
+ waste += costCluster.getWaste();
+ int nodesInCluster = costCluster.getClusterInfo().getHostnames().size();
+ util = Math.max(util, nodesInCluster*costCluster.getResultUtilization().getMaxUtilization());
+ }
+
+ this.utilization = util;
+ this.waste = waste;
+ this.tco = tco;
+ }
+
+ public Map<String, ClusterCost> getCluster() {
+ return clusters;
+ }
+
+ public double getTco() {
+ return tco;
+ }
+
+ public double getUtilization() {
+ return utilization;
+ }
+
+ public double getWaste() {
+ return waste;
+ }
+}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/RootHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/RootHandler.java
index 9283b1c3018..50c4efc2d27 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/RootHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/RootHandler.java
@@ -66,7 +66,6 @@ public class RootHandler extends LoggingRequestHandler {
jerseyService(services, "statuspage", "/statuspage/v1/", "/statuspage/application.wadl");
jerseyService(services, "zone", "/zone/v1/", "/zone/application.wadl");
jerseyService(services, "zone", "/zone/v2/", "/zone/application.wadl");
- jerseyService(services, "cost", "/cost/v1/", "/cost/application.wadl");
handlerService(services, "application", "/application/v4/");
handlerService(services, "deployment", "/deployment/v1/");
handlerService(services, "screwdriver", "/screwdriver/v1/release/vespa");
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 2f11530b1f5..1fbfb1822ed 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
@@ -55,17 +55,17 @@ import com.yahoo.vespa.hosted.controller.api.integration.athens.NToken;
import com.yahoo.vespa.hosted.controller.api.integration.athens.ZmsException;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Log;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostApplication;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.restapi.CostJsonModelAdapter;
import com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.ApplicationRevision;
import com.yahoo.vespa.hosted.controller.application.Change;
+import com.yahoo.vespa.hosted.controller.application.ClusterCost;
+import com.yahoo.vespa.hosted.controller.application.ClusterUtilization;
import com.yahoo.vespa.hosted.controller.application.Deployment;
import com.yahoo.vespa.hosted.controller.application.DeploymentJobs;
+import com.yahoo.vespa.hosted.controller.application.DeploymentCost;
import com.yahoo.vespa.hosted.controller.application.JobStatus;
import com.yahoo.vespa.hosted.controller.application.SourceRevision;
-import com.yahoo.vespa.hosted.controller.common.NotFoundCheckedException;
import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse;
import com.yahoo.vespa.hosted.controller.restapi.MessageResponse;
import com.yahoo.vespa.hosted.controller.restapi.Path;
@@ -427,19 +427,14 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
application.deploymentJobs().projectId().ifPresent(i -> response.setString("screwdriverId", String.valueOf(i)));
sourceRevisionToSlime(deployment.revision().source(), response);
- com.yahoo.config.provision.ApplicationId applicationId = com.yahoo.config.provision.ApplicationId.from(tenantName, applicationName, instanceName);
- Zone zoneId = new Zone(Environment.from(environment), RegionName.from(region));
-
// Cost
- try {
- CostApplication appCost = controller.getApplicationCost(applicationId, zoneId);
- Cursor costObject = response.setObject("cost");
- CostJsonModelAdapter.toSlime(appCost, costObject);
- } catch (NotFoundCheckedException nfce) {
- log.log(Level.FINE, "Application cost data not found. " + nfce.getMessage());
- }
+ DeploymentCost appCost = deployment.calculateCost();
+ Cursor costObject = response.setObject("cost");
+ toSlime(appCost, costObject);
// Metrics
+ com.yahoo.config.provision.ApplicationId applicationId = com.yahoo.config.provision.ApplicationId.from(tenantName, applicationName, instanceName);
+ Zone zoneId = new Zone(Environment.from(environment), RegionName.from(region));
try {
MetricsService.DeploymentMetrics metrics = controller.metricsService().getDeploymentMetrics(applicationId, zoneId);
Cursor metricsObject = response.setObject("metrics");
@@ -1087,4 +1082,50 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
return controller.systemVersion();
}
+ public static void toSlime(DeploymentCost deploymentCost, Cursor object) {
+ object.setLong("tco", (long)deploymentCost.getTco());
+ object.setDouble("utilization", deploymentCost.getUtilization());
+ object.setDouble("waste", deploymentCost.getWaste());
+ Cursor clustersObject = object.setObject("cluster");
+ for (Map.Entry<String, ClusterCost> clusterEntry : deploymentCost.getCluster().entrySet())
+ toSlime(clusterEntry.getValue(), clustersObject.setObject(clusterEntry.getKey()));
+ }
+
+ private static void toSlime(ClusterCost clusterCost, Cursor object) {
+ object.setLong("count", clusterCost.getClusterInfo().getHostnames().size());
+ object.setString("resource", getResourceName(clusterCost.getResultUtilization()));
+ object.setDouble("utilization", clusterCost.getResultUtilization().getMaxUtilization());
+ object.setLong("tco", (int)clusterCost.getTco());
+ object.setString("flavor", clusterCost.getClusterInfo().getClusterType().name());
+ object.setLong("waste", (int)clusterCost.getWaste());
+ object.setString("type", clusterCost.getClusterInfo().getClusterType().name());
+ Cursor utilObject = object.setObject("util");
+ utilObject.setDouble("cpu", clusterCost.getResultUtilization().getCpu());
+ utilObject.setDouble("mem", clusterCost.getResultUtilization().getMemory());
+ utilObject.setDouble("disk", clusterCost.getResultUtilization().getDisk());
+ utilObject.setDouble("diskBusy", clusterCost.getResultUtilization().getDiskBusy());
+ Cursor usageObject = object.setObject("usage");
+ usageObject.setDouble("cpu", clusterCost.getSystemUtilization().getCpu() * 100);
+ usageObject.setDouble("mem", clusterCost.getSystemUtilization().getMemory() * 100);
+ usageObject.setDouble("disk", clusterCost.getSystemUtilization().getDisk() * 100);
+ usageObject.setDouble("diskBusy", clusterCost.getSystemUtilization().getDiskBusy() * 100);
+ Cursor hostnamesArray = object.setArray("hostnames");
+ for (String hostname : clusterCost.getClusterInfo().getHostnames())
+ hostnamesArray.addString(hostname);
+ }
+
+ private static String getResourceName(ClusterUtilization utilization) {
+ String name = "cpu";
+ double max = utilization.getMaxUtilization();
+
+ if (utilization.getMemory() == max) {
+ name = "mem";
+ } else if (utilization.getDisk() == max) {
+ name = "disk";
+ } else if (utilization.getDiskBusy() == max) {
+ name = "diskbusy";
+ }
+
+ return name;
+ }
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java
index de6e1b9af35..2aebc8bddab 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java
@@ -32,7 +32,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.jira.JiraMock;
import com.yahoo.vespa.hosted.controller.api.integration.routing.MemoryGlobalRoutingService;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.Change;
-import com.yahoo.vespa.hosted.controller.cost.CostMock;
import com.yahoo.vespa.hosted.controller.integration.MockMetricsService;
import com.yahoo.vespa.hosted.controller.persistence.ControllerDb;
import com.yahoo.vespa.hosted.controller.persistence.CuratorDb;
@@ -78,7 +77,6 @@ public final class ControllerTester {
new MemoryEntityService(),
new MemoryGlobalRoutingService(),
zoneRegistryMock,
- new CostMock(),
configServerClientMock,
new MockMetricsService(),
nameService,
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilizationTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilizationTest.java
new file mode 100644
index 00000000000..ca67e605682
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/ClusterUtilizationTest.java
@@ -0,0 +1,29 @@
+package com.yahoo.vespa.hosted.controller.application;
+
+import org.junit.Assert;
+import org.junit.Test;
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+/**
+ * @author smorgrav
+ */
+public class ClusterUtilizationTest {
+
+ private static final double delta = Double.MIN_NORMAL;
+
+ @Test
+ public void getMaxUtilization() throws Exception {
+ ClusterUtilization resources = new ClusterUtilization(0.3, 0.1, 0.4, 0.5);
+ Assert.assertEquals(0.5, resources.getMaxUtilization(), delta);
+
+ resources = new ClusterUtilization(0.3, 0.1, 0.4, 0.0);
+ Assert.assertEquals(0.4, resources.getMaxUtilization(), delta);
+
+ resources = new ClusterUtilization(0.4, 0.3, 0.3, 0.0);
+ Assert.assertEquals(0.4, resources.getMaxUtilization(), delta);
+
+ resources = new ClusterUtilization(0.1, 0.3, 0.3, 0.0);
+ Assert.assertEquals(0.3, resources.getMaxUtilization(), delta);
+ }
+
+} \ No newline at end of file
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/cost/CostMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/cost/CostMock.java
deleted file mode 100644
index ae4ca35ecaf..00000000000
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/cost/CostMock.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.cost;
-
-import com.yahoo.component.AbstractComponent;
-import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.config.provision.Zone;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.Cost;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostApplication;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostClusterInfo;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostResources;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author mpolden
- */
-public class CostMock extends AbstractComponent implements Cost {
-
- private final Map<ApplicationId, CostApplication> applicationCost = new HashMap<>();
-
- @Override
- public List<CostApplication> getApplicationCost() {
- return new ArrayList<>(applicationCost.values());
- }
-
- @Override
- public Map<Zone, List<ApplicationId>> getApplications() {
- return null;
- }
-
- @Override
- public Map<String, CostClusterInfo> getClusterInfo(Zone zone, ApplicationId app) {
- return null;
- }
-
- @Override
- public Map<String, CostResources> getClusterUtilization(Zone zone, ApplicationId app) {
- return null;
- }
-
- public void setApplicationCost(ApplicationId application, CostApplication cost) {
- applicationCost.put(application, cost);
- }
-}
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 4ac1cc82485..7deda5f68d7 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
@@ -4,8 +4,6 @@ package com.yahoo.vespa.hosted.controller.restapi.application;
import com.yahoo.application.container.handler.Request;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Environment;
-import com.yahoo.config.provision.RegionName;
-import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.hosted.controller.ConfigServerClientMock;
import com.yahoo.vespa.hosted.controller.api.identifiers.AthensDomain;
import com.yahoo.vespa.hosted.controller.api.identifiers.UserId;
@@ -15,11 +13,8 @@ import com.yahoo.vespa.hosted.controller.api.integration.athens.mock.AthensDbMoc
import com.yahoo.vespa.hosted.controller.api.integration.athens.mock.AthensMock;
import com.yahoo.vespa.hosted.controller.api.integration.athens.mock.ZmsClientFactoryMock;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostApplication;
-import com.yahoo.vespa.hosted.controller.api.integration.cost.CostCluster;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.DeploymentJobs;
-import com.yahoo.vespa.hosted.controller.cost.CostMock;
import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester;
import com.yahoo.vespa.hosted.controller.restapi.ContainerTester;
@@ -687,28 +682,6 @@ public class ApplicationApiTest extends ControllerContainerTest {
AthensDbMock.Domain domain = mock.getSetup().domains.get(new AthensDomain(domainName));
domain.admin(new AthensPrincipal(new AthensDomain(athensScrewdriverDomain), new UserId(screwdriverUserId)));
}
-
- private void addMockObservedApplicationCost(String tenant, String application, String instance) {
- CostMock mock = (CostMock) container.components().getComponent("com.yahoo.vespa.hosted.controller.cost.MockInsightBackend");
-
- CostCluster cost = new CostCluster(null, null, null);
-/* cost.setCount(2);
- cost.setResource("cpu");
- cost.setUtilization(1.0f);
- cost.setTco(25);
- cost.setFlavor("flavor1");
- cost.setWaste(10);
- cost.setType("content");
- List<String> hostnames = new ArrayList<>();
- hostnames.add("host1");
- hostnames.add("host2");
- cost.setHostnames(hostnames);
- Map<String, CostCluster> clusterCosts = new HashMap<>();
- clusterCosts.put("cluster1", cost);*/
-
- mock.setApplicationCost(new ApplicationId.Builder().tenant(tenant).applicationName(application).instanceName(instance).build(),
- new CostApplication(new Zone(Environment.prod, RegionName.from("prod.us-west-1")),null, null));
- }
private void startAndTestChange(ContainerControllerTester controllerTester, ApplicationId application, long projectId,
HttpEntity deployData) throws IOException {
@@ -745,4 +718,6 @@ public class ApplicationApiTest extends ControllerContainerTest {
"Deactivated " + stagingPath.replaceFirst("/application/v4/", ""));
controllerTester.notifyJobCompletion(application, projectId, true, DeploymentJobs.JobType.stagingTest);
}
+
+ private void addMockObservedApplicationCost(String tenant, String application, String instance) {}
}