Search in sources :

Example 1 with KubernetesConfigMap

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);
}
Also used : KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap)

Example 2 with KubernetesConfigMap

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));
}
Also used : KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with KubernetesConfigMap

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));
    }
}
Also used : KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) Arrays(java.util.Arrays) KubernetesTestUtils(org.apache.flink.kubernetes.KubernetesTestUtils) ExceptionUtils(org.apache.flink.util.ExceptionUtils) KubernetesService(org.apache.flink.kubernetes.kubeclient.resources.KubernetesService) KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod) CONFIG_FILE_LOG4J_NAME(org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOG4J_NAME) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ExternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator) BlobServerOptions(org.apache.flink.configuration.BlobServerOptions) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) KubernetesClientTestBase(org.apache.flink.kubernetes.KubernetesClientTestBase) JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) Matchers.is(org.hamcrest.Matchers.is) Constants(org.apache.flink.kubernetes.utils.Constants) ClusterSpecification(org.apache.flink.client.deployment.ClusterSpecification) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) KubernetesConfigOptionsInternal(org.apache.flink.kubernetes.configuration.KubernetesConfigOptionsInternal) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) ArrayList(java.util.ArrayList) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) RestOptions(org.apache.flink.configuration.RestOptions) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KubernetesJobManagerParameters(org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters) Matchers.isIn(org.hamcrest.Matchers.isIn) KubernetesDeploymentTarget(org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget) ExecutorService(java.util.concurrent.ExecutorService) Assert.assertNotNull(org.junit.Assert.assertNotNull) Pod(io.fabric8.kubernetes.api.model.Pod) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) KubernetesSessionClusterEntrypoint(org.apache.flink.kubernetes.entrypoint.KubernetesSessionClusterEntrypoint) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ExecutionException(java.util.concurrent.ExecutionException) Assert.assertNull(org.junit.Assert.assertNull) CONFIG_FILE_LOGBACK_NAME(org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOGBACK_NAME) KubernetesJobManagerFactory(org.apache.flink.kubernetes.kubeclient.factory.KubernetesJobManagerFactory) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Assert.assertEquals(org.junit.Assert.assertEquals) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) KubernetesSessionClusterEntrypoint(org.apache.flink.kubernetes.entrypoint.KubernetesSessionClusterEntrypoint) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with KubernetesConfigMap

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));
            });
        }
    };
}
Also used : KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) VoidBlobStore(org.apache.flink.runtime.blob.VoidBlobStore) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 5 with KubernetesConfigMap

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();
    }
}
Also used : KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap)

Aggregations

KubernetesConfigMap (org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap)13 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 PossibleInconsistentStateException (org.apache.flink.runtime.persistence.PossibleInconsistentStateException)4 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionException (java.util.concurrent.CompletionException)3 ExecutionException (java.util.concurrent.ExecutionException)3 KubernetesConfigOptions (org.apache.flink.kubernetes.configuration.KubernetesConfigOptions)3 KubernetesException (org.apache.flink.kubernetes.kubeclient.resources.KubernetesException)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 OwnerReference (io.fabric8.kubernetes.api.model.OwnerReference)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 Service (io.fabric8.kubernetes.api.model.Service)2