diff options
author | Håkon Hallingstad <hakon@yahooinc.com> | 2023-10-04 10:43:19 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@yahooinc.com> | 2023-10-04 10:43:19 +0200 |
commit | 8c6c9073c60c0bdbb711f8a7d6176f15eeac1045 (patch) | |
tree | 8dc8434976e6ed6447786d37cbf1b366bc9959a1 /node-repository | |
parent | 3b2ffb15084344fda6a444b271433c517c534028 (diff) |
Avoid sorting IP addresses when serializing node
Diffstat (limited to 'node-repository')
33 files changed, 98 insertions, 182 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java index d9eba6cc8a5..dc61ead9180 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.hosted.provision.node; import com.google.common.net.InetAddresses; -import com.google.common.primitives.UnsignedBytes; import com.yahoo.config.provision.CloudAccount; import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.HostName; @@ -75,31 +74,6 @@ public record IP() { public int hashCode() { return Objects.hash(version); } } - /** Comparator for sorting IP addresses by their natural order */ - public static final Comparator<InetAddress> NATURAL_ORDER = (ip1, ip2) -> { - byte[] address1 = ip1.getAddress(); - byte[] address2 = ip2.getAddress(); - - // IPv4 always sorts before IPv6 - if (address1.length < address2.length) return -1; - if (address1.length > address2.length) return 1; - - // Compare each octet - for (int i = 0; i < address1.length; i++) { - int b1 = UnsignedBytes.toInt(address1[i]); - int b2 = UnsignedBytes.toInt(address2[i]); - if (b1 == b2) { - continue; - } - if (b1 < b2) { - return -1; - } else { - return 1; - } - } - return 0; - }; - /** * IP configuration of a node * @@ -253,6 +227,10 @@ public record IP() { /** * Find a free allocation in this pool. Note that the allocation is not final until it is assigned to a node * + * <p>TODO(2023-09-20): Once all dynamically provisioned hosts have been reprovisioned, the order of IP addresses + * is significant and should be 1:1 with the order of hostnames, if both are filled. This needs to be verified. + * This can be used to strengthen validation, and simplify the selection of the Allocation to return.</p> + * * @param context allocation context * @param nodes a locked list of all nodes in the repository * @return an allocation from the pool, if any can be made diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java index 73531d650d5..27e9922727a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java @@ -237,7 +237,7 @@ public class NodeSerializer { private void toSlime(List<String> addresses, Cursor array, boolean dummyDueToErasure) { // Validating IP address string literals is expensive, so we do it at serialization time instead of Node // construction time - addresses.stream().map(IP::parse).sorted(IP.NATURAL_ORDER).map(IP::asString).forEach(array::addString); + addresses.stream().map(IP::parse).map(IP::asString).forEach(array::addString); } private void toSlime(List<HostName> hostnames, Cursor object) { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java index 1c513e78de1..6ce888c2e5c 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java @@ -14,7 +14,6 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -36,44 +35,6 @@ public class IPTest { } @Test - public void test_natural_order() { - Set<String> ipAddresses = Set.of( - "192.168.254.1", - "192.168.254.254", - "127.7.3.1", - "127.5.254.1", - "172.16.100.1", - "172.16.254.2", - "2001:db8:0:0:0:0:0:ffff", - "2001:db8:95a3:0:0:0:0:7334", - "2001:db8:85a3:0:0:8a2e:370:7334", - "::1", - "::10", - "::20"); - - assertEquals( - List.of( - "127.5.254.1", - "127.7.3.1", - "172.16.100.1", - "172.16.254.2", - "192.168.254.1", - "192.168.254.254", - "::1", - "::10", - "::20", - "2001:db8::ffff", - "2001:db8:85a3::8a2e:370:7334", - "2001:db8:95a3::7334"), - ipAddresses.stream() - .map(IP::parse) - .sorted(IP.NATURAL_ORDER) - .map(IP::asString) - .toList() - ); - } - - @Test public void test_find_allocation_ipv6_only() { IP.Pool pool = createNode(List.of( "::1", 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 b862f3fa3b8..0470d004976 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 @@ -54,26 +54,26 @@ public class NodesV2ApiTest { @Test public void test_requests() throws Exception { // GET - assertJsonFile(new Request("http://localhost:8080/nodes/v2/"), "root.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/state/"), "states.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/state/?recursive=true"), "states-recursive.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/state/active?recursive=true"), "active-nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/"), "nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true"), "nodes-recursive.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&includeDeprovisioned=true"), "nodes-recursive-include-deprovisioned.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?enclave=true"), "enclave-nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&enclave=true"), "enclave-nodes-recursive.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com"), "node2.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/stats"), "stats.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/maintenance/"), "maintenance.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/wireguard/"), "wireguard.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/"), "root.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/state/"), "states.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/state/?recursive=true"), "states-recursive.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/state/active?recursive=true"), "active-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/"), "nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true"), "nodes-recursive.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&includeDeprovisioned=true"), "nodes-recursive-include-deprovisioned.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?enclave=true"), "enclave-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&enclave=true"), "enclave-nodes-recursive.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com"), "node2.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/stats"), "stats.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/maintenance/"), "maintenance.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/wireguard/"), "wireguard.json"); // GET with filters - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&hostname=host6.yahoo.com%20host2.yahoo.com"), "application2-nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&clusterType=content"), "content-nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&clusterId=id2"), "application2-nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&application=tenant2.application2.instance2"), "application2-nodes.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&parentHost=dockerhost1.yahoo.com"), "child-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&hostname=host6.yahoo.com%20host2.yahoo.com"), "application2-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&clusterType=content"), "content-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&clusterId=id2"), "application2-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&application=tenant2.application2.instance2"), "application2-nodes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&parentHost=dockerhost1.yahoo.com"), "child-nodes.json"); // POST restart command assertRestart(1, new Request("http://localhost:8080/nodes/v2/command/restart?hostname=host2.yahoo.com", @@ -105,10 +105,10 @@ public class NodesV2ApiTest { getBytes(StandardCharsets.UTF_8), Request.Method.POST), "{\"message\":\"Added 4 nodes to the provisioned state\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host8.yahoo.com"), "node8.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host9.yahoo.com"), "node9.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host11.yahoo.com"), "node11.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/parent2.yahoo.com"), "parent2.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host8.yahoo.com"), "node8.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host9.yahoo.com"), "node9.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host11.yahoo.com"), "node11.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/parent2.yahoo.com"), "parent2.json"); // POST duplicate node tester.assertResponse(new Request("http://localhost:8080/nodes/v2/node", @@ -235,7 +235,7 @@ public class NodesV2ApiTest { ((OrchestratorMock) tester.container().components().getComponent(OrchestratorMock.class.getName())) .suspend(new HostName("host4.yahoo.com")); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-after-changes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-after-changes.json"); // Park and remove host assertResponse(new Request("http://localhost:8080/nodes/v2/state/parked/dockerhost1.yahoo.com", @@ -265,11 +265,11 @@ public class NodesV2ApiTest { @Test public void test_application_requests() throws Exception { - assertJsonFile(new Request("http://localhost:8080/nodes/v2/application/"), "applications.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/application/tenant1.application1.instance1"), - "application1.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/application/tenant2.application2.instance2"), - "application2.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/application/"), "applications.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/application/tenant1.application1.instance1"), + "application1.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/application/tenant2.application2.instance2"), + "application2.json"); // Update (PATCH) an application assertResponse(new Request("http://localhost:8080/nodes/v2/application/tenant1.application1.instance1", @@ -375,24 +375,24 @@ public class NodesV2ApiTest { @Test public void patch_hostnames() throws IOException { - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4.json"); assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"additionalHostnames\": [\"a\",\"b\"]}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-with-hostnames.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-with-hostnames.json"); assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"additionalHostnames\": []}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4.json"); } @Test public void patch_wireguard_pubkey() throws IOException { - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4.json"); tester.assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"wireguardPubkey\": \"not a wg key\"}"), Request.Method.PATCH), 400, @@ -402,7 +402,7 @@ public class NodesV2ApiTest { Utf8.toBytes("{\"wireguardPubkey\": \"lololololololololololololololololololololoo=\"}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-wg.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-wg.json"); } @Test @@ -415,7 +415,7 @@ public class NodesV2ApiTest { Request.Method.POST), "{\"message\":\"Added 1 nodes to the provisioned state\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/controller1.yahoo.com"), "controller1.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/controller1.yahoo.com"), "controller1.json"); } @Test @@ -460,12 +460,12 @@ public class NodesV2ApiTest { @Test public void acls_for_inclave_tenant_host() throws Exception { - assertJsonFile(new Request("http://localhost:8080/nodes/v2/acl/host5.yahoo.com"), "acl-tenant-node.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/acl/host5.yahoo.com"), "acl-tenant-node.json"); } @Test public void acl_request_by_config_server() throws Exception { - assertJsonFile(new Request("http://localhost:8080/nodes/v2/acl/cfg1.yahoo.com"), "acl-config-server.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/acl/cfg1.yahoo.com"), "acl-config-server.json"); } @Test @@ -588,7 +588,7 @@ public class NodesV2ApiTest { Request.Method.PATCH), "{\"message\":\"Updated host5.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com"), "node5-after-changes.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com"), "node5-after-changes.json"); } @Test @@ -616,7 +616,7 @@ public class NodesV2ApiTest { "}"), Request.Method.PATCH), "{\"message\":\"Updated dockerhost1.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports.json"); // Patching with an empty reports is no-op tester.assertResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com", @@ -624,7 +624,7 @@ public class NodesV2ApiTest { Request.Method.PATCH), 200, "{\"message\":\"Updated dockerhost1.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports.json"); // Patching existing report overwrites tester.assertResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com", @@ -638,21 +638,21 @@ public class NodesV2ApiTest { Request.Method.PATCH), 200, "{\"message\":\"Updated dockerhost1.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports-2.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports-2.json"); // Clearing one report assertResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com", Utf8.toBytes("{\"reports\": { \"diskSpace\": null } }"), Request.Method.PATCH), "{\"message\":\"Updated dockerhost1.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports-3.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports-3.json"); // Clearing all reports assertResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com", Utf8.toBytes("{\"reports\": null }"), Request.Method.PATCH), "{\"message\":\"Updated dockerhost1.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports-4.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-reports-4.json"); } @Test @@ -835,7 +835,7 @@ public class NodesV2ApiTest { Utf8.toBytes("{\"currentOsVersion\": \"7.5.2\"}"), Request.Method.PATCH), "{\"message\":\"Updated dockerhost1.yahoo.com\"}"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-os-upgrade-complete.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), "docker-node1-os-upgrade-complete.json"); // Override wantedOsVersion assertResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com", @@ -873,12 +873,12 @@ public class NodesV2ApiTest { "{\"message\":\"Will request firmware checks on all hosts.\"}"); // dockerhost1 displays both values. - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), - "dockerhost1-with-firmware-data.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com"), + "dockerhost1-with-firmware-data.json"); // host1 has no wantedFirmwareCheck, as it's not a docker host. - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host1.yahoo.com"), - "node1.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host1.yahoo.com"), + "node1.json"); // Cancel the firmware check. assertResponse(new Request("http://localhost:8080/nodes/v2/upgrade/firmware", new byte[0], Request.Method.DELETE), @@ -887,8 +887,8 @@ public class NodesV2ApiTest { @Test public void test_capacity() throws Exception { - assertJsonFile(new Request("http://localhost:8080/nodes/v2/capacity/?json=true"), "capacity-zone.json"); - assertJsonFile(new Request("http://localhost:8080/nodes/v2/capacity?json=true"), "capacity-zone.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/capacity/?json=true"), "capacity-zone.json"); + assertFile(new Request("http://localhost:8080/nodes/v2/capacity?json=true"), "capacity-zone.json"); List<String> hostsToRemove = List.of( "dockerhost1.yahoo.com", @@ -898,12 +898,12 @@ public class NodesV2ApiTest { ); String requestUriTemplate = "http://localhost:8080/nodes/v2/capacity/?json=true&hosts=%s"; - assertJsonFile(new Request(String.format(requestUriTemplate, - String.join(",", hostsToRemove.subList(0, 3)))), - "capacity-hostremoval-possible.json"); - assertJsonFile(new Request(String.format(requestUriTemplate, - String.join(",", hostsToRemove))), - "capacity-hostremoval-impossible.json"); + assertFile(new Request(String.format(requestUriTemplate, + String.join(",", hostsToRemove.subList(0, 3)))), + "capacity-hostremoval-possible.json"); + assertFile(new Request(String.format(requestUriTemplate, + String.join(",", hostsToRemove))), + "capacity-hostremoval-impossible.json"); } @@ -912,7 +912,7 @@ public class NodesV2ApiTest { public void test_single_node_rendering() throws Exception { for (int i = 1; i <= 14; i++) { if (i == 8 || i == 9 || i == 11 || i == 12) continue; // these nodes are added later - assertJsonFile(new Request("http://localhost:8080/nodes/v2/node/host" + i + ".yahoo.com"), "node" + i + ".json"); + assertFile(new Request("http://localhost:8080/nodes/v2/node/host" + i + ".yahoo.com"), "node" + i + ".json"); } } @@ -1116,8 +1116,8 @@ public class NodesV2ApiTest { tester.assertResponse(request, 200, "{\"message\":\"Scheduled reboot of " + rebootCount + " matching nodes\"}"); } - private void assertJsonFile(Request request, String file) throws IOException { - tester.assertJsonFile(request, file); + private void assertFile(Request request, String file) throws IOException { + tester.assertFile(request, file); } private void assertResponse(Request request, String response) throws IOException { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java index 94f1e1e2509..413813196ac 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java @@ -59,35 +59,12 @@ public class RestApiTester { responseSnippet, response), match, response.contains(responseSnippet)); } - public void assertJsonFile(Request request, String responseFile) throws IOException { - String expectedResponse = IOUtils.readFile(new File(responsesPath + responseFile)); - JsonTestHelper.Options options = new JsonTestHelper.Options().setCompact(true); - expectedResponse = include(expectedResponse); - expectedResponse = JsonTestHelper.normalize(options, expectedResponse); - expectedResponse = expectedResponse.replaceAll("(\"[^\"]*\")|\\s*", "$1"); // Remove whitespace - String responseString = container.handleRequest(request).getBodyAsString(); - responseString = JsonTestHelper.normalize(options, responseString); - if (expectedResponse.contains("(ignore)")) { - // Convert expected response to a literal pattern and replace any ignored field with a pattern that matches - // until the first stop character - String stopCharacters = "[^,:\\\\[\\\\]{}]"; - String expectedResponsePattern = Pattern.quote(expectedResponse) - .replaceAll("\"?\\(ignore\\)\"?", "\\\\E" + - stopCharacters + "*\\\\Q"); - if (!Pattern.matches(expectedResponsePattern, responseString)) { - throw new ComparisonFailure(responseFile + " (with ignored fields)", expectedResponsePattern, - responseString); - } - } else { - assertEquals(responseFile, expectedResponse, responseString); - } - } - public void assertFile(Request request, String responseFile) throws IOException { String expectedResponse = IOUtils.readFile(new File(responsesPath + responseFile)); expectedResponse = include(expectedResponse); - expectedResponse = expectedResponse.replaceAll("(\"[^\"]*\")|\\s*", "$1"); // Remove whitespace + expectedResponse = JsonTestHelper.normalize(expectedResponse); String responseString = container.handleRequest(request).getBodyAsString(); + responseString = JsonTestHelper.normalize(responseString); if (expectedResponse.contains("(ignore)")) { // Convert expected response to a literal pattern and replace any ignored field with a pattern that matches // until the first stop character diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/acl-config-server.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/acl-config-server.json index e3b487325f8..9ac7fcadefe 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/acl-config-server.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/acl-config-server.json @@ -81,7 +81,7 @@ { "hostname": "host13.yahoo.com", "type": "tenant", - "ipAddress": "127.0.13.1", + "ipAddress": "::13:1", "ports": [ 19070 ], @@ -90,7 +90,7 @@ { "hostname": "host13.yahoo.com", "type": "tenant", - "ipAddress": "::13:1", + "ipAddress": "127.0.13.1", "ports": [ 19070 ], diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg1.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg1.json index 54a0e7e9757..4a55128e831 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg1.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg1.json @@ -114,8 +114,8 @@ } ], "ipAddresses": [ - "127.0.201.1", - "::201:1" + "::201:1", + "127.0.201.1" ], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444", diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg2.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg2.json index 7f9830ac1e8..a45800771eb 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg2.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/cfg2.json @@ -114,8 +114,8 @@ } ], "ipAddresses": [ - "127.0.202.1", - "::202:1" + "::202:1", + "127.0.202.1" ], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-os-upgrade-complete.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-os-upgrade-complete.json index 84b34a72e78..03fc9ddec8f 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-os-upgrade-complete.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-os-upgrade-complete.json @@ -115,7 +115,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-2.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-2.json index bc1c11c8d06..36403ed66d5 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-2.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-2.json @@ -124,7 +124,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "reports": { "actualCpuCores": { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-3.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-3.json index 3b7970a9ec0..7665188a6e7 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-3.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-3.json @@ -124,7 +124,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "reports": { "actualCpuCores": { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-4.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-4.json index d99e71bab49..411a55fe499 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-4.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports-4.json @@ -124,7 +124,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports.json index 88bfd9d9418..ffeda0c6113 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1-reports.json @@ -124,7 +124,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "reports": { "actualCpuCores": { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1.json index f70b2dc1b72..903ee9c23a1 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node1.json @@ -114,7 +114,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node2.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node2.json index d3f1a8082ae..0ddacb1e381 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node2.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node2.json @@ -114,7 +114,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.101.1", "::101:1"], + "ipAddresses": ["::101:1", "127.0.101.1"], "additionalIpAddresses": ["::101:2", "::101:3", "::101:4"], "cloudAccount": "aws:777888999000", "wireguard": { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node3.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node3.json index c597b7afa14..5a1a6c79340 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node3.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node3.json @@ -114,7 +114,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.102.1", "::102:1"], + "ipAddresses": ["::102:1", "127.0.102.1"], "additionalIpAddresses": ["::102:2", "::102:3", "::102:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node4.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node4.json index 8a85d55e0df..7166236dc01 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node4.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node4.json @@ -114,7 +114,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.103.1", "::103:1"], + "ipAddresses": ["::103:1", "127.0.103.1"], "additionalIpAddresses": ["::103:2", "::103:3", "::103:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node5.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node5.json index 70b5e465de8..4feab74a85a 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node5.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/docker-node5.json @@ -114,7 +114,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.104.1", "::104:1"], + "ipAddresses": ["::104:1", "127.0.104.1"], "additionalIpAddresses": ["::104:2", "::104:3", "::104:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/dockerhost1-with-firmware-data.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/dockerhost1-with-firmware-data.json index 85b49dd5113..ad8021315ac 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/dockerhost1-with-firmware-data.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/dockerhost1-with-firmware-data.json @@ -126,7 +126,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.100.1", "::100:1"], + "ipAddresses": ["::100:1", "127.0.100.1"], "additionalIpAddresses": ["::100:2", "::100:3", "::100:4"], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node1.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node1.json index c39c5fca4ef..a6202f8f273 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node1.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node1.json @@ -112,7 +112,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.1.1", "::1:1"], + "ipAddresses": ["::1:1", "127.0.1.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node10.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node10.json index 3f0ba1dcbec..3e5bc9ccc5c 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node10.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node10.json @@ -115,7 +115,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.10.1", "::10:1"], + "ipAddresses": ["::10:1", "127.0.10.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node13.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node13.json index a0b00877dca..e87924b9805 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node13.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node13.json @@ -74,8 +74,8 @@ } ], "ipAddresses": [ - "127.0.13.1", - "::13:1" + "::13:1", + "127.0.13.1" ], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node14.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node14.json index 6657f6ba609..7ceeeae7763 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node14.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node14.json @@ -74,8 +74,8 @@ } ], "ipAddresses": [ - "127.0.14.1", - "::14:1" + "::14:1", + "127.0.14.1" ], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node2.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node2.json index 342a5e861df..75e2b0b021d 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node2.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node2.json @@ -112,7 +112,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.2.1", "::2:1"], + "ipAddresses": ["::2:1", "127.0.2.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node3.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node3.json index d9cd6ef9f29..268f1074b6f 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node3.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node3.json @@ -62,7 +62,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.3.1", "::3:1"], + "ipAddresses": ["::3:1", "127.0.3.1"], "additionalIpAddresses": [], "cloudAccount": "aws:777888999000" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-wg.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-wg.json index 404cf9a9a80..20ed276a1c8 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-wg.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-wg.json @@ -115,7 +115,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.4.1", "::4:1"], + "ipAddresses": ["::4:1", "127.0.4.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444", "wireguard": { diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-with-hostnames.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-with-hostnames.json index 8a8d45c7e65..608448907f4 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-with-hostnames.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4-with-hostnames.json @@ -115,7 +115,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.4.1", "::4:1"], + "ipAddresses": ["::4:1", "127.0.4.1"], "additionalIpAddresses": [], "additionalHostnames": ["a", "b"], "cloudAccount": "aws:111222333444" diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4.json index 396ab1c5675..d40b5c70bed 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node4.json @@ -115,7 +115,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.4.1", "::4:1"], + "ipAddresses": ["::4:1", "127.0.4.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5-after-changes.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5-after-changes.json index 015a52d3446..fafaf61ef78 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5-after-changes.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5-after-changes.json @@ -73,7 +73,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.5.1", "::5:1"], + "ipAddresses": ["::5:1", "127.0.5.1"], "additionalIpAddresses": [], "cloudAccount": "aws:777888999000" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5.json index 900f360bc9e..aae4fe84fb8 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node5.json @@ -75,7 +75,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.5.1", "::5:1"], + "ipAddresses": ["::5:1", "127.0.5.1"], "additionalIpAddresses": [], "cloudAccount": "aws:777888999000" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node55.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node55.json index bbc51dc8e5e..7b0ca88a837 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node55.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node55.json @@ -57,7 +57,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.55.1", "::55:1"], + "ipAddresses": ["::55:1", "127.0.55.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node6.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node6.json index 69a5282e48a..946ef4277a5 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node6.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node6.json @@ -112,7 +112,7 @@ "agent": "application" } ], - "ipAddresses": ["127.0.6.1", "::6:1"], + "ipAddresses": ["::6:1", "127.0.6.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node7.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node7.json index 2b05b21639d..a5d84ad6f8c 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node7.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/node7.json @@ -47,7 +47,7 @@ "agent": "system" } ], - "ipAddresses": ["127.0.7.1", "::7:1"], + "ipAddresses": ["::7:1", "127.0.7.1"], "additionalIpAddresses": [], "cloudAccount": "aws:111222333444" } |