diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-02-20 16:56:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-20 16:56:05 +0100 |
commit | 4f3121fdb4e86a8df0760c3b06113cceaac36160 (patch) | |
tree | a893c29d2b58bfbc174aafa8033e0488bec0ebe5 | |
parent | 4c63cacc52cdbb507d504e97a0dfa6d9c6f081e4 (diff) | |
parent | b177f78b379fb0310810387401055b53ce2ec9bf (diff) |
Merge pull request #26118 from vespa-engine/bratseth/duplicate-node-is-illegal-state
Assume a duplicate node is an illegal state, not an erronous request
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java | 4 | ||||
-rw-r--r-- | node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java | 4 |
2 files changed, 4 insertions, 4 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 9134c376f38..5690a685345 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 @@ -126,7 +126,7 @@ public class Nodes { illegal("Cannot add " + node + ": Child nodes need to be allocated"); Optional<Node> existing = node(node.hostname()); if (existing.isPresent()) - illegal("Cannot add " + node + ": A node with this name already exists"); + throw new IllegalStateException("Cannot add " + node + ": A node with this name already exists"); } return db.addNodesInState(nodes.asList(), Node.State.reserved, Agent.system); } @@ -152,7 +152,7 @@ public class Nodes { Optional<Node> existing = node(node.hostname()); if (existing.isPresent()) { if (existing.get().state() != Node.State.deprovisioned) - illegal("Cannot add " + node + ": A node with this name already exists"); + throw new IllegalStateException("Cannot add " + node + ": A node with this name already exists"); node = node.with(existing.get().history()); node = node.with(existing.get().reports()); node = node.with(node.status().withFailCount(existing.get().status().failCount())); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java index 1d7b7ec7454..43676518330 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java @@ -112,8 +112,8 @@ public class NodesV2ApiTest { // POST duplicate node tester.assertResponse(new Request("http://localhost:8080/nodes/v2/node", ("[" + asNodeJson("host8.yahoo.com", "default", "127.0.254.8") + "]").getBytes(StandardCharsets.UTF_8), - Request.Method.POST), 400, - "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Cannot add provisioned host host8.yahoo.com: A node with this name already exists\"}"); + Request.Method.POST), 500, + "{\"error-code\":\"INTERNAL_SERVER_ERROR\",\"message\":\"Cannot add provisioned host host8.yahoo.com: A node with this name already exists\"}"); // DELETE a provisioned node assertResponse(new Request("http://localhost:8080/nodes/v2/node/host9.yahoo.com", |