Ensure all active nodes are in contention before relinquishing a partition

Change-Id: I846f810547b286736d26d319f315048398334a83
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 3080143..2d09bcf 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
@@ -200,8 +200,12 @@
 
         for (int i = 0; i < relinquish; i++) {
             String topic = myPartitions.get(i);
-            leadershipService.withdraw(topic);
-            executor.schedule(() -> recontest(topic), BACKOFF_TIME, TimeUnit.SECONDS);
+            // Wait till all active nodes are in contention for partition ownership.
+            // This avoids too many relinquish/reclaim cycles.
+            if (leadershipService.getCandidates(topic).size() == activeNodes) {
+                leadershipService.withdraw(topic);
+                executor.schedule(() -> recontest(topic), BACKOFF_TIME, TimeUnit.SECONDS);
+            }
         }
     }