Mastership role is determined by whether the node is leader or merely a candidate for device mastership topic.

Change-Id: Ic2142aaa1ec0b215d2247596b934dbbfb0cedc25
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 6ff050c..292330c 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
@@ -90,8 +90,6 @@
     private NodeId localNodeId;
     private final Set<DeviceId> connectedDevices = Sets.newHashSet();
 
-    private static final MessageSubject ROLE_QUERY_SUBJECT =
-            new MessageSubject("mastership-store-device-role-query");
     private static final MessageSubject ROLE_RELINQUISH_SUBJECT =
             new MessageSubject("mastership-store-device-role-relinquish");
     private static final MessageSubject TRANSITION_FROM_MASTER_TO_STANDBY_SUBJECT =
@@ -129,11 +127,6 @@
         transferExecutor =
                 Executors.newSingleThreadScheduledExecutor(
                         groupedThreads("onos/store/device/mastership", "mastership-transfer-executor"));
-        clusterCommunicator.<DeviceId, MastershipRole>addSubscriber(ROLE_QUERY_SUBJECT,
-                SERIALIZER::decode,
-                deviceId -> getRole(localNodeId, deviceId),
-                SERIALIZER::encode,
-                messageHandlingExecutor);
         clusterCommunicator.<DeviceId, MastershipEvent>addSubscriber(ROLE_RELINQUISH_SUBJECT,
                 SERIALIZER::decode,
                 this::relinquishLocalRole,
@@ -152,7 +145,6 @@
 
     @Deactivate
     public void deactivate() {
-        clusterCommunicator.removeSubscriber(ROLE_QUERY_SUBJECT);
         clusterCommunicator.removeSubscriber(ROLE_RELINQUISH_SUBJECT);
         clusterCommunicator.removeSubscriber(TRANSITION_FROM_MASTER_TO_STANDBY_SUBJECT);
         messageHandlingExecutor.shutdown();
@@ -193,21 +185,8 @@
         if (leadership != null && nodeId.equals(leadership.leader())) {
             return MastershipRole.MASTER;
         }
-
-        if (localNodeId.equals(nodeId)) {
-            if (connectedDevices.contains(deviceId)) {
-                return MastershipRole.STANDBY;
-            } else {
-                return MastershipRole.NONE;
-            }
-        }
-        MastershipRole role = futureGetOrElse(clusterCommunicator.sendAndReceive(
-                deviceId,
-                ROLE_QUERY_SUBJECT,
-                SERIALIZER::encode,
-                SERIALIZER::decode,
-                nodeId), null);
-        return role == null ? MastershipRole.NONE : role;
+        return leadershipService.getCandidates(leadershipTopic).contains(nodeId) ?
+                MastershipRole.STANDBY : MastershipRole.NONE;
     }
 
     @Override