summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/admin/Configserver.java
blob: a2839ec0fb60864af00bd398e74e053207fb58f6 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.admin;

import com.yahoo.config.model.api.ConfigServerSpec;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.model.AbstractService;

/**
 * Represents a Configserver. There may be one or more Configservers in a
 * Vespa system.
 *
 * NOTE: The Configserver is not started by the config system, and
 * does not receive any config. It's included here so we know what host
 * it runs on, and to give an error message if another service tries
 * to reserve the ports it is using.
 *
 * @author  gjoranv
 */
public class Configserver extends AbstractService {
    private static final long serialVersionUID = 1L;
    public static final int defaultRpcPort = 19070;

    private final int rpcPort;

    public Configserver(AbstractConfigProducer parent, String name, int rpcPort) {
        super(parent, name);
        this.rpcPort = rpcPort;
        portsMeta.on(0).tag("rpc").tag("config");
        portsMeta.on(1).tag("http").tag("config").tag("state");
        setProp("clustertype", "admin");
        setProp("clustername", "admin");
    }

    /**
     * Returns the desired base port for this service.
     */
    public int getWantedPort() {
        return rpcPort;
    }

    /**
     * The desired base port is the only allowed base port.
     * @return 'true' always
     */
    public boolean requiresWantedPort() {
        return getId() < 2;
    }

     /**
     * @return the number of ports needed by the configserver.
     */
    public int getPortCount() { return 2; }

    @Override
    public String[] getPortSuffixes() {
        return new String[]{ "rpc", "http" };
    }

    /**
     * The configserver is not started by the config system!
     */
    public boolean getAutostartFlag()   { return false; }

    /**
     * The configserver is not started by the config system!
     */
    public boolean getAutorestartFlag() { return false; }

    private int getConfigServerRpcPort() {
        return getRelativePort(0);
    }

    private int getConfigServerHttpPort() {
        return getRelativePort(1);
    }

    ConfigServerSpec getConfigServerSpec() {
        return new Spec(getHostName(), getConfigServerRpcPort(), getConfigServerHttpPort(), ZooKeepersConfigProvider.zkPort);
    }

    @Override
    public int getHealthPort()  {
        return getRelativePort(1);
    }

    // TODO: Remove this implementation when we are on Hosted Vespa.
    public static class Spec implements ConfigServerSpec {

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

        public String getHostName() {
            return hostName;
        }

        public int getConfigServerPort() {
            return configServerPort;
        }

        public int getHttpPort() {
            return httpPort;
        }

        public int getZooKeeperPort() {
            return zooKeeperPort;
        }

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

                return hostName.equals(other.getHostName()) &&
                        configServerPort == other.getConfigServerPort() &&
                        httpPort == other.getHttpPort() &&
                        zooKeeperPort == other.getZooKeeperPort();
            } else {
                return false;
            }
        }

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

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

}