diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-02-20 16:26:05 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2023-02-20 16:26:05 +0100 |
commit | b177f78b379fb0310810387401055b53ce2ec9bf (patch) | |
tree | 7b8b3ebc59ebd0c6c401271a2c4171db9a4ef571 | |
parent | c4ddd4bd951d319437a38ead21037d9c17f1b70d (diff) |
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", |