SharedLoadBalancerService implements LoadBalancerService { @Override public LoadBalancerInstance create(LoadBalancerSpec spec, boolean force) { var proxyNodes = new ArrayList<>(nodeRepository.getNodes(NodeType.proxy)); proxyNodes.sort(hostnameComparator); if (proxyNodes.size() == 0) { throw new IllegalStateException("Missing proxy nodes in node repository"); } var firstProxyNode = proxyNodes.get(0); var networkNames = proxyNodes.stream() .flatMap(node -> node.ipConfig().primary().stream()) .map(SharedLoadBalancerService::withPrefixLength) .collect(Collectors.toSet()); return new LoadBalancerInstance( HostName.from(firstProxyNode.hostname()), Optional.empty(), Set.of(4080, 4443), networkNames, spec.reals() ); } SharedLoadBalancerService(NodeRepository nodeRepository); @Override LoadBalancerInstance create(LoadBalancerSpec spec, boolean force); @Override void remove(ApplicationId application, ClusterSpec.Id cluster); @Override Protocol protocol(); @Override boolean canForwardTo(NodeType nodeType, ClusterSpec.Type clusterType);  }
@Test public void test_create_lb() { tester.makeReadyNodes(2, "default", NodeType.proxy); var lb = loadBalancerService.create(new LoadBalancerSpec(applicationId, clusterId, reals), false); assertEquals(HostName.from("host-1.yahoo.com"), lb.hostname()); assertEquals(Optional.empty(), lb.dnsZone()); assertEquals(Set.of("127.0.0.1/32", "127.0.0.2/32", "::1/128", "::2/128"), lb.networks()); assertEquals(Set.of(4080, 4443), lb.ports()); }
@Test(expected = IllegalStateException.class) public void test_exception_on_missing_proxies() { loadBalancerService.create(new LoadBalancerSpec(applicationId, clusterId, reals), false); }