blob: 45b96ab2b34ee4c9be3c58406ad232d7bc2c7c66 [file] [log] [blame]
Ayaka Koshibeabedb092014-10-20 17:01:31 -07001package org.onlab.onos.cluster;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07002
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07003import java.util.List;
4import java.util.Objects;
5
Yuta HIGUCHI40d01772014-10-21 00:08:44 -07006import com.google.common.collect.ImmutableList;
7
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07008/**
9 * A container for detailed role information for a device,
10 * within the current cluster. Role attributes include current
11 * master and a preference-ordered list of backup nodes.
12 */
13public class RoleInfo {
14 private final NodeId master;
15 private final List<NodeId> backups;
16
17 public RoleInfo(NodeId master, List<NodeId> backups) {
18 this.master = master;
Yuta HIGUCHI40d01772014-10-21 00:08:44 -070019 this.backups = ImmutableList.copyOf(backups);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070020 }
21
22 public NodeId master() {
23 return master;
24 }
25
26 public List<NodeId> backups() {
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070027 return backups;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070028 }
29
30 @Override
31 public boolean equals(Object other) {
32 if (other == null) {
33 return false;
34 }
35 if (!(other instanceof RoleInfo)) {
36 return false;
37 }
38 RoleInfo that = (RoleInfo) other;
39 if (!Objects.equals(this.master, that.master)) {
40 return false;
41 }
42 if (!Objects.equals(this.backups, that.backups)) {
43 return false;
44 }
45 return true;
46 }
47
48 @Override
49 public int hashCode() {
50 return Objects.hash(master, backups.hashCode());
51 }
52
53 @Override
54 public String toString() {
55 final StringBuilder builder = new StringBuilder();
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070056 builder.append("master:").append(master).append(",");
57 builder.append("backups:");
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070058 for (NodeId n : backups) {
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070059 builder.append(" ").append(n);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070060 }
61 return builder.toString();
62 }
63}