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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
import java.util.Optional;
/**
* A capacity request.
*
* @author lulf
* @author bratseth
*/
public final class Capacity {
private final int nodeCount;
private final boolean required;
private final Optional<String> flavor;
private Capacity(int nodeCount, boolean required, Optional<String> flavor) {
this.nodeCount = nodeCount;
this.flavor = flavor;
this.required = required;
}
/** Returns the number of nodes requested */
public int nodeCount() { return nodeCount; }
/** Returns whether the requested number of nodes must be met exactly for a request for this to succeed */
public boolean isRequired() { return required; }
/**
* The node flavor requested, or empty if no particular flavor is specified.
* This may be satisfied by the requested flavor or a suitable replacement
*/
public Optional<String> flavor() { return flavor; }
@Override
public String toString() {
return nodeCount + " nodes " + ( flavor.isPresent() ? "of flavor " + flavor.get() : "(default flavor)" );
}
/** Creates this from a desired node count: The request may be satisfied with a smaller number of nodes. */
public static Capacity fromNodeCount(int capacity) {
return fromNodeCount(capacity, Optional.empty());
}
/** Creates this from a desired node count: The request may be satisfied with a smaller number of nodes. */
public static Capacity fromNodeCount(int nodeCount, String flavor) {
return fromNodeCount(nodeCount, Optional.of(flavor));
}
/** Creates this from a desired node count: The request may be satisfied with a smaller number of nodes. */
public static Capacity fromNodeCount(int nodeCount, Optional<String> flavor) {
return new Capacity(nodeCount, false, flavor);
}
/** Creates this from a required node count: Requests must fail unless the node count can be satisfied exactly */
public static Capacity fromRequiredNodeCount(int nodeCount) {
return fromRequiredNodeCount(nodeCount, Optional.empty());
}
/** Creates this from a required node count: Requests must fail unless the node count can be satisfied exactly */
public static Capacity fromRequiredNodeCount(int nodeCount, String flavor) {
return fromRequiredNodeCount(nodeCount, Optional.of(flavor));
}
/** Creates this from a required node count: Requests must fail unless the node count can be satisfied exactly */
public static Capacity fromRequiredNodeCount(int nodeCount, Optional<String> flavor) {
return new Capacity(nodeCount, true, flavor);
}
}
|