blob: aad0b07a2c42ff161914ebe18d01beec9826a104 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package com.yahoo.vespa.hosted.dockerapi;
/**
* @author valerijf
*/
public class ContainerResources {
public static final ContainerResources UNLIMITED = ContainerResources.from(0, 0);
public final int cpuShares;
public final long memoryBytes;
ContainerResources(int cpuShares, long memoryBytes) {
this.cpuShares = cpuShares;
this.memoryBytes = memoryBytes;
}
public static ContainerResources from(double cpuCores, double memoryGb) {
return new ContainerResources(
(int) Math.round(10 * cpuCores),
(long) ((1L << 30) * memoryGb));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContainerResources that = (ContainerResources) o;
if (cpuShares != that.cpuShares) return false;
return memoryBytes == that.memoryBytes;
}
@Override
public int hashCode() {
int result = cpuShares;
result = 31 * result + (int) (memoryBytes ^ (memoryBytes >>> 32));
return result;
}
@Override
public String toString() {
return cpuShares + " CPU Shares, " + memoryBytes + "B memory";
}
}
|