NodeSerializer { public Node fromJson(Node.State state, byte[] data) { var key = Hashing.sipHash24().newHasher() .putString(state.name(), StandardCharsets.UTF_8) .putBytes(data).hash() .asLong(); try { return cache.get(key, () -> nodeFromSlime(state, SlimeUtils.jsonToSlime(data).get())); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } } NodeSerializer(NodeFlavors flavors, long cacheSize); byte[] toJson(Node node); CacheStats cacheStats(); Node fromJson(Node.State state, byte[] data);  }
@Test public void reboot_and_restart_and_type_no_current_values_serialization() { String nodeData = "{\n" + " \"type\" : \"tenant\",\n" + " \"rebootGeneration\" : 1,\n" + " \"currentRebootGeneration\" : 2,\n" + " \"flavor\" : \"large\",\n" + " \"history\" : [\n" + " {\n" + " \"type\" : \"provisioned\",\n" + " \"at\" : 1444391401389,\n" + " \"agent\" : \"system\"\n" + " },\n" + " {\n" + " \"type\" : \"reserved\",\n" + " \"at\" : 1444391402611,\n" + " \"agent\" : \"system\"\n" + " }\n" + " ],\n" + " \"instance\" : {\n" + " \"applicationId\" : \"myApplication\",\n" + " \"tenantId\" : \"myTenant\",\n" + " \"instanceId\" : \"myInstance\",\n" + " \"serviceId\" : \"content/myId/0/0\",\n" + " \"restartGeneration\" : 3,\n" + " \"currentRestartGeneration\" : 4,\n" + " \"removable\" : true,\n" + " \"wantedVespaVersion\": \"6.42.2\"\n" + " },\n" + " \"openStackId\" : \"myId\",\n" + " \"hostname\" : \"myHostname\",\n" + " \"ipAddresses\" : [\"127.0.0.1\"]\n" + "}"; Node node = nodeSerializer.fromJson(Node.State.provisioned, Utf8.toBytes(nodeData)); assertEquals("large", node.flavor().name()); assertEquals(1, node.status().reboot().wanted()); assertEquals(2, node.status().reboot().current()); assertEquals(3, node.allocation().get().restartGeneration().wanted()); assertEquals(4, node.allocation().get().restartGeneration().current()); assertEquals(Arrays.asList(History.Event.Type.provisioned, History.Event.Type.reserved), node.history().events().stream().map(History.Event::type).collect(Collectors.toList())); assertTrue(node.allocation().get().isRemovable()); assertEquals(NodeType.tenant, node.type()); }
@Test public void serializes_multiple_ip_addresses() { byte[] nodeWithMultipleIps = createNodeJson("node4.yahoo.tld", "127.0.0.4", "::4"); Node deserializedNode = nodeSerializer.fromJson(State.provisioned, nodeWithMultipleIps); assertEquals(ImmutableSet.of("127.0.0.4", "::4"), deserializedNode.ipConfig().primary()); }
@Test public void want_to_retire_defaults_to_false() { String nodeData = "{\n" + " \"type\" : \"tenant\",\n" + " \"flavor\" : \"large\",\n" + " \"openStackId\" : \"myId\",\n" + " \"hostname\" : \"myHostname\",\n" + " \"ipAddresses\" : [\"127.0.0.1\"]\n" + "}"; Node node = nodeSerializer.fromJson(State.provisioned, Utf8.toBytes(nodeData)); assertFalse(node.status().wantToRetire()); }
@Test public void want_to_deprovision_defaults_to_false() { String nodeData = "{\n" + " \"type\" : \"tenant\",\n" + " \"flavor\" : \"large\",\n" + " \"openStackId\" : \"myId\",\n" + " \"hostname\" : \"myHostname\",\n" + " \"ipAddresses\" : [\"127.0.0.1\"]\n" + "}"; Node node = nodeSerializer.fromJson(State.provisioned, Utf8.toBytes(nodeData)); assertFalse(node.status().wantToDeprovision()); }