aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerSpec.java
blob: dc3170c7e835e46d3703b4cd305d113f978ecaf2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;

import com.yahoo.cloud.config.ConfigserverConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tony Vaagenes
 */
public class ConfigServerSpec implements com.yahoo.config.model.api.ConfigServerSpec {

    private final String hostName;
    private final int configServerPort;
    private final int zooKeeperPort;

    public String getHostName() {
        return hostName;
    }

    public int getConfigServerPort() {
        return configServerPort;
    }

    public int getZooKeeperPort() {
        return zooKeeperPort;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof ConfigServerSpec) {
            ConfigServerSpec other = (ConfigServerSpec)o;

            return hostName.equals(other.hostName) &&
                    configServerPort == other.configServerPort &&
                    zooKeeperPort == other.zooKeeperPort;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return hostName.hashCode();
    }

    public ConfigServerSpec(String hostName, int configServerPort, int zooKeeperPort) {
        this.hostName = hostName;
        this.configServerPort = configServerPort;
        this.zooKeeperPort = zooKeeperPort;
    }

    public static List<com.yahoo.config.model.api.ConfigServerSpec> fromConfig(ConfigserverConfig configserverConfig) {
        List<com.yahoo.config.model.api.ConfigServerSpec> specs = new ArrayList<>();
        for (ConfigserverConfig.Zookeeperserver server : configserverConfig.zookeeperserver()) {
            specs.add(new ConfigServerSpec(server.hostname(), configserverConfig.rpcport(), server.port()));
        }
        return specs;
    }

    @Override
    public String toString() {
        return "hostname=" + hostName + ", rpc port=" + configServerPort + ", zookeeper port=" + zooKeeperPort;
    }

}