Search in sources :

Example 1 with LEADER_ADDRESS_KEY

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));
    }
}
Also used : LEADER_ADDRESS_KEY(org.apache.flink.kubernetes.utils.Constants.LEADER_ADDRESS_KEY) LABEL_CONFIGMAP_TYPE_HIGH_AVAILABILITY(org.apache.flink.kubernetes.utils.Constants.LABEL_CONFIGMAP_TYPE_HIGH_AVAILABILITY) KubernetesConfigMapSharedWatcher(org.apache.flink.kubernetes.kubeclient.KubernetesConfigMapSharedWatcher) LoggerFactory(org.slf4j.LoggerFactory) KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) KubernetesLeaderElectionConfiguration(org.apache.flink.kubernetes.configuration.KubernetesLeaderElectionConfiguration) Map(java.util.Map) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) KubernetesUtils.checkConfigMaps(org.apache.flink.kubernetes.utils.KubernetesUtils.checkConfigMaps) LeaderElectionEventHandler(org.apache.flink.runtime.leaderelection.LeaderElectionEventHandler) LeaderElectionException(org.apache.flink.runtime.leaderelection.LeaderElectionException) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) ExecutorService(java.util.concurrent.ExecutorService) KubernetesUtils(org.apache.flink.kubernetes.utils.KubernetesUtils) Logger(org.slf4j.Logger) KubernetesUtils.getLeaderInformationFromConfigMap(org.apache.flink.kubernetes.utils.KubernetesUtils.getLeaderInformationFromConfigMap) LeaderElectionDriver(org.apache.flink.runtime.leaderelection.LeaderElectionDriver) UUID(java.util.UUID) LeaderInformation(org.apache.flink.runtime.leaderelection.LeaderInformation) Watch(org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch) List(java.util.List) KubernetesException(org.apache.flink.kubernetes.kubeclient.resources.KubernetesException) Optional(java.util.Optional) LEADER_SESSION_ID_KEY(org.apache.flink.kubernetes.utils.Constants.LEADER_SESSION_ID_KEY) KubernetesLeaderElector(org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) UUID(java.util.UUID) LeaderElectionException(org.apache.flink.runtime.leaderelection.LeaderElectionException) KubernetesException(org.apache.flink.kubernetes.kubeclient.resources.KubernetesException) KubernetesException(org.apache.flink.kubernetes.kubeclient.resources.KubernetesException)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 ExecutorService (java.util.concurrent.ExecutorService)1 KubernetesLeaderElectionConfiguration (org.apache.flink.kubernetes.configuration.KubernetesLeaderElectionConfiguration)1 FlinkKubeClient (org.apache.flink.kubernetes.kubeclient.FlinkKubeClient)1 KubernetesConfigMapSharedWatcher (org.apache.flink.kubernetes.kubeclient.KubernetesConfigMapSharedWatcher)1 Watch (org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch)1 KubernetesConfigMap (org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap)1 KubernetesException (org.apache.flink.kubernetes.kubeclient.resources.KubernetesException)1 KubernetesLeaderElector (org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector)1 LABEL_CONFIGMAP_TYPE_HIGH_AVAILABILITY (org.apache.flink.kubernetes.utils.Constants.LABEL_CONFIGMAP_TYPE_HIGH_AVAILABILITY)1 LEADER_ADDRESS_KEY (org.apache.flink.kubernetes.utils.Constants.LEADER_ADDRESS_KEY)1 LEADER_SESSION_ID_KEY (org.apache.flink.kubernetes.utils.Constants.LEADER_SESSION_ID_KEY)1 KubernetesUtils (org.apache.flink.kubernetes.utils.KubernetesUtils)1 KubernetesUtils.checkConfigMaps (org.apache.flink.kubernetes.utils.KubernetesUtils.checkConfigMaps)1 KubernetesUtils.getLeaderInformationFromConfigMap (org.apache.flink.kubernetes.utils.KubernetesUtils.getLeaderInformationFromConfigMap)1 LeaderElectionDriver (org.apache.flink.runtime.leaderelection.LeaderElectionDriver)1 LeaderElectionEventHandler (org.apache.flink.runtime.leaderelection.LeaderElectionEventHandler)1