in src/main/java/org/apache/sling/discovery/oak/cluster/ClusterReader.java [84:104]
private String readLeaderElectionId(String slingId) {
if (slingId==null) {
throw new IllegalStateException("slingId must not be null");
}
final String myClusterNodePath = config.getClusterInstancesPath()+"/"+slingId;
// SLING-6924 case 1 : /var/discovery/oak/clusterInstances/<slingId> can be non existant == null
final Resource myClusterNode = resourceResolver.getResource(myClusterNodePath);
if (myClusterNode == null) {
// SLING-6924 : return null case 1
return null;
}
ValueMap resourceMap = myClusterNode.adaptTo(ValueMap.class);
// SLING-6924 case 2 : /var/discovery/oak/clusterInstances/<slingId> can exist BUT leaderElectionId not yet set
// namely the "leaderElectionId" is only written when resetLeaderElectionId() is called - which happens
// on OakViewChecker.activate (or when isolated) - and this activate *can* happen after properties
// or announcements have been written - those end up below /var/discovery/oak/clusterInstances/<slingId>/
String result = resourceMap.get("leaderElectionId", String.class);
// SLING-6924 : return null case 2 (if leaderElectionId is indeed null, that is)
return result;
}