RealNodeRepository implements NodeRepository { @Override public void addNodes(List<AddNode> nodes) { List<NodeRepositoryNode> nodesToPost = nodes.stream() .map(RealNodeRepository::nodeRepositoryNodeFromAddNode) .collect(Collectors.toList()); NodeMessageResponse response = configServerApi.post("/nodes/v2/node", nodesToPost, NodeMessageResponse.class); if (Strings.isNullOrEmpty(response.errorCode)) return; throw new NodeRepositoryException("Failed to add nodes: " + response.message + " " + response.errorCode); } RealNodeRepository(ConfigServerApi configServerApi); @Override void addNodes(List<AddNode> nodes); @Override List<NodeSpec> getNodes(String baseHostName); @Override Optional<NodeSpec> getOptionalNode(String hostName); @Override Map<String, Acl> getAcls(String hostName); @Override void updateNodeAttributes(String hostName, NodeAttributes nodeAttributes); @Override void setNodeState(String hostName, NodeState nodeState); static NodeRepositoryNode nodeRepositoryNodeFromNodeAttributes(NodeAttributes nodeAttributes);  }
@Test public void testAddNodes() { AddNode host = AddNode.forHost("host123.domain.tld", "default", Optional.of(FlavorOverrides.ofDisk(123)), NodeType.confighost, Set.of("::1"), Set.of("::2", "::3")); NodeResources nodeResources = new NodeResources(1, 2, 3, 4, NodeResources.DiskSpeed.slow, NodeResources.StorageType.local); AddNode node = AddNode.forNode("host123-1.domain.tld", "host123.domain.tld", nodeResources, NodeType.config, Set.of("::2", "::3")); assertFalse(nodeRepositoryApi.getOptionalNode("host123.domain.tld").isPresent()); nodeRepositoryApi.addNodes(List.of(host, node)); NodeSpec hostSpec = nodeRepositoryApi.getOptionalNode("host123.domain.tld").orElseThrow(); assertEquals("default", hostSpec.flavor()); assertEquals(123, hostSpec.diskGb(), 0); assertEquals(NodeType.confighost, hostSpec.type()); NodeSpec nodeSpec = nodeRepositoryApi.getOptionalNode("host123-1.domain.tld").orElseThrow(); assertEquals(nodeResources, nodeSpec.resources()); assertEquals(NodeType.config, nodeSpec.type()); }