summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorMartin Polden <martin.polden@gmail.com>2016-06-28 13:11:17 +0200
committerMartin Polden <martin.polden@gmail.com>2016-06-28 13:11:17 +0200
commitd691a588d599f225e425b52fe7660daca3488227 (patch)
tree08a7db7e06f6c584bf0851a50b77e5e8f34a3cfe /node-repository
parentdb8e60d1553b9c625ae943416a174d9767aa7cb0 (diff)
Reject deallocate for nodes with hardware failure
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java8
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java19
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 11892c69c1c..bef8b6ce1db 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
@@ -182,7 +182,9 @@ 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(Node.State.failed, hostname);
@@ -190,6 +192,10 @@ public class NodeRepository extends AbstractComponent {
nodeToDeallocate = getNode(Node.State.parked, hostname);
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",