diff options
author | Martin Polden <martin.polden@gmail.com> | 2017-02-13 09:09:36 +0100 |
---|---|---|
committer | Martin Polden <martin.polden@gmail.com> | 2017-02-13 09:15:13 +0100 |
commit | 8440a75685f2ccc8229acb5108c2c81c2667246f (patch) | |
tree | f0aad8f4d51d92fe7a2fda5ab857a37e7f93281c /node-repository | |
parent | 7b21fcfec9ad35482e65a710de743e36dd8ba80d (diff) |
Deny setting unallocated node active
Diffstat (limited to 'node-repository')
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java | 6 | ||||
-rw-r--r-- | node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java | 15 |
2 files changed, 15 insertions, 6 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 26fadbf7e91..fb1f9edad31 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 @@ -352,8 +352,12 @@ public class NodeRepository extends AbstractComponent { public Node move(String hostname, Node.State toState) { Optional<Node> node = getNode(hostname); - if ( ! node.isPresent()) + if ( ! node.isPresent()) { throw new NotFoundException("Could not move " + hostname + " to " + toState + ": Node not found"); + } + if (toState == Node.State.active && !node.get().allocation().isPresent()) { + throw new IllegalArgumentException("Could not set " + hostname + " active. It has no allocation."); + } try (Mutex lock = lock(node.get())) { return zkClient.writeTo(toState, node.get()); } 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 e1ab2914cff..f5dd7b6a10d 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 @@ -97,15 +97,15 @@ public class RestApiTest { "{\"message\":\"Nothing done; host8.yahoo.com is already ready\"}"); // PUT a node in failed ... - assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/host8.yahoo.com", + assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/host3.yahoo.com", new byte[0], Request.Method.PUT), - "{\"message\":\"Moved host8.yahoo.com to failed\"}"); - assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/host8.yahoo.com"), + "{\"message\":\"Moved host3.yahoo.com to failed\"}"); + assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/host3.yahoo.com"), "\"state\":\"failed\""); // ... and put it back in active (after fixing). This is useful to restore data when multiple nodes fail. - assertResponse(new Request("http://localhost:8080/nodes/v2/state/active/host8.yahoo.com", + assertResponse(new Request("http://localhost:8080/nodes/v2/state/active/host3.yahoo.com", new byte[0], Request.Method.PUT), - "{\"message\":\"Moved host8.yahoo.com to active\"}"); + "{\"message\":\"Moved host3.yahoo.com to active\"}"); // PUT a node in parked ... assertResponse(new Request("http://localhost:8080/nodes/v2/state/parked/host8.yahoo.com", @@ -347,6 +347,11 @@ public class RestApiTest { assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"flavor\": 1}"), Request.Method.PATCH), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not set field 'flavor': Expected a STRING value, got a LONG\"}"); + + // Attempt to set unallocated node active + assertResponse(new Request("http://localhost:8080/nodes/v2/state/active/host2.yahoo.com", + new byte[0], Request.Method.PUT), 400, + "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not set host2.yahoo.com active. It has no allocation.\"}"); } |