summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-09-29 12:40:52 +0200
committerJon Bratseth <bratseth@gmail.com>2020-09-29 12:40:52 +0200
commit7cd6975779e424422cee39ffccc2c37ea2acd9ff (patch)
tree653f17956081070346617dadaf5c65a35c745cf9 /node-repository
parent8385e15c0bbca0ccc1030a949c6f2dd346b3a013 (diff)
Avoid candidate node field access
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java32
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java9
2 files changed, 25 insertions, 16 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java
index 0a44a651635..c7b6b3876b9 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java
@@ -243,7 +243,8 @@ class NodeAllocation {
}
private Node acceptNode(NodeCandidate candidate, boolean wantToRetire, boolean resizeable) {
- Node node = candidate.node;
+ candidate = candidate.withNode();
+ Node node = candidate.toNode();
if (node.allocation().isPresent()) // Record the currently requested resources
node = node.with(node.allocation().get().withRequestedResources(requestedNodes.resources().orElse(node.resources())));
@@ -273,14 +274,10 @@ class NodeAllocation {
candidate = candidate.withNode(node);
indexes.add(node.allocation().get().membership().index());
highestIndex.set(Math.max(highestIndex.get(), node.allocation().get().membership().index()));
- put(candidate);
+ nodes.put(node.hostname(), candidate);
return node;
}
- private void put(NodeCandidate candidate) {
- nodes.put(candidate.node.hostname(), candidate);
- }
-
private Node resize(Node node) {
NodeResources hostResources = allNodes.parentOf(node).get().flavor().resources();
return node.with(new Flavor(requestedNodes.resources().get()
@@ -332,8 +329,9 @@ class NodeAllocation {
if (deltaRetiredCount > 0) { // retire until deltaRetiredCount is 0
for (NodeCandidate candidate : byRetiringPriority(nodes.values())) {
if ( ! candidate.allocation().get().membership().retired() && candidate.state() == Node.State.active) {
- candidate = candidate.withNode(candidate.node.retire(Agent.application, nodeRepository.clock().instant()));
- put(candidate);
+ candidate = candidate.withNode();
+ candidate = candidate.withNode(candidate.toNode().retire(Agent.application, nodeRepository.clock().instant()));
+ nodes.put(candidate.toNode().hostname(), candidate);
if (--deltaRetiredCount == 0) break;
}
}
@@ -341,10 +339,11 @@ class NodeAllocation {
else if (deltaRetiredCount < 0) { // unretire until deltaRetiredCount is 0
for (NodeCandidate candidate : byUnretiringPriority(nodes.values())) {
if ( candidate.allocation().get().membership().retired() && hasCompatibleFlavor(candidate) ) {
+ candidate = candidate.withNode();
if (candidate.isResizable)
- candidate = candidate.withNode(resize(candidate.node));
- candidate = candidate.withNode(candidate.node.unretire());
- put(candidate);
+ candidate = candidate.withNode(resize(candidate.toNode()));
+ candidate = candidate.withNode(candidate.toNode().unretire());
+ nodes.put(candidate.toNode().hostname(), candidate);
if (++deltaRetiredCount == 0) break;
}
}
@@ -352,13 +351,14 @@ class NodeAllocation {
for (NodeCandidate candidate : nodes.values()) {
// Set whether the node is exclusive
- Allocation allocation = candidate.node.allocation().get();
- candidate = candidate.withNode(candidate.node.with(allocation.with(allocation.membership()
+ candidate = candidate.withNode();
+ Allocation allocation = candidate.allocation().get();
+ candidate = candidate.withNode(candidate.toNode().with(allocation.with(allocation.membership()
.with(allocation.membership().cluster().exclusive(requestedNodes.isExclusive())))));
- put(candidate);
+ nodes.put(candidate.toNode().hostname(), candidate);
}
- return nodes.values().stream().map(n -> n.node).collect(Collectors.toList());
+ return nodes.values().stream().map(n -> n.toNode()).collect(Collectors.toList());
}
List<Node> reservableNodes() {
@@ -374,7 +374,7 @@ class NodeAllocation {
private List<Node> nodesFilter(Predicate<NodeCandidate> predicate) {
return nodes.values().stream()
.filter(predicate)
- .map(n -> n.node)
+ .map(n -> n.toNode())
.collect(Collectors.toList());
}
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java
index 508a64e9da5..162334ef952 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java
@@ -84,6 +84,15 @@ class NodeCandidate implements Nodelike, Comparable<NodeCandidate> {
freeParentCapacity, parent, violatesSpares, isSurplusNode, isNewNode, isResizable);
}
+ /** Called when the node described by this candidate must be created */
+ public NodeCandidate withNode() {
+ if (node != null) return this;
+ throw new RuntimeException("Not implemented");
+ }
+
+ /** Returns the node instance of this candidate, or throws IllegalStateException if there is none */
+ public Node toNode() { return node; }
+
/**
* Compare this candidate to another
*