summaryrefslogtreecommitdiffstats
path: root/docker-api
diff options
context:
space:
mode:
authorValerij Fredriksen <freva@users.noreply.github.com>2019-01-24 09:27:10 +0100
committerGitHub <noreply@github.com>2019-01-24 09:27:10 +0100
commit22e8b3766a2e35f6861ba699493f15719ef4e920 (patch)
tree02383aeacce8c1cf04fe49dcce3af57fc1a85612 /docker-api
parentee82856886e5f00793a61ce45cdd5c9bc7263115 (diff)
parentc59e99d143b0d2bc42dd2e07b57614816406142b (diff)
Merge pull request #8169 from vespa-engine/freva/restart-on-memory-change
Restart container on memory change
Diffstat (limited to 'docker-api')
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java31
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/CreateContainerCommandImpl.java1
2 files changed, 26 insertions, 6 deletions
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java
index 64d8fd6a1e8..d6462b823f1 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java
@@ -65,14 +65,23 @@ public class ContainerResources {
return memoryBytes;
}
+
+ /** Returns true iff the memory component(s) of between <code>this</code> and <code>other</code> are equal */
+ public boolean equalsMemory(ContainerResources other) {
+ return memoryBytes == other.memoryBytes;
+ }
+
+ /** Returns true iff the CPU component(s) of between <code>this</code> and <code>other</code> are equal */
+ public boolean equalsCpu(ContainerResources other) {
+ return Math.abs(other.cpus - cpus) < 0.0001 && cpuShares == other.cpuShares;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContainerResources that = (ContainerResources) o;
- return Math.abs(that.cpus - cpus) < 0.0001 &&
- cpuShares == that.cpuShares &&
- memoryBytes == that.memoryBytes;
+ return equalsMemory(that) && equalsCpu(that);
}
@Override
@@ -80,10 +89,20 @@ public class ContainerResources {
return Objects.hash(cpus, cpuShares, memoryBytes);
}
+
+ /** Returns only the memory component(s) of {@link #toString()} */
+ public String toStringMemory() {
+ return (memoryBytes > 0 ? memoryBytes + "B" : "unlimited") + " memory";
+ }
+
+ /** Returns only the CPU component(s) of {@link #toString()} */
+ public String toStringCpu() {
+ return (cpus > 0 ? cpus : "unlimited") +" CPUs, " +
+ (cpuShares > 0 ? cpuShares : "unlimited") + " CPU Shares";
+ }
+
@Override
public String toString() {
- return (cpus > 0 ? cpus : "unlimited") +" CPUs, " +
- (cpuShares > 0 ? cpuShares : "unlimited") + " CPU Shares, " +
- (memoryBytes > 0 ? memoryBytes + "B" : "unlimited") + " memory";
+ return toStringCpu() + ", " + toStringMemory();
}
}
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/CreateContainerCommandImpl.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/CreateContainerCommandImpl.java
index 596b582b52b..5a8785328c7 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/CreateContainerCommandImpl.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/CreateContainerCommandImpl.java
@@ -162,6 +162,7 @@ class CreateContainerCommandImpl implements Docker.CreateContainerCommand {
containerResources.ifPresent(cr -> hostConfig
.withCpuShares(cr.cpuShares())
.withMemory(cr.memoryBytes())
+ // MemorySwap is the total amount of memory and swap, if MemorySwap == Memory, then container has no access swap
.withMemorySwap(cr.memoryBytes())
.withCpuPeriod(cr.cpuQuota() > 0 ? cr.cpuPeriod() : null)
.withCpuQuota(cr.cpuQuota() > 0 ? cr.cpuQuota() : null));