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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.application;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.RegionName;
import com.yahoo.vespa.hosted.controller.rotation.RotationId;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Contains the tuple of [clusterId, endpointId, rotationId, regions[]], to keep track
* of which services have assigned which rotations under which name.
*
* @author ogronnesby
*/
public class AssignedRotation {
private final ClusterSpec.Id clusterId;
private final EndpointId endpointId;
private final RotationId rotationId;
private final Set<RegionName> regions;
public AssignedRotation(ClusterSpec.Id clusterId, EndpointId endpointId, RotationId rotationId, Set<RegionName> regions) {
this.clusterId = requireNonEmpty(clusterId, clusterId.value(), "clusterId");
this.endpointId = Objects.requireNonNull(endpointId);
this.rotationId = Objects.requireNonNull(rotationId);
this.regions = Set.copyOf(Objects.requireNonNull(regions));
}
public ClusterSpec.Id clusterId() { return clusterId; }
public EndpointId endpointId() { return endpointId; }
public RotationId rotationId() { return rotationId; }
public Set<RegionName> regions() { return regions; }
@Override
public String toString() {
return "AssignedRotation{" +
"clusterId=" + clusterId +
", endpointId='" + endpointId + '\'' +
", rotationId=" + rotationId +
", regions=" + regions +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AssignedRotation that = (AssignedRotation) o;
return clusterId.equals(that.clusterId) &&
endpointId.equals(that.endpointId) &&
rotationId.equals(that.rotationId) &&
regions.equals(that.regions);
}
@Override
public int hashCode() {
return Objects.hash(clusterId, endpointId, rotationId, regions);
}
private static <T> T requireNonEmpty(T object, String value, String field) {
Objects.requireNonNull(object);
Objects.requireNonNull(value);
if (value.isEmpty()) {
throw new IllegalArgumentException("Field '" + field + "' was empty");
}
return object;
}
/** Convenience method intended for tests */
public static AssignedRotation fromStrings(String clusterId, String endpointId, String rotationId, Collection<String> regions) {
return new AssignedRotation(
new ClusterSpec.Id(clusterId),
EndpointId.of(endpointId),
new RotationId(rotationId),
regions.stream().map(RegionName::from).collect(Collectors.toSet())
);
}
}
|