summaryrefslogtreecommitdiffstats
path: root/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/VespaUniqueInstanceId.java
blob: 5539ba53882e45da89df45c255074b6caf5b3a95 (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
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.identityprovider.api;

import java.util.Objects;

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

    private final int clusterIndex;
    private final String clusterId;
    private final String instance;
    private final String application;
    private final String tenant;
    private final String region;
    private final String environment;

    public VespaUniqueInstanceId(int clusterIndex,
                                 String clusterId,
                                 String instance,
                                 String application,
                                 String tenant,
                                 String region,
                                 String environment) {
        this.clusterIndex = clusterIndex;
        this.clusterId = clusterId;
        this.instance = instance;
        this.application = application;
        this.tenant = tenant;
        this.region = region;
        this.environment = environment;
    }

    public static VespaUniqueInstanceId fromDottedString(String instanceId) {
        String[] tokens = instanceId.split("\\.");
        if (tokens.length != 7) {
            throw new IllegalArgumentException("Invalid instance id: " + instanceId);
        }
        return new VespaUniqueInstanceId(
                Integer.parseInt(tokens[0]), tokens[1], tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
    }

    public String asDottedString() {
        return String.format(
                "%d.%s.%s.%s.%s.%s.%s",
                clusterIndex, clusterId, instance, application, tenant, region, environment);
    }

    public int clusterIndex() {
        return clusterIndex;
    }

    public String clusterId() {
        return clusterId;
    }

    public String instance() {
        return instance;
    }

    public String application() {
        return application;
    }

    public String tenant() {
        return tenant;
    }

    public String region() {
        return region;
    }

    public String environment() {
        return environment;
    }

    @Override
    public String toString() {
        return "VespaUniqueInstanceId{" +
                "clusterIndex=" + clusterIndex +
                ", clusterId='" + clusterId + '\'' +
                ", instance='" + instance + '\'' +
                ", application='" + application + '\'' +
                ", tenant='" + tenant + '\'' +
                ", region='" + region + '\'' +
                ", environment='" + environment + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        VespaUniqueInstanceId that = (VespaUniqueInstanceId) o;
        return clusterIndex == that.clusterIndex &&
                Objects.equals(clusterId, that.clusterId) &&
                Objects.equals(instance, that.instance) &&
                Objects.equals(application, that.application) &&
                Objects.equals(tenant, that.tenant) &&
                Objects.equals(region, that.region) &&
                Objects.equals(environment, that.environment);
    }

    @Override
    public int hashCode() {
        return Objects.hash(clusterIndex, clusterId, instance, application, tenant, region, environment);
    }
}