diff options
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java | 8 | ||||
-rw-r--r-- | node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java index c90fea04e46..63163bce9d1 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java @@ -185,12 +185,18 @@ public class NodeRepository extends AbstractComponent { /** * Deallocate a node which is in the failed or parked state. - * Use this to recycle failed nodes which have been repaired or put on hold. + * Use this to recycle failed nodes which have been repaired or put on hold. + * + * @throws IllegalArgumentException if the node has hardware failure */ public Node deallocate(String hostname) { Optional<Node> nodeToDeallocate = getNode(hostname, Node.State.failed, Node.State.parked); if ( ! nodeToDeallocate.isPresent()) throw new IllegalArgumentException("Could not deallocate " + hostname + ": No such node in the failed or parked state"); + if (nodeToDeallocate.get().status().hardwareFailure()) { + throw new IllegalArgumentException(String.format("Could not deallocate %s: Hardware failure flag is set", + hostname)); + } return deallocate(Collections.singletonList(nodeToDeallocate.get())).get(0); } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java index 3992e808830..da826b2c221 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java @@ -169,6 +169,25 @@ public class RestApiTest { } @Test + public void fails_to_deallocate_node_with_hardware_failure() throws IOException { + assertResponse(new Request("http://localhost:8080/nodes/v2/node", + ("[" + asNodeJson("host12.yahoo.com", "default") + "]"). + getBytes(StandardCharsets.UTF_8), + Request.Method.POST), + "{\"message\":\"Added 1 nodes to the provisioned state\"}"); + assertResponse(new Request("http://localhost:8080/nodes/v2/node/host12.yahoo.com", + Utf8.toBytes("{\"hardwareFailure\": true}"), + Request.Method.PATCH), + "{\"message\":\"Updated host12.yahoo.com\"}"); + assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/host12.yahoo.com", + new byte[0], Request.Method.PUT), + "{\"message\":\"Moved host12.yahoo.com to failed\"}"); + assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/host12.yahoo.com", + new byte[0], Request.Method.PUT), 400, + "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not deallocate host12.yahoo.com: Hardware failure flag is set\"}"); + } + + @Test public void testInvalidRequests() throws IOException { // Attempt to fail and ready an allocated node without going through dirty assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/host1.yahoo.com", |