use of org.apache.flink.kubernetes.utils.Constants.LEADER_ADDRESS_KEY in project flink by apache.
the class KubernetesLeaderElectionDriver method writeLeaderInformation.
@Override
public void writeLeaderInformation(LeaderInformation leaderInformation) {
assert (running);
final UUID confirmedLeaderSessionID = leaderInformation.getLeaderSessionID();
final String confirmedLeaderAddress = leaderInformation.getLeaderAddress();
try {
kubeClient.checkAndUpdateConfigMap(configMapName, configMap -> {
if (KubernetesLeaderElector.hasLeadership(configMap, lockIdentity)) {
// Get the updated ConfigMap with new leader information
if (confirmedLeaderAddress == null) {
configMap.getData().remove(LEADER_ADDRESS_KEY);
} else {
configMap.getData().put(LEADER_ADDRESS_KEY, confirmedLeaderAddress);
}
if (confirmedLeaderSessionID == null) {
configMap.getData().remove(LEADER_SESSION_ID_KEY);
} else {
configMap.getData().put(LEADER_SESSION_ID_KEY, confirmedLeaderSessionID.toString());
}
configMap.getLabels().putAll(configMapLabels);
return Optional.of(configMap);
}
return Optional.empty();
}).get();
if (LOG.isDebugEnabled()) {
LOG.debug("Successfully wrote leader information: Leader={}, session ID={}.", confirmedLeaderAddress, confirmedLeaderSessionID);
}
} catch (Exception e) {
fatalErrorHandler.onFatalError(new KubernetesException("Could not write leader information since ConfigMap " + configMapName + " does not exist.", e));
}
}
Aggregations