diff options
Diffstat (limited to 'node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java')
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java index d641f59eafb..ec3e2539170 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java @@ -638,30 +638,35 @@ public class Nodes { /** Retire and deprovision given host and all of its children */ public List<Node> deprovision(String hostname, Agent agent, Instant instant) { - return decommission(hostname, DecommissionOperation.deprovision, agent, instant); + return decommission(hostname, HostOperation.deprovision, agent, instant); } - /** Retire and rebuild given host and all of its children */ - public List<Node> rebuild(String hostname, Agent agent, Instant instant) { - return decommission(hostname, DecommissionOperation.rebuild, agent, instant); + /** Rebuild given host */ + public List<Node> rebuild(String hostname, boolean soft, Agent agent, Instant instant) { + return decommission(hostname, soft ? HostOperation.softRebuild : HostOperation.rebuild, agent, instant); } - private List<Node> decommission(String hostname, DecommissionOperation op, Agent agent, Instant instant) { + private List<Node> decommission(String hostname, HostOperation op, Agent agent, Instant instant) { Optional<NodeMutex> nodeMutex = lockAndGet(hostname); if (nodeMutex.isEmpty()) return List.of(); Node host = nodeMutex.get().node(); if (!host.type().isHost()) throw new IllegalArgumentException("Cannot " + op + " non-host " + host); - List<Node> result; - boolean wantToDeprovision = op == DecommissionOperation.deprovision; - boolean wantToRebuild = op == DecommissionOperation.rebuild; + + boolean wantToDeprovision = op == HostOperation.deprovision; + boolean wantToRebuild = op == HostOperation.rebuild || op == HostOperation.softRebuild; + boolean wantToRetire = op.needsRetirement(); + List<Node> result = new ArrayList<>(); try (NodeMutex lock = nodeMutex.get(); Mutex allocationLock = lockUnallocated()) { // This takes allocationLock to prevent any further allocation of nodes on this host host = lock.node(); - result = performOn(list(allocationLock).childrenOf(host), (node, nodeLock) -> { - Node newNode = node.withWantToRetire(true, wantToDeprovision, wantToRebuild, agent, instant); - return write(newNode, nodeLock); - }); - Node newHost = host.withWantToRetire(true, wantToDeprovision, wantToRebuild, agent, instant); + if (wantToRetire) { // Apply recursively if we're retiring + List<Node> updatedNodes = performOn(list(allocationLock).childrenOf(host), (node, nodeLock) -> { + Node newNode = node.withWantToRetire(wantToRetire, wantToDeprovision, wantToRebuild, agent, instant); + return write(newNode, nodeLock); + }); + result.addAll(updatedNodes); + } + Node newHost = host.withWantToRetire(wantToRetire, wantToDeprovision, wantToRebuild, agent, instant); result.add(write(newHost, lock)); } return result; @@ -863,10 +868,28 @@ public class Nodes { retirementRequestedByOperator; } - /** The different ways a host can be decommissioned */ - private enum DecommissionOperation { - deprovision, - rebuild, + private enum HostOperation { + + /** Host is deprovisioned and data is destroyed */ + deprovision(true), + + /** Host is deprovisioned, the same host is later re-provisioned and data is destroyed */ + rebuild(true), + + /** Host is stopped and re-bootstrapped, data is preserved */ + softRebuild(false); + + private final boolean needsRetirement; + + HostOperation(boolean needsRetirement) { + this.needsRetirement = needsRetirement; + } + + /** Returns whether this operation requires the host and its children to be retired */ + public boolean needsRetirement() { + return needsRetirement; + } + } } |