use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class KubernetesTestFixture method createLeaderConfigMap.
// This method need be called when before the leader is granted. Since the
// TestingKubernetesLeaderElector
// will not create the leader ConfigMap automatically.
private void createLeaderConfigMap() {
final KubernetesConfigMap configMap = new TestingFlinkKubeClient.MockKubernetesConfigMap(leaderConfigmapName);
configMap.getAnnotations().put(LEADER_ANNOTATION_KEY, lockIdentity);
flinkKubeClient.createConfigMap(configMap);
}
use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class Fabric8FlinkKubeClientTest method testCreateConfigMapAlreadyExisting.
@Test
public void testCreateConfigMapAlreadyExisting() throws Exception {
final KubernetesConfigMap configMap = buildTestingConfigMap();
this.flinkKubeClient.createConfigMap(configMap).get();
mockCreateConfigMapAlreadyExisting(configMap.getInternalResource());
configMap.getData().put(TESTING_CONFIG_MAP_KEY, TESTING_CONFIG_MAP_NEW_VALUE);
try {
this.flinkKubeClient.createConfigMap(configMap).get();
fail("Overwrite an already existing config map should fail with an exception.");
} catch (Exception ex) {
final String errorMsg = "Failed to create ConfigMap " + TESTING_CONFIG_MAP_NAME;
assertThat(ex, FlinkMatchers.containsMessage(errorMsg));
}
// Create failed we should still get the old value
final Optional<KubernetesConfigMap> currentOpt = this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME);
assertThat(currentOpt.isPresent(), is(true));
assertThat(currentOpt.get().getData().get(TESTING_CONFIG_MAP_KEY), is(TESTING_CONFIG_MAP_VALUE));
}
use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class Fabric8FlinkKubeClientTest method testCheckAndUpdateConfigMapWhenGetConfigMapFailed.
@Test
public void testCheckAndUpdateConfigMapWhenGetConfigMapFailed() throws Exception {
final int configuredRetries = flinkConfig.getInteger(KubernetesConfigOptions.KUBERNETES_TRANSACTIONAL_OPERATION_MAX_RETRIES);
final KubernetesConfigMap configMap = buildTestingConfigMap();
this.flinkKubeClient.createConfigMap(configMap).get();
mockGetConfigMapFailed(configMap.getInternalResource());
final int initialRequestCount = server.getRequestCount();
try {
this.flinkKubeClient.checkAndUpdateConfigMap(TESTING_CONFIG_MAP_NAME, c -> {
throw new AssertionError("The replace operation should have never been triggered.");
}).get();
fail("checkAndUpdateConfigMap should fail without a PossibleInconsistentStateException being the cause when number of retries has been exhausted.");
} catch (Exception ex) {
assertThat(ex, FlinkMatchers.containsMessage("Could not complete the " + "operation. Number of retries has been exhausted."));
final int actualRetryCount = server.getRequestCount() - initialRequestCount;
assertThat(actualRetryCount, is(configuredRetries + 1));
assertThat("An error while retrieving the ConfigMap should not cause a PossibleInconsistentStateException.", ExceptionUtils.findThrowable(ex, PossibleInconsistentStateException.class).isPresent(), is(false));
}
}
use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class KubernetesHaServicesTest method testInternalJobCleanupShouldCleanupConfigMaps.
@Test
public void testInternalJobCleanupShouldCleanupConfigMaps() throws Exception {
new Context() {
{
runTest(() -> {
final KubernetesHaServices kubernetesHaServices = new KubernetesHaServices(flinkKubeClient, executorService, configuration, new VoidBlobStore());
JobID jobID = new JobID();
String configMapName = kubernetesHaServices.getLeaderPathForJobManager(jobID);
final KubernetesConfigMap configMap = new TestingFlinkKubeClient.MockKubernetesConfigMap(configMapName);
flinkKubeClient.createConfigMap(configMap);
assertThat(flinkKubeClient.getConfigMap(configMapName).isPresent(), is(true));
kubernetesHaServices.internalCleanupJobData(jobID);
assertThat(flinkKubeClient.getConfigMap(configMapName).isPresent(), is(false));
});
}
};
}
use of org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap in project flink by apache.
the class KubernetesStateHandleStore method getAndLock.
/**
* Gets the {@link RetrievableStateHandle} stored in the given ConfigMap.
*
* @param key Key in ConfigMap
* @return The retrieved state handle from the specified ConfigMap and key
* @throws IOException if the method failed to deserialize the stored state handle
* @throws NotExistException when the name does not exist
* @throws Exception if get state handle from ConfigMap failed
*/
@Override
public RetrievableStateHandle<T> getAndLock(String key) throws Exception {
checkNotNull(key, "Key in ConfigMap.");
final Optional<KubernetesConfigMap> optional = kubeClient.getConfigMap(configMapName);
if (optional.isPresent()) {
final KubernetesConfigMap configMap = optional.get();
if (configMap.getData().containsKey(key)) {
return deserializeObject(configMap.getData().get(key));
} else {
throw getKeyNotExistException(key);
}
} else {
throw getConfigMapNotExistException();
}
}
Aggregations