use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class KubernetesLeaderElectionDriverTest method testLeaderConfigMapModifiedExternallyShouldBeCorrected.
@Test
public void testLeaderConfigMapModifiedExternallyShouldBeCorrected() throws Exception {
new Context() {
{
runTest(() -> {
leaderCallbackGrantLeadership();
final FlinkKubeClient.WatchCallbackHandler<KubernetesConfigMap> callbackHandler = getLeaderElectionConfigMapCallback();
// Update ConfigMap with wrong data
final KubernetesConfigMap updatedConfigMap = getLeaderConfigMap();
final UUID leaderSessionId = UUID.fromString(updatedConfigMap.getData().get(LEADER_SESSION_ID_KEY));
final LeaderInformation faultyLeader = LeaderInformation.known(UUID.randomUUID(), "faultyLeaderAddress");
updatedConfigMap.getData().put(LEADER_ADDRESS_KEY, faultyLeader.getLeaderAddress());
updatedConfigMap.getData().put(LEADER_SESSION_ID_KEY, faultyLeader.getLeaderSessionID().toString());
callbackHandler.onModified(Collections.singletonList(updatedConfigMap));
// The leader should be corrected
assertThat(getLeaderConfigMap().getData().get(LEADER_ADDRESS_KEY), is(LEADER_ADDRESS));
assertThat(getLeaderConfigMap().getData().get(LEADER_SESSION_ID_KEY), is(leaderSessionId.toString()));
});
}
};
}
use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class Fabric8FlinkKubeClient method attemptCheckAndUpdateConfigMap.
private CompletableFuture<Boolean> attemptCheckAndUpdateConfigMap(String configMapName, Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> updateFunction) {
return CompletableFuture.supplyAsync(() -> {
final KubernetesConfigMap configMap = getConfigMap(configMapName).orElseThrow(() -> new CompletionException(new KubernetesException("Cannot retry checkAndUpdateConfigMap with configMap " + configMapName + " because it does not exist.")));
final Optional<KubernetesConfigMap> maybeUpdate = updateFunction.apply(configMap);
if (maybeUpdate.isPresent()) {
try {
internalClient.configMaps().withName(configMapName).lockResourceVersion(maybeUpdate.get().getResourceVersion()).replace(maybeUpdate.get().getInternalResource());
return true;
} catch (Throwable throwable) {
LOG.debug("Failed to update ConfigMap {} with data {}. Trying again.", configMap.getName(), configMap.getData());
// handling here
throw new CompletionException(new PossibleInconsistentStateException(throwable));
}
}
return false;
}, kubeClientExecutorService);
}
use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class KubernetesMultipleComponentLeaderElectionDriver method hasLeadership.
@Override
public boolean hasLeadership() {
Preconditions.checkState(running.get());
final Optional<KubernetesConfigMap> optionalConfigMap = kubeClient.getConfigMap(configMapName);
if (optionalConfigMap.isPresent()) {
return KubernetesLeaderElector.hasLeadership(optionalConfigMap.get(), lockIdentity);
} else {
fatalErrorHandler.onFatalError(new KubernetesException(String.format("ConfigMap %s does not exist. This indicates that somebody has interfered with Flink's operation.", configMapName)));
return false;
}
}
Aggregations