Mark couple of expensive LeadershipService methods as deprecated

Change-Id: Iff9207a917de5855153f641ddabe1afba0178d53
diff --git a/core/api/src/main/java/org/onosproject/cluster/LeadershipService.java b/core/api/src/main/java/org/onosproject/cluster/LeadershipService.java
index 95fe723..560b7b6 100644
--- a/core/api/src/main/java/org/onosproject/cluster/LeadershipService.java
+++ b/core/api/src/main/java/org/onosproject/cluster/LeadershipService.java
@@ -89,14 +89,18 @@
      * Returns the current leader board.
      *
      * @return mapping from topic to leadership info.
+     * @deprecated 1.6.0 Goldeneye release. Replace usages with {@link #getLeadership(String)}
      */
+    @Deprecated
     Map<String, Leadership> getLeaderBoard();
 
     /**
      * Returns the candidate nodes for each topic.
      *
      * @return A mapping from topics to corresponding list of candidates.
+     * @deprecated 1.6.0 Goldeneye release. Replace usages with {@link #getLeadership(String)}
      */
+    @Deprecated
     default Map<String, List<NodeId>> getCandidates() {
         return ImmutableMap.copyOf(Maps.transformValues(getLeaderBoard(), v -> ImmutableList.copyOf(v.candidates())));
     }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java
index 1db6534..0ac9647 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java
@@ -43,6 +43,7 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /**
  * Manages the assignment of intent keyspace partitions to instances.
@@ -135,7 +136,8 @@
 
     @Override
     public boolean isMine(Key intentKey) {
-        return Objects.equals(leadershipService.getLeader(getPartitionPath(getPartitionForKey(intentKey))),
+        return Objects.equals(leadershipService.getLeadership(getPartitionPath(getPartitionForKey(intentKey)))
+                                               .leaderNodeId(),
                               localNodeId);
     }
 
@@ -177,24 +179,20 @@
 
         int myShare = (int) Math.ceil((double) NUM_PARTITIONS / activeNodes);
 
-        List<Leadership> myPartitions = leadershipService.getLeaderBoard().values()
-                .stream()
-                .filter(l -> localNodeId.equals(l.leaderNodeId()))
-                .filter(l -> l.topic().startsWith(ELECTION_PREFIX))
-                .collect(Collectors.toList());
+        List<String> myPartitions = IntStream.range(0, NUM_PARTITIONS)
+                                             .mapToObj(this::getPartitionPath)
+                                             .map(leadershipService::getLeadership)
+                                             .filter(Objects::nonNull)
+                                             .filter(leadership -> localNodeId.equals(leadership.leaderNodeId()))
+                                             .map(Leadership::topic)
+                                             .collect(Collectors.toList());
 
         int relinquish = myPartitions.size() - myShare;
 
-        if (relinquish <= 0) {
-            return;
-        }
-
         for (int i = 0; i < relinquish; i++) {
-            String topic = myPartitions.get(i).topic();
+            String topic = myPartitions.get(i);
             leadershipService.withdraw(topic);
-
-            executor.schedule(() -> recontest(topic),
-                              BACKOFF_TIME, TimeUnit.SECONDS);
+            executor.schedule(() -> recontest(topic), BACKOFF_TIME, TimeUnit.SECONDS);
         }
     }
 
diff --git a/core/store/dist/src/test/java/org/onosproject/store/intent/impl/IntentPartitionManagerTest.java b/core/store/dist/src/test/java/org/onosproject/store/intent/impl/IntentPartitionManagerTest.java
index 2ecd78d..89ee8d3 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/intent/impl/IntentPartitionManagerTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/intent/impl/IntentPartitionManagerTest.java
@@ -33,11 +33,11 @@
 import org.onosproject.net.intent.Key;
 
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Map;
+import java.util.List;
 import java.util.Objects;
 import java.util.Set;
+
 import static junit.framework.TestCase.assertFalse;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.anyString;
@@ -100,29 +100,22 @@
      * @param numMine number of partitions that should be owned by the local node
      */
     private void setUpLeadershipService(int numMine) {
-
-        Map<String, Leadership> leaderBoard = new HashMap<>();
-
+        List<NodeId> allNodes = Arrays.asList(MY_NODE_ID, OTHER_NODE_ID);
         for (int i = 0; i < numMine; i++) {
-            expect(leadershipService.getLeader(ELECTION_PREFIX + i))
-                    .andReturn(MY_NODE_ID).anyTimes();
-            leaderBoard.put(ELECTION_PREFIX + i,
-                            new Leadership(ELECTION_PREFIX + i,
-                                    new Leader(MY_NODE_ID, 0, 0),
-                                    Arrays.asList(MY_NODE_ID)));
+            expect(leadershipService.getLeadership(ELECTION_PREFIX + i))
+                                    .andReturn(new Leadership(ELECTION_PREFIX + i,
+                                                              new Leader(MY_NODE_ID, 1, 1000),
+                                                              allNodes))
+                                    .anyTimes();
         }
 
         for (int i = numMine; i < IntentPartitionManager.NUM_PARTITIONS; i++) {
-            expect(leadershipService.getLeader(ELECTION_PREFIX + i))
-                    .andReturn(OTHER_NODE_ID).anyTimes();
-
-            leaderBoard.put(ELECTION_PREFIX + i,
-                            new Leadership(ELECTION_PREFIX + i,
-                                    new Leader(OTHER_NODE_ID, 0, 0),
-                                    Arrays.asList(OTHER_NODE_ID)));
+            expect(leadershipService.getLeadership(ELECTION_PREFIX + i))
+                                    .andReturn(new Leadership(ELECTION_PREFIX + i,
+                                                              new Leader(OTHER_NODE_ID, 1, 1000),
+                                                              allNodes))
+                                    .anyTimes();
         }
-
-        expect(leadershipService.getLeaderBoard()).andReturn(leaderBoard).anyTimes();
     }
 
     /**