Search in sources :

Example 1 with TestingKubernetesPod

use of org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod in project flink by apache.

the class KubernetesResourceManagerDriverTest method testOnPodAdded.

@Test
public void testOnPodAdded() throws Exception {
    new Context() {

        {
            final CompletableFuture<KubernetesPod> createPodFuture = new CompletableFuture<>();
            final CompletableFuture<KubernetesWorkerNode> requestResourceFuture = new CompletableFuture<>();
            flinkKubeClientBuilder.setCreateTaskManagerPodFunction((pod) -> {
                createPodFuture.complete(pod);
                return FutureUtils.completedVoidFuture();
            });
            runTest(() -> {
                // request new pod
                runInMainThread(() -> getDriver().requestResource(TASK_EXECUTOR_PROCESS_SPEC).thenAccept(requestResourceFuture::complete));
                final KubernetesPod pod = new TestingKubernetesPod(createPodFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS).getName(), true, false);
                // prepare validation:
                // - complete requestResourceFuture in main thread with correct
                // KubernetesWorkerNode
                final CompletableFuture<Void> validationFuture = requestResourceFuture.thenAccept((workerNode) -> {
                    validateInMainThread();
                    assertThat(workerNode.getResourceID().toString(), is(pod.getName()));
                });
                // send onAdded event
                getPodCallbackHandler().onAdded(Collections.singletonList(pod));
                // make sure finishing validation
                validationFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS);
            });
        }
    };
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestingKubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod) TestingKubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod) Test(org.junit.Test)

Example 2 with TestingKubernetesPod

use of org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod in project flink by apache.

the class KubernetesResourceManagerDriverTest method testRecoverPreviousAttemptWorkersPodTerminated.

@Test
public void testRecoverPreviousAttemptWorkersPodTerminated() throws Exception {
    new Context() {

        {
            final KubernetesPod previousAttemptPod = new TestingKubernetesPod(CLUSTER_ID + "-taskmanager-1-1", true, true);
            final CompletableFuture<String> stopPodFuture = new CompletableFuture<>();
            final CompletableFuture<Collection<KubernetesWorkerNode>> recoveredWorkersFuture = new CompletableFuture<>();
            flinkKubeClientBuilder.setGetPodsWithLabelsFunction((ignore) -> Collections.singletonList(previousAttemptPod)).setStopPodFunction((podName) -> {
                stopPodFuture.complete(podName);
                return FutureUtils.completedVoidFuture();
            });
            resourceEventHandlerBuilder.setOnPreviousAttemptWorkersRecoveredConsumer(recoveredWorkersFuture::complete);
            runTest(() -> {
                // validate the terminated pod from previous attempt is not recovered
                // and is removed
                assertThat(recoveredWorkersFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS), empty());
                assertThat(stopPodFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS), is(previousAttemptPod.getName()));
            });
        }
    };
}
Also used : TaskExecutorProcessSpec(org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec) Deadline(org.apache.flink.api.common.time.Deadline) TestingKubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod) CompletableFuture(java.util.concurrent.CompletableFuture) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod) ArrayList(java.util.ArrayList) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Duration(java.time.Duration) Assert.fail(org.junit.Assert.fail) KubernetesResourceManagerDriverConfiguration(org.apache.flink.kubernetes.configuration.KubernetesResourceManagerDriverConfiguration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingFlinkKubeClient(org.apache.flink.kubernetes.kubeclient.TestingFlinkKubeClient) Matchers.empty(org.hamcrest.Matchers.empty) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) ResourceManagerDriver(org.apache.flink.runtime.resourcemanager.active.ResourceManagerDriver) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) WatchCallbackHandler(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient.WatchCallbackHandler) KubernetesTooOldResourceVersionException(org.apache.flink.kubernetes.kubeclient.resources.KubernetesTooOldResourceVersionException) ResourceManagerDriverTestBase(org.apache.flink.runtime.resourcemanager.active.ResourceManagerDriverTestBase) Matchers.is(org.hamcrest.Matchers.is) CommonTestUtils(org.apache.flink.runtime.testutils.CommonTestUtils) Constants(org.apache.flink.kubernetes.utils.Constants) Collections(java.util.Collections) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) CompletableFuture(java.util.concurrent.CompletableFuture) TestingKubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod) Collection(java.util.Collection) TestingKubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod) Test(org.junit.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 KubernetesPod (org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod)2 TestingKubernetesPod (org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod)2 Test (org.junit.Test)2 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 Deadline (org.apache.flink.api.common.time.Deadline)1 TaskManagerOptions (org.apache.flink.configuration.TaskManagerOptions)1 KubernetesConfigOptions (org.apache.flink.kubernetes.configuration.KubernetesConfigOptions)1 KubernetesResourceManagerDriverConfiguration (org.apache.flink.kubernetes.configuration.KubernetesResourceManagerDriverConfiguration)1 FlinkKubeClient (org.apache.flink.kubernetes.kubeclient.FlinkKubeClient)1 WatchCallbackHandler (org.apache.flink.kubernetes.kubeclient.FlinkKubeClient.WatchCallbackHandler)1 TestingFlinkKubeClient (org.apache.flink.kubernetes.kubeclient.TestingFlinkKubeClient)1 KubernetesTooOldResourceVersionException (org.apache.flink.kubernetes.kubeclient.resources.KubernetesTooOldResourceVersionException)1