Madan Jampani
Committed by Gerrit Code Review

Use similar return types for LeadershipService.getCandidates() and LeadershipSer…

…vice.getCandidates(topic)

Change-Id: I9aaea9dfa14e4e9916103a61c8e59290ad656aa7
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 package org.onosproject.cli.net; 16 package org.onosproject.cli.net;
17 17
18 import java.util.Comparator; 18 import java.util.Comparator;
19 -import java.util.Map;
20 import java.util.List; 19 import java.util.List;
20 +import java.util.Map;
21 import java.util.regex.Pattern; 21 import java.util.regex.Pattern;
22 22
23 import org.apache.karaf.shell.commands.Argument; 23 import org.apache.karaf.shell.commands.Argument;
...@@ -94,7 +94,7 @@ public class LeaderCommand extends AbstractShellCommand { ...@@ -94,7 +94,7 @@ public class LeaderCommand extends AbstractShellCommand {
94 } 94 }
95 95
96 private void displayCandidates(Map<String, Leadership> leaderBoard, 96 private void displayCandidates(Map<String, Leadership> leaderBoard,
97 - Map<String, Leadership> candidates) { 97 + Map<String, List<NodeId>> candidates) {
98 print("--------------------------------------------------------------"); 98 print("--------------------------------------------------------------");
99 print(FMT_C, "Topic", "Leader", "Candidates"); 99 print(FMT_C, "Topic", "Leader", "Candidates");
100 print("--------------------------------------------------------------"); 100 print("--------------------------------------------------------------");
...@@ -104,7 +104,7 @@ public class LeaderCommand extends AbstractShellCommand { ...@@ -104,7 +104,7 @@ public class LeaderCommand extends AbstractShellCommand {
104 .filter(l -> allTopics || pattern.matcher(l.topic()).matches()) 104 .filter(l -> allTopics || pattern.matcher(l.topic()).matches())
105 .sorted(leadershipComparator) 105 .sorted(leadershipComparator)
106 .forEach(l -> { 106 .forEach(l -> {
107 - List<NodeId> list = candidates.get(l.topic()).candidates(); 107 + List<NodeId> list = candidates.get(l.topic());
108 print(FMT_C, 108 print(FMT_C,
109 l.topic(), 109 l.topic(),
110 l.leader(), 110 l.leader(),
...@@ -156,7 +156,7 @@ public class LeaderCommand extends AbstractShellCommand { ...@@ -156,7 +156,7 @@ public class LeaderCommand extends AbstractShellCommand {
156 print("%s", json(leaderBoard)); 156 print("%s", json(leaderBoard));
157 } else { 157 } else {
158 if (showCandidates) { 158 if (showCandidates) {
159 - Map<String, Leadership> candidates = leaderService.getCandidates(); 159 + Map<String, List<NodeId>> candidates = leaderService.getCandidates();
160 displayCandidates(leaderBoard, candidates); 160 displayCandidates(leaderBoard, candidates);
161 } else { 161 } else {
162 displayLeaders(leaderBoard); 162 displayLeaders(leaderBoard);
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
15 */ 15 */
16 package org.onosproject.cluster; 16 package org.onosproject.cluster;
17 17
18 +import java.util.List;
18 import java.util.Map; 19 import java.util.Map;
19 import java.util.Set; 20 import java.util.Set;
20 -import java.util.List;
21 21
22 /** 22 /**
23 * Service for leader election. 23 * Service for leader election.
...@@ -76,9 +76,9 @@ public interface LeadershipService { ...@@ -76,9 +76,9 @@ public interface LeadershipService {
76 /** 76 /**
77 * Returns the candidates for all known topics. 77 * Returns the candidates for all known topics.
78 * 78 *
79 - * @return A mapping from topics to up-to-date candidate info. 79 + * @return A mapping from topics to corresponding list of candidates.
80 */ 80 */
81 - Map<String, Leadership> getCandidates(); 81 + Map<String, List<NodeId>> getCandidates();
82 82
83 /** 83 /**
84 * Returns the candidates for a given topic. 84 * Returns the candidates for a given topic.
......
...@@ -65,7 +65,7 @@ public class LeadershipServiceAdapter implements LeadershipService { ...@@ -65,7 +65,7 @@ public class LeadershipServiceAdapter implements LeadershipService {
65 } 65 }
66 66
67 @Override 67 @Override
68 - public Map<String, Leadership> getCandidates() { 68 + public Map<String, List<NodeId>> getCandidates() {
69 return null; 69 return null;
70 } 70 }
71 71
......
...@@ -576,7 +576,7 @@ public class HazelcastLeadershipService implements LeadershipService { ...@@ -576,7 +576,7 @@ public class HazelcastLeadershipService implements LeadershipService {
576 } 576 }
577 577
578 @Override 578 @Override
579 - public Map<String, Leadership> getCandidates() { 579 + public Map<String, List<NodeId>> getCandidates() {
580 return null; 580 return null;
581 } 581 }
582 582
......
...@@ -166,8 +166,8 @@ public class DistributedLeadershipManager implements LeadershipService { ...@@ -166,8 +166,8 @@ public class DistributedLeadershipManager implements LeadershipService {
166 } 166 }
167 167
168 @Override 168 @Override
169 - public Map<String, Leadership> getCandidates() { 169 + public Map<String, List<NodeId>> getCandidates() {
170 - return ImmutableMap.copyOf(candidateBoard); 170 + return Maps.toMap(candidateBoard.keySet(), this::getCandidates);
171 } 171 }
172 172
173 @Override 173 @Override
......
...@@ -111,7 +111,7 @@ public class SimpleLeadershipManager implements LeadershipService { ...@@ -111,7 +111,7 @@ public class SimpleLeadershipManager implements LeadershipService {
111 } 111 }
112 112
113 @Override 113 @Override
114 - public Map<String, Leadership> getCandidates() { 114 + public Map<String, List<NodeId>> getCandidates() {
115 return null; 115 return null;
116 } 116 }
117 117
......