summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@oath.com>2019-03-25 10:35:12 +0100
committerOla Aunrønning <olaa@oath.com>2019-03-25 11:23:48 +0100
commit387df73c6b506ff1b0d250c295df81ecd2b5a8e5 (patch)
treec486f936403f3131e0a76a8a4e00620c6b3c5295 /controller-api
parent9eb0399b5c643ab6b042be2e0593aaa53b7880c1 (diff)
Metering maintainer
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java45
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java27
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshotConsumer.java14
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockResourceSnapshotConsumer.java18
4 files changed, 104 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java
new file mode 100644
index 00000000000..8c1b300f713
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java
@@ -0,0 +1,45 @@
+// 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.vespa.hosted.controller.api.integration.noderepository.NodeRepositoryNode;
+
+import java.util.List;
+
+public class ResourceAllocation {
+
+ final double cpuCores;
+ final double memoryGb;
+ final double diskGb;
+
+ private ResourceAllocation(double cpuCores, double memoryGb, double diskGb) {
+ this.cpuCores = cpuCores;
+ this.memoryGb = memoryGb;
+ this.diskGb = diskGb;
+ }
+
+ public static ResourceAllocation from(List<NodeRepositoryNode> nodes) {
+ return new ResourceAllocation(
+ nodes.stream().mapToDouble(NodeRepositoryNode::getMinCpuCores).sum(),
+ nodes.stream().mapToDouble(NodeRepositoryNode::getMinMainMemoryAvailableGb).sum(),
+ nodes.stream().mapToDouble(NodeRepositoryNode::getMinDiskAvailableGb).sum()
+ );
+ }
+
+ public double usageFraction(ResourceAllocation total) {
+ return (cpuCores / total.cpuCores + memoryGb / total.memoryGb + diskGb / total.diskGb) / 3;
+ }
+
+ public double getCpuCores() {
+ return cpuCores;
+ }
+
+ public double getMemoryGb() {
+ return memoryGb;
+ }
+
+ public double getDiskGb() {
+ return diskGb;
+ }
+
+}
+
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java
new file mode 100644
index 00000000000..7f7a6b758d5
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java
@@ -0,0 +1,27 @@
+// 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 java.time.Instant;
+
+/**
+ * @author olaa
+ */
+public class ResourceSnapshot {
+
+ private final ResourceAllocation resourceAllocation;
+ private final Instant timestamp;
+
+ public ResourceSnapshot(ResourceAllocation resourceAllocation, Instant timestamp) {
+ this.resourceAllocation = resourceAllocation;
+ this.timestamp = timestamp;
+ }
+
+ public ResourceAllocation getResourceAllocation() {
+ return resourceAllocation;
+ }
+
+ public Instant getTimestamp() {
+ return timestamp;
+ }
+
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshotConsumer.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshotConsumer.java
new file mode 100644
index 00000000000..eeb42ff8f0f
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshotConsumer.java
@@ -0,0 +1,14 @@
+// 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.vespa.hosted.controller.api.identifiers.ApplicationId;
+
+import java.util.Map;
+
+/**
+ * @author olaa
+ */
+public interface ResourceSnapshotConsumer {
+
+ public void consume(Map<ApplicationId, ResourceSnapshot> resources);
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockResourceSnapshotConsumer.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockResourceSnapshotConsumer.java
new file mode 100644
index 00000000000..4cd4665503d
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockResourceSnapshotConsumer.java
@@ -0,0 +1,18 @@
+// 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.stubs;
+
+import com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId;
+import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot;
+import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshotConsumer;
+
+import java.util.Map;
+
+/**
+ * @author olaa
+ */
+public class MockResourceSnapshotConsumer implements ResourceSnapshotConsumer {
+
+ @Override
+ public void consume(Map<ApplicationId, ResourceSnapshot> resources){}
+
+}