aboutsummaryrefslogtreecommitdiffstats
path: root/application-model/src/main/java/com/yahoo/vespa/applicationmodel/ClusterId.java
blob: 9ccd3e4d706f44da7b7f0b2061b0de90ed87d89f (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.applicationmodel;

import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Objects;

/**
 * @author bjorncs
 */
public class ClusterId {

    public static final ClusterId CONFIG_SERVER = new ClusterId(InfrastructureApplication.CONFIG_SERVER.applicationName());
    public static final ClusterId CONTROLLER = new ClusterId(InfrastructureApplication.CONTROLLER.applicationName());
    public static final ClusterId CONFIG_SERVER_HOST = new ClusterId(InfrastructureApplication.CONFIG_SERVER_HOST.applicationName());
    public static final ClusterId CONTROLLER_HOST = new ClusterId(InfrastructureApplication.CONTROLLER_HOST.applicationName());
    public static final ClusterId PROXY_HOST = new ClusterId(InfrastructureApplication.PROXY_HOST.applicationName());
    public static final ClusterId ROUTING = new ClusterId(InfrastructureApplication.PROXY.applicationName());
    public static final ClusterId TENANT_HOST = new ClusterId(InfrastructureApplication.TENANT_HOST.applicationName());

    private final String id;

    public ClusterId(String id) {
        this.id = id;
    }

    // Jackson's StdKeySerializer uses toString() (and ignores annotations) for objects used as Map keys.
    // Therefore, we use toString() as the JSON-producing method, which is really sad.
    @JsonValue
    @Override
    public String toString() {
        return id;
    }

    // For compatibility with original Scala case class
    public String s() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ClusterId clusterId = (ClusterId) o;
        return Objects.equals(id, clusterId.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

}