private boolean tryUpdateController(HelixManager manager)
{
// DataAccessor dataAccessor = manager.getDataAccessor();
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = new LiveInstance(manager.getInstanceName());
try
{
leader.setLiveInstance(ManagementFactory.getRuntimeMXBean().getName());
// TODO: this session id is not the leader's session id in distributed mode
leader.setSessionId(manager.getSessionId());
leader.setHelixVersion(manager.getVersion());
if(ZKPropertyTransferServer.getInstance() != null)
{
String zkPropertyTransferServiceUrl = ZKPropertyTransferServer.getInstance().getWebserviceUrl();
if(zkPropertyTransferServiceUrl != null)
{
leader.setWebserviceUrl(zkPropertyTransferServiceUrl);
}
}
else
{
LOG.warn("ZKPropertyTransferServer instnace is null");
}
boolean success = accessor.createProperty(keyBuilder.controllerLeader(), leader);
if (success)
{
return true;
}
else
{
LOG.info("Unable to become leader probably because some other controller becames the leader");
}
}
catch (Exception e)
{
LOG.error("Exception when trying to updating leader record in cluster:"
+ manager.getClusterName()
+ ". Need to check again whether leader node has been created or not",
e);
}
leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader != null)
{
String leaderName = leader.getInstanceName(); // leader.getLeader();
LOG.info("Leader exists for cluster:" + manager.getClusterName()
+ ", currentLeader:" + leaderName);