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
|
// 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;
/**
* Represents the unique instance id as used in Vespa's integration with Athenz Copper Argos
*
* @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;
private final IdentityType type;
public VespaUniqueInstanceId(int clusterIndex,
String clusterId,
String instance,
String application,
String tenant,
String region,
String environment,
IdentityType type) {
this.clusterIndex = clusterIndex;
this.clusterId = clusterId;
this.instance = instance;
this.application = application;
this.tenant = tenant;
this.region = region;
this.environment = environment;
this.type = type;
}
public static VespaUniqueInstanceId fromDottedString(String instanceId) {
String[] tokens = instanceId.split("\\.");
if (tokens.length != 8) {
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], IdentityType.fromId(tokens[7]));
}
public String asDottedString() {
return String.format(
"%d.%s.%s.%s.%s.%s.%s.%s",
clusterIndex, clusterId, instance, application, tenant, region, environment, type.id());
}
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;
}
public IdentityType type() { return type; }
@Override
public String toString() {
return "VespaUniqueInstanceId{" +
"clusterIndex=" + clusterIndex +
", clusterId='" + clusterId + '\'' +
", instance='" + instance + '\'' +
", application='" + application + '\'' +
", tenant='" + tenant + '\'' +
", region='" + region + '\'' +
", environment='" + environment + '\'' +
", type=" + type +
'}';
}
@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) &&
type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(clusterIndex, clusterId, instance, application, tenant, region, environment, type);
}
}
|