diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-01-03 23:06:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 23:06:23 +0100 |
commit | 21a63553b099e37f480ea3b4b1a65862388e3655 (patch) | |
tree | 70e703d06caeeab57b97dd36c96dddc0a4ebacb7 | |
parent | 76cd523c8377c24029c3eac337be5e6a72176d07 (diff) | |
parent | 4c321a250afacbdf9cbeb6598c89a6cbebbbb583 (diff) |
Merge pull request #25375 from vespa-engine/mpolden/unified-nodes-path
Write node objects to unified path
2 files changed, 54 insertions, 8 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java index 37583f00547..a9e134f7db5 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java @@ -62,6 +62,7 @@ public class CuratorDatabaseClient { private static final Path root = Path.fromString("/provision/v1"); private static final Path lockPath = root.append("locks"); + private static final Path nodesPath = root.append("nodes"); private static final Path loadBalancersPath = root.append("loadBalancers"); private static final Path applicationsPath = root.append("applications"); private static final Path inactiveJobsPath = root.append("inactiveJobs"); @@ -91,6 +92,8 @@ public class CuratorDatabaseClient { private void initZK() { db.create(root); + db.create(nodesPath); + // TODO(mpolden): Remove state paths after migration to nodesPath for (Node.State state : Node.State.values()) db.create(toPath(state)); db.create(applicationsPath); @@ -225,14 +228,21 @@ public class CuratorDatabaseClient { private void writeNode(Node.State toState, CuratorTransaction curatorTransaction, Node node, Node newNode) { byte[] nodeData = nodeSerializer.toJson(newNode); - String currentNodePath = toPath(node).getAbsolute(); - String newNodePath = toPath(toState, newNode.hostname()).getAbsolute(); - if (newNodePath.equals(currentNodePath)) { - curatorTransaction.add(CuratorOperations.setData(currentNodePath, nodeData)); - } else { - curatorTransaction.add(CuratorOperations.delete(currentNodePath)) - .add(CuratorOperations.create(newNodePath, nodeData)); + { // TODO(mpolden): Remove this after migration to nodesPath + String currentNodePath = toPath(node).getAbsolute(); + String newNodePath = toPath(toState, newNode.hostname()).getAbsolute(); + if (newNodePath.equals(currentNodePath)) { + curatorTransaction.add(CuratorOperations.setData(currentNodePath, nodeData)); + } else { + curatorTransaction.add(CuratorOperations.delete(currentNodePath)) + .add(CuratorOperations.create(newNodePath, nodeData)); + } + } + Path nodePath = nodePath(newNode); + if (db.exists(nodePath)) { + curatorTransaction.add(CuratorOperations.delete(nodePath.getAbsolute())); } + curatorTransaction.add(CuratorOperations.create(nodePath.getAbsolute(), nodeData)); } private Status newNodeStatus(Node node, Node.State toState) { @@ -294,6 +304,10 @@ public class CuratorDatabaseClient { return root.append(toDir(nodeState)).append(nodeName); } + private Path nodePath(Node node) { + return nodesPath.append(node.hostname()); + } + /** Creates and returns the path to the lock for this application */ private Path lockPath(ApplicationId application) { Path lockPath = CuratorDatabaseClient.lockPath.append(application.tenant().value()) diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java index 94707f7f429..f448266b94b 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java @@ -48,7 +48,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; /** * Serializes a node to/from JSON. @@ -69,6 +68,7 @@ public class NodeSerializer { private final NodeFlavors flavors; // Node fields + private static final String stateKey = "state"; private static final String hostnameKey = "hostname"; private static final String ipAddressesKey = "ipAddresses"; private static final String ipAddressPoolKey = "additionalIpAddresses"; @@ -166,6 +166,7 @@ public class NodeSerializer { private void toSlime(Node node, Cursor object) { object.setString(hostnameKey, node.hostname()); + object.setString(stateKey, toString(node.state())); toSlime(node.ipConfig().primary(), object.setArray(ipAddressesKey)); toSlime(node.ipConfig().pool().ipSet(), object.setArray(ipAddressPoolKey)); toSlime(node.ipConfig().pool().getAddressList(), object); @@ -539,4 +540,35 @@ public class NodeSerializer { }; } + static Node.State nodeStateFromString(String state) { + return switch (state) { + case "active" -> Node.State.active; + case "dirty" -> Node.State.dirty; + case "failed" -> Node.State.failed; + case "inactive" -> Node.State.inactive; + case "parked" -> Node.State.parked; + case "provisioned" -> Node.State.provisioned; + case "ready" -> Node.State.ready; + case "reserved" -> Node.State.reserved; + case "deprovisioned" -> Node.State.deprovisioned; + case "breakfixed" -> Node.State.breakfixed; + default -> throw new IllegalArgumentException("Unknown node state '" + state + "'"); + }; + } + + static String toString(Node.State state) { + return switch (state) { + case active -> "active"; + case dirty -> "dirty"; + case failed -> "failed"; + case inactive -> "inactive"; + case parked -> "parked"; + case provisioned -> "provisioned"; + case ready -> "ready"; + case reserved -> "reserved"; + case deprovisioned -> "deprovisioned"; + case breakfixed -> "breakfixed"; + }; + } + } |