// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.component;

import com.yahoo.vespa.athenz.api.AthenzService;

import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Information necessary to e.g. establish communication with the config servers
 *
 * @author hakon
 */
public class ConfigServerInfo {
    private final List<String> configServerHostNames;
    private final URI loadBalancerEndpoint;
    private final AthenzService configServerIdentity;
    private final Function<String, URI> configServerHostnameToUriMapper;
    private final List<URI> configServerURIs;

    public ConfigServerInfo(String loadBalancerHostName, List<String> configServerHostNames,
                            String scheme, int port, AthenzService configServerAthenzIdentity) {
        this.configServerHostNames = configServerHostNames;
        this.loadBalancerEndpoint = createLoadBalancerEndpoint(loadBalancerHostName, scheme, port);
        this.configServerIdentity = configServerAthenzIdentity;
        this.configServerHostnameToUriMapper = hostname -> URI.create(scheme + "://" + hostname + ":" + port);
        this.configServerURIs = configServerHostNames.stream()
                .map(configServerHostnameToUriMapper)
                .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
    }

    private static URI createLoadBalancerEndpoint(String loadBalancerHost, String scheme, int port) {
        return URI.create(scheme + "://" + loadBalancerHost + ":" + port);
    }

    public List<String> getConfigServerHostNames() {
        return configServerHostNames;
    }

    public List<URI> getConfigServerUris() {
        return configServerURIs;
    }

    public URI getConfigServerUri(String hostname) {
        return configServerHostnameToUriMapper.apply(hostname);
    }

    public URI getLoadBalancerEndpoint() {
        return loadBalancerEndpoint;
    }

    public AthenzService getConfigServerIdentity() {
        return configServerIdentity;
    }
}

@@ -508,62 +508,8 @@
 o %7B%0A
-    private final List%3CString%3E configServerHostNames;%0A
     
@@ -916,68 +916,8 @@
 ) %7B%0A
-        this.configServerHostNames = configServerHostNames;%0A
     
@@ -1607,106 +1607,8 @@
  %7D%0A%0A
-    public List%3CString%3E getConfigServerHostNames() %7B%0A        return configServerHostNames;%0A    %7D%0A%0A
     

Revert "Revert "Remove unused method and variable from ConfigServerInfo""