public static RoutingTable from(LbServicesConfig config, long generation) {
        Map<Endpoint, Target> entries = new TreeMap<>();
        for (var tenants : config.tenants().entrySet()) {
            TenantName tenantName = TenantName.from(tenants.getKey());
            if (tenantName.value().equals(HOSTED_VESPA_TENANT_NAME)) continue;
            for (var applications : tenants.getValue().applications().entrySet()) {
                String[] parts = applications.getKey().split(":");
                if (parts.length != 4) throw new IllegalArgumentException("Invalid deployment ID '" + applications.getKey() + "'");

                ApplicationName application = ApplicationName.from(parts[0]);
                ZoneId zone = ZoneId.from(parts[1], parts[2]);
                InstanceName instance = InstanceName.from(parts[3]);

                for (var configuredEndpoint : applications.getValue().endpoints()) {
                    List<Real> reals = configuredEndpoint.hosts().stream()
                                                         .map(hostname -> new Real(hostname,
                                                                                   4443,
                                                                                   configuredEndpoint.weight(),
                                                                                   applications.getValue().activeRotation()))
                                                         .toList();
                    Endpoint endpoint = new Endpoint(configuredEndpoint.dnsName(), routingMethodFrom(configuredEndpoint));
                    ClusterSpec.Id cluster = ClusterSpec.Id.from(configuredEndpoint.clusterId());
                    Target target;
                    boolean applicationEndpoint = configuredEndpoint.scope() == LbServicesConfig.Tenants.Applications.Endpoints.Scope.Enum.application;
                    if (applicationEndpoint) {
                        target = Target.create(endpoint.dnsName, tenantName, application, cluster, zone, reals);
                    } else {
                        target = Target.create(ApplicationId.from(tenantName, application, instance), cluster, zone, reals);
                    }
                    entries.merge(endpoint, target, (oldValue, value) -> {
                        if (applicationEndpoint) {
                            List<Real> merged = new ArrayList<>(oldValue.reals());
                            merged.addAll(value.reals());
                            return value.withReals(merged);
                        }
                        return oldValue;
                    });
                }
            }
        }
        return new RoutingTable(entries, generation);
    }
@Test
    public void translate_from_lb_services_config() {
        RoutingTable expected = new RoutingTable(Map.of(
                new Endpoint("beta.music.vespa.us-north-1.vespa.oath.cloud", RoutingMethod.sharedLayer4),
                Target.create(ApplicationId.from("vespa", "music", "beta"),
                              ClusterSpec.Id.from("default"), ZoneId.from("prod.us-north-1"),
                              List.of(new Real("host3-beta", 4443, 1, true),
                                      new Real("host4-beta", 4443, 1, true))),

                new Endpoint("music.vespa.global.vespa.oath.cloud", RoutingMethod.sharedLayer4),
                Target.create(ApplicationId.from("vespa", "music", "default"),
                              ClusterSpec.Id.from("default"), ZoneId.from("prod.us-north-1"),
                              List.of(new Real("host1-default", 4443, 1, true),
                                      new Real("host2-default", 4443, 1, true))),

                new Endpoint("music.vespa.us-north-1.vespa.oath.cloud", RoutingMethod.sharedLayer4),
                Target.create(ApplicationId.from("vespa", "music", "default"),
                              ClusterSpec.Id.from("default"), ZoneId.from("prod.us-north-1"),
                              List.of(new Real("host1-default", 4443, 1, true),
                                      new Real("host2-default", 4443, 1, true))),

                new Endpoint("rotation-02.vespa.global.routing", RoutingMethod.sharedLayer4),
                Target.create(ApplicationId.from("vespa", "music", "default"),
                              ClusterSpec.Id.from("default"), ZoneId.from("prod.us-north-1"),
                              List.of(new Real("host1-default", 4443, 1, true),
                                      new Real("host2-default", 4443, 1, true))),

                new Endpoint("use-weighted.music.vespa.us-north-1-r.vespa.oath.cloud", RoutingMethod.sharedLayer4),
                Target.create("use-weighted.music.vespa.us-north-1-r.vespa.oath.cloud", TenantName.from("vespa"), ApplicationName.from("music"),
                              ClusterSpec.Id.from("default"), ZoneId.from("prod.us-north-1"),
                              List.of(new Real("host3-beta", 4443, 1, true),
                                      new Real("host4-beta", 4443, 1, true),
                                      new Real("host1-default", 4443, 0, true),
                                      new Real("host2-default", 4443, 0, true)))
        ), 42);

        RoutingTable actual = TestUtil.readRoutingTable("lbservices-config");
        assertEquals(expected, actual);
    }