Simpler Leadership equality check + Use getLeader in place of getLeadership when appropriate
Change-Id: I527353feb18a8a7cd8e4a58cc1fb4f6954a27913
diff --git a/core/api/src/main/java/org/onosproject/cluster/Leadership.java b/core/api/src/main/java/org/onosproject/cluster/Leadership.java
index c0e0b80..44a05a6 100644
--- a/core/api/src/main/java/org/onosproject/cluster/Leadership.java
+++ b/core/api/src/main/java/org/onosproject/cluster/Leadership.java
@@ -143,10 +143,7 @@
if (obj instanceof Leadership) {
final Leadership other = (Leadership) obj;
return Objects.equals(this.topic, other.topic) &&
- Objects.equals(this.leader, other.leader) &&
- Objects.equals(this.candidates, other.candidates) &&
- Objects.equals(this.epoch, other.epoch) &&
- Objects.equals(this.electedTime, other.electedTime);
+ Objects.equals(this.epoch, other.epoch);
}
return false;
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/mastership/impl/ConsistentDeviceMastershipStore.java b/core/store/dist/src/main/java/org/onosproject/store/mastership/impl/ConsistentDeviceMastershipStore.java
index a791a7c..3d852b1 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/mastership/impl/ConsistentDeviceMastershipStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/mastership/impl/ConsistentDeviceMastershipStore.java
@@ -166,8 +166,8 @@
? MastershipRole.MASTER : MastershipRole.STANDBY;
});
} else {
- Leadership leadership = leadershipService.getLeadership(leadershipTopic);
- if (leadership != null && leadership.leader().equals(localNodeId)) {
+ NodeId leader = leadershipService.getLeader(leadershipTopic);
+ if (Objects.equal(localNodeId, leader)) {
return CompletableFuture.completedFuture(MastershipRole.MASTER);
} else {
return CompletableFuture.completedFuture(MastershipRole.STANDBY);
@@ -181,8 +181,8 @@
checkArgument(deviceId != null, DEVICE_ID_NULL);
String leadershipTopic = createDeviceMastershipTopic(deviceId);
- Leadership leadership = leadershipService.getLeadership(leadershipTopic);
- if (leadership != null && nodeId.equals(leadership.leader())) {
+ NodeId leader = leadershipService.getLeader(leadershipTopic);
+ if (Objects.equal(localNodeId, leader)) {
return MastershipRole.MASTER;
}
return leadershipService.getCandidates(leadershipTopic).contains(nodeId) ?
@@ -194,8 +194,7 @@
checkArgument(deviceId != null, DEVICE_ID_NULL);
String leadershipTopic = createDeviceMastershipTopic(deviceId);
- Leadership leadership = leadershipService.getLeadership(leadershipTopic);
- return leadership != null ? leadership.leader() : null;
+ return leadershipService.getLeader(leadershipTopic);
}
@Override