summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorAndreas Eriksen <andreer@yahoo-inc.com>2017-02-15 13:39:25 +0100
committerAndreas Eriksen <andreer@yahoo-inc.com>2017-02-15 13:39:25 +0100
commit53532d0bfb46d299f9614aba302ea99cc6d8bdd9 (patch)
tree74e6cab032635b6872054631d3e344d50b041d74 /node-repository
parent4cacb06d47c48bb186738f0b4c3eddf6ecc57740 (diff)
make it possible to patch ip addresses in node repo
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java6
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java19
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java3
3 files changed, 28 insertions, 0 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java
index 8d556b08776..9f867bf68e9 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java
@@ -204,6 +204,12 @@ public final class Node {
return new Node(openStackId, ipAddresses, hostname, parentHostname, flavor, status, state, allocation, history, type);
}
+ /** Returns a copy of this node with the IP addresses set to the given value. */
+ public Node withIpAddresses(Set<String> ipAddresses) {
+ return new Node(openStackId, ipAddresses, hostname, parentHostname, flavor, status, state,
+ allocation, history, type);
+ }
+
/** Returns a copy of this node with the parent hostname assigned to the given value. */
public Node withParentHostname(String parentHostname) {
return new Node(openStackId, ipAddresses, hostname, Optional.of(parentHostname), flavor, status, state,
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java
index 3248ba5b058..8ef63542a22 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java
@@ -15,6 +15,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.time.Clock;
import java.util.Optional;
+import java.util.Set;
+import java.util.TreeSet;
/**
* A class which can take a partial JSON node/v2 node JSON structure and apply it to a node object.
@@ -81,11 +83,28 @@ public class NodePatcher {
return node.with(node.status().withHardwareFailure(toHardwareFailureType(asString(value))));
case "parentHostname" :
return node.withParentHostname(asString(value));
+ case "ipAddresses" :
+ return node.withIpAddresses(asStringSet(value));
default :
throw new IllegalArgumentException("Could not apply field '" + name + "' on a node: No such modifiable field");
}
}
+ private Set<String> asStringSet(Inspector field) {
+ if ( ! field.type().equals(Type.ARRAY))
+ throw new IllegalArgumentException("Expected an ARRAY value, got a " + field.type());
+
+ TreeSet<String> strings = new TreeSet<>();
+ for (int i = 0; i < field.entries(); i++) {
+ Inspector entry = field.entry(i);
+ if ( ! entry.type().equals(Type.STRING))
+ throw new IllegalArgumentException("Expected a STRING value, got a " + entry.type());
+ strings.add(entry.asString());
+ }
+
+ return strings;
+ }
+
private Node patchCurrentRestartGeneration(Long value) {
Optional<Allocation> allocation = node.allocation();
if (allocation.isPresent())
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 f5dd7b6a10d..f89ccc3c53c 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
@@ -154,6 +154,9 @@ public class RestApiTest {
assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com",
Utf8.toBytes("{\"parentHostname\": \"parent.yahoo.com\"}"), Request.Method.PATCH),
"{\"message\":\"Updated host4.yahoo.com\"}");
+ assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com",
+ Utf8.toBytes("{\"ipAddresses\": [\"127.0.0.1\",\"::1\"]}"), Request.Method.PATCH),
+ "{\"message\":\"Updated host4.yahoo.com\"}");
assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-after-changes.json");
}